use of org.apache.helix.model.MaintenanceSignal in project helix by apache.
the class TestClusterAccessor method testEnableDisableMaintenanceMode.
@Test(dependsOnMethods = "testGetClusterConfig")
public void testEnableDisableMaintenanceMode() {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();
String reason = "Test reason";
HelixDataAccessor accessor = new ZKHelixDataAccessor(cluster, _baseAccessor);
post("clusters/" + cluster, ImmutableMap.of("command", "enableMaintenanceMode"), Entity.entity(reason, MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode());
MaintenanceSignal signal = accessor.getProperty(accessor.keyBuilder().maintenance());
Assert.assertNotNull(signal);
Assert.assertEquals(reason, signal.getReason());
post("clusters/" + cluster, ImmutableMap.of("command", "disableMaintenanceMode"), Entity.entity(new String(), MediaType.APPLICATION_JSON_TYPE), Response.Status.OK.getStatusCode());
Assert.assertNull(accessor.getProperty(accessor.keyBuilder().maintenance()));
}
use of org.apache.helix.model.MaintenanceSignal in project helix by apache.
the class ZKHelixAdmin method enableMaintenanceMode.
@Override
public void enableMaintenanceMode(String clusterName, boolean enabled, String reason) {
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
if (!enabled) {
accessor.removeProperty(keyBuilder.maintenance());
} else {
MaintenanceSignal maintenanceSignal = new MaintenanceSignal("maintenance");
if (reason != null) {
maintenanceSignal.setReason(reason);
}
if (!accessor.createMaintenance(maintenanceSignal)) {
throw new HelixException("Failed to create maintenance signal");
}
}
}
use of org.apache.helix.model.MaintenanceSignal 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.MaintenanceSignal in project helix by apache.
the class TestClusterInMaintenanceModeWhenReachingOfflineInstancesLimit method testWithOfflineInstancesLimit.
@Test(dependsOnMethods = "testWithDisabledInstancesLimit")
public void testWithOfflineInstancesLimit() throws Exception {
MaintenanceSignal maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNull(maintenanceSignal);
int i;
for (i = 2; i < 2 + _maxOfflineInstancesAllowed; i++) {
_participants.get(i).syncStop();
}
Thread.sleep(500);
maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNull(maintenanceSignal);
_participants.get(i).syncStop();
Thread.sleep(500);
maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNotNull(maintenanceSignal);
Assert.assertNotNull(maintenanceSignal.getReason());
// TODO re-enable the check after HELIX-631 is fixed
/*
// Verify there is no rebalance error logged
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
PropertyKey errorNodeKey =
accessor.keyBuilder().controllerTaskError(RebalanceResourceFailure.name());
Assert.assertNotNull(accessor.getProperty(errorNodeKey));
Long value =
(Long) _server.getAttribute(getMbeanName(CLUSTER_NAME), "RebalanceFailureGauge");
Assert.assertNotNull(value);
Assert.assertTrue(value.longValue() > 0);
*/
}
use of org.apache.helix.model.MaintenanceSignal in project helix by apache.
the class TestClusterInMaintenanceModeWhenReachingOfflineInstancesLimit method testWithDisabledInstancesLimit.
@Test
public void testWithDisabledInstancesLimit() throws Exception {
MaintenanceSignal maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNull(maintenanceSignal);
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
// disable instance
int i;
for (i = 2; i < 2 + _maxOfflineInstancesAllowed; i++) {
String instance = _participants.get(i).getInstanceName();
admin.enableInstance(CLUSTER_NAME, instance, false);
}
Thread.sleep(500);
maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNull(maintenanceSignal);
String instance = _participants.get(i).getInstanceName();
admin.enableInstance(CLUSTER_NAME, instance, false);
Thread.sleep(500);
maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
Assert.assertNotNull(maintenanceSignal);
Assert.assertNotNull(maintenanceSignal.getReason());
for (i = 2; i < 2 + _maxOfflineInstancesAllowed + 1; i++) {
instance = _participants.get(i).getInstanceName();
admin.enableInstance(CLUSTER_NAME, instance, true);
}
admin.enableMaintenanceMode(CLUSTER_NAME, false);
}
Aggregations