}
@Process(actionType = CopyServer.class)
public void onSaveCopy(CopyServer.Values copyValues, final Dispatcher.Channel channel) {
final Server original = copyValues.getOriginal();
final Server newServer = copyValues.getNewServer();
final String targetHost = copyValues.getTargetHost();
final ModelNode operation = new ModelNode();
operation.get(OP).set(READ_RESOURCE_OPERATION);
operation.get(ADDRESS).setEmptyList();
operation.get(ADDRESS).add("host", hostStore.getSelectedHost());
operation.get(ADDRESS).add("server-config", original.getName());
operation.get(RECURSIVE).set(true);
dispatcher.execute(new DMRAction(operation, false), new AsyncCallback<DMRResponse>() {
@Override
public void onFailure(Throwable caught) {
Console.error("Failed to read server-config: " + original.getName(), caught.getMessage());
channel.nack(caught);
}
@Override
public void onSuccess(DMRResponse result) {
ModelNode response = result.get();
if (response.isFailure()) {
Console.error("Failed to read server-config: " + original.getName(), response.getFailureDescription());
} else {
ModelNode model = response.get("result").asObject();
// required attribute changes: portOffset & serverGroup
model.get("socket-binding-port-offset").set(newServer.getPortOffset());
model.remove("name");
// re-create node
ModelNode compositeOp = new ModelNode();
compositeOp.get(OP).set(COMPOSITE);
compositeOp.get(ADDRESS).setEmptyList();
List<ModelNode> steps = new ArrayList<ModelNode>();
final ModelNode rootResourceOp = new ModelNode();
rootResourceOp.get(OP).set(ADD);
rootResourceOp.get(ADDRESS).add("host", targetHost);
rootResourceOp.get(ADDRESS).add("server-config", newServer.getName());
steps.add(rootResourceOp);
DMRUtil.copyResourceValues(model, rootResourceOp, steps);
compositeOp.get(STEPS).set(steps);
dispatcher.execute(new DMRAction(compositeOp), new SimpleCallback<DMRResponse>() {
@Override
public void onSuccess(DMRResponse dmrResponse) {
ModelNode response = dmrResponse.get();
if (response.isFailure()) {
Console.error("Failed to copy server-config", response.getFailureDescription());
} else {
Console.info("Successfully copied server-config '" + newServer.getName() + "'");
}
onRefresh(channel);
}
});