}
}
private DomainLevelResult executeOnDomainControllers(Operation operation, ResultHandler handler, OperationRouting routing) throws OperationFailedException {
ControllerTransaction transaction = new ControllerTransaction();
try {
ModelNode operationNode = operation.getOperation();
// Get a copy of the rollout plan so it doesn't get disrupted by any handlers
ModelNode rolloutPlan = operationNode.hasDefined(OPERATION_HEADERS) && operationNode.get(OPERATION_HEADERS).has(ROLLOUT_PLAN)
? operationNode.get(OPERATION_HEADERS).remove(ROLLOUT_PLAN) : null;
// System.out.println("---- Push to hosts");
// Push to hosts, formulate plan, push to servers
Map<String, ModelNode> hostResults = null;
try {
hostResults = pushToHosts(operation, routing, transaction);
}
catch (Exception e) {
ModelNode failureMsg = new ModelNode();
failureMsg.get(DOMAIN_FAILURE_DESCRIPTION).set(e.toString());
throw new OperationFailedException(failureMsg);
}
// System.out.println("---- Pushed to hosts");
ModelNode masterFailureResult = null;
ModelNode hostFailureResults = null;
ModelNode masterResult = hostResults.get(localHostName);
// System.out.println("-----Checking host results");
if (masterResult != null && masterResult.hasDefined(OUTCOME) && FAILED.equals(masterResult.get(OUTCOME).asString())) {
transaction.setRollbackOnly();
masterFailureResult = masterResult.hasDefined(FAILURE_DESCRIPTION) ? masterResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
}
else {
for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
ModelNode hostResult = entry.getValue();
if (hostResult.hasDefined(OUTCOME) && FAILED.equals(hostResult.get(OUTCOME).asString())) {
if (hostFailureResults == null) {
transaction.setRollbackOnly();
hostFailureResults = new ModelNode();
}
ModelNode desc = hostResult.hasDefined(FAILURE_DESCRIPTION) ? hostResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
hostFailureResults.add(entry.getKey(), desc);
}
}
}
// for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
// System.out.println("======================================================");
// System.out.println(entry.getKey());
// System.out.println("======================================================");
// System.out.println(entry.getValue());
// }
if (transaction.isRollbackOnly()) {
ModelNode failureMsg = new ModelNode();
if (masterFailureResult != null) {
failureMsg.get(DOMAIN_FAILURE_DESCRIPTION).set(masterFailureResult);
}
else if (hostFailureResults != null) {
failureMsg.get(HOST_FAILURE_DESCRIPTIONS).set(hostFailureResults);
}
throw new OperationFailedException(failureMsg);
}
// TODO formulate the domain-level result
//....
// Formulate plan
Map<String, Map<ServerIdentity, ModelNode>> opsByGroup = getOpsByGroup(hostResults);
ModelNode compensatingOperation = getCompensatingOperation(operationNode, hostResults);
// System.out.println(compensatingOperation);
DomainLevelResult result;
if (opsByGroup.size() == 0) {
ModelNode singleHostResult = getSingleHostResult(hostResults);
result = new DomainLevelResult(singleHostResult, compensatingOperation);
}
else {
try {
rolloutPlan = getRolloutPlan(rolloutPlan, opsByGroup);
// System.out.println(rolloutPlan);
}
catch (OperationFailedException ofe) {
// treat as a master DC failure
ModelNode failureMsg = new ModelNode();
failureMsg.get(DOMAIN_FAILURE_DESCRIPTION).set(ofe.getFailureDescription());
throw new OperationFailedException(failureMsg);
}
result = new DomainLevelResult(opsByGroup, compensatingOperation, rolloutPlan);
}
return result;
} catch (OperationFailedException ofe) {
transaction.setRollbackOnly();
throw ofe;
} finally {
transaction.commit();
}
}