for (String resourceName : resourceMap.keySet())
{
Resource resource = resourceMap.get(resourceName);
int bucketSize = resource.getBucketSize();
StateModelDefinition stateModelDef = cache.getStateModelDef(resource.getStateModelDefRef());
for (Partition partition : resource.getPartitions())
{
Map<String, String> instanceStateMap = bestPossibleStateOutput.getInstanceStateMap(
resourceName, partition);
for (String instanceName : instanceStateMap.keySet())
{
String desiredState = instanceStateMap.get(instanceName);
String currentState = currentStateOutput.getCurrentState(resourceName, partition,
instanceName);
if (currentState == null)
{
currentState = stateModelDef.getInitialState();
}
if (desiredState.equalsIgnoreCase(currentState))
{
continue;
}
String pendingState = currentStateOutput.getPendingState(resourceName, partition,
instanceName);
String nextState = stateModelDef.getNextStateForTransition(currentState, desiredState);
if (nextState == null)
{
logger.error("Unable to find a next state for partition: "
+ partition.getPartitionName() + " from stateModelDefinition"
+ stateModelDef.getClass() + " from:" + currentState + " to:" + desiredState);
continue;
}
if (pendingState != null)
{
if (nextState.equalsIgnoreCase(pendingState))
{
logger.debug("Message already exists for " + instanceName + " to transit "
+ partition.getPartitionName() + " from " + currentState + " to " + nextState);
} else if (currentState.equalsIgnoreCase(pendingState))
{
logger.info("Message hasn't been removed for " + instanceName + " to transit"
+ partition.getPartitionName() + " to " + pendingState + ", desiredState: "
+ desiredState);
} else
{
logger.info("IdealState changed before state transition completes for "
+ partition.getPartitionName() + " on " + instanceName + ", pendingState: "
+ pendingState + ", currentState: " + currentState + ", nextState: " + nextState);
}
} else
{
Message message = createMessage(manager, resourceName, partition.getPartitionName(),
instanceName, currentState, nextState, sessionIdMap.get(instanceName),
stateModelDef.getId(), resource.getStateModelFactoryname(), bucketSize);
IdealState idealState = cache.getIdealState(resourceName);
// Set timeout of needed
String stateTransition = currentState + "-" + nextState + "_"
+ Message.Attributes.TIMEOUT;
if (idealState != null