final String matchPattern, final MatchPatternStrategy matchPatternStrategy) {
return new DomainDeployment(client, domain, content, name, type, matchPattern, matchPatternStrategy);
}
private DeploymentPlan createPlan(final DeploymentPlanBuilder builder) throws IOException, DuplicateDeploymentNameException, DeploymentFailureException {
DeploymentActionsCompleteBuilder completeBuilder = null;
List<String> existingDeployments = DeploymentInspector.getDeployments(client, name, matchPattern);
switch (type) {
case ADD: {
completeBuilder = builder.add(name, content);
break;
}
case FORCE_ADD: {
if (existingDeployments.contains(name)) {
completeBuilder = builder.replace(name, content);
} else {
completeBuilder = builder.add(name, content);
}
break;
}
case DEPLOY: {
completeBuilder = builder.add(name, content).andDeploy();
break;
}
case FORCE_DEPLOY: {
if (existingDeployments.contains(name)) {
completeBuilder = builder.replace(name, content).deploy(name);
} else {
completeBuilder = builder.add(name, content).andDeploy();
}
break;
}
case REDEPLOY: {
completeBuilder = builder.replace(name, content);
break;
}
case UNDEPLOY: {
validateExistingDeployments(existingDeployments);
completeBuilder = undeployAndRemoveUndeployed(builder, existingDeployments);
break;
}
case UNDEPLOY_IGNORE_MISSING: {
validateExistingDeployments(existingDeployments);
if (!existingDeployments.isEmpty()) {
completeBuilder = undeployAndRemoveUndeployed(builder, existingDeployments);
} else {
return null;
}
}
}
if (completeBuilder != null) {
ServerGroupDeploymentPlanBuilder groupDeploymentBuilder = null;
for (String serverGroupName : domain.getServerGroups()) {
groupDeploymentBuilder = (groupDeploymentBuilder == null ? completeBuilder.toServerGroup(serverGroupName) :
groupDeploymentBuilder.toServerGroup(serverGroupName));
}
if (groupDeploymentBuilder == null) {
throw new DeploymentFailureException("No server groups were defined for the deployment.");
}