Examples of CurrentStateOutput


Examples of com.linkedin.helix.controller.stages.CurrentStateOutput

    setupIdealState(5, resources, 10, 1);
    setupLiveInstances(5);
    setupStateModel();

    Map<String, Resource> resourceMap = getResourceMap();
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.toString(),
        resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.toString(),
        currentStateOutput);
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    setupIdealState(5, resources, 10, 1);
    setupLiveInstances(5);
    setupStateModel();

    Map<String, Resource> resourceMap = getResourceMap();
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.toString(),
        resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.toString(),
        currentStateOutput);
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    Map<String, Resource> resourceMap = getResourceMap();
    event.addAttribute(AttributeName.RESOURCES.toString(), resourceMap);
    CurrentStateComputationStage stage = new CurrentStateComputationStage();
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output =
        event.getAttribute(AttributeName.CURRENT_STATE.toString());
    AssertJUnit.assertEquals(output.getCurrentStateMap("testResourceName",
                                                       new Partition("testResourceName_0"))
                                   .size(),
                             0);
  }
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    event.addAttribute(AttributeName.RESOURCES.toString(), resourceMap);
    CurrentStateComputationStage stage = new CurrentStateComputationStage();
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output1 =
        event.getAttribute(AttributeName.CURRENT_STATE.toString());
    AssertJUnit.assertEquals(output1.getCurrentStateMap("testResourceName",
                                                        new Partition("testResourceName_0"))
                                    .size(),
                             0);

    // Add a state transition messages
    Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1");
    message.setFromState("OFFLINE");
    message.setToState("SLAVE");
    message.setResourceName("testResourceName");
    message.setPartitionName("testResourceName_1");
    message.setTgtName("localhost_3");
    message.setTgtSessionId("session_3");

    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.message("localhost_" + 3, message.getId()), message);

    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output2 =
        event.getAttribute(AttributeName.CURRENT_STATE.toString());
    String pendingState =
        output2.getPendingState("testResourceName",
                                new Partition("testResourceName_1"),
                                "localhost_3");
    AssertJUnit.assertEquals(pendingState, "SLAVE");

    ZNRecord record1 = new ZNRecord("testResourceName");
    // Add a current state that matches sessionId and one that does not match
    CurrentState stateWithLiveSession = new CurrentState(record1);
    stateWithLiveSession.setSessionId("session_3");
    stateWithLiveSession.setStateModelDefRef("MasterSlave");
    stateWithLiveSession.setState("testResourceName_1", "OFFLINE");
    ZNRecord record2 = new ZNRecord("testResourceName");
    CurrentState stateWithDeadSession = new CurrentState(record2);
    stateWithDeadSession.setSessionId("session_dead");
    stateWithDeadSession.setStateModelDefRef("MasterSlave");
    stateWithDeadSession.setState("testResourceName_1", "MASTER");

    accessor.setProperty(keyBuilder.currentState("localhost_3",
                                                 "session_3",
                                                 "testResourceName"),
                         stateWithLiveSession);
    accessor.setProperty(keyBuilder.currentState("localhost_3",
                                                 "session_dead",
                                                 "testResourceName"),
                         stateWithDeadSession);
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output3 =
        event.getAttribute(AttributeName.CURRENT_STATE.toString());
    String currentState =
        output3.getCurrentState("testResourceName",
                                new Partition("testResourceName_1"),
                                "localhost_3");
    AssertJUnit.assertEquals(currentState, "OFFLINE");

  }
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    setupIdealState(5, resources, 10, 1, RebalanceMode.SEMI_AUTO);
    setupLiveInstances(5);
    setupStateModel();

    Map<String, Resource> resourceMap = getResourceMap();
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.toString(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.toString(), currentStateOutput);

    ReadClusterDataStage stage1 = new ReadClusterDataStage();
    runStage(event, stage1);
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    Map<String, Resource> resourceMap = getResourceMap();
    event.addAttribute(AttributeName.RESOURCES.toString(), resourceMap);
    CurrentStateComputationStage stage = new CurrentStateComputationStage();
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output = event.getAttribute(AttributeName.CURRENT_STATE.toString());
    AssertJUnit.assertEquals(
        output.getCurrentStateMap("testResourceName", new Partition("testResourceName_0")).size(),
        0);
  }
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    event.addAttribute(AttributeName.RESOURCES.toString(), resourceMap);
    CurrentStateComputationStage stage = new CurrentStateComputationStage();
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE.toString());
    AssertJUnit.assertEquals(
        output1.getCurrentStateMap("testResourceName", new Partition("testResourceName_0")).size(),
        0);

    // Add a state transition messages
    Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1");
    message.setFromState("OFFLINE");
    message.setToState("SLAVE");
    message.setResourceName("testResourceName");
    message.setPartitionName("testResourceName_1");
    message.setTgtName("localhost_3");
    message.setTgtSessionId("session_3");

    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.message("localhost_" + 3, message.getId()), message);

    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE.toString());
    String pendingState =
        output2.getPendingState("testResourceName", new Partition("testResourceName_1"),
            "localhost_3");
    AssertJUnit.assertEquals(pendingState, "SLAVE");

    ZNRecord record1 = new ZNRecord("testResourceName");
    // Add a current state that matches sessionId and one that does not match
    CurrentState stateWithLiveSession = new CurrentState(record1);
    stateWithLiveSession.setSessionId("session_3");
    stateWithLiveSession.setStateModelDefRef("MasterSlave");
    stateWithLiveSession.setState("testResourceName_1", "OFFLINE");
    ZNRecord record2 = new ZNRecord("testResourceName");
    CurrentState stateWithDeadSession = new CurrentState(record2);
    stateWithDeadSession.setSessionId("session_dead");
    stateWithDeadSession.setStateModelDefRef("MasterSlave");
    stateWithDeadSession.setState("testResourceName_1", "MASTER");

    accessor.setProperty(keyBuilder.currentState("localhost_3", "session_3", "testResourceName"),
        stateWithLiveSession);
    accessor.setProperty(
        keyBuilder.currentState("localhost_3", "session_dead", "testResourceName"),
        stateWithDeadSession);
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);
    CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE.toString());
    String currentState =
        output3.getCurrentState("testResourceName", new Partition("testResourceName_1"),
            "localhost_3");
    AssertJUnit.assertEquals(currentState, "OFFLINE");

  }
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
    ClusterDataCache cache = new ClusterDataCache();
    cache.refresh(accessor);

    // adapt ResourceCurrentState to CurrentStateOutput
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    for (ResourceId resource : currentState.getResourceIds()) {
      currentStateOutput.setBucketSize(resource.stringify(), currentState.getBucketSize(resource));
      currentStateOutput.setResourceStateModelDef(resource.stringify(), currentState
          .getResourceStateModelDef(resource).stringify());
      Set<PartitionId> partitions = currentState.getCurrentStateMappedPartitions(resource);
      for (PartitionId partitionId : partitions) {
        // set current state
        Map<ParticipantId, State> currentStateMap =
            currentState.getCurrentStateMap(resource, partitionId);
        for (ParticipantId participantId : currentStateMap.keySet()) {
          currentStateOutput.setCurrentState(resource.stringify(),
              new Partition(partitionId.stringify()), participantId.stringify(), currentStateMap
                  .get(participantId).toString());
        }

        // set pending current state
        Map<ParticipantId, State> pendingStateMap =
            currentState.getPendingStateMap(resource, partitionId);
        for (ParticipantId participantId : pendingStateMap.keySet()) {
          currentStateOutput.setPendingState(resource.stringify(),
              new Partition(partitionId.stringify()), participantId.stringify(), pendingStateMap
                  .get(participantId).toString());
        }
      }
    }
View Full Code Here

Examples of org.apache.helix.controller.stages.CurrentStateOutput

    // get the cluster data cache (unfortunately involves a second read of the cluster)
    ClusterDataCache cache = new ClusterDataCache();
    cache.refresh(accessor);

    // adapt ResourceCurrentState to CurrentStateOutput
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    for (ResourceId resource : currentState.getResourceIds()) {
      currentStateOutput.setBucketSize(resource.stringify(), currentState.getBucketSize(resource));
      currentStateOutput.setResourceStateModelDef(resource.stringify(), currentState
          .getResourceStateModelDef(resource).stringify());
      Set<PartitionId> partitions = currentState.getCurrentStateMappedPartitions(resource);
      for (PartitionId partitionId : partitions) {
        // set current state
        Map<ParticipantId, State> currentStateMap =
            currentState.getCurrentStateMap(resource, partitionId);
        for (ParticipantId participantId : currentStateMap.keySet()) {
          currentStateOutput.setCurrentState(resource.stringify(),
              new Partition(partitionId.stringify()), participantId.stringify(), currentStateMap
                  .get(participantId).toString());
        }

        // set pending current state
        Map<ParticipantId, State> pendingStateMap =
            currentState.getPendingStateMap(resource, partitionId);
        for (ParticipantId participantId : pendingStateMap.keySet()) {
          currentStateOutput.setPendingState(resource.stringify(),
              new Partition(partitionId.stringify()), participantId.stringify(), pendingStateMap
                  .get(participantId).toString());
        }
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.