Package org.apache.helix.model

Examples of org.apache.helix.model.ResourceAssignment


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

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

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


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

    Cluster cluster = clusterAccessor.readCluster();

    ResourceId resourceId = ResourceId.from("TestDB0");
    Resource resource = cluster.getResource(resourceId);
    ResourceCurrentState currentStateOutput = new ResourceCurrentState();
    ResourceAssignment semiAutoResult =
        resource.getRebalancerConfig().getRebalancer()
            .computeResourceMapping(resource.getRebalancerConfig(), cluster, currentStateOutput);
    verifySemiAutoRebalance(resource, semiAutoResult);

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

    HelixDataAccessor accessor = helixManager.getHelixDataAccessor();
    ResourceAccessor resourceAccessor = new ResourceAccessor(accessor);
    BestPossibleStateOutput assignments =
        event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());
    for (ResourceId resourceId : assignments.getAssignedResources()) {
      ResourceAssignment assignment = assignments.getResourceAssignment(resourceId);
      resourceAccessor.setResourceAssignment(resourceId, assignment);
    }
  }
View Full Code Here

          config.getRebalancerContext(PartitionedRebalancerContext.class);
      StateModelDefinition stateModelDef =
          cluster.getStateModelMap().get(context.getStateModelDefId());
      List<ParticipantId> liveParticipants =
          new ArrayList<ParticipantId>(cluster.getLiveParticipantMap().keySet());
      ResourceAssignment resourceMapping = new ResourceAssignment(context.getResourceId());
      int i = 0;
      for (PartitionId partitionId : context.getPartitionSet()) {
        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;
      return resourceMapping;
    }
View Full Code Here

      RebalancerContext rebalancerCtx =
          resourceConfig.getRebalancerConfig().getRebalancerContext(RebalancerContext.class);
      StateModelDefinition stateModelDef = stateModelDefMap.get(rebalancerCtx.getStateModelDefId());

      ResourceAssignment resourceAssignment =
          bestPossibleStateOutput.getResourceAssignment(resourceId);
      for (PartitionId subUnitId : resourceAssignment.getMappedPartitionIds()) {
        Map<ParticipantId, State> instanceStateMap = resourceAssignment.getReplicaMap(subUnitId);

        // we should generate message based on the desired-state priority
        // 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>>();
View Full Code Here

   * @param stateModelDef state model the resource follows
   * @return assignment for the dropped resource
   */
  private ResourceAssignment mapDroppedResource(Cluster cluster, ResourceId resourceId,
      ResourceCurrentState currentStateOutput, StateModelDefinition stateModelDef) {
    ResourceAssignment partitionMapping = new ResourceAssignment(resourceId);
    Set<PartitionId> mappedPartitions =
        currentStateOutput.getCurrentStateMappedPartitions(resourceId);
    if (mappedPartitions == null) {
      return partitionMapping;
    }
    for (PartitionId partitionId : mappedPartitions) {
      Set<ParticipantId> disabledParticipantsForPartition =
          ConstraintBasedAssignment.getDisabledParticipants(cluster.getParticipantMap(),
              partitionId);
      Map<State, String> upperBounds =
          ConstraintBasedAssignment
              .stateConstraints(stateModelDef, resourceId, cluster.getConfig());
      partitionMapping.addReplicaMap(partitionId, ConstraintBasedAssignment
          .computeAutoBestStateForPartition(upperBounds, cluster.getLiveParticipantMap().keySet(),
              stateModelDef, null, currentStateOutput.getCurrentStateMap(resourceId, partitionId),
              disabledParticipantsForPartition));
    }
    return partitionMapping;
View Full Code Here

      }
      ResourceConfig resourceConfig = resourceMap.get(resourceId);
      RebalancerConfig rebalancerConfig = resourceConfig.getRebalancerConfig();
      RebalancerContext context = rebalancerConfig.getRebalancerContext(RebalancerContext.class);
      StateModelDefinition stateModelDef = stateModelDefs.get(context.getStateModelDefId());
      ResourceAssignment resourceAssignment = null;
      if (rebalancerConfig != null) {
        HelixRebalancer rebalancer = rebalancerConfig.getRebalancer();
        HelixManager manager = event.getAttribute("helixmanager");
        if (rebalancer == null) {
          rebalancer = new FallbackRebalancer();
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

    if (!isReady) {
      return emptyAssignment(resourceName, currStateOutput);
    }

    // Grab the old assignment, or an empty one if it doesn't exist
    ResourceAssignment prevAssignment = TaskUtil.getPrevResourceAssignment(_manager, resourceName);
    if (prevAssignment == null) {
      prevAssignment = new ResourceAssignment(resourceName);
    }

    // Will contain the list of partitions that must be explicitly dropped from the ideal state that
    // is stored in zk.
    // Fetch the previous resource assignment from the property store. This is required because of
    // HELIX-230.
    Set<Integer> partitionsToDrop = new TreeSet<Integer>();

    ResourceAssignment newAssignment =
        computeResourceMapping(resourceName, workflowCfg, jobCfg, prevAssignment, clusterData
            .getLiveInstances().keySet(), currStateOutput, workflowCtx, jobCtx, partitionsToDrop,
            clusterData);

    if (!partitionsToDrop.isEmpty()) {
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.