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;
}