public static Map<String, String> getInstanceConfigsMapFor(String instanceName, String clusterName, HelixAdmin admin) { final HelixConfigScope scope = getInstanceScopefor(clusterName, instanceName); final List<String> keys = admin.getConfigKeys(scope); return admin.getConfig(scope, keys); }
public boolean isAutoBalancingEnabled() { HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(_helixClusterName) .build(); Map<String, String> config = _helixAdmin.getConfig(scope, Arrays.asList(AUTO_BALANCING)); if (config.containsKey(AUTO_BALANCING) && config.get(AUTO_BALANCING).equals(DISABLE)) { return false; } return true; }
public boolean isAutoBalancingEnabled() { HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(_helixClusterName) .build(); Map<String, String> config = _helixAdmin.getConfig(scope, Arrays.asList(AUTO_BALANCING)); if (config.containsKey(AUTO_BALANCING) && config.get(AUTO_BALANCING).equals(DISABLE)) { return false; } return true; }
public static Map<String, String> getResourceConfigsFor(String clusterName, String resourceName, HelixAdmin admin) { final HelixConfigScope scope = getResourceScopeFor(clusterName, resourceName); final List<String> keys = admin.getConfigKeys(scope); return admin.getConfig(scope, keys); }
/** * get configs * @param type config-scope-type, e.g. CLUSTER, RESOURCE, etc. * @param scopeArgsCsv csv-formatted scope-args, e.g myCluster,testDB * @param keysCsv csv-formatted keys. e.g. k1,k2 * @return json-formated key-value pairs, e.g. {k1=v1,k2=v2} */ public String getConfig(ConfigScopeProperty type, String scopeArgsCsv, String keysCsv) { // ConfigScope scope = new ConfigScopeBuilder().build(scopesStr); String[] scopeArgs = scopeArgsCsv.split("[\\s,]"); HelixConfigScope scope = new HelixConfigScopeBuilder(type, scopeArgs).build(); String[] keys = keysCsv.split("[\\s,]"); // parse keys // String[] keys = keysStr.split("[\\s,]"); // Set<String> keysSet = new HashSet<String>(Arrays.asList(keys)); Map<String, String> keyValueMap = _admin.getConfig(scope, Arrays.asList(keys)); ZNRecord record = new ZNRecord(type.toString()); // record.setMapField(scopesStr, propertiesMap); record.getSimpleFields().putAll(keyValueMap); ZNRecordSerializer serializer = new ZNRecordSerializer(); return new String(serializer.serialize(record)); }
StringRepresentation getConfigs(ConfigScopeProperty scopeProperty, String... keys) throws Exception { StringRepresentation representation = null; ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); HelixAdmin admin = setupTool.getClusterManagementTool(); ZNRecord record = new ZNRecord(scopeProperty + " Config"); HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build(); List<String> configKeys = admin.getConfigKeys(scope); Map<String, String> configs = admin.getConfig(scope, configKeys); record.setSimpleFields(configs); representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record), MediaType.APPLICATION_JSON); return representation; }
/** * get configs * @param type config-scope-type, e.g. CLUSTER, RESOURCE, etc. * @param scopeArgsCsv csv-formatted scope-args, e.g myCluster,testDB * @param keysCsv csv-formatted keys. e.g. k1,k2 * @return json-formated key-value pairs, e.g. {k1=v1,k2=v2} */ public String getConfig(ConfigScopeProperty type, String scopeArgsCsv, String keysCsv) { // ConfigScope scope = new ConfigScopeBuilder().build(scopesStr); String[] scopeArgs = scopeArgsCsv.split("[\\s,]"); HelixConfigScope scope = new HelixConfigScopeBuilder(type, scopeArgs).build(); String[] keys = keysCsv.split("[\\s,]"); // parse keys // String[] keys = keysStr.split("[\\s,]"); // Set<String> keysSet = new HashSet<String>(Arrays.asList(keys)); Map<String, String> keyValueMap = _admin.getConfig(scope, Arrays.asList(keys)); ZNRecord record = new ZNRecord(type.toString()); // record.setMapField(scopesStr, propertiesMap); record.getSimpleFields().putAll(keyValueMap); ZNRecordSerializer serializer = new ZNRecordSerializer(); return new String(serializer.serialize(record)); }
adminTool.setConfig(scope, properties); properties = adminTool.getConfig(scope, Arrays.asList("pKey1", "pKey2")); Assert.assertEquals(properties.size(), 2); Assert.assertEquals(properties.get("pKey1"), "pValue1");
tool.setConfig(scope, properties); Map<String, String> newProperties = tool.getConfig(scope, new ArrayList<String>(properties.keySet())); Assert.assertEquals(newProperties.size(), 2); Assert.assertEquals(newProperties.get("pKey1"), "pValue1");