* @param cluster
* @return
*/
private Map<State, Bounds> computeStateConstraints(StateModelDefinition stateModelDefinition,
RebalancerConfig rebalancerConfig, Cluster cluster) {
ReplicatedRebalancerContext context =
(rebalancerConfig != null) ? rebalancerConfig
.getRebalancerContext(ReplicatedRebalancerContext.class) : null;
Map<State, Bounds> stateConstraints = new HashMap<State, Bounds>();
List<State> statePriorityList = stateModelDefinition.getTypedStatesPriorityList();
for (State state : statePriorityList) {
String numInstancesPerState =
cluster.getStateUpperBoundConstraint(Scope.cluster(cluster.getId()),
stateModelDefinition.getStateModelDefId(), state);
int max = -1;
if ("N".equals(numInstancesPerState)) {
max = cluster.getLiveParticipantMap().size();
} else if ("R".equals(numInstancesPerState)) {
// idealState is null when resource has been dropped,
// R can't be evaluated and ignore state constraints
if (context != null) {
if (context.anyLiveParticipant()) {
max = cluster.getLiveParticipantMap().size();
} else {
max = context.getReplicaCount();
}
}
} else {
try {
max = Integer.parseInt(numInstancesPerState);