Package org.apache.helix.api

Examples of org.apache.helix.api.RunningInstance


    Map<ParticipantId, Participant> liveInstances = new HashMap<ParticipantId, Participant>();
    Set<PartitionId> disabledPartitions = Collections.emptySet();
    Set<String> tags = Collections.emptySet();
    Map<ResourceId, CurrentState> currentStateMap = Collections.emptyMap();
    Map<MessageId, Message> messageMap = Collections.emptyMap();
    RunningInstance runningInstance0 =
        new RunningInstance(SessionId.from("session_0"), HelixVersion.from("1.2.3.4"),
            ProcId.from("0"));
    RunningInstance runningInstance1 =
        new RunningInstance(SessionId.from("session_1"), HelixVersion.from("1.2.3.4"),
            ProcId.from("1"));
    liveInstances.put(ParticipantId.from("localhost_0"),
        new Participant(ParticipantId.from("localhost_0"), "localhost", 0, true,
            disabledPartitions, tags, runningInstance0, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_0")))));
View Full Code Here


    Map<ParticipantId, Participant> liveInstances = new HashMap<ParticipantId, Participant>();
    Set<PartitionId> disabledPartitions = Collections.emptySet();
    Set<String> tags = Collections.emptySet();
    Map<ResourceId, CurrentState> currentStateMap = Collections.emptyMap();
    Map<MessageId, Message> messageMap = Collections.emptyMap();
    RunningInstance runningInstance0 =
        new RunningInstance(SessionId.from("session_0"), HelixVersion.from("1.2.3.4"),
            ProcId.from("0"));
    RunningInstance runningInstance1 =
        new RunningInstance(SessionId.from("session_1"), HelixVersion.from("1.2.3.4"),
            ProcId.from("1"));
    liveInstances.put(ParticipantId.from("localhost_0"),
        new Participant(ParticipantId.from("localhost_0"), "localhost", 0, true,
            disabledPartitions, tags, runningInstance0, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_0")))));
View Full Code Here

            .append(", messages: ").append(participant.getMessageMap().toString())
            .append(participant.getCurrentStateMap().toString()).append(", alive: ")
            .append(participant.isAlive()).append(", userConfig: ")
            .append(participant.getUserConfig().toString());
    if (participant.isAlive()) {
      RunningInstance runningInstance = participant.getRunningInstance();
      sb.append(", sessionId: ").append(runningInstance.getSessionId().stringify())
          .append(", processId: ").append(runningInstance.getPid().stringify())
          .append(", helixVersion: ").append(runningInstance.getVersion().toString());
    }
    System.out.println(sb.toString());
  }
View Full Code Here

    Participant participant = readParticipant(participantId);
    if (!participant.isAlive()) {
      LOG.error("Cannot reset partitions because the participant is not running");
      return false;
    }
    RunningInstance runningInstance = participant.getRunningInstance();

    // check that the resource exists
    ResourceAccessor resourceAccessor = resourceAccessor();
    Resource resource = resourceAccessor.readResource(resourceId);
    if (resource == null || resource.getRebalancerConfig() == null) {
      LOG.error("Cannot reset partitions because the resource is not present");
      return false;
    }

    // need the rebalancer context for the resource
    RebalancerContext context =
        resource.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
    if (context == null) {
      LOG.error("Rebalancer context for resource does not exist");
      return false;
    }

    // ensure that all partitions to reset exist
    Set<PartitionId> partitionSet = ImmutableSet.copyOf(context.getSubUnitIdSet());
    if (!partitionSet.containsAll(resetPartitionIdSet)) {
      LOG.error("Not all of the specified partitions to reset exist for the resource");
      return false;
    }

    // check for a valid current state that has all specified partitions in ERROR state
    CurrentState currentState = participant.getCurrentStateMap().get(resourceId);
    if (currentState == null) {
      LOG.error("The participant does not have a current state for the resource");
      return false;
    }
    for (PartitionId partitionId : resetPartitionIdSet) {
      if (!currentState.getState(partitionId).equals(State.from(HelixDefinedState.ERROR))) {
        LOG.error("Partition " + partitionId + " is not in error state, aborting reset");
        return false;
      }
    }

    // make sure that there are no pending transition messages
    for (Message message : participant.getMessageMap().values()) {
      if (!MessageType.STATE_TRANSITION.toString().equalsIgnoreCase(message.getMsgType())
          || !runningInstance.getSessionId().equals(message.getTypedTgtSessionId())
          || !resourceId.equals(message.getResourceId())
          || !resetPartitionIdSet.contains(message.getPartitionId())) {
        continue;
      }
      LOG.error("Cannot reset partitions because of the following pending message: " + message);
      return false;
    }

    // set up the source id
    String adminName = null;
    try {
      adminName = InetAddress.getLocalHost().getCanonicalHostName() + "-ADMIN";
    } catch (UnknownHostException e) {
      // can ignore it
      if (LOG.isInfoEnabled()) {
        LOG.info("Unable to get host name. Will set it to UNKNOWN, mostly ignorable", e);
      }
      adminName = "UNKNOWN";
    }

    // build messages to signal the transition
    StateModelDefId stateModelDefId = context.getStateModelDefId();
    StateModelDefinition stateModelDef =
        _accessor.getProperty(_keyBuilder.stateModelDef(stateModelDefId.stringify()));
    Map<MessageId, Message> messageMap = Maps.newHashMap();
    for (PartitionId partitionId : resetPartitionIdSet) {
      // send ERROR to initialState message
      MessageId msgId = MessageId.from(UUID.randomUUID().toString());
      Message message = new Message(MessageType.STATE_TRANSITION, msgId);
      message.setSrcName(adminName);
      message.setTgtName(participantId.stringify());
      message.setMsgState(MessageState.NEW);
      message.setPartitionId(partitionId);
      message.setResourceId(resourceId);
      message.setTgtSessionId(runningInstance.getSessionId());
      message.setStateModelDef(stateModelDefId);
      message.setFromState(State.from(HelixDefinedState.ERROR.toString()));
      message.setToState(stateModelDef.getTypedInitialState());
      message.setStateModelFactoryId(context.getStateModelFactoryId());
View Full Code Here

      }
    }

    Set<String> tags = new HashSet<String>(instanceConfig.getTags());

    RunningInstance runningInstance = null;
    if (liveInstance != null) {
      runningInstance =
          new RunningInstance(liveInstance.getTypedSessionId(),
              liveInstance.getTypedHelixVersion(), liveInstance.getProcessId());
    }

    Map<MessageId, Message> msgMap = new HashMap<MessageId, Message>();
    if (instanceMsgMap != null) {
View Full Code Here

TOP

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

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.