Search in sources :

Example 1 with ClusterStatus

use of org.apache.helix.model.ClusterStatus in project helix by apache.

the class TestClusterFreezeMode method testEnableFreezeMode.

/*
   * Tests below scenarios:
   * 1. cluster is in progress to freeze mode if there is a pending state transition message;
   * 2. after state transition is completed, cluster freeze mode is completed
   *
   * Also tests cluster status and management mode history recording.
   */
@Test
public void testEnableFreezeMode() throws Exception {
    String methodName = TestHelper.getTestMethodName();
    // Not in freeze mode
    PropertyKey.Builder keyBuilder = _accessor.keyBuilder();
    PauseSignal pauseSignal = _accessor.getProperty(keyBuilder.pause());
    Assert.assertNull(pauseSignal);
    // Block state transition for participants[1]
    CountDownLatch latch = new CountDownLatch(1);
    _participants[1].setTransition(new BlockingTransition(latch));
    // Send a state transition message to participants[1]
    Resource resource = new Resource("TestDB0");
    resource.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
    Message message = MessageUtil.createStateTransitionMessage(_manager.getInstanceName(), _manager.getSessionId(), resource, "TestDB0_1", _participants[1].getInstanceName(), "SLAVE", "OFFLINE", _participants[1].getSessionId(), "MasterSlave");
    Assert.assertTrue(_accessor.updateProperty(keyBuilder.message(message.getTgtName(), message.getMsgId()), message));
    // Freeze cluster
    ClusterManagementModeRequest request = ClusterManagementModeRequest.newBuilder().withClusterName(_clusterName).withMode(ClusterManagementMode.Type.CLUSTER_FREEZE).withReason(methodName).build();
    _gSetupTool.getClusterManagementTool().setClusterManagementMode(request);
    // Wait for all live instances are marked as frozen
    verifyLiveInstanceStatus(_participants, LiveInstance.LiveInstanceStatus.FROZEN);
    // Pending ST message exists
    Assert.assertTrue(_gZkClient.exists(keyBuilder.message(message.getTgtName(), message.getMsgId()).getPath()));
    // Even live instance status is marked as frozen, Cluster is in progress to cluster freeze
    // because there is a pending state transition message
    ClusterStatus expectedClusterStatus = new ClusterStatus();
    expectedClusterStatus.setManagementMode(ClusterManagementMode.Type.CLUSTER_FREEZE);
    expectedClusterStatus.setManagementModeStatus(ClusterManagementMode.Status.IN_PROGRESS);
    verifyClusterStatus(expectedClusterStatus);
    // Verify management mode history is empty
    ControllerHistory controllerHistory = _accessor.getProperty(_accessor.keyBuilder().controllerLeaderHistory());
    List<String> managementHistory = controllerHistory.getManagementModeHistory();
    Assert.assertTrue(managementHistory.isEmpty());
    // Unblock to finish state transition and delete the ST message
    latch.countDown();
    // Verify live instance status and cluster status
    verifyLiveInstanceStatus(_participants, LiveInstance.LiveInstanceStatus.FROZEN);
    expectedClusterStatus = new ClusterStatus();
    expectedClusterStatus.setManagementMode(ClusterManagementMode.Type.CLUSTER_FREEZE);
    expectedClusterStatus.setManagementModeStatus(ClusterManagementMode.Status.COMPLETED);
    verifyClusterStatus(expectedClusterStatus);
    // Verify management mode history
    Assert.assertTrue(TestHelper.verify(() -> {
        ControllerHistory tmpControllerHistory = _accessor.getProperty(keyBuilder.controllerLeaderHistory());
        List<String> tmpManagementHistory = tmpControllerHistory.getManagementModeHistory();
        if (tmpManagementHistory == null || tmpManagementHistory.isEmpty()) {
            return false;
        }
        // Should not have duplicate entries
        if (tmpManagementHistory.size() > 1) {
            return false;
        }
        String lastHistory = tmpManagementHistory.get(0);
        return lastHistory.contains("MODE=" + ClusterManagementMode.Type.CLUSTER_FREEZE) && lastHistory.contains("STATUS=" + ClusterManagementMode.Status.COMPLETED) && lastHistory.contains("REASON=" + methodName);
    }, TestHelper.WAIT_DURATION));
}
Also used : Message(org.apache.helix.model.Message) ClusterManagementModeRequest(org.apache.helix.api.status.ClusterManagementModeRequest) Resource(org.apache.helix.model.Resource) ControllerHistory(org.apache.helix.model.ControllerHistory) CountDownLatch(java.util.concurrent.CountDownLatch) PauseSignal(org.apache.helix.model.PauseSignal) List(java.util.List) PropertyKey(org.apache.helix.PropertyKey) ClusterStatus(org.apache.helix.model.ClusterStatus) Test(org.testng.annotations.Test)

Example 2 with ClusterStatus

use of org.apache.helix.model.ClusterStatus in project helix by apache.

the class ManagementModeStage method recordClusterStatus.

private void recordClusterStatus(ClusterManagementMode mode, PauseSignal pauseSignal, String controllerName, HelixDataAccessor accessor) {
    // Read cluster status from metadata store
    PropertyKey statusPropertyKey = accessor.keyBuilder().clusterStatus();
    ClusterStatus clusterStatus = accessor.getProperty(statusPropertyKey);
    if (clusterStatus == null) {
        clusterStatus = new ClusterStatus();
    }
    if (mode.getMode().equals(clusterStatus.getManagementMode()) && mode.getStatus().equals(clusterStatus.getManagementModeStatus())) {
        // No need to update status and avoid duplicates when it's the same as metadata store
        LOG.debug("Skip recording duplicate status mode={}, status={}", mode.getMode(), mode.getStatus());
        return;
    }
    // Update cluster status in metadata store
    clusterStatus.setManagementMode(mode.getMode());
    clusterStatus.setManagementModeStatus(mode.getStatus());
    if (!accessor.updateProperty(statusPropertyKey, clusterStatus)) {
        LOG.error("Failed to update cluster status {}", clusterStatus);
    }
    recordManagementModeHistory(mode, pauseSignal, controllerName, accessor);
}
Also used : PropertyKey(org.apache.helix.PropertyKey) ClusterStatus(org.apache.helix.model.ClusterStatus)

Example 3 with ClusterStatus

use of org.apache.helix.model.ClusterStatus in project helix by apache.

the class TestClusterFreezeMode method verifyClusterStatus.

private void verifyClusterStatus(ClusterStatus expectedMode) throws Exception {
    final PropertyKey statusPropertyKey = _accessor.keyBuilder().clusterStatus();
    TestHelper.verify(() -> {
        ClusterStatus clusterStatus = _accessor.getProperty(statusPropertyKey);
        return clusterStatus != null && expectedMode.getManagementMode().equals(clusterStatus.getManagementMode()) && expectedMode.getManagementModeStatus().equals(clusterStatus.getManagementModeStatus());
    }, TestHelper.WAIT_DURATION);
}
Also used : PropertyKey(org.apache.helix.PropertyKey) ClusterStatus(org.apache.helix.model.ClusterStatus)

Example 4 with ClusterStatus

use of org.apache.helix.model.ClusterStatus in project helix by apache.

the class TestClusterFreezeMode method testUnfreezeCluster.

@Test(dependsOnMethods = "testCreateResourceWhenFrozen")
public void testUnfreezeCluster() throws Exception {
    String methodName = TestHelper.getTestMethodName();
    // Unfreeze cluster
    ClusterManagementModeRequest request = ClusterManagementModeRequest.newBuilder().withClusterName(_clusterName).withMode(ClusterManagementMode.Type.NORMAL).withReason(methodName).build();
    _gSetupTool.getClusterManagementTool().setClusterManagementMode(request);
    verifyLiveInstanceStatus(_participants, LiveInstance.LiveInstanceStatus.NORMAL);
    ClusterStatus expectedClusterStatus = new ClusterStatus();
    expectedClusterStatus.setManagementMode(ClusterManagementMode.Type.NORMAL);
    expectedClusterStatus.setManagementModeStatus(ClusterManagementMode.Status.COMPLETED);
    verifyClusterStatus(expectedClusterStatus);
    // Verify management mode history: NORMAL + COMPLETED
    Assert.assertTrue(TestHelper.verify(() -> {
        ControllerHistory history = _accessor.getProperty(_accessor.keyBuilder().controllerLeaderHistory());
        List<String> managementHistory = history.getManagementModeHistory();
        if (managementHistory == null || managementHistory.isEmpty()) {
            return false;
        }
        String lastHistory = managementHistory.get(managementHistory.size() - 1);
        return lastHistory.contains("MODE=" + ClusterManagementMode.Type.NORMAL) && lastHistory.contains("STATUS=" + ClusterManagementMode.Status.COMPLETED);
    }, TestHelper.WAIT_DURATION));
    // Verify cluster's normal rebalance ability after unfrozen.
    Assert.assertTrue(ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, _clusterName)));
}
Also used : ClusterManagementModeRequest(org.apache.helix.api.status.ClusterManagementModeRequest) ControllerHistory(org.apache.helix.model.ControllerHistory) List(java.util.List) ClusterStatus(org.apache.helix.model.ClusterStatus) Test(org.testng.annotations.Test)

Example 5 with ClusterStatus

use of org.apache.helix.model.ClusterStatus in project helix by apache.

the class ZKHelixAdmin method getClusterManagementMode.

@Override
public ClusterManagementMode getClusterManagementMode(String clusterName) {
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_zkClient));
    ClusterStatus status = accessor.getProperty(accessor.keyBuilder().clusterStatus());
    return status == null ? null : new ClusterManagementMode(status.getManagementMode(), status.getManagementModeStatus());
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ClusterManagementMode(org.apache.helix.api.status.ClusterManagementMode) ClusterStatus(org.apache.helix.model.ClusterStatus)

Aggregations

ClusterStatus (org.apache.helix.model.ClusterStatus)6 PropertyKey (org.apache.helix.PropertyKey)4 ClusterManagementModeRequest (org.apache.helix.api.status.ClusterManagementModeRequest)3 ControllerHistory (org.apache.helix.model.ControllerHistory)3 Test (org.testng.annotations.Test)3 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 HelixDataAccessor (org.apache.helix.HelixDataAccessor)1 HelixException (org.apache.helix.HelixException)1 ClusterManagementMode (org.apache.helix.api.status.ClusterManagementMode)1 ManagementControllerDataProvider (org.apache.helix.controller.dataproviders.ManagementControllerDataProvider)1 Pipeline (org.apache.helix.controller.pipeline.Pipeline)1 LiveInstance (org.apache.helix.model.LiveInstance)1 Message (org.apache.helix.model.Message)1 PauseSignal (org.apache.helix.model.PauseSignal)1 Resource (org.apache.helix.model.Resource)1