Search in sources :

Example 1 with MaintenanceSignal

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()));
}
Also used : ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixDataAccessor(org.apache.helix.HelixDataAccessor) MaintenanceSignal(org.apache.helix.model.MaintenanceSignal) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 2 with MaintenanceSignal

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");
        }
    }
}
Also used : HelixException(org.apache.helix.HelixException) HelixDataAccessor(org.apache.helix.HelixDataAccessor) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) MaintenanceSignal(org.apache.helix.model.MaintenanceSignal) ZNRecord(org.apache.helix.ZNRecord)

Example 3 with MaintenanceSignal

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());
}
Also used : MaintenanceSignal(org.apache.helix.model.MaintenanceSignal) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 4 with MaintenanceSignal

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);
    */
}
Also used : MaintenanceSignal(org.apache.helix.model.MaintenanceSignal) Test(org.testng.annotations.Test)

Example 5 with MaintenanceSignal

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);
}
Also used : ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) MaintenanceSignal(org.apache.helix.model.MaintenanceSignal) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) Test(org.testng.annotations.Test)

Aggregations

MaintenanceSignal (org.apache.helix.model.MaintenanceSignal)6 Test (org.testng.annotations.Test)4 HelixDataAccessor (org.apache.helix.HelixDataAccessor)2 Builder (org.apache.helix.PropertyKey.Builder)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConfigAccessor (org.apache.helix.ConfigAccessor)1 HelixAdmin (org.apache.helix.HelixAdmin)1 HelixException (org.apache.helix.HelixException)1 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)1 ZNRecord (org.apache.helix.ZNRecord)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)1 ClusterConfig (org.apache.helix.model.ClusterConfig)1 LiveInstance (org.apache.helix.model.LiveInstance)1 StateModelDefinition (org.apache.helix.model.StateModelDefinition)1