}
}
public static void validateRolloutPlanStructure(ModelNode plan) throws OperationFailedException {
if(plan == null) {
throw new OperationFailedException(MESSAGES.nullVar("plan").getLocalizedMessage());
}
if(!plan.hasDefined(ROLLOUT_PLAN)) {
throw new OperationFailedException(MESSAGES.requiredChildIsMissing(ROLLOUT_PLAN, ROLLOUT_PLAN, plan.toString()));
}
ModelNode rolloutPlan1 = plan.get(ROLLOUT_PLAN);
final Set<String> keys;
try {
keys = rolloutPlan1.keys();
} catch (IllegalArgumentException e) {
throw new OperationFailedException(MESSAGES.requiredChildIsMissing(ROLLOUT_PLAN, IN_SERIES, plan.toString()));
}
if(!keys.contains(IN_SERIES)) {
throw new OperationFailedException(MESSAGES.requiredChildIsMissing(ROLLOUT_PLAN, IN_SERIES, plan.toString()));
}
if(keys.size() > 2 || keys.size() == 2 && !keys.contains(ROLLBACK_ACROSS_GROUPS)) {
throw new OperationFailedException(MESSAGES.unrecognizedChildren(ROLLOUT_PLAN, IN_SERIES + ", " + ROLLBACK_ACROSS_GROUPS, plan.toString()));
}
final ModelNode inSeries = rolloutPlan1.get(IN_SERIES);
if(!inSeries.isDefined()) {
throw new OperationFailedException(MESSAGES.requiredChildIsMissing(ROLLOUT_PLAN, IN_SERIES, plan.toString()));
}
final List<ModelNode> groups = inSeries.asList();
if(groups.isEmpty()) {
throw new OperationFailedException(MESSAGES.inSeriesIsMissingGroups(plan.toString()));
}
for(ModelNode group : groups) {
if(group.hasDefined(SERVER_GROUP)) {
final ModelNode serverGroup = group.get(SERVER_GROUP);
final Set<String> groupKeys;
try {
groupKeys = serverGroup.keys();
} catch(IllegalArgumentException e) {
throw new OperationFailedException(MESSAGES.serverGroupExpectsSingleChild(plan.toString()));
}
if(groupKeys.size() != 1) {
throw new OperationFailedException(MESSAGES.serverGroupExpectsSingleChild(plan.toString()));
}
validateInSeriesServerGroup(serverGroup.asProperty().getValue());
} else if(group.hasDefined(CONCURRENT_GROUPS)) {
final ModelNode concurrent = group.get(CONCURRENT_GROUPS);
for(ModelNode child: concurrent.asList()) {
validateInSeriesServerGroup(child.asProperty().getValue());
}
} else {
throw new OperationFailedException(MESSAGES.unexpectedInSeriesGroup(plan.toString()));
}
}
}