Package org.apache.helix.api

Examples of org.apache.helix.api.State


    ClusterId clusterId = ClusterId.from(clusterName);
    ControllerId controllerId = ControllerId.from("controller");
    final ParticipantId participantId = ParticipantId.from("participant1");

    ResourceId resourceId = ResourceId.from("testDB");
    State master = State.from("MASTER");
    State slave = State.from("SLAVE");
    State offline = State.from("OFFLINE");
    State dropped = State.from("DROPPED");
    StateModelDefId stateModelDefId = StateModelDefId.from("MasterSlave");

    // create connection
    HelixConnection connection = new ZkHelixConnection(zkAddr);
    connection.connect();
View Full Code Here


      HelixManager manager = context.getManager();
      String clusterName = manager.getClusterName();

      String instance = message.getTgtName();
      PartitionId partitionId = message.getPartitionId();
      State fromState = message.getTypedFromState();
      State toState = message.getTypedToState();
      if (instance.equals("localhost_12919") && partitionId.equals(PartitionId.from("TestDB0_0"))) {
        if (fromState.equals("SLAVE") && toState.equals("OFFLINE")) {
          slaveToOfflineCnt++;

          try {
            String command =
                "--zkSvr " + ZK_ADDR + " --enablePartition true " + clusterName
                    + " localhost_12919 TestDB0 TestDB0_0";

            ClusterSetup.processCommandLineArgs(command.split("\\s+"));
          } catch (Exception e) {
            LOG.error("Exception in cluster setup", e);
          }

        } else if (slaveToOfflineCnt > 0 && fromState.equals(State.from("OFFLINE"))
            && toState.equals(State.from("SLAVE"))) {
          offlineToSlave++;
        }
      }
    }
View Full Code Here

        // so keep generated messages in a temp map keyed by state
        // desired-state->list of generated-messages
        Map<State, List<Message>> messageMap = new HashMap<State, List<Message>>();

        for (ParticipantId participantId : instanceStateMap.keySet()) {
          State desiredState = instanceStateMap.get(participantId);

          State currentState =
              currentStateOutput.getCurrentState(resourceId, subUnitId, participantId);
          if (currentState == null) {
            currentState = stateModelDef.getTypedInitialState();
          }

          if (desiredState.equals(currentState)) {
            continue;
          }

          State pendingState =
              currentStateOutput.getPendingState(resourceId, subUnitId, participantId);

          // TODO fix it
          State nextState = stateModelDef.getNextStateForTransition(currentState, desiredState);
          if (nextState == null) {
            LOG.error("Unable to find a next state for partition: " + subUnitId
                + " from stateModelDefinition" + stateModelDef.getClass() + " from:" + currentState
                + " to:" + desiredState);
            continue;
          }

          if (pendingState != null) {
            if (nextState.equals(pendingState)) {
              LOG.debug("Message already exists for " + participantId + " to transit " + subUnitId
                  + " from " + currentState + " to " + nextState);
            } else if (currentState.equals(pendingState)) {
              LOG.info("Message hasn't been removed for " + participantId + " to transit"
                  + subUnitId + " to " + pendingState + ", desiredState: " + desiredState);
View Full Code Here

  public class WildcardAlertTransition extends MockTransition {
    @Override
    public void doTransition(Message message, NotificationContext context) {
      HelixManager manager = context.getManager();
      HelixDataAccessor accessor = manager.getHelixDataAccessor();
      State fromState = message.getTypedFromState();
      State toState = message.getTypedToState();
      String instance = message.getTgtName();

      if (fromState.toString().equalsIgnoreCase("SLAVE")
          && toState.toString().equalsIgnoreCase("MASTER")) {
        // add a stat and report to ZK
        // perhaps should keep reporter per instance...
        ParticipantHealthReportCollectorImpl reporter =
            new ParticipantHealthReportCollectorImpl(manager, instance);
        MockEspressoHealthReportProvider provider = new MockEspressoHealthReportProvider();
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

        idealState.setPreferenceList(partitionId, newPreferenceList);
      }
      Map<ParticipantId, State> preferenceMap = idealState.getParticipantStateMap(partitionId);
      if (preferenceMap != null) {
        if (preferenceMap.containsKey(oldParticipantId)) {
          State state = preferenceMap.get(oldParticipantId);
          preferenceMap.remove(oldParticipantId);
          preferenceMap.put(newParticipantId, state);
        }
        idealState.setParticipantStateMap(partitionId, preferenceMap);
      }
View Full Code Here

      Map<ParticipantId, Set<PartitionId>> resetPartitionIds = Maps.newHashMap();
      for (PartitionId partitionId : extView.getPartitionIdSet()) {
        Map<ParticipantId, State> stateMap = extView.getStateMap(partitionId);
        for (ParticipantId participantId : stateMap.keySet()) {
          State state = stateMap.get(participantId);
          if (state.equals(State.from(HelixDefinedState.ERROR))) {
            if (!resetPartitionIds.containsKey(participantId)) {
              resetPartitionIds.put(participantId, new HashSet<PartitionId>());
            }
            resetPartitionIds.get(participantId).add(partitionId);
          }
View Full Code Here

    List<Message> selectedMessages = new ArrayList<Message>();
    Map<State, Bounds> bounds = new HashMap<State, Bounds>();

    // count currentState, if no currentState, count as in initialState
    for (ParticipantId liveParticipantId : liveParticipants.keySet()) {
      State state = initialState;
      if (currentStates.containsKey(liveParticipantId)) {
        state = currentStates.get(liveParticipantId);
      }

      if (!bounds.containsKey(state)) {
        bounds.put(state, new Bounds(0, 0));
      }
      bounds.get(state).increaseLowerBound();
      bounds.get(state).increaseUpperBound();
    }

    // count pendingStates
    for (ParticipantId participantId : pendingStates.keySet()) {
      State state = pendingStates.get(participantId);
      if (!bounds.containsKey(state)) {
        bounds.put(state, new Bounds(0, 0));
      }
      // TODO: add lower bound, need to refactor pendingState to include fromState also
      bounds.get(state).increaseUpperBound();
    }

    // group messages based on state transition priority
    Map<Integer, List<Message>> messagesGroupByStateTransitPriority =
        new TreeMap<Integer, List<Message>>();
    for (Message message : messages) {
      State fromState = message.getTypedFromState();
      State toState = message.getTypedToState();
      String transition = fromState.toString() + "-" + toState.toString();
      int priority = Integer.MAX_VALUE;

      if (stateTransitionPriorities.containsKey(transition)) {
        priority = stateTransitionPriorities.get(transition);
      }

      if (!messagesGroupByStateTransitPriority.containsKey(priority)) {
        messagesGroupByStateTransitPriority.put(priority, new ArrayList<Message>());
      }
      messagesGroupByStateTransitPriority.get(priority).add(message);
    }

    // select messages
    for (List<Message> messageList : messagesGroupByStateTransitPriority.values()) {
      for (Message message : messageList) {
        State fromState = message.getTypedFromState();
        State toState = message.getTypedToState();

        if (!bounds.containsKey(fromState)) {
          LOG.error("Message's fromState is not in currentState. message: " + message);
          continue;
        }
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

    @Override
    public void doTransition(Message message, NotificationContext context) {
      HelixManager manager = context.getManager();
      HelixDataAccessor accessor = manager.getHelixDataAccessor();
      State fromState = message.getTypedFromState();
      State toState = message.getTypedToState();
      String instance = message.getTgtName();

      if (fromState.toString().equalsIgnoreCase("SLAVE")
          && toState.toString().equalsIgnoreCase("MASTER")) {

        // add a stat and report to ZK
        // perhaps should keep reporter per instance...
        ParticipantHealthReportCollectorImpl reporter =
            new ParticipantHealthReportCollectorImpl(manager, instance);
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.