Search in sources :

Example 6 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project helix by apache.

the class ConfigAccessor method getResourceConfig.

/**
 * Get resource config for given resource in given cluster.
 *
 * @param clusterName
 * @param resourceName
 *
 * @return
 */
public ResourceConfig getResourceConfig(String clusterName, String resourceName) {
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName).forResource(resourceName).build();
    ZNRecord record = getConfigZnRecord(scope);
    if (record == null) {
        LOG.warn("No config found at " + scope.getZkPath());
        return null;
    }
    return new ResourceConfig(record);
}
Also used : HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope) ResourceConfig(org.apache.helix.model.ResourceConfig)

Example 7 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project helix by apache.

the class ConfigAccessor method updateClusterConfig.

private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig, boolean overwrite) {
    if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
        throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup.");
    }
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
    String zkPath = scope.getZkPath();
    if (overwrite) {
        ZKUtil.createOrReplace(zkClient, zkPath, clusterConfig.getRecord(), true);
    } else {
        ZKUtil.createOrUpdate(zkClient, zkPath, clusterConfig.getRecord(), true, true);
    }
}
Also used : HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope)

Example 8 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project helix by apache.

the class ConfigAccessor method updateInstanceConfig.

private void updateInstanceConfig(String clusterName, String instanceName, InstanceConfig instanceConfig, boolean overwrite) {
    if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
        throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
    }
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName).forParticipant(instanceName).build();
    String zkPath = scope.getZkPath();
    if (overwrite) {
        ZKUtil.createOrReplace(zkClient, zkPath, instanceConfig.getRecord(), true);
    } else {
        ZKUtil.createOrUpdate(zkClient, zkPath, instanceConfig.getRecord(), true, true);
    }
}
Also used : HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope)

Example 9 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project helix by apache.

the class TestZkClusterManager method testAdministrator.

@Test()
public void testAdministrator() throws Exception {
    System.out.println("START " + className + ".testAdministrator() at " + new Date(System.currentTimeMillis()));
    final String clusterName = CLUSTER_PREFIX + "_" + className + "_admin";
    // basic test
    if (_gZkClient.exists("/" + clusterName)) {
        _gZkClient.deleteRecursively("/" + clusterName);
    }
    ZKHelixManager admin = new ZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR, ZK_ADDR);
    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
    admin.connect();
    AssertJUnit.assertTrue(admin.isConnected());
    HelixAdmin adminTool = admin.getClusterManagmentTool();
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTITION).forCluster(clusterName).forResource("testResource").forPartition("testPartition").build();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("pKey1", "pValue1");
    properties.put("pKey2", "pValue2");
    adminTool.setConfig(scope, properties);
    properties = adminTool.getConfig(scope, Arrays.asList("pKey1", "pKey2"));
    Assert.assertEquals(properties.size(), 2);
    Assert.assertEquals(properties.get("pKey1"), "pValue1");
    Assert.assertEquals(properties.get("pKey2"), "pValue2");
    admin.disconnect();
    AssertJUnit.assertFalse(admin.isConnected());
    System.out.println("END " + className + ".testAdministrator() at " + new Date(System.currentTimeMillis()));
}
Also used : HashMap(java.util.HashMap) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope) HelixAdmin(org.apache.helix.HelixAdmin) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 10 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project helix by apache.

the class TestResourceThreadpoolSize method setResourceThreadPoolSize.

private void setResourceThreadPoolSize(String resourceName, int threadPoolSize) {
    HelixManager manager = _participants[0];
    ConfigAccessor accessor = manager.getConfigAccessor();
    HelixConfigScope scope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.RESOURCE).forCluster(manager.getClusterName()).forResource(resourceName).build();
    accessor.set(scope, HelixTaskExecutor.MAX_THREADS, "" + threadPoolSize);
}
Also used : HelixManager(org.apache.helix.HelixManager) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) ConfigAccessor(org.apache.helix.ConfigAccessor) HelixConfigScope(org.apache.helix.model.HelixConfigScope)

Aggregations

HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)35 HelixConfigScope (org.apache.helix.model.HelixConfigScope)33 HashMap (java.util.HashMap)12 HelixAdmin (org.apache.helix.HelixAdmin)10 Test (org.testng.annotations.Test)9 Date (java.util.Date)8 ConfigAccessor (org.apache.helix.ConfigAccessor)8 ZNRecord (org.apache.helix.ZNRecord)6 HelixException (org.apache.helix.HelixException)5 HelixManager (org.apache.helix.HelixManager)5 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)5 InstanceConfig (org.apache.helix.model.InstanceConfig)4 StateModelDefinition (org.apache.helix.model.StateModelDefinition)4 ClusterSetup (org.apache.helix.tools.ClusterSetup)4 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)3 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)3 ZkClient (org.apache.helix.manager.zk.ZkClient)3 ClusterConfig (org.apache.helix.model.ClusterConfig)3 IdealState (org.apache.helix.model.IdealState)3 File (java.io.File)2