use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.
the class CommonUtilsTest method createHelixPropertyStoreTest.
/**
* Tests for {@link CommonUtils#createHelixPropertyStore(String, HelixPropertyStoreConfig, List)}.
*/
@Test
public void createHelixPropertyStoreTest() throws IOException {
Properties storeProps = new Properties();
storeProps.setProperty("helix.property.store.root.path", "/Ambry-Test/" + ClusterMapUtils.PROPERTYSTORE_STR);
HelixPropertyStoreConfig propertyStoreConfig = new HelixPropertyStoreConfig(new VerifiableProperties(storeProps));
String tempDirPath = getTempDir("clusterMapUtils-");
ZkInfo zkInfo = new ZkInfo(tempDirPath, "DC1", (byte) 0, 2200, true);
try {
CommonUtils.createHelixPropertyStore(null, propertyStoreConfig, Collections.emptyList());
fail("create HelixPropertyStore with invalid arguments should fail");
} catch (IllegalArgumentException e) {
// expected
}
try {
CommonUtils.createHelixPropertyStore("", propertyStoreConfig, Collections.emptyList());
fail("create HelixPropertyStore with invalid arguments should fail");
} catch (IllegalArgumentException e) {
// expected
}
try {
CommonUtils.createHelixPropertyStore("localhost:" + zkInfo.getPort(), (HelixPropertyStoreConfig) null, Collections.emptyList());
fail("create HelixPropertyStore with invalid arguments should fail");
} catch (IllegalArgumentException e) {
// expected
}
HelixPropertyStore<ZNRecord> propertyStore = CommonUtils.createHelixPropertyStore("localhost:" + zkInfo.getPort(), propertyStoreConfig, Collections.singletonList(propertyStoreConfig.rootPath));
assertNotNull(propertyStore);
// Ensure the HelixPropertyStore works correctly
List<String> list = Arrays.asList("first", "second", "third");
String path = propertyStoreConfig.rootPath + ClusterMapUtils.PARTITION_OVERRIDE_ZNODE_PATH;
ZNRecord znRecord = new ZNRecord(ClusterMapUtils.PARTITION_OVERRIDE_STR);
znRecord.setListField("AmbryList", list);
if (!propertyStore.set(path, znRecord, AccessOption.PERSISTENT)) {
fail("Failed to set HelixPropertyStore");
}
// Verify path exists
assertTrue("The record path doesn't exist", propertyStore.exists(path, AccessOption.PERSISTENT));
// Verify record
ZNRecord result = propertyStore.get(path, null, AccessOption.PERSISTENT);
assertEquals("Mismatch in list content", new HashSet<>(list), new HashSet<>(result.getListField("AmbryList")));
zkInfo.shutdown();
}
use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.
the class HelixAccountServiceTest method testBackgroundUpdater.
/**
* Tests the background updater for updating accounts from remote. During the initialization of
* {@link HelixAccountService}, its internal {@link HelixPropertyStore} will be read to first time get account data.
* Because of the background account updater, it should continuously make get calls to the {@link HelixPropertyStore},
* even no notification for account updates is received. Therefore, there will be more than 1 get calls to the
* {@link HelixPropertyStore}.
* @throws Exception
*/
@Test
public void testBackgroundUpdater() throws Exception {
helixConfigProps.setProperty(HelixAccountServiceConfig.UPDATER_POLLING_INTERVAL_MS_KEY, "1");
vHelixConfigProps = new VerifiableProperties(helixConfigProps);
storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps);
String updaterThreadPrefix = UUID.randomUUID().toString();
MockHelixAccountServiceFactory mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, updaterThreadPrefix, mockRouter);
accountService = mockHelixAccountServiceFactory.getAccountService();
CountDownLatch latch = new CountDownLatch(1);
mockHelixAccountServiceFactory.getHelixStore(ZK_CONNECT_STRING, storeConfig).setReadLatch(latch);
assertEquals("Wrong number of thread for account updater.", 1, numThreadsByThisName(updaterThreadPrefix));
awaitLatchOrTimeout(latch, 100);
}
use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.
the class HelixAccountServiceTest method testUpdateDisabled.
/**
* Tests disabling account updates. By setting the {@link HelixAccountServiceConfig#UPDATE_DISABLED} to be true, all the
* account update request should be rejected.
*/
@Test
public void testUpdateDisabled() throws Exception {
helixConfigProps.setProperty(HelixAccountServiceConfig.UPDATE_DISABLED, "true");
vHelixConfigProps = new VerifiableProperties(helixConfigProps);
storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps);
String updaterThreadPrefix = UUID.randomUUID().toString();
MockHelixAccountServiceFactory mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, updaterThreadPrefix, mockRouter);
accountService = mockHelixAccountServiceFactory.getAccountService();
// add a new account
Account newAccountWithoutContainer = new AccountBuilder(refAccountId, refAccountName, refAccountStatus).build();
List<Account> accountsToUpdate = Collections.singletonList(newAccountWithoutContainer);
try {
accountService.updateAccounts(accountsToUpdate);
fail("Update accounts should be disabled");
} catch (AccountServiceException e) {
assertEquals("Mismatch in error code", AccountServiceErrorCode.UpdateDisabled, e.getErrorCode());
}
}
use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.
the class HelixBootstrapUpgradeUtil method createHelixPropertyStore.
/**
* Create a {@link HelixPropertyStore} for given datacenter.
* @param dcName the name of datacenter
* @return {@link HelixPropertyStore} associated with given dc.
*/
private HelixPropertyStore<ZNRecord> createHelixPropertyStore(String dcName) {
Properties storeProps = new Properties();
storeProps.setProperty("helix.property.store.root.path", "/" + clusterName + "/" + PROPERTYSTORE_STR);
HelixPropertyStoreConfig propertyStoreConfig = new HelixPropertyStoreConfig(new VerifiableProperties(storeProps));
// The number of zk endpoints has been validated in the ctor of HelixBootstrapUpgradeUtil, no need to check it again
String zkConnectStr = dataCenterToZkAddress.get(dcName).getZkConnectStrs().get(0);
return CommonUtils.createHelixPropertyStore(zkConnectStr, propertyStoreConfig, null);
}
use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.
the class HelixParticipant method awaitDisablingPartition.
/**
* Wait until disabling partition process has completed. This is to avoid race condition where server and Helix may
* modify same InstanceConfig.
* TODO remove this method after migrating ambry to PropertyStore (in Helix).
* @throws InterruptedException
*/
private void awaitDisablingPartition() throws InterruptedException {
Properties properties = new Properties();
properties.setProperty("helix.property.store.root.path", "/" + clusterName + "/" + PROPERTYSTORE_STR);
HelixPropertyStoreConfig propertyStoreConfig = new HelixPropertyStoreConfig(new VerifiableProperties(properties));
HelixPropertyStore<ZNRecord> helixPropertyStore = CommonUtils.createHelixPropertyStore(zkConnectStr, propertyStoreConfig, null);
String path = PARTITION_DISABLED_ZNODE_PATH + instanceName;
int count = 1;
while (helixPropertyStore.exists(path, AccessOption.PERSISTENT)) {
// Thread.sleep() pauses the current thread but does not release any locks
Thread.sleep(clusterMapConfig.clustermapRetryDisablePartitionCompletionBackoffMs);
logger.info("{} th attempt on checking the completion of disabling partition.", ++count);
}
helixPropertyStore.stop();
}
Aggregations