public ModelNode buildRequest(CommandContext ctx) throws CommandFormatException {
ParsedCommandLine args = ctx.getParsedCommandLine();
if (!args.hasProperties()) {
throw new OperationFormatException("Required arguments are missing.");
}
final String filePath = path.getValue(args);
String name = this.name.getValue(args);
String runtimeName = rtName.getValue(args);
final File f;
if(filePath != null ) {
f = new File(filePath);
if(!f.exists()) {
throw new OperationFormatException(f.getAbsolutePath() + " doesn't exist.");
}
if(name == null) {
name = f.getName();
}
} else {
f = null;
if(name == null) {
throw new CommandFormatException("Either file path or --name has to be specified.");
}
}
if(Util.isDeploymentInRepository(name, ctx.getModelControllerClient()) && f != null) {
if(force.isPresent(args)) {
DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
// replace
builder = new DefaultOperationRequestBuilder();
builder.setOperationName(Util.FULL_REPLACE_DEPLOYMENT);
builder.addProperty(Util.NAME, name);
if(runtimeName != null) {
builder.addProperty(Util.RUNTIME_NAME, runtimeName);
}
byte[] bytes = readBytes(f);
builder.getModelNode().get(Util.CONTENT).get(0).get(Util.BYTES).set(bytes);
return builder.buildRequest();
} else {
throw new OperationFormatException("'" + name + "' is already deployed (use -f to force re-deploy).");
}
}
final List<String> serverGroups;
if (ctx.isDomainMode()) {
if(allServerGroups.isPresent(args)) {
serverGroups = Util.getServerGroups(ctx.getModelControllerClient());
} else {
String serverGroupsStr = this.serverGroups.getValue(args);
if(serverGroupsStr == null) {
throw new OperationFormatException("Either --all-server-groups or --server-groups must be specified.");
}
serverGroups = Arrays.asList(serverGroupsStr.split(","));
}
if(serverGroups.isEmpty() && !disabled.isPresent(args)) {
new OperationFormatException("No server group is available.");
}
} else {
serverGroups = null;
}