for (String partitionName : partErrStates.keySet())
{
String instanceName = partErrStates.get(partitionName);
Map<String, String> partStateMap =
bestPossOutput.getInstanceStateMap(resourceName,
new Partition(partitionName));
partStateMap.put(instanceName, "ERROR");
}
}
}
for (String resourceName : idealStates.keySet())
{
ExternalView extView = extViews.get(resourceName);
if (extView == null)
{
LOG.info("externalView for " + resourceName + " is not available");
return false;
}
// step 0: remove empty map and DROPPED state from best possible state
Map<Partition, Map<String, String>> bpStateMap =
bestPossOutput.getResourceMap(resourceName);
Iterator<Entry<Partition, Map<String, String>>> iter =
bpStateMap.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry<Partition, Map<String, String>> entry = iter.next();
Map<String, String> instanceStateMap = entry.getValue();
if (instanceStateMap.isEmpty())
{
iter.remove();
} else
{
// remove instances with DROPPED state
Iterator<Map.Entry<String, String>> insIter = instanceStateMap.entrySet().iterator();
while (insIter.hasNext())
{
Map.Entry<String, String> insEntry = insIter.next();
String state = insEntry.getValue();
if (state.equalsIgnoreCase("DROPPED"))
{
insIter.remove();
}
}
}
}
// System.err.println("resource: " + resourceName + ", bpStateMap: " + bpStateMap);
// step 1: externalView and bestPossibleState has equal size
int extViewSize = extView.getRecord().getMapFields().size();
int bestPossStateSize = bestPossOutput.getResourceMap(resourceName).size();
if (extViewSize != bestPossStateSize)
{
LOG.info("exterView size (" + extViewSize
+ ") is different from bestPossState size (" + bestPossStateSize
+ ") for resource: " + resourceName);
// System.out.println("extView: " + extView.getRecord().getMapFields());
// System.out.println("bestPossState: " +
// bestPossOutput.getResourceMap(resourceName));
return false;
}
// step 2: every entry in external view is contained in best possible state
for (String partition : extView.getRecord().getMapFields().keySet())
{
Map<String, String> evInstanceStateMap =
extView.getRecord().getMapField(partition);
Map<String, String> bpInstanceStateMap =
bestPossOutput.getInstanceStateMap(resourceName, new Partition(partition));
boolean result =
ClusterStateVerifier.<String, String> compareMap(evInstanceStateMap,
bpInstanceStateMap);
if (result == false)