public void addInstanceToCluster(String clusterName, String instanceId) { InstanceConfig config = InstanceConfig.toInstanceConfig(instanceId); _admin.addInstance(clusterName, config); }
public void addInstanceToCluster(String clusterName, String instanceId) { InstanceConfig config = InstanceConfig.toInstanceConfig(instanceId); _admin.addInstance(clusterName, config); }
public void dropInstanceFromCluster(String clusterName, String instanceId) { ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); InstanceConfig instanceConfig = InstanceConfig.toInstanceConfig(instanceId); instanceId = instanceConfig.getInstanceName(); // ensure node is not live LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instanceId)); if (liveInstance != null) { throw new HelixException(String .format("Cannot drop instance %s as it is still live. Please stop it first", instanceId)); } InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceId)); if (config == null) { String error = "Node " + instanceId + " does not exist, cannot drop"; _logger.warn(error); throw new HelixException(error); } ClusterConfig clusterConfig = accessor.getProperty(keyBuilder.clusterConfig()); // ensure node is disabled, otherwise fail if (config.getInstanceEnabled() && (clusterConfig.getDisabledInstances() == null || !clusterConfig.getDisabledInstances().containsKey(instanceId))) { String error = "Node " + instanceId + " is enabled, cannot drop"; _logger.warn(error); throw new HelixException(error); } _admin.dropInstance(clusterName, config); }
public void dropInstanceFromCluster(String clusterName, String instanceId) { ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); InstanceConfig instanceConfig = InstanceConfig.toInstanceConfig(instanceId); instanceId = instanceConfig.getInstanceName(); // ensure node is not live LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instanceId)); if (liveInstance != null) { throw new HelixException(String .format("Cannot drop instance %s as it is still live. Please stop it first", instanceId)); } InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceId)); if (config == null) { String error = "Node " + instanceId + " does not exist, cannot drop"; _logger.warn(error); throw new HelixException(error); } ClusterConfig clusterConfig = accessor.getProperty(keyBuilder.clusterConfig()); // ensure node is disabled, otherwise fail if (config.getInstanceEnabled() && (clusterConfig.getDisabledInstances() == null || !clusterConfig.getDisabledInstances().containsKey(instanceId))) { String error = "Node " + instanceId + " is enabled, cannot drop"; _logger.warn(error); throw new HelixException(error); } _admin.dropInstance(clusterName, config); }
@Test (dependsOnMethods = {"testClusterExpansion"}) public void testClusterExpansionByEnableInstance() throws Exception { Assert.assertTrue(_clusterVerifier.verifyByPolling()); _migrationVerifier.reset(); _migrationVerifier.start(); int numNodes = _participants.size(); // add new instances with all disabled for (int i = numNodes; i < numNodes + NUM_NODE; i++) { String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); InstanceConfig config = InstanceConfig.toInstanceConfig(storageNodeName); config.setInstanceEnabled(false); config.getRecord().getSimpleFields() .remove(InstanceConfig.InstanceConfigProperty.HELIX_ENABLED_TIMESTAMP.name()); _gSetupTool.getClusterManagementTool().addInstance(CLUSTER_NAME, config); // start dummy participants MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName); participant.syncStart(); _participants.add(participant); } // enable new instance one by one for (int i = numNodes; i < numNodes + NUM_NODE; i++) { String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); _gSetupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, storageNodeName, true); Thread.sleep(100); } Assert.assertTrue(_clusterVerifier.verifyByPolling()); Assert.assertFalse(_migrationVerifier.hasLessReplica()); _migrationVerifier.stop(); }