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));
}
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);
}
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);
}
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)));
}
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());
}
Aggregations