* @param batchMessageMode true if batch messaging allowed, false otherwise
* @return IdealState, or null
*/
static IdealState rebalancerConfigToIdealState(RebalancerConfig config, int bucketSize,
boolean batchMessageMode) {
PartitionedRebalancerContext partitionedContext =
config.getRebalancerContext(PartitionedRebalancerContext.class);
if (partitionedContext != null) {
IdealState idealState = new IdealState(partitionedContext.getResourceId());
idealState.setRebalanceMode(partitionedContext.getRebalanceMode());
idealState.setRebalancerRef(partitionedContext.getRebalancerRef());
String replicas = null;
if (partitionedContext.anyLiveParticipant()) {
replicas = StateModelToken.ANY_LIVEINSTANCE.toString();
} else {
replicas = Integer.toString(partitionedContext.getReplicaCount());
}
idealState.setReplicas(replicas);
idealState.setNumPartitions(partitionedContext.getPartitionSet().size());
idealState.setInstanceGroupTag(partitionedContext.getParticipantGroupTag());
idealState.setMaxPartitionsPerInstance(partitionedContext.getMaxPartitionsPerParticipant());
idealState.setStateModelDefId(partitionedContext.getStateModelDefId());
idealState.setStateModelFactoryId(partitionedContext.getStateModelFactoryId());
idealState.setBucketSize(bucketSize);
idealState.setBatchMessageMode(batchMessageMode);
if (partitionedContext.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
SemiAutoRebalancerContext semiAutoContext =
config.getRebalancerContext(SemiAutoRebalancerContext.class);
for (PartitionId partitionId : semiAutoContext.getPartitionSet()) {
idealState.setPreferenceList(partitionId, semiAutoContext.getPreferenceList(partitionId));
}
} else if (partitionedContext.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
CustomRebalancerContext customContext =
config.getRebalancerContext(CustomRebalancerContext.class);
for (PartitionId partitionId : customContext.getPartitionSet()) {
idealState.setParticipantStateMap(partitionId,
customContext.getPreferenceMap(partitionId));
}
} else {
for (PartitionId partitionId : partitionedContext.getPartitionSet()) {
List<ParticipantId> preferenceList = Collections.emptyList();
idealState.setPreferenceList(partitionId, preferenceList);
Map<ParticipantId, State> participantStateMap = Collections.emptyMap();
idealState.setParticipantStateMap(partitionId, participantStateMap);
}