Search in sources :

Example 1 with StateTransitionTimeoutConfig

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);
}
Also used : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) StateTransitionTimeoutConfig(org.apache.helix.api.config.StateTransitionTimeoutConfig) ZNRecord(org.apache.helix.ZNRecord) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 2 with StateTransitionTimeoutConfig

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);
}
Also used : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) StateTransitionTimeoutConfig(org.apache.helix.api.config.StateTransitionTimeoutConfig) ResourceConfig(org.apache.helix.model.ResourceConfig) ZNRecord(org.apache.helix.ZNRecord) RebalanceConfig(org.apache.helix.api.config.RebalanceConfig) Test(org.testng.annotations.Test)

Example 3 with StateTransitionTimeoutConfig

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;
}
Also used : StateTransitionTimeoutConfig(org.apache.helix.api.config.StateTransitionTimeoutConfig) StageException(org.apache.helix.controller.pipeline.StageException)

Example 4 with StateTransitionTimeoutConfig

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);
}
Also used : StateTransitionTimeoutConfig(org.apache.helix.api.config.StateTransitionTimeoutConfig) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Aggregations

StateTransitionTimeoutConfig (org.apache.helix.api.config.StateTransitionTimeoutConfig)4 ZNRecord (org.apache.helix.ZNRecord)3 Test (org.testng.annotations.Test)3 MasterNbInExtViewVerifier (org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier)2 RebalanceConfig (org.apache.helix.api.config.RebalanceConfig)1 StageException (org.apache.helix.controller.pipeline.StageException)1 ClusterConfig (org.apache.helix.model.ClusterConfig)1 ResourceConfig (org.apache.helix.model.ResourceConfig)1