Package org.apache.helix.api

Examples of org.apache.helix.api.State


      Map<ParticipantId, State> pendingStateMap =
          currStateOutput.getPendingStateMap(ResourceId.from(targetResource),
              PartitionId.from(partition));
      for (Map.Entry<ParticipantId, State> e : stateMap.entrySet()) {
        ParticipantId instanceName = e.getKey();
        State state = e.getValue();
        State pending = pendingStateMap.get(instanceName);
        if (pending != null) {
          continue;
        }
        if (targetStates == null || targetStates.isEmpty()
            || targetStates.contains(state.toString())) {
View Full Code Here


      IdealState idealState = accessor.getProperty(keyBuilder.idealStates(_resourceName));
      int numberOfPartitions = idealState.getRecord().getListFields().size();
      String stateModelDefName = idealState.getStateModelDefId().stringify();
      StateModelDefinition stateModelDef =
          accessor.getProperty(keyBuilder.stateModelDef(stateModelDefName));
      State masterValue = stateModelDef.getTypedStatesPriorityList().get(0);
      Map<String, LiveInstance> liveInstanceMap =
          accessor.getChildValuesMap(keyBuilder.liveInstances());
      int replicas = Integer.parseInt(idealState.getReplicas());
      return verifyBalanceExternalView(accessor.getProperty(keyBuilder.externalView(_resourceName))
          .getRecord(), numberOfPartitions, masterValue.toString(), replicas,
          liveInstanceMap.size(), idealState.getMaxPartitionsPerInstance());
    }
View Full Code Here

    for (PartitionId partition : idealState.getPartitionIdSet()) {
      Map<ParticipantId, State> curStateMap =
          currentStateOutput.getCurrentStateMap(idealState.getResourceId(), partition);
      map.put(partition, new HashMap<ParticipantId, State>());
      for (ParticipantId node : curStateMap.keySet()) {
        State state = curStateMap.get(node);
        if (stateCountMap.containsKey(state)) {
          map.get(partition).put(node, state);
        }
      }

      Map<ParticipantId, State> pendingStateMap =
          currentStateOutput.getPendingStateMap(idealState.getResourceId(), partition);
      for (ParticipantId node : pendingStateMap.keySet()) {
        State state = pendingStateMap.get(node);
        if (stateCountMap.containsKey(state)) {
          map.get(partition).put(node, state);
        }
      }
    }
View Full Code Here

    }

    HelixDataAccessor accessor = _manager.getHelixDataAccessor();

    PartitionId partitionId = _message.getPartitionId();
    State fromState = _message.getTypedFromState();

    // Verify the fromState and current state of the stateModel
    String state = _currentStateDelta.getState(partitionId.stringify());

    if (fromState != null && !fromState.equals("*")
        && !fromState.toString().equalsIgnoreCase(state)) {
      String errorMessage =
          "Current state of stateModel does not match the fromState in Message"
              + ", Current State:" + state + ", message expected:" + fromState + ", partition: "
              + partitionId + ", from: " + _message.getMsgSrc() + ", to: " + _message.getTgtName();

View Full Code Here

    // Set the INFO property.
    _currentStateDelta.setInfo(partitionId, taskResult.getInfo());

    if (taskResult.isSuccess()) {
      // String fromState = message.getFromState();
      State toState = _message.getTypedToState();
      _currentStateDelta.setState(partitionId, toState);

      if (toState.toString().equalsIgnoreCase(HelixDefinedState.DROPPED.toString())) {
        // for "OnOfflineToDROPPED" message, we need to remove the resource key record
        // from the current state of the instance because the resource key is dropped.
        // In the state model it will be stayed as "OFFLINE", which is OK.

        ZNRecord rec = new ZNRecord(_currentStateDelta.getId());
        // remove mapField keyed by partitionId
        rec.setMapField(partitionId.stringify(), null);
        ZNRecordDelta delta = new ZNRecordDelta(rec, MergeOperation.SUBTRACT);

        List<ZNRecordDelta> deltaList = new ArrayList<ZNRecordDelta>();
        deltaList.add(delta);
        _currentStateDelta.setDeltaList(deltaList);
        _stateModelFactory.removeTransitionHandler(partitionId);
      } else {
        // if the partition is not to be dropped, update _stateModel to the TO_STATE
        _stateModel.updateState(toState.toString());
      }
    } else {
      if (exception instanceof HelixStateMismatchException) {
        // if fromState mismatch, set current state on zk to stateModel's current state
        logger.warn("Force CurrentState on Zk to be stateModel's CurrentState. partitionKey: "
View Full Code Here

    _statusUpdateUtil.logInfo(message, HelixStateTransitionHandler.class,
        "Message handling invoking", accessor);

    // by default, we invoke state transition function in state model
    Method methodToInvoke = null;
    State fromState = message.getTypedFromState();
    State toState = message.getTypedToState();
    methodToInvoke =
        _transitionMethodFinder.getMethodForTransition(_stateModel.getClass(),
            fromState.toString(), toState.toString(), new Class[] {
                Message.class, NotificationContext.class
            });
    if (methodToInvoke != null) {
      logger.info(String.format(
          "Instance %s, partition %s received state transition from %s to %s on session %s.",
View Full Code Here

        IdealState idealState = accessor.getProperty(keyBuilder.idealStates(_resourceName));
        int numberOfPartitions = idealState.getRecord().getListFields().size();
        String stateModelDefName = idealState.getStateModelDefId().stringify();
        StateModelDefinition stateModelDef =
            accessor.getProperty(keyBuilder.stateModelDef(stateModelDefName));
        State masterValue = stateModelDef.getTypedStatesPriorityList().get(0);
        int replicas = Integer.parseInt(idealState.getReplicas());
        String instanceGroupTag = idealState.getInstanceGroupTag();
        int instances = 0;
        Map<String, LiveInstance> liveInstanceMap =
            accessor.getChildValuesMap(keyBuilder.liveInstances());
        Map<String, InstanceConfig> instanceCfgMap =
            accessor.getChildValuesMap(keyBuilder.instanceConfigs());
        for (String liveInstanceName : liveInstanceMap.keySet()) {
          if (instanceCfgMap.get(liveInstanceName).containsTag(instanceGroupTag)) {
            instances++;
          }
        }
        if (instances == 0) {
          instances = liveInstanceMap.size();
        }
        ExternalView externalView = accessor.getProperty(keyBuilder.externalView(_resourceName));
        return verifyBalanceExternalView(externalView.getRecord(), numberOfPartitions,
            masterValue.toString(), replicas, instances);
      } catch (Exception e) {
        return false;
      }
    }
View Full Code Here

    // make this a LinkedHashSet to preserve iteration order
    Set<String> notAssigned = new LinkedHashSet<String>(preferenceList);
    List<String> newPreferenceList = new ArrayList<String>();
    int replicas = Math.min(countStateReplicas(), preferenceList.size());
    for (int i = 0; i < replicas; i++) {
      State state = _stateMap.get(i);
      String node = getMinimumNodeForReplica(state, notAssigned, nodeReplicaCounts);
      newPreferenceList.add(node);
      notAssigned.remove(node);
      Map<String, Integer> counts = nodeReplicaCounts.get(node);
      counts.put(state.toString(), counts.get(state.toString()) + 1);
    }
    preferenceList.clear();
    preferenceList.addAll(newPreferenceList);
  }
View Full Code Here

        new ResourceConfig.Builder(resourceId).idealState(idealStateBuilder.build()).userConfig(userConfig);
    return resourceBuilder.build();
  }

  private static StateModelDefinition getLockUnlockModel() {
    final State LOCKED = State.from("LOCKED");
    final State RELEASED = State.from("RELEASED");
    final State DROPPED = State.from("DROPPED");
    StateModelDefId stateModelId = StateModelDefId.from("LockUnlock");
    StateModelDefinition.Builder stateModelBuilder =
        new StateModelDefinition.Builder(stateModelId).addState(LOCKED, 0).addState(RELEASED, 1).addState(DROPPED, 2)
            .addTransition(RELEASED, LOCKED, 0).addTransition(LOCKED, RELEASED, 1).addTransition(RELEASED, DROPPED, 2)
            .upperBound(LOCKED, 1).upperBound(RELEASED, -1).upperBound(DROPPED, -1).initialState(RELEASED);
View Full Code Here

    StateModelDefinition stateModelDef = cluster.getStateModelMap().get(stateModelDefId);
    if (stateModelDef.getStatesPriorityList().size() < 1) {
      LOG.error("Invalid state model definition. There should be at least one state.");
      return assignment;
    }
    State lockState = stateModelDef.getTypedStatesPriorityList().get(0);

    // Count the number of participants allowed to lock each lock
    String stateCount = stateModelDef.getNumParticipantsPerState(lockState);
    int lockHolders = 0;
    try {
View Full Code Here

TOP

Related Classes of org.apache.helix.api.State

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.