Examples of ResourceAssignment


Examples of org.apache.helix.model.ResourceAssignment

    StateModelDefinition stateModelDef =
        cluster.getStateModelMap().get(idealState.getStateModelDefId());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Processing resource:" + idealState.getResourceId());
    }
    ResourceAssignment partitionMapping = new ResourceAssignment(idealState.getResourceId());
    for (PartitionId partition : idealState.getPartitionIdSet()) {
      Map<ParticipantId, State> currentStateMap =
          currentState.getCurrentStateMap(idealState.getResourceId(), partition);
      Set<ParticipantId> disabledInstancesForPartition =
          ConstraintBasedAssignment.getDisabledParticipants(cluster.getParticipantMap(), partition);
      Map<ParticipantId, State> bestStateForPartition =
          ConstraintBasedAssignment.computeCustomizedBestStateForPartition(cluster
              .getLiveParticipantMap().keySet(), stateModelDef, idealState
              .getParticipantStateMap(partition), currentStateMap, disabledInstancesForPartition,
              isEnabled);
      partitionMapping.addReplicaMap(partition, bestStateForPartition);
    }
    return partitionMapping;
  }
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

    // compute a full partition mapping for the resource
    if (LOG.isDebugEnabled()) {
      LOG.debug("Processing resource:" + idealState.getResourceId());
    }
    ResourceAssignment partitionMapping = new ResourceAssignment(idealState.getResourceId());
    for (PartitionId partition : partitions) {
      Set<ParticipantId> disabledParticipantsForPartition =
          ConstraintBasedAssignment.getDisabledParticipants(allParticipants, partition);
      List<String> rawPreferenceList = newMapping.getListField(partition.stringify());
      if (rawPreferenceList == null) {
        rawPreferenceList = Collections.emptyList();
      }
      List<ParticipantId> preferenceList =
          Lists.transform(rawPreferenceList, new Function<String, ParticipantId>() {
            @Override
            public ParticipantId apply(String participantName) {
              return ParticipantId.from(participantName);
            }
          });
      preferenceList =
          ConstraintBasedAssignment.getPreferenceList(cluster, partition, preferenceList);
      Map<ParticipantId, State> bestStateForPartition =
          ConstraintBasedAssignment.computeAutoBestStateForPartition(upperBounds,
              liveParticipants.keySet(), stateModelDef, preferenceList,
              currentState.getCurrentStateMap(idealState.getResourceId(), partition),
              disabledParticipantsForPartition, isEnabled);
      partitionMapping.addReplicaMap(partition, bestStateForPartition);
    }
    return partitionMapping;
  }
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

    StateModelDefinition stateModelDef =
        cluster.getStateModelMap().get(idealState.getStateModelDefId());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Processing resource:" + idealState.getResourceId());
    }
    ResourceAssignment partitionMapping = new ResourceAssignment(idealState.getResourceId());

    for (PartitionId partition : idealState.getPartitionIdSet()) {
      Map<ParticipantId, State> currentStateMap =
          currentState.getCurrentStateMap(idealState.getResourceId(), partition);
      Set<ParticipantId> disabledInstancesForPartition =
          ConstraintBasedAssignment.getDisabledParticipants(cluster.getParticipantMap(), partition);
      List<ParticipantId> preferenceList =
          ConstraintBasedAssignment.getPreferenceList(cluster, partition,
              idealState.getPreferenceList(partition));
      Map<State, String> upperBounds =
          ConstraintBasedAssignment.stateConstraints(stateModelDef, idealState.getResourceId(),
              cluster.getConfig());

      Map<ParticipantId, State> bestStateForPartition =
          ConstraintBasedAssignment.computeAutoBestStateForPartition(upperBounds, cluster
              .getLiveParticipantMap().keySet(), stateModelDef, preferenceList, currentStateMap,
              disabledInstancesForPartition, isEnabled);
      partitionMapping.addReplicaMap(partition, bestStateForPartition);
    }
    return partitionMapping;
  }
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

        ResourceCurrentState currentState) {
      StateModelDefinition stateModelDef =
          cluster.getStateModelMap().get(idealState.getStateModelDefId());
      List<ParticipantId> liveParticipants =
          new ArrayList<ParticipantId>(cluster.getLiveParticipantMap().keySet());
      ResourceAssignment resourceMapping = new ResourceAssignment(idealState.getResourceId());
      int i = 0;
      for (PartitionId partitionId : idealState.getPartitionIdSet()) {
        int nodeIndex = i % liveParticipants.size();
        Map<ParticipantId, State> replicaMap = new HashMap<ParticipantId, State>();
        replicaMap.put(liveParticipants.get(nodeIndex), stateModelDef.getTypedStatesPriorityList()
            .get(0));
        resourceMapping.addReplicaMap(partitionId, replicaMap);
        i++;
      }
      testRebalancerInvoked = true;

      // set some basic context
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

    // TODO all ideal-states should be included in external-views

    for (String resourceName : externalViews.keySet()) {
      ExternalView externalView = externalViews.get(resourceName);
      ResourceAssignment assignment =
          bestPossbileStates.getResourceAssignment(ResourceId.from(resourceName));
      final Map<PartitionId, Map<String, String>> bestPossibleState = Maps.newHashMap();
      for (PartitionId partitionId : assignment.getMappedPartitionIds()) {
        Map<String, String> rawStateMap =
            ResourceAssignment.stringMapFromReplicaMap(assignment.getReplicaMap(partitionId));
        bestPossibleState.put(partitionId, rawStateMap);
      }
      success = verifyExternalView(externalView, bestPossibleState);
      if (!success) {
        LOG.info("external-view for resource: " + resourceName + " not match");
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

  @Override
  public ResourceAssignment computeResourceMapping(IdealState idealState,
      RebalancerConfig rebalancerConfig, ResourceAssignment prevAssignment, Cluster cluster,
      ResourceCurrentState currentState) {
    // Initialize an empty mapping of locks to participants
    ResourceAssignment assignment = new ResourceAssignment(idealState.getResourceId());

    // Get the list of live participants in the cluster
    List<ParticipantId> liveParticipants =
        new ArrayList<ParticipantId>(cluster.getLiveParticipantMap().keySet());

    // Get the state model (should be a simple lock/unlock model) and the highest-priority state
    StateModelDefId stateModelDefId = idealState.getStateModelDefId();
    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 {
      // a numeric value is a custom-specified number of participants allowed to lock the lock
      lockHolders = Integer.parseInt(stateCount);
    } catch (NumberFormatException e) {
      LOG.error("Invalid state model definition. The lock state does not have a valid count");
      return assignment;
    }

    // Fairly assign the lock state to the participants using a simple mod-based sequential
    // assignment. For instance, if each lock can be held by 3 participants, lock 0 would be held
    // by participants (0, 1, 2), lock 1 would be held by (1, 2, 3), and so on, wrapping around the
    // number of participants as necessary.
    // This assumes a simple lock-unlock model where the only state of interest is which nodes have
    // acquired each lock.
    int i = 0;
    for (PartitionId partition : idealState.getPartitionIdSet()) {
      Map<ParticipantId, State> replicaMap = new HashMap<ParticipantId, State>();
      for (int j = i; j < i + lockHolders; j++) {
        int participantIndex = j % liveParticipants.size();
        ParticipantId participant = liveParticipants.get(participantIndex);
        // enforce that a participant can only have one instance of a given lock
        if (!replicaMap.containsKey(participant)) {
          replicaMap.put(participant, lockState);
        }
      }
      assignment.addReplicaMap(partition, replicaMap);
      i++;
    }
    return assignment;
  }
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

    // Convert to perInstanceResource beanName->partition->state
    Map<PerInstanceResourceMonitor.BeanName, Map<PartitionId, State>> beanMap =
        new HashMap<PerInstanceResourceMonitor.BeanName, Map<PartitionId, State>>();
    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)) {
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

      // set error states
      if (errStates != null) {
        for (String resourceName : errStates.keySet()) {
          ResourceId resourceId = ResourceId.from(resourceName);
          Map<String, String> partErrStates = errStates.get(resourceName);
          ResourceAssignment resourceAssignment = bestPossOutput.getResourceAssignment(resourceId);

          ResourceAssignmentBuilder raBuilder = new ResourceAssignmentBuilder(resourceId);
          List<? extends PartitionId> mappedPartitions = resourceAssignment.getMappedPartitionIds();
          for (PartitionId partitionId : mappedPartitions) {
            raBuilder.addAssignments(partitionId, resourceAssignment.getReplicaMap(partitionId));
          }

          for (String partitionName : partErrStates.keySet()) {
            String instanceName = partErrStates.get(partitionName);
            PartitionId partitionId = PartitionId.from(partitionName);
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

    // Verify the result
    BestPossibleStateOutput bestPossibleStateOutput =
        event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());
    Assert.assertNotNull(bestPossibleStateOutput);
    ResourceId resourceId = ResourceId.from("TestDB0");
    ResourceAssignment assignment = bestPossibleStateOutput.getResourceAssignment(resourceId);
    Assert.assertNotNull(assignment);
    Resource resource = cluster.getResource(resourceId);
    verifySemiAutoRebalance(resource, assignment);

    System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
View Full Code Here

Examples of org.apache.helix.model.ResourceAssignment

    Cluster cluster = clusterAccessor.readCluster();

    ResourceId resourceId = ResourceId.from("TestDB0");
    Resource resource = cluster.getResource(resourceId);
    ResourceCurrentState currentStateOutput = new ResourceCurrentState();
    ResourceAssignment semiAutoResult =
        resource
            .getIdealState()
            .getRebalancerRef()
            .getRebalancer()
            .computeResourceMapping(resource.getIdealState(), resource.getRebalancerConfig(), null,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.