Package org.apache.helix.model

Examples of org.apache.helix.model.ResourceAssignment


      return null;
    }

    ExternalView externalView =
        _accessor.getProperty(_keyBuilder.externalView(resourceId.stringify()));
    ResourceAssignment resourceAssignment =
        _accessor.getProperty(_keyBuilder.resourceAssignment(resourceId.stringify()));
    return createResource(resourceId, config, idealState, externalView, resourceAssignment);
  }
View Full Code Here


    IdealState newIdealState =
        rebalancer.computeResourceMapping(resourceId.stringify(), idealState, currentStateOutput,
            cache);

    // do the resource assignments
    ResourceAssignment assignment = new ResourceAssignment(resourceId);
    if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
      // customized ideal state uses a map
      for (PartitionId partitionId : newIdealState.getPartitionIdSet()) {
        Set<ParticipantId> disabledParticipants =
            ConstraintBasedAssignment.getDisabledParticipants(cluster.getParticipantMap(),
                partitionId);
        Map<ParticipantId, State> replicaMap =
            ConstraintBasedAssignment.computeCustomizedBestStateForPartition(cluster
                .getLiveParticipantMap().keySet(), stateModelDef, newIdealState
                .getParticipantStateMap(partitionId), currentState.getCurrentStateMap(resourceId,
                partitionId), disabledParticipants, idealState.isEnabled());
        assignment.addReplicaMap(partitionId, replicaMap);
      }
    } else {
      // other modes use auto assignment
      Map<State, String> upperBounds =
          ConstraintBasedAssignment
              .stateConstraints(stateModelDef, resourceId, cluster.getConfig());
      for (PartitionId partitionId : newIdealState.getPartitionIdSet()) {
        Set<ParticipantId> disabledParticipants =
            ConstraintBasedAssignment.getDisabledParticipants(cluster.getParticipantMap(),
                partitionId);
        Map<ParticipantId, State> replicaMap =
            ConstraintBasedAssignment.computeAutoBestStateForPartition(upperBounds, cluster
                .getLiveParticipantMap().keySet(), stateModelDef, newIdealState
                .getPreferenceList(partitionId), currentState.getCurrentStateMap(resourceId,
                partitionId), disabledParticipants, idealState.isEnabled());
        assignment.addReplicaMap(partitionId, replicaMap);
      }
    }
    return assignment;
  }
View Full Code Here

    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

    // 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

    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

        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

    // 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

  @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

    // 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

      // 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

TOP

Related Classes of org.apache.helix.model.ResourceAssignment

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.