Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.helix.controller.rebalancer.context;
  
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
 
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
  * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */

RebalancerContext for a resource that should be rebalanced in CUSTOMIZED mode. By default, it corresponds to org.apache.helix.controller.rebalancer.CustomRebalancer
 
Instantiate a CustomRebalancerContext
 
   public CustomRebalancerContext() {
     setRebalancerRef(RebalancerRef.from(CustomRebalancer.class));
      = Maps.newHashMap();
   }

  
Get the preference maps of the partitions and replicas of the resource

Returns:
map of partition to participant and state
 
     return ;
   }

  
Set the preference maps of the partitions and replicas of the resource

Parameters:
preferenceMaps map of partition to participant and state
 
   public void setPreferenceMaps(Map<PartitionIdMap<ParticipantIdState>> preferenceMaps) {
      = preferenceMaps;
   }

  
Get the preference map of a partition

Parameters:
partitionId the partition to look up
Returns:
map of participant to state
 
   public Map<ParticipantIdStategetPreferenceMap(PartitionId partitionId) {
     return .get(partitionId);
   }

  
Generate preference maps based on a default cluster setup

Parameters:
stateModelDef the state model definition to follow
participantSet the set of participant ids to configure for
 
   @Override
   public void generateDefaultConfiguration(StateModelDefinition stateModelDef,
       Set<ParticipantIdparticipantSet) {
     // compute default upper bounds
     Map<StateStringupperBounds = Maps.newHashMap();
     for (State state : stateModelDef.getTypedStatesPriorityList()) {
       upperBounds.put(statestateModelDef.getNumParticipantsPerState(state));
    }
    // determine the current mapping
    Map<PartitionIdMap<ParticipantIdState>> currentMapping = getPreferenceMaps();
    // determine the preference maps
    LinkedHashMap<StateIntegerstateCounts =
        ConstraintBasedAssignment.stateCount(upperBoundsstateModelDefparticipantSet.size(),
            getReplicaCount());
    ReplicaPlacementScheme placementScheme = new DefaultPlacementScheme();
    List<ParticipantIdparticipantList = new ArrayList<ParticipantId>(participantSet);
    List<PartitionIdpartitionList = new ArrayList<PartitionId>(getPartitionSet());
    AutoRebalanceStrategy strategy =
        new AutoRebalanceStrategy(ResourceId.from(""), partitionListstateCounts,
            getMaxPartitionsPerParticipant(), placementScheme);
    Map<StringMap<StringString>> rawPreferenceMaps =
        strategy.typedComputePartitionAssignment(participantListcurrentMappingparticipantList)
            .getMapFields();
    Map<PartitionIdMap<ParticipantIdState>> preferenceMaps =
        Maps.newHashMap(ResourceAssignment.replicaMapsFromStringMaps(rawPreferenceMaps));
    setPreferenceMaps(preferenceMaps);
  }

  
Build a CustomRebalancerContext. By default, it corresponds to org.apache.helix.controller.rebalancer.CustomRebalancer
  public static final class Builder extends PartitionedRebalancerContext.AbstractBuilder<Builder> {
    private final Map<PartitionIdMap<ParticipantIdState>> _preferenceMaps;

    
Instantiate for a resource

Parameters:
resourceId resource id
    public Builder(ResourceId resourceId) {
      super(resourceId);
      super.rebalancerRef(RebalancerRef.from(CustomRebalancer.class));
       = Maps.newHashMap();
    }

    
Add a preference map for a partition

Parameters:
partitionId partition to set
preferenceList map of participant id to state indicating where replicas are served
Returns:
Builder
    public Builder preferenceMap(PartitionId partitionIdMap<ParticipantIdStatepreferenceMap) {
      .put(partitionIdpreferenceMap);
      return self();
    }
    @Override
    protected Builder self() {
      return this;
    }
    @Override
    public CustomRebalancerContext build() {
      CustomRebalancerContext context = new CustomRebalancerContext();
      super.update(context);
      return context;
    }
  }
New to GrepCode? Check out our FAQ X