FileInputStream is = null;
try {
is = new FileInputStream(f);
ModelNode request = builder.buildRequest();
OperationBuilder op = new OperationBuilder(request);
op.addInputStream(is);
request.get(Util.CONTENT).get(0).get(Util.INPUT_STREAM_INDEX).set(0);
result = client.execute(op.build());
} catch(Exception e) {
ctx.printLine("Failed to replace the deployment: " + e.getLocalizedMessage());
return;
} finally {
StreamUtils.safeClose(is);
}
if(!Util.isSuccess(result)) {
ctx.printLine(Util.getFailureDescription(result));
return;
}
ctx.printLine("'" + name + "' re-deployed successfully.");
} else {
ctx.printLine("'" + name + "' is already deployed (use " + force.getFullName() + " to force re-deploy).");
}
return;
} else {
// deploy
// Actually, the add is performed first.
// But the deploy request is build before to make sure all the required parameters have been provided
ModelNode deployRequest = null;
if (!disabled.isPresent(args)) {
if (ctx.isDomainMode()) {
final List<String> serverGroups;
if (ctx.isDomainMode()) {
if(allServerGroups.isPresent(args)) {
serverGroups = Util.getServerGroups(client);
} else {
String serverGroupsStr = this.serverGroups.getValue(args);
if(serverGroupsStr == null) {
final StringBuilder buf = new StringBuilder();
buf.append("One of ");
if(f != null) {
buf.append(disabled.getFullName()).append(", ");
}
buf.append("--all-server-groups or --server-groups is missing.");
ctx.printLine(buf.toString());
return;
}
serverGroups = Arrays.asList(serverGroupsStr.split(","));
}
if(serverGroups.isEmpty()) {
ctx.printLine("No server group is available.");
return;
}
} else {
serverGroups = null;
}
deployRequest = new ModelNode();
deployRequest.get(Util.OPERATION).set(Util.COMPOSITE);
deployRequest.get(Util.ADDRESS).setEmptyList();
ModelNode steps = deployRequest.get(Util.STEPS);
for (String serverGroup : serverGroups) {
steps.add(Util.configureDeploymentOperation(Util.ADD, name, serverGroup));
}
for (String serverGroup : serverGroups) {
steps.add(Util.configureDeploymentOperation(Util.DEPLOY, name, serverGroup));
}
} else {
deployRequest = new ModelNode();
deployRequest.get(Util.OPERATION).set(Util.DEPLOY);
deployRequest.get(Util.ADDRESS, Util.DEPLOYMENT).set(name);
}
}
// add
if (f != null) {
ModelNode request = new ModelNode();
request.get(Util.OPERATION).set(Util.ADD);
request.get(Util.ADDRESS, Util.DEPLOYMENT).set(name);
if (runtimeName != null) {
request.get(Util.RUNTIME_NAME).set(runtimeName);
}
ModelNode result;
FileInputStream is = null;
try {
is = new FileInputStream(f);
OperationBuilder op = new OperationBuilder(request);
op.addInputStream(is);
request.get(Util.CONTENT).get(0).get(Util.INPUT_STREAM_INDEX).set(0);
result = client.execute(op.build());
} catch (Exception e) {
ctx.printLine("Failed to add the deployment content to the repository: " + e.getLocalizedMessage());
return;
} finally {
StreamUtils.safeClose(is);