Search in sources :

Example 1 with CurrentStateOutput

use of org.apache.helix.controller.stages.CurrentStateOutput in project helix by apache.

the class TestJobStateOnCreation method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    _cache = new ClusterDataCache();
    _idealState = new IdealState(WORKFLOW_NAME);
    _resource = new Resource(WORKFLOW_NAME);
    _currStateOutput = new CurrentStateOutput();
    _participants = new MockParticipantManager[_numNodes];
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    createManagers();
}
Also used : ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) Resource(org.apache.helix.model.Resource) ClusterSetup(org.apache.helix.tools.ClusterSetup) IdealState(org.apache.helix.model.IdealState) CurrentStateOutput(org.apache.helix.controller.stages.CurrentStateOutput) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with CurrentStateOutput

use of org.apache.helix.controller.stages.CurrentStateOutput in project helix by apache.

the class TestRebalancerMetrics method copyCurrentStateFromBestPossible.

private CurrentStateOutput copyCurrentStateFromBestPossible(BestPossibleStateOutput bestPossibleStateOutput, String resource) {
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    PartitionStateMap partitionStateMap = bestPossibleStateOutput.getPartitionStateMap(resource);
    for (Partition partition : partitionStateMap.partitionSet()) {
        Map<String, String> stateMap = partitionStateMap.getPartitionMap(partition);
        for (String instance : stateMap.keySet()) {
            currentStateOutput.setCurrentState(resource, partition, instance, stateMap.get(instance));
        }
    }
    return currentStateOutput;
}
Also used : PartitionStateMap(org.apache.helix.controller.common.PartitionStateMap) Partition(org.apache.helix.model.Partition) CurrentStateOutput(org.apache.helix.controller.stages.CurrentStateOutput)

Example 3 with CurrentStateOutput

use of org.apache.helix.controller.stages.CurrentStateOutput in project helix by apache.

the class TestRebalancerMetrics method testLoadBalanceMetrics.

@Test
public void testLoadBalanceMetrics() {
    System.out.println("START testLoadBalanceMetrics at " + new Date(System.currentTimeMillis()));
    String resource = "testResourceName";
    int numPartition = 100;
    int numReplica = 3;
    int maxPending = 3;
    setupIdealState(5, new String[] { resource }, numPartition, numReplica, IdealState.RebalanceMode.FULL_AUTO, BuiltInStateModelDefinitions.MasterSlave.name());
    setupInstances(5);
    setupLiveInstances(4);
    setupStateModel();
    Map<String, Resource> resourceMap = getResourceMap(new String[] { resource }, numPartition, BuiltInStateModelDefinitions.MasterSlave.name());
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    ClusterStatusMonitor monitor = new ClusterStatusMonitor(_clusterName);
    monitor.active();
    event.addAttribute(AttributeName.clusterStatusMonitor.name(), monitor);
    runStage(event, new ReadClusterDataStage());
    runStage(event, new BestPossibleStateCalcStage());
    BestPossibleStateOutput bestPossibleStateOutput = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
    currentStateOutput = copyCurrentStateFromBestPossible(bestPossibleStateOutput, resource);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    setupLiveInstances(4);
    runStage(event, new ReadClusterDataStage());
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
    setupThrottleConfig(cache.getClusterConfig(), StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, maxPending);
    runStage(event, new BestPossibleStateCalcStage());
    runStage(event, new IntermediateStateCalcStage());
    ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
    ResourceMonitor resourceMonitor = clusterStatusMonitor.getResourceMonitor(resource);
    long numPendingLoadBalance = resourceMonitor.getPendingLoadRebalancePartitionGauge();
    Assert.assertTrue(numPendingLoadBalance > 0);
    Assert.assertEquals(resourceMonitor.getLoadRebalanceThrottledPartitionGauge(), numPendingLoadBalance - maxPending);
    System.out.println("END testLoadBalanceMetrics at " + new Date(System.currentTimeMillis()));
}
Also used : BestPossibleStateOutput(org.apache.helix.controller.stages.BestPossibleStateOutput) ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) IntermediateStateCalcStage(org.apache.helix.controller.stages.IntermediateStateCalcStage) Resource(org.apache.helix.model.Resource) Date(java.util.Date) CurrentStateOutput(org.apache.helix.controller.stages.CurrentStateOutput) BestPossibleStateCalcStage(org.apache.helix.controller.stages.BestPossibleStateCalcStage) Test(org.testng.annotations.Test) BaseStageTest(org.apache.helix.controller.stages.BaseStageTest)

Example 4 with CurrentStateOutput

use of org.apache.helix.controller.stages.CurrentStateOutput in project helix by apache.

the class TestP2PStateTransitionMessages method testP2PMessage.

private void testP2PMessage(ClusterConfig clusterConfig, Boolean p2pMessageEnabled) throws Exception {
    Map<String, Resource> resourceMap = getResourceMap(new String[] { db }, numPartition, BuiltInStateModelDefinitions.MasterSlave.name(), clusterConfig, null);
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), new CurrentStateOutput());
    event.addAttribute(AttributeName.helixmanager.name(), manager);
    Pipeline pipeline = createPipeline();
    pipeline.handle(event);
    BestPossibleStateOutput bestPossibleStateOutput = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
    CurrentStateOutput currentStateOutput = populateCurrentStateFromBestPossible(bestPossibleStateOutput);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    Partition p = new Partition(db + "_0");
    String masterInstance = getTopStateInstance(bestPossibleStateOutput.getInstanceStateMap(db, p), MasterSlaveSMD.States.MASTER.name());
    Assert.assertNotNull(masterInstance);
    admin.enableInstance(_clusterName, masterInstance, false);
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
    cache.notifyDataChange(HelixConstants.ChangeType.INSTANCE_CONFIG);
    pipeline.handle(event);
    bestPossibleStateOutput = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
    MessageSelectionStageOutput messageOutput = event.getAttribute(AttributeName.MESSAGES_SELECTED.name());
    List<Message> messages = messageOutput.getMessages(db, p);
    Assert.assertEquals(messages.size(), 1);
    Message message = messages.get(0);
    Assert.assertEquals(message.getTgtName(), masterInstance);
    Assert.assertEquals(message.getFromState(), MasterSlaveSMD.States.MASTER.name());
    Assert.assertEquals(message.getToState(), MasterSlaveSMD.States.SLAVE.name());
    if (p2pMessageEnabled) {
        Assert.assertEquals(message.getRelayMessages().entrySet().size(), 1);
        String newMasterInstance = getTopStateInstance(bestPossibleStateOutput.getInstanceStateMap(db, p), MasterSlaveSMD.States.MASTER.name());
        Message relayMessage = message.getRelayMessage(newMasterInstance);
        Assert.assertNotNull(relayMessage);
        Assert.assertEquals(relayMessage.getMsgSubType(), Message.MessageType.RELAYED_MESSAGE.name());
        Assert.assertEquals(relayMessage.getTgtName(), newMasterInstance);
        Assert.assertEquals(relayMessage.getRelaySrcHost(), masterInstance);
        Assert.assertEquals(relayMessage.getFromState(), MasterSlaveSMD.States.SLAVE.name());
        Assert.assertEquals(relayMessage.getToState(), MasterSlaveSMD.States.MASTER.name());
    } else {
        Assert.assertTrue(message.getRelayMessages().entrySet().isEmpty());
    }
}
Also used : Partition(org.apache.helix.model.Partition) BestPossibleStateOutput(org.apache.helix.controller.stages.BestPossibleStateOutput) MessageSelectionStageOutput(org.apache.helix.controller.stages.MessageSelectionStageOutput) ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) Message(org.apache.helix.model.Message) Resource(org.apache.helix.model.Resource) CurrentStateOutput(org.apache.helix.controller.stages.CurrentStateOutput) Pipeline(org.apache.helix.controller.pipeline.Pipeline)

Example 5 with CurrentStateOutput

use of org.apache.helix.controller.stages.CurrentStateOutput in project helix by apache.

the class TestRebalancerMetrics method testRecoveryRebalanceMetrics.

@Test
public void testRecoveryRebalanceMetrics() {
    System.out.println("START testRecoveryRebalanceMetrics at " + new Date(System.currentTimeMillis()));
    String resource = "testResourceName";
    int numPartition = 100;
    int numReplica = 3;
    int maxPending = 3;
    setupIdealState(5, new String[] { resource }, numPartition, numReplica, IdealState.RebalanceMode.FULL_AUTO, BuiltInStateModelDefinitions.MasterSlave.name());
    setupInstances(5);
    setupLiveInstances(5);
    setupStateModel();
    Map<String, Resource> resourceMap = getResourceMap(new String[] { resource }, numPartition, BuiltInStateModelDefinitions.MasterSlave.name());
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    ClusterStatusMonitor monitor = new ClusterStatusMonitor(_clusterName);
    monitor.active();
    event.addAttribute(AttributeName.clusterStatusMonitor.name(), monitor);
    runStage(event, new ReadClusterDataStage());
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
    setupThrottleConfig(cache.getClusterConfig(), StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, maxPending);
    runStage(event, new BestPossibleStateCalcStage());
    runStage(event, new IntermediateStateCalcStage());
    ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
    ResourceMonitor resourceMonitor = clusterStatusMonitor.getResourceMonitor(resource);
    Assert.assertEquals(resourceMonitor.getPendingRecoveryRebalancePartitionGauge(), numPartition);
    Assert.assertEquals(resourceMonitor.getRecoveryRebalanceThrottledPartitionGauge(), numPartition - maxPending);
    System.out.println("END testRecoveryRebalanceMetrics at " + new Date(System.currentTimeMillis()));
}
Also used : ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) BestPossibleStateCalcStage(org.apache.helix.controller.stages.BestPossibleStateCalcStage) IntermediateStateCalcStage(org.apache.helix.controller.stages.IntermediateStateCalcStage) Resource(org.apache.helix.model.Resource) Date(java.util.Date) CurrentStateOutput(org.apache.helix.controller.stages.CurrentStateOutput) Test(org.testng.annotations.Test) BaseStageTest(org.apache.helix.controller.stages.BaseStageTest)

Aggregations

CurrentStateOutput (org.apache.helix.controller.stages.CurrentStateOutput)5 ClusterDataCache (org.apache.helix.controller.stages.ClusterDataCache)4 Resource (org.apache.helix.model.Resource)4 Date (java.util.Date)2 BaseStageTest (org.apache.helix.controller.stages.BaseStageTest)2 BestPossibleStateCalcStage (org.apache.helix.controller.stages.BestPossibleStateCalcStage)2 BestPossibleStateOutput (org.apache.helix.controller.stages.BestPossibleStateOutput)2 IntermediateStateCalcStage (org.apache.helix.controller.stages.IntermediateStateCalcStage)2 ReadClusterDataStage (org.apache.helix.controller.stages.ReadClusterDataStage)2 Partition (org.apache.helix.model.Partition)2 Test (org.testng.annotations.Test)2 PartitionStateMap (org.apache.helix.controller.common.PartitionStateMap)1 Pipeline (org.apache.helix.controller.pipeline.Pipeline)1 MessageSelectionStageOutput (org.apache.helix.controller.stages.MessageSelectionStageOutput)1 IdealState (org.apache.helix.model.IdealState)1 Message (org.apache.helix.model.Message)1 ClusterSetup (org.apache.helix.tools.ClusterSetup)1 BeforeClass (org.testng.annotations.BeforeClass)1