use of org.apache.helix.api.config.StateTransitionTimeoutConfig in project helix by apache.
the class TestStateTransitionTimeoutWithResource method testStateTransitionTimeoutByClusterLevel.
@Test
public void testStateTransitionTimeoutByClusterLevel() throws InterruptedException {
_setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB + 1, _PARTITIONS, STATE_MODEL);
_setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB + 1, false);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB + 1, 3);
StateTransitionTimeoutConfig stateTransitionTimeoutConfig = new StateTransitionTimeoutConfig(new ZNRecord(TEST_DB + 1));
stateTransitionTimeoutConfig.setStateTransitionTimeout("SLAVE", "MASTER", 300);
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.setStateTransitionTimeoutConfig(stateTransitionTimeoutConfig);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
setParticipants(TEST_DB + 1);
_setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB + 1, true);
boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
verify(TEST_DB + 1);
}
use of org.apache.helix.api.config.StateTransitionTimeoutConfig in project helix by apache.
the class TestStateTransitionTimeoutWithResource method testStateTransitionTimeOut.
@Test
public void testStateTransitionTimeOut() throws Exception {
_setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, _PARTITIONS, STATE_MODEL);
_setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB, false);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 3);
// Set the timeout values
StateTransitionTimeoutConfig stateTransitionTimeoutConfig = new StateTransitionTimeoutConfig(new ZNRecord(TEST_DB));
stateTransitionTimeoutConfig.setStateTransitionTimeout("SLAVE", "MASTER", 300);
ResourceConfig resourceConfig = new ResourceConfig.Builder(TEST_DB).setStateTransitionTimeoutConfig(stateTransitionTimeoutConfig).setRebalanceConfig(new RebalanceConfig(new ZNRecord(TEST_DB))).setNumPartitions(_PARTITIONS).setHelixEnabled(false).build();
_configAccessor.setResourceConfig(CLUSTER_NAME, TEST_DB, resourceConfig);
setParticipants(TEST_DB);
_setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB, true);
boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
verify(TEST_DB);
}
use of org.apache.helix.api.config.StateTransitionTimeoutConfig in project helix by apache.
the class MessageGenerationPhase method getTimeOut.
private int getTimeOut(ClusterConfig clusterConfig, ResourceConfig resourceConfig, String currentState, String nextState, IdealState idealState, Partition partition) {
// Set timeout of needed
int timeout = -1;
StateTransitionTimeoutConfig stateTransitionTimeoutConfig = clusterConfig.getStateTransitionTimeoutConfig();
timeout = stateTransitionTimeoutConfig != null ? stateTransitionTimeoutConfig.getStateTransitionTimeout(currentState, nextState) : -1;
String timeOutStr = null;
// Check IdealState whether has timeout set
if (idealState != null) {
String stateTransition = currentState + "-" + nextState + "_" + Message.Attributes.TIMEOUT;
timeOutStr = idealState.getRecord().getSimpleField(stateTransition);
if (timeOutStr == null && idealState.getStateModelDefRef().equalsIgnoreCase(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
// scheduled task queue
if (idealState.getRecord().getMapField(partition.getPartitionName()) != null) {
timeOutStr = idealState.getRecord().getMapField(partition.getPartitionName()).get(Message.Attributes.TIMEOUT.toString());
}
}
}
if (timeOutStr != null) {
try {
timeout = Integer.parseInt(timeOutStr);
} catch (Exception e) {
logger.error("", e);
}
}
if (resourceConfig != null) {
// If resource config has timeout, replace the cluster timeout.
stateTransitionTimeoutConfig = resourceConfig.getStateTransitionTimeoutConfig();
timeout = stateTransitionTimeoutConfig != null ? stateTransitionTimeoutConfig.getStateTransitionTimeout(currentState, nextState) : -1;
}
return timeout;
}
use of org.apache.helix.api.config.StateTransitionTimeoutConfig in project helix by apache.
the class TestStateTransitionProperty method testTimeoutSetAndGet.
@Test
public void testTimeoutSetAndGet() {
StateTransitionTimeoutConfig stateTransitionTimeoutConfig = new StateTransitionTimeoutConfig(new ZNRecord("TEST"));
stateTransitionTimeoutConfig.setStateTransitionTimeout("MASTER", "SLAVE", 300);
Assert.assertEquals(stateTransitionTimeoutConfig.getStateTransitionTimeout("MASTER", "SLAVE"), 300);
stateTransitionTimeoutConfig.setStateTransitionTimeout("*", "MASTER", 500);
Assert.assertEquals(stateTransitionTimeoutConfig.getStateTransitionTimeout("OFFLINE", "MASTER"), 500);
Assert.assertEquals(stateTransitionTimeoutConfig.getStateTransitionTimeout("SLAVE", "OFFLINE"), -1);
}
Aggregations