Search in sources :

Example 1 with HelixPropertyStoreConfig

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();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) Test(org.junit.Test)

Example 2 with HelixPropertyStoreConfig

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with HelixPropertyStoreConfig

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());
    }
}
Also used : Account(com.github.ambry.account.Account) VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 4 with HelixPropertyStoreConfig

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 5 with HelixPropertyStoreConfig

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();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord)

Aggregations

HelixPropertyStoreConfig (com.github.ambry.config.HelixPropertyStoreConfig)12 VerifiableProperties (com.github.ambry.config.VerifiableProperties)12 MetricRegistry (com.codahale.metrics.MetricRegistry)7 Test (org.junit.Test)7 Properties (java.util.Properties)6 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Account (com.github.ambry.account.Account)1 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HelixException (org.apache.helix.HelixException)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 IdealState (org.apache.helix.model.IdealState)1 InstanceConfig (org.apache.helix.model.InstanceConfig)1 JSONException (org.json.JSONException)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1