final List<INodeEntry> nodes1 = INodeEntryComparator.rankOrderedNodes(nodes, context
.getNodeRankAttribute(),
context.isNodeRankOrderAscending());
//reorder based on configured rank property and order
NodeStepException caught = null;
INodeEntry failedNode = null;
for (final INodeEntry node : nodes1) {
if (thread.isInterrupted()
|| thread instanceof ServiceThreadBase && ((ServiceThreadBase) thread).isAborted()) {
interrupted = true;
break;
}
context.getExecutionListener().log(Constants.DEBUG_LEVEL,
"Executing command on node: " + node.getNodename() + ", "
+ node.toString());
try {
if (thread.isInterrupted()
|| thread instanceof ServiceThreadBase && ((ServiceThreadBase) thread).isAborted()) {
interrupted = true;
break;
}
final NodeStepResult result;
//execute the step or dispatchable
if (null != item) {
result = framework.getExecutionService().executeNodeStep(context, item, node);
} else {
result = toDispatch.dispatch(context, node);
}
resultMap.put(node.getNodename(), result);
if (!result.isSuccess()) {
success = false;
// context.getExecutionListener().log(Constants.ERR_LEVEL,
// "Failed execution for node " + node.getNodename() + ": " + result);
failures.put(node.getNodename(), result);
if (!keepgoing) {
failedNode = node;
break;
}
} else {
nodeNames.remove(node.getNodename());
}
} catch (NodeStepException e) {
success = false;
failures.put(node.getNodename(),
new NodeStepResultImpl(e, e.getFailureReason(), e.getMessage(), node)
);
context.getExecutionListener().log(Constants.ERR_LEVEL,
"Failed dispatching to node " + node.getNodename() + ": "
+ e.getMessage());
final StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
context.getExecutionListener().log(Constants.DEBUG_LEVEL,
"Failed dispatching to node " + node.getNodename() + ": "
+ stringWriter.toString());
if (!keepgoing) {
failedNode = node;
caught = e;
break;
}
}
}
if (!keepgoing && failures.size() > 0 && null != failedListener) {
//tell listener of failed node list
failedListener.nodesFailed(failures);
}
if (!keepgoing && null != caught) {
throw new DispatcherException(
"Failed dispatching to node " + failedNode.getNodename() + ": " + caught.getMessage(), caught,
failedNode);
}
if (keepgoing && nodeNames.size() > 0) {
if (null != failedListener) {
//tell listener of failed node list