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);
}
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);
}
}
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);
}
}
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()));
}
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);
}
Aggregations