operation.get(STEPS).set(steps);
dispatcher.execute(new DMRAction(operation), new SimpleCallback<DMRResponse>() {
@Override
public void onSuccess(final DMRResponse response) {
Principals principals = new Principals();
RoleAssignments assignments = new RoleAssignments();
Roles roles = new Roles();
ModelNode result = response.get();
if (result.isFailure()) {
control.getContext().setError(
new RuntimeException("Failed to load contents: " + result.getFailureDescription()));
control.abort();
} else {
ModelNode stepsResult = result.get(RESULT);
// the order of processing is important!
ModelNode standardRoleNames = stepsResult.get("step-1");
if (standardRoleNames.get(RESULT).isDefined()) {
for (ModelNode node : standardRoleNames.get(RESULT).asList()) {
StandardRole.add(node.asString());
}
for (StandardRole standardRole : StandardRole.values()) {
roles.add(new Role(standardRole));
}
}
if (!presenter.isStandalone()) {
List<ModelNode> hostScopedRoles = stepsResult.get("step-2").get(RESULT).asList();
for (ModelNode node : hostScopedRoles) {
addScopedRole(roles, node.asProperty(), "hosts", HOST);
}
List<ModelNode> serverGroupScopedRoles = stepsResult.get("step-3").get(RESULT).asList();
for (ModelNode node : serverGroupScopedRoles) {
addScopedRole(roles, node.asProperty(), "server-groups", SERVER_GROUP);
}
}
List<ModelNode> roleMappings =
stepsResult.get(presenter.isStandalone() ? "step-2" : "step-4").get(RESULT)
.asList();
for (ModelNode node : roleMappings) {
addInternalRoleAssignment(principals, assignments, roles, node.asProperty());
}
// All entities are read - now transform the role assignments from the management model to
// role assignments used in the UI
assignments.toUI(principals);
if (!presenter.isInitialized()) {
String provider = "undefined";
String step = presenter.isStandalone() ? "step-3" : "step-5";
ModelNode providerNode = stepsResult.get(step);