Package org.apache.helix.api

Examples of org.apache.helix.api.State


    String timeout = message.getRecord().getSimpleField(CommandAttribute.TIMEOUT.getName());
    String pidFile = message.getRecord().getSimpleField(CommandAttribute.PID_FILE.getName());

    HelixManager manager = context.getManager();
    String clusterName = manager.getClusterName();
    State fromState = message.getTypedFromState();
    State toState = message.getTypedToState();

    // construct keys for command-config
    String cmdKey = buildKey(fromState.toString(), toState.toString(), CommandAttribute.COMMAND);
    String workingDirKey =
        buildKey(fromState.toString(), toState.toString(), CommandAttribute.WORKING_DIR);
    String timeoutKey =
        buildKey(fromState.toString(), toState.toString(), CommandAttribute.TIMEOUT);
    String pidFileKey =
        buildKey(fromState.toString(), toState.toString(), CommandAttribute.PID_FILE);
    List<String> cmdConfigKeys = Arrays.asList(cmdKey, workingDirKey, timeoutKey, pidFileKey);

    // read command from resource-scope configures
    if (cmd == null) {
      HelixConfigScope resourceScope =
View Full Code Here


    for (ResourceId resource : bestPossibleStates.getAssignedResources()) {
      ResourceAssignment assignment = bestPossibleStates.getResourceAssignment(resource);
      for (PartitionId partition : assignment.getMappedPartitionIds()) {
        Map<ParticipantId, State> instanceStateMap = assignment.getReplicaMap(partition);
        for (ParticipantId instance : instanceStateMap.keySet()) {
          State state = instanceStateMap.get(instance);
          PerInstanceResourceMonitor.BeanName beanName =
              new PerInstanceResourceMonitor.BeanName(instance.toString(), resource.toString());
          if (!beanMap.containsKey(beanName)) {
            beanMap.put(beanName, new HashMap<PartitionId, State>());
          }
View Full Code Here

      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> instanceConfigMap =
          accessor.getChildValuesMap(keyBuilder.instanceConfigs());
      for (String liveInstanceName : liveInstanceMap.keySet()) {
        if (instanceConfigMap.get(liveInstanceName).containsTag(instanceGroupTag)) {
          instances++;
        }
      }
      if (instances == 0) {
        instances = liveInstanceMap.size();
      }
      ExternalView ev = accessor.getProperty(keyBuilder.externalView(_resourceName));
      if (ev == null) {
        return false;
      }
      return verifyBalanceExternalView(ev.getRecord(), numberOfPartitions, masterValue.toString(),
          replicas, instances);
    }
View Full Code Here

    }

    @Override
    public void doTransition(Message message, NotificationContext context) {
      super.doTransition(message, context);
      State fromState = message.getTypedFromState();
      State toState = message.getTypedToState();
      if (fromState.toString().equals("ERROR") && toState.toString().equals("OFFLINE")) {
        // System.err.println("doReset() invoked");
        _errToOfflineInvoked.incrementAndGet();
      }
    }
View Full Code Here

      Assert.assertEquals(replicaMap.size(), preferenceList.size());
      Assert.assertEquals(replicaMap.size(), r);
      boolean hasMaster = false;
      for (ParticipantId participant : preferenceList) {
        Assert.assertTrue(replicaMap.containsKey(participant));
        State state = replicaMap.get(participant);
        if (state.equals(State.from("MASTER"))) {
          Assert.assertFalse(hasMaster);
          hasMaster = true;
        }
      }
      Assert.assertEquals(replicaMap.get(preferenceList.get(0)), State.from("MASTER"));
View Full Code Here

      // get the error participants
      Map<ParticipantId, State> currentStateMap =
          currentStateOutput.getCurrentStateMap(resourceId, partitionId);
      Set<ParticipantId> errorParticipants = Sets.newHashSet();
      for (ParticipantId participantId : currentStateMap.keySet()) {
        State state = currentStateMap.get(participantId);
        if (State.from(HelixDefinedState.ERROR).equals(state)) {
          errorParticipants.add(participantId);
        }
      }

      // get the dropped and disabled map
      State initialState = stateModelDef.getTypedInitialState();
      Map<ParticipantId, State> participantStateMap = resourceAssignment.getReplicaMap(partitionId);
      Set<ParticipantId> participants = participantStateMap.keySet();
      Map<ParticipantId, State> droppedAndDisabledMap =
          ConstraintBasedAssignment.dropAndDisablePartitions(currentStateMap, participants,
              disabledParticipants, true, initialState);
View Full Code Here

    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

        if (containerConfig != null) {
          containerId = containerConfig.getId();
          containerState = containerConfig.getState();
        }
        State participantState = null;
        if (serviceStateMap != null) {
          participantState = serviceStateMap.get(participant.getId());
        }
        if (participantState == null) {
          participantState = State.from("UNKNOWN");
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

      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 " + _zkaddr + " --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

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.