use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestClusterInMaintenanceModeWhenReachingMaxPartition method testDisableCluster.
@Test
public void testDisableCluster() throws Exception {
ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
ClusterConfig clusterConfig = configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.setMaxPartitionsPerInstance(10);
configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
int i = 0;
for (String stateModel : TestStateModels) {
String db = "Test-DB-" + i++;
createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, _replica, -1);
_testDBs.add(db);
}
Thread.sleep(100);
Assert.assertTrue(_clusterVerifier.verify());
MaintenanceSignal maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNull(maintenanceSignal);
for (i = 2; i < NUM_NODE; i++) {
_participants.get(i).syncStop();
}
Thread.sleep(500);
maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNotNull(maintenanceSignal);
Assert.assertNotNull(maintenanceSignal.getReason());
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestP2PMessageSemiAuto method enableP2PInCluster.
private void enableP2PInCluster(boolean enable) {
// enable p2p message in cluster.
if (enable) {
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.enableP2PMessage(true);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
} else {
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.getRecord().getSimpleFields().remove(HelixConfigProperty.P2P_MESSAGE_ENABLED.name());
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
}
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestJobFailureTaskNotStarted method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_participants = new MockParticipantManager[_numNodes];
_numDbs = 1;
_numNodes = 2;
_numParitions = 2;
_numReplicas = 1;
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
_setupTool.addCluster(CLUSTER_NAME, true);
setupParticipants();
setupDBs();
startParticipantsWithStuckTaskStateModelFactory();
createManagers();
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, CONTROLLER_PREFIX);
_controller.syncStart();
// Enable cancellation
ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient);
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.stateTransitionCancelEnabled(true);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class ClusterSetup method swapInstance.
public void swapInstance(String clusterName, String oldInstanceName, String newInstanceName) {
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
InstanceConfig oldConfig = accessor.getProperty(keyBuilder.instanceConfig(oldInstanceName));
if (oldConfig == null) {
String error = "Old instance " + oldInstanceName + " does not exist, cannot swap";
_logger.warn(error);
throw new HelixException(error);
}
InstanceConfig newConfig = accessor.getProperty(keyBuilder.instanceConfig(newInstanceName));
if (newConfig == null) {
String error = "New instance " + newInstanceName + " does not exist, cannot swap";
_logger.warn(error);
throw new HelixException(error);
}
ClusterConfig clusterConfig = accessor.getProperty(keyBuilder.clusterConfig());
// ensure old instance is disabled, otherwise fail
if (oldConfig.getInstanceEnabled() && (clusterConfig.getDisabledInstances() == null || !clusterConfig.getDisabledInstances().containsKey(oldInstanceName))) {
String error = "Old instance " + oldInstanceName + " is enabled, it need to be disabled and turned off";
_logger.warn(error);
throw new HelixException(error);
}
// ensure old instance is down, otherwise fail
List<String> liveInstanceNames = accessor.getChildNames(accessor.keyBuilder().liveInstances());
if (liveInstanceNames.contains(oldInstanceName)) {
String error = "Old instance " + oldInstanceName + " is still on, it need to be disabled and turned off";
_logger.warn(error);
throw new HelixException(error);
}
dropInstanceFromCluster(clusterName, oldInstanceName);
List<IdealState> existingIdealStates = accessor.getChildValues(accessor.keyBuilder().idealStates());
for (IdealState idealState : existingIdealStates) {
swapInstanceInIdealState(idealState, oldInstanceName, newInstanceName);
accessor.setProperty(accessor.keyBuilder().idealStates(idealState.getResourceName()), idealState);
}
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class ClusterSetup method dropInstanceFromCluster.
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 stopped
LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instanceId));
if (liveInstance != null) {
throw new HelixException("Can't drop " + instanceId + ", please stop " + instanceId + " before drop it");
}
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);
}
Aggregations