private void updateAccounts(Collection<Account> accounts) throws AccountServiceException {
    Collection<Account> existingAccounts = accountService.getAllAccounts();
    Map<Short, Account> existingAccountsMap = new HashMap<>();
    for (Account account : existingAccounts) {
      existingAccountsMap.put(account.getId(), account);
    }
    Collection<Account> newAccounts = new ArrayList<>(accounts.size());
    // resolve the snapshot conflict.
    for (Account account : accounts) {
      Account accountInMap = existingAccountsMap.get(account.getId());
      if (accountInMap != null && accountInMap.getSnapshotVersion() != account.getSnapshotVersion()) {
        newAccounts.add(new AccountBuilder(account).snapshotVersion(accountInMap.getSnapshotVersion()).build());
      } else {
        newAccounts.add(account);
      }
    }
    accountService.updateAccountsWithAccountMetadataStore(newAccounts, routerStore);
  }
Overwrite the current {@link Account} metadata with the given {@link Collection} and publish the new {@link Account}
metadata if the update succeeds.
@param accounts The new {@link Account} metadata.
@throws AccountServiceException if the update fails.
ambry-tools/src/main/java/com/github/ambry/account/AccountTool.java