@Override public List<String> getClusters() { List<String> zkToplevelPathes = _zkClient.getChildren("/"); List<String> result = new ArrayList<String>(); for (String pathName : zkToplevelPathes) { if (ZKUtil.isClusterSetup(pathName, _zkClient)) { result.add(pathName); } } return result; }
private boolean isClusterExist(String cluster) { HelixZkClient zkClient = getHelixZkClient(); if (ZKUtil.isClusterSetup(cluster, zkClient)) { return true; } return false; } }
@Override public List<String> getClusters() { List<String> zkToplevelPathes = _zkClient.getChildren("/"); List<String> result = new ArrayList<String>(); for (String pathName : zkToplevelPathes) { if (ZKUtil.isClusterSetup(pathName, _zkClient)) { result.add(pathName); } } return result; }
@Test() public void testIsClusterSetup() { boolean result = ZKUtil.isClusterSetup(clusterName, _gZkClient); AssertJUnit.assertTrue(result); }
@BeforeClass() public void beforeClass() throws Exception { boolean result = ZKUtil.isClusterSetup(clusterName, _gZkClient); AssertJUnit.assertFalse(result); result = ZKUtil.isClusterSetup(null, _gZkClient); AssertJUnit.assertFalse(result); result = ZKUtil.isClusterSetup(null, null); AssertJUnit.assertFalse(result); result = ZKUtil.isClusterSetup(clusterName, null); AssertJUnit.assertFalse(result); TestHelper.setupEmptyCluster(_gZkClient, clusterName); }
@Override public void enableBatchMessageMode(String clusterName, boolean enabled) { logger .info("{} batch message mode for cluster {}.", enabled ? "Enable" : "Disable", clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } ConfigAccessor accessor = new ConfigAccessor(_zkClient); ClusterConfig clusterConfig = accessor.getClusterConfig(clusterName); clusterConfig.setBatchMessageMode(enabled); accessor.setClusterConfig(clusterName, clusterConfig); }
@Override public void enableBatchMessageMode(String clusterName, boolean enabled) { logger .info("{} batch message mode for cluster {}.", enabled ? "Enable" : "Disable", clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } ConfigAccessor accessor = new ConfigAccessor(_zkClient); ClusterConfig clusterConfig = accessor.getClusterConfig(clusterName); clusterConfig.setBatchMessageMode(enabled); accessor.setClusterConfig(clusterName, clusterConfig); }
private ZNRecord getConfigZnRecord(HelixConfigScope scope) { String clusterName = scope.getClusterName(); if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to get configs. cluster " + clusterName + " is not setup yet"); } return zkClient.readData(scope.getZkPath(), true); }
private ZNRecord getConfigZnRecord(HelixConfigScope scope) { String clusterName = scope.getClusterName(); if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to get configs. cluster " + clusterName + " is not setup yet"); } return zkClient.readData(scope.getZkPath(), true); }
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); } }
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); } }
@Override public void addInstanceTag(String clusterName, String instanceName, String tag) { logger .info("Add instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) { throw new HelixException("cluster " + clusterName + " instance " + instanceName + " is not setup yet"); } HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); config.addTag(tag); accessor.setProperty(keyBuilder.instanceConfig(instanceName), config); }
@Override public void addInstanceTag(String clusterName, String instanceName, String tag) { logger .info("Add instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) { throw new HelixException( "cluster " + clusterName + " instance " + instanceName + " is not setup yet"); } HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); config.addTag(tag); accessor.setProperty(keyBuilder.instanceConfig(instanceName), config); }
@Override public void removeInstanceTag(String clusterName, String instanceName, String tag) { logger.info("Remove instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) { throw new HelixException( "cluster " + clusterName + " instance " + instanceName + " is not setup yet"); } ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); config.removeTag(tag); accessor.setProperty(keyBuilder.instanceConfig(instanceName), config); }
@Override public void setInstanceZoneId(String clusterName, String instanceName, String zoneId) { logger.info("Set instance zoneId {} for instance {} in cluster {}.", zoneId, instanceName, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) { throw new HelixException( "cluster " + clusterName + " instance " + instanceName + " is not setup yet"); } HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); config.setZoneId(zoneId); accessor.setProperty(keyBuilder.instanceConfig(instanceName), config); }
@Override public void removeInstanceTag(String clusterName, String instanceName, String tag) { logger.info("Remove instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) { throw new HelixException( "cluster " + clusterName + " instance " + instanceName + " is not setup yet"); } ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); config.removeTag(tag); accessor.setProperty(keyBuilder.instanceConfig(instanceName), config); }
private void updateResourceConfig(String clusterName, String resourceName, ResourceConfig resourceConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName) .forResource(resourceName).build(); String zkPath = scope.getZkPath(); if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true); } }
private void updateResourceConfig(String clusterName, String resourceName, ResourceConfig resourceConfig, boolean overwrite) { if (!ZKUtil.isClusterSetup(clusterName, zkClient)) { throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup."); } HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName) .forResource(resourceName).build(); String zkPath = scope.getZkPath(); if (overwrite) { ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true); } else { ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true); } }
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); } } }
@Override public void addInstance(String clusterName, InstanceConfig instanceConfig) { logger.info("Add instance {} to cluster {}.", instanceConfig.getInstanceName(), clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName); String nodeId = instanceConfig.getId(); String instanceConfigPath = instanceConfigsPath + "/" + nodeId; if (_zkClient.exists(instanceConfigPath)) { throw new HelixException("Node " + nodeId + " already exists in cluster " + clusterName); } ZKUtil.createChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord()); _zkClient.createPersistent(PropertyPathBuilder.instanceMessage(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceCurrentState(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceError(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceStatusUpdate(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceHistory(clusterName, nodeId), true); }