Search in sources :

Example 1 with HelixStoreOperator

use of com.github.ambry.clustermap.HelixStoreOperator in project ambry by linkedin.

the class HelixAccountServiceTest method writeAccountsToHelixPropertyStore.

/**
 * Pre-populates a collection of {@link Account}s to the underlying {@link org.apache.helix.store.HelixPropertyStore}
 * using {@link com.github.ambry.clustermap.HelixStoreOperator} (not through the {@link HelixAccountService}). This method
 * does not check any conflict among the {@link Account}s to write.
 * @throws Exception Any unexpected exception.
 */
private void writeAccountsToHelixPropertyStore(Collection<Account> accounts, boolean shouldNotify) throws Exception {
    HelixStoreOperator storeOperator = new HelixStoreOperator(mockHelixAccountServiceFactory.getHelixStore(ZK_CONNECT_STRING, storeConfig));
    ZNRecord zNRecord = new ZNRecord(String.valueOf(System.currentTimeMillis()));
    Map<String, String> accountMap = new HashMap<>();
    for (Account account : accounts) {
        accountMap.put(String.valueOf(account.getId()), objectMapper.writeValueAsString(new AccountBuilder(account).snapshotVersion(refAccount.getSnapshotVersion() + 1).build()));
    }
    if (useNewZNodePath) {
        String blobID = RouterStore.writeAccountMapToRouter(accountMap, mockRouter);
        List<String> list = Collections.singletonList(new RouterStore.BlobIDAndVersion(blobID, 1).toJson());
        zNRecord.setListField(RouterStore.ACCOUNT_METADATA_BLOB_IDS_LIST_KEY, list);
        storeOperator.write(RouterStore.ACCOUNT_METADATA_BLOB_IDS_PATH, zNRecord);
    } else {
        zNRecord.setMapField(LegacyMetadataStore.ACCOUNT_METADATA_MAP_KEY, accountMap);
        // Write account metadata into HelixPropertyStore.
        storeOperator.write(LegacyMetadataStore.FULL_ACCOUNT_METADATA_PATH, zNRecord);
    }
    if (shouldNotify) {
        notifier.publish(ACCOUNT_METADATA_CHANGE_TOPIC, FULL_ACCOUNT_METADATA_CHANGE_MESSAGE);
    }
}
Also used : HelixStoreOperator(com.github.ambry.clustermap.HelixStoreOperator) Account(com.github.ambry.account.Account) HashMap(java.util.HashMap) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord)

Example 2 with HelixStoreOperator

use of com.github.ambry.clustermap.HelixStoreOperator in project ambry by linkedin.

the class RouterStoreTest method cleanUp.

/**
 * cleanup after each test case.
 * @throws Exception Any unexpected exception.
 */
@After
public void cleanUp() throws Exception {
    HelixStoreOperator operator = new HelixStoreOperator(helixStore);
    if (operator.exist("/")) {
        operator.delete("/");
    }
    if (Files.exists(accountBackupDir)) {
        Utils.deleteFileOrDirectory(accountBackupDir.toFile());
    }
    router.close();
}
Also used : HelixStoreOperator(com.github.ambry.clustermap.HelixStoreOperator) After(org.junit.After)

Aggregations

HelixStoreOperator (com.github.ambry.clustermap.HelixStoreOperator)2 Account (com.github.ambry.account.Account)1 HashMap (java.util.HashMap)1 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)1 After (org.junit.After)1