ModelNode steps = op.get(STEPS);
steps.setEmptyList();
op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(plan.isSingleServerRollback());
// FIXME deal with shutdown params
OperationBuilder builder = new OperationBuilder(op);
int stepNum = 1;
for (DeploymentActionImpl action : plan.getDeploymentActionImpls()) {
final List<String> actionStepIds = new ArrayList<String>();
actionsById.put(action.getId(), actionStepIds);
List<ModelNode> actionSteps = new ArrayList<ModelNode>();
String uniqueName = action.getDeploymentUnitUniqueName();
switch (action.getType()) {
case ADD: {
if (!deployments.contains(uniqueName)) {
// We need to add to the domain
ModelNode step = configureDeploymentOperation(ADD, uniqueName, null);
step.get(RUNTIME_NAME).set(action.getNewContentFileName());
step.get(CONTENT).get(0).get("hash").set(action.getNewContentHash());
actionSteps.add(step);
}
for (String group : serverGroups) {
ModelNode groupStep = configureDeploymentOperation(ADD, uniqueName, group);
actionSteps.add(groupStep);
}
break;
}
case DEPLOY: {
for (String group : serverGroups) {
ModelNode groupStep = configureDeploymentOperation(DEPLOYMENT_DEPLOY_OPERATION, uniqueName, group);
actionSteps.add(groupStep);
}
break;
}
case FULL_REPLACE: {
ModelNode step = new ModelNode();
step.get(OP).set(DEPLOYMENT_FULL_REPLACE_OPERATION);
step.get(OP_ADDR).setEmptyList();
step.get(NAME).set(uniqueName);
step.get(RUNTIME_NAME).set(action.getNewContentFileName());
step.get(CONTENT).get(0).get("hash").set(action.getNewContentHash());
actionSteps.add(step);
break;
}
case REDEPLOY: {
for (String group : serverGroups) {
ModelNode groupStep = configureDeploymentOperation(DEPLOYMENT_REDEPLOY_OPERATION, uniqueName, group);
actionSteps.add(groupStep);
}
break;
}
case REMOVE: {
// From each group
for (String group : serverGroups) {
ModelNode groupStep = configureDeploymentOperation(DEPLOYMENT_REMOVE_OPERATION, uniqueName, group);
actionSteps.add(groupStep);
}
// and from the domain
ModelNode step = configureDeploymentOperation(DEPLOYMENT_REMOVE_OPERATION, uniqueName, null);
actionSteps.add(step);
break;
}
case REPLACE: {
for (String group : serverGroups) {
ModelNode groupStep = new ModelNode();
groupStep.get(OP).set(DEPLOYMENT_REPLACE_OPERATION);
groupStep.get(OP_ADDR).add("server-group", group);
groupStep.get(NAME).set(uniqueName);
groupStep.get(TO_REPLACE).set(action.getReplacedDeploymentUnitUniqueName());
actionSteps.add(groupStep);
}
break;
}
case UNDEPLOY: {
for (String group : serverGroups) {
ModelNode groupStep = configureDeploymentOperation(DEPLOYMENT_UNDEPLOY_OPERATION, uniqueName, group);
actionSteps.add(groupStep);
}
break;
}
default: {
throw MESSAGES.unknownActionType(action.getType());
}
}
for (ModelNode actionStep : actionSteps) {
actionStepIds.add(String.format("step-%d", stepNum++));
steps.add(actionStep);
}
}
return builder.build();
}