Package org.apache.helix.api

Examples of org.apache.helix.api.Participant


      containerConfig = new ContainerConfig(containerId, containerSpec, containerState);
    }

    // Populate the logical class
    ParticipantConfig participantConfig = ParticipantConfig.from(instanceConfig);
    return new Participant(participantConfig, liveInstance, curStateMap, msgMap, containerConfig);
  }
View Full Code Here


    Map<String, Integer> throttleCounterMap = new HashMap<String, Integer>();

    if (constraint != null) {
      // go through all pending messages, they should be counted but not throttled
      for (ParticipantId participantId : cluster.getLiveParticipantMap().keySet()) {
        Participant liveParticipant = cluster.getLiveParticipantMap().get(participantId);
        throttle(throttleCounterMap, constraint, new ArrayList<Message>(liveParticipant
            .getMessageMap().values()), false);
      }
    }

    // go through all new messages, throttle if necessary
View Full Code Here

            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")))));
    liveInstances.put(ParticipantId.from("localhost_1"),
        new Participant(ParticipantId.from("localhost_1"), "localhost", 1, true,
            disabledPartitions, tags, runningInstance1, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_1")))));

    Map<ParticipantId, State> currentStates = new HashMap<ParticipantId, State>();
    currentStates.put(ParticipantId.from("localhost_0"), State.from("SLAVE"));
View Full Code Here

            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")))));
    liveInstances.put(ParticipantId.from("localhost_1"),
        new Participant(ParticipantId.from("localhost_1"), "localhost", 1, true,
            disabledPartitions, tags, runningInstance1, currentStateMap, messageMap,
            new UserConfig(Scope.participant(ParticipantId.from("localhost_1")))));

    Map<ParticipantId, State> currentStates = new HashMap<ParticipantId, State>();
    currentStates.put(ParticipantId.from("localhost_0"), State.from("SLAVE"));
View Full Code Here

    boolean created = createParticipant(participantId, accessor, MODIFIER, 1);
    Assert.assertTrue(created);

    // read the participant
    ParticipantAccessor participantAccessor = new ParticipantAccessor(helixAccessor);
    Participant participantSnapshot = participantAccessor.readParticipant(participantId);
    Assert.assertEquals(participantSnapshot.getUserConfig().getIntField(MODIFIER, -1), 1);

    // create a participant with the same id
    boolean created2 = createParticipant(participantId, accessor, MODIFIER, 2);
    Assert.assertFalse(created2); // should fail since participant exists

    // remove a required property
    helixAccessor.removeProperty(helixAccessor.keyBuilder().messages(participantId.stringify()));

    // try again, should work this time
    created2 = createParticipant(participantId, accessor, MODIFIER, 2);
    Assert.assertTrue(created2);

    // read the cluster again
    participantSnapshot = participantAccessor.readParticipant(participantId);
    Assert.assertEquals(participantSnapshot.getUserConfig().getIntField(MODIFIER, -1), 2);

    accessor.dropCluster();
  }
View Full Code Here

    Set<ParticipantId> participantSet = new HashSet<ParticipantId>(participantMap.keySet());
    Set<ParticipantId> disabledParticipantsForPartition =
        Sets.filter(participantSet, new Predicate<ParticipantId>() {
          @Override
          public boolean apply(ParticipantId participantId) {
            Participant participant = participantMap.get(participantId);
            return !participant.isEnabled()
                || participant.getDisabledPartitionIds().contains(partitionId);
          }
        });
    return disabledParticipantsForPartition;
  }
View Full Code Here

    ParticipantAccessor accessor =
        new AtomicParticipantAccessor(_clusterId, _accessor, _lockProvider);
    List<String> participantNames = _accessor.getChildNames(_keyBuilder.instanceConfigs());
    for (String participantName : participantNames) {
      ParticipantId participantId = ParticipantId.from(participantName);
      Participant participant = accessor.readParticipant(participantId);
      if (participant != null) {
        participants.put(participantId, participant);
      }
    }
    return participants;
View Full Code Here

  void listParticipantInfo(String[] optValues) {
    String clusterName = optValues[0];
    String participantName = optValues[1];
    ParticipantAccessor accessor = participantAccessor(clusterName);
    ParticipantId participantId = ParticipantId.from(participantName);
    Participant participant = accessor.readParticipant(participantId);
    StringBuilder sb =
        new StringBuilder("Participant ").append(participantName).append(" in cluster ")
            .append(clusterName).append(":\n").append("hostName: ")
            .append(participant.getHostName()).append(", port: ").append(participant.getPort())
            .append(", enabled: ").append(participant.isEnabled()).append(", disabledPartitions: ")
            .append(participant.getDisabledPartitionIds().toString()).append(", tags:")
            .append(participant.getTags().toString()).append(", currentState: ")
            .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

   * @return true if partitions reset, false otherwise
   */
  public boolean resetPartitionsForParticipant(ParticipantId participantId, ResourceId resourceId,
      Set<PartitionId> resetPartitionIdSet) {
    // make sure the participant is running
    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;
View Full Code Here

   * @param participantDelta changes to the participant
   * @return ParticipantConfig, or null if participant is not persisted
   */
  public ParticipantConfig updateParticipant(ParticipantId participantId,
      ParticipantConfig.Delta participantDelta) {
    Participant participant = readParticipant(participantId);
    if (participant == null) {
      LOG.error("Participant " + participantId + " does not exist, cannot be updated");
      return null;
    }
    ParticipantConfig config = participantDelta.mergeInto(participant.getConfig());
    setParticipant(config);
    return config;
  }
View Full Code Here

TOP

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

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.