Package org.apache.helix.model

Examples of org.apache.helix.model.CurrentState


    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.liveInstance(instanceName), liveInstance);
    accessor.setProperty(keyBuilder.instanceConfig(instanceName), instanceConfig);

    String oldResource = "testResourceOld";
    CurrentState currentState = new CurrentState(oldResource);
    currentState.setState(PartitionId.from("testResourceOld_0"), State.from("OFFLINE"));
    currentState.setState(PartitionId.from("testResourceOld_1"), State.from("SLAVE"));
    currentState.setState(PartitionId.from("testResourceOld_2"), State.from("MASTER"));
    currentState.setStateModelDefRef("MasterSlave");
    accessor.setProperty(keyBuilder.currentState(instanceName, sessionId, oldResource),
        currentState);

    ResourceComputationStage stage = new ResourceComputationStage();
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);

    Map<ResourceId, ResourceConfig> resourceMap =
        event.getAttribute(AttributeName.RESOURCES.toString());
    // +1 because it will have one for current state
    AssertJUnit.assertEquals(resources.length + 1, resourceMap.size());

    for (int i = 0; i < resources.length; i++) {
      String resourceName = resources[i];
      ResourceId resourceId = ResourceId.from(resourceName);
      IdealState idealState = idealStates.get(i);
      AssertJUnit.assertTrue(resourceMap.containsKey(resourceId));
      AssertJUnit.assertEquals(resourceMap.get(resourceId).getId(), resourceId);
      AssertJUnit.assertEquals(resourceMap.get(resourceId).getIdealState().getStateModelDefId(),
          idealState.getStateModelDefId());
      AssertJUnit.assertEquals(resourceMap.get(resourceId).getSubUnitSet().size(),
          idealState.getNumPartitions());
    }
    // Test the data derived from CurrentState
    ResourceId oldResourceId = ResourceId.from(oldResource);
    AssertJUnit.assertTrue(resourceMap.containsKey(oldResourceId));
    AssertJUnit.assertEquals(resourceMap.get(oldResourceId).getId(), oldResourceId);
    AssertJUnit.assertEquals(resourceMap.get(oldResourceId).getIdealState().getStateModelDefId(),
        currentState.getStateModelDefId());
    AssertJUnit.assertEquals(resourceMap.get(oldResourceId).getSubUnitSet().size(), currentState
        .getTypedPartitionStateMap().size());

  }
View Full Code Here


  Map<ResourceId, ResourceConfig> getCurStateResourceCfgMap(Cluster cluster) throws StageException {
    Map<ResourceId, IdealState> idealStateMap = new HashMap<ResourceId, IdealState>();

    for (Participant liveParticipant : cluster.getLiveParticipantMap().values()) {
      for (ResourceId resourceId : liveParticipant.getCurrentStateMap().keySet()) {
        CurrentState currentState = liveParticipant.getCurrentStateMap().get(resourceId);
        Map<String, String> resourceStateMap = currentState.getPartitionStateMap();
        if (resourceStateMap.isEmpty()) {
          // skip empty current state for dropped resource
          continue;
        }

        if (currentState.getStateModelDefRef() == null) {
          LOG.error("state model def is null." + "resource:" + currentState.getResourceId()
              + ", partitions: " + currentState.getPartitionStateMap().keySet() + ", states: "
              + currentState.getPartitionStateMap().values());
          throw new StageException("State model def is null for resource:"
              + currentState.getResourceId());
        }

        if (!idealStateMap.containsKey(resourceId)) {
          IdealState idealState = new IdealState(resourceId);
          idealState.setStateModelDefId(currentState.getStateModelDefId());
          idealState.setStateModelFactoryName(currentState.getStateModelFactoryName());
          idealState.setBucketSize(currentState.getBucketSize());
          idealState.setBatchMessageMode(currentState.getBatchMessageMode());
          idealStateMap.put(resourceId, idealState);
        }

        IdealState idealState = idealStateMap.get(resourceId);
        for (PartitionId partitionId : currentState.getTypedPartitionStateMap().keySet()) {
          idealState.setParticipantStateMap(partitionId, new HashMap<ParticipantId, State>());
          idealState.setPreferenceList(partitionId, new ArrayList<ParticipantId>());
        }
      }
    }
View Full Code Here

    LOG.debug(String.format("Requesting a state transition to %s for partition %s.", state,
        partition));
    try {
      PropertyKey.Builder keyBuilder = accessor.keyBuilder();
      PropertyKey key = keyBuilder.currentState(instance, sessionId, resource);
      CurrentState currStateDelta = new CurrentState(resource);
      currStateDelta.setRequestedState(PartitionId.from(partition), State.from(state.name()));

      return accessor.updateProperty(key, currStateDelta);
    } catch (Exception e) {
      LOG.error(String.format("Error when requesting a state transition to %s for partition %s.",
          state, partition), e);
View Full Code Here

  /**
   * @param resourceId
   * @param bucketSize
   */
  public void setBucketSize(ResourceId resourceId, int bucketSize) {
    CurrentState curStateMeta = _curStateMetaMap.get(resourceId);
    if (curStateMeta == null) {
      curStateMeta = new CurrentState(resourceId);
      _curStateMetaMap.put(resourceId, curStateMeta);
    }
    curStateMeta.setBucketSize(bucketSize);
  }
View Full Code Here

   * @param resourceId
   * @return
   */
  public int getBucketSize(ResourceId resourceId) {
    int bucketSize = 0;
    CurrentState curStateMeta = _curStateMetaMap.get(resourceId);
    if (curStateMeta != null) {
      bucketSize = curStateMeta.getBucketSize();
    }

    return bucketSize;
  }
View Full Code Here

      String resourceKey, String sessionId, String state) {
    ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();

    CurrentState curState = new CurrentState(resourceGroupName);
    curState.setState(PartitionId.from(resourceKey), State.from(state));
    curState.setSessionId(SessionId.from(sessionId));
    curState.setStateModelDefRef("MasterSlave");
    accessor.setProperty(keyBuilder.currentState(instance, sessionId, resourceGroupName), curState);
  }
View Full Code Here

            PartitionId.from("testResourceName_1"), ParticipantId.from("localhost_3"));
    AssertJUnit.assertEquals(pendingState, State.from("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(SessionId.from("session_3"));
    stateWithLiveSession.setStateModelDefRef("MasterSlave");
    stateWithLiveSession.setState(PartitionId.from("testResourceName_1"), State.from("OFFLINE"));
    ZNRecord record2 = new ZNRecord("testResourceName");
    CurrentState stateWithDeadSession = new CurrentState(record2);
    stateWithDeadSession.setSessionId(SessionId.from("session_dead"));
    stateWithDeadSession.setStateModelDefRef("MasterSlave");
    stateWithDeadSession.setState(PartitionId.from("testResourceName_1"), State.from("MASTER"));

    accessor.setProperty(keyBuilder.currentState("localhost_3", "session_3", "testResourceName"),
        stateWithLiveSession);
    accessor.setProperty(
        keyBuilder.currentState("localhost_3", "session_dead", "testResourceName"),
View Full Code Here

    Builder keyBuilder = accessor.keyBuilder();
    accessor.setProperty(keyBuilder.liveInstance(instanceName), liveInstance);
    accessor.setProperty(keyBuilder.instanceConfig(instanceName), instanceConfig);

    String oldResource = "testResourceOld";
    CurrentState currentState = new CurrentState(oldResource);
    currentState.setState(PartitionId.from("testResourceOld_0"), State.from("OFFLINE"));
    currentState.setState(PartitionId.from("testResourceOld_1"), State.from("SLAVE"));
    currentState.setState(PartitionId.from("testResourceOld_2"), State.from("MASTER"));
    currentState.setStateModelDefRef("MasterSlave");
    accessor.setProperty(keyBuilder.currentState(instanceName, sessionId, oldResource),
        currentState);

    ResourceComputationStage stage = new ResourceComputationStage();
    runStage(event, new ReadClusterDataStage());
    runStage(event, stage);

    Map<ResourceId, ResourceConfig> resourceMap =
        event.getAttribute(AttributeName.RESOURCES.toString());
    // +1 because it will have one for current state
    AssertJUnit.assertEquals(resources.length + 1, resourceMap.size());

    for (int i = 0; i < resources.length; i++) {
      String resourceName = resources[i];
      ResourceId resourceId = ResourceId.from(resourceName);
      IdealState idealState = idealStates.get(i);
      AssertJUnit.assertTrue(resourceMap.containsKey(resourceId));
      AssertJUnit.assertEquals(resourceMap.get(resourceId).getId(), resourceId);
      AssertJUnit.assertEquals(resourceMap.get(resourceId).getRebalancerConfig()
          .getRebalancerContext(RebalancerContext.class).getStateModelDefId(),
          idealState.getStateModelDefId());
      AssertJUnit.assertEquals(resourceMap.get(resourceId).getSubUnitSet().size(),
          idealState.getNumPartitions());
    }
    // Test the data derived from CurrentState
    ResourceId oldResourceId = ResourceId.from(oldResource);
    AssertJUnit.assertTrue(resourceMap.containsKey(oldResourceId));
    AssertJUnit.assertEquals(resourceMap.get(oldResourceId).getId(), oldResourceId);
    AssertJUnit.assertEquals(resourceMap.get(oldResourceId).getRebalancerConfig()
        .getRebalancerContext(RebalancerContext.class).getStateModelDefId(),
        currentState.getStateModelDefId());
    AssertJUnit.assertEquals(resourceMap.get(oldResourceId).getSubUnitSet().size(), currentState
        .getTypedPartitionStateMap().size());
    AssertJUnit.assertNotNull(resourceMap.get(oldResourceId).getSubUnit(
        PartitionId.from("testResourceOld_0")));
    AssertJUnit.assertNotNull(resourceMap.get(oldResourceId).getSubUnit(
        PartitionId.from("testResourceOld_1")));
View Full Code Here

            && !createCurStateNames.contains(resourceId.stringify())) {
          createCurStateNames.add(resourceId.stringify());
          createCurStateKeys.add(keyBuilder.currentState(instanceName, sessionId,
              resourceId.stringify()));

          CurrentState metaCurState = new CurrentState(resourceId.stringify());
          metaCurState.setBucketSize(message.getBucketSize());
          metaCurState.setStateModelDefRef(message.getStateModelDef());
          metaCurState.setSessionId(SessionId.from(sessionId));
          metaCurState.setBatchMessageMode(message.getBatchMessageMode());
          String ftyName = message.getStateModelFactoryName();
          if (ftyName != null) {
            metaCurState.setStateModelFactoryName(ftyName);
          } else {
            metaCurState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
          }

          metaCurStates.add(metaCurState);
        }
      }
View Full Code Here

    try {
      // set current state to ERROR for the partition
      // if the transition is not canceled, it should go into error state
      if (code == ErrorCode.ERROR) {
        CurrentState currentStateDelta = new CurrentState(resourceId.stringify());
        currentStateDelta.setState(partition, State.from(HelixDefinedState.ERROR.toString()));
        _stateModel.updateState(HelixDefinedState.ERROR.toString());

        // if transit from ERROR state, disable the partition
        if (_message.getTypedFromState().toString().equalsIgnoreCase(HelixDefinedState.ERROR.toString())) {
          disablePartition();
View Full Code Here

TOP

Related Classes of org.apache.helix.model.CurrentState

Copyright © 2018 www.massapicom. 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.