use of org.jboss.as.cli.RequestWithAttachments in project wildfly-core by wildfly.
the class OperationRequestHandler method handle.
/* (non-Javadoc)
* @see org.jboss.as.cli.CommandHandler#handle(org.jboss.as.cli.CommandContext)
*/
@Override
public void handle(CommandContext ctx) throws CommandLineException {
ModelControllerClient client = ctx.getModelControllerClient();
if (client == null) {
throw new CommandFormatException("You are disconnected at the moment." + " Type 'connect' to connect to the server" + " or 'help' for the list of supported commands.");
}
RequestWithAttachments reqWithAttachments = (RequestWithAttachments) ctx.get(Scope.REQUEST, "OP_REQ");
if (reqWithAttachments == null) {
throw new CommandLineException("Parsed request isn't available.");
}
ModelNode request = reqWithAttachments.getRequest();
OperationBuilder opBuilder = new OperationBuilder(request, true);
for (String path : reqWithAttachments.getAttachedFiles()) {
opBuilder.addFileAsAttachment(new File(path));
}
Operation op = opBuilder.build();
if (ctx.getConfig().isValidateOperationRequests()) {
ModelNode opDescOutcome = Util.validateRequest(ctx, request);
if (opDescOutcome != null) {
// operation has params that might need to be replaced
Util.replaceFilePathsWithBytes(request, opDescOutcome);
}
}
try {
final ModelNode result = ctx.execute(op, "Operation request");
if (Util.isSuccess(result)) {
ctx.printDMR(result);
} else {
if (!ctx.getConfig().isOutputJSON()) {
throw new CommandLineException(result.toString());
} else {
throw new CommandLineException(result.toJSONString(false));
}
}
} catch (NoSuchElementException e) {
throw new CommandLineException("ModelNode request is incomplete", e);
} catch (CancellationException e) {
throw new CommandLineException("The result couldn't be retrieved (perhaps the task was cancelled", e);
} catch (IOException e) {
if (e.getCause() != null && !(e.getCause() instanceof InterruptedException)) {
ctx.disconnectController();
}
throw new CommandLineException("Communication error", e);
} catch (RuntimeException e) {
throw new CommandLineException("Failed to execute operation.", e);
}
}
use of org.jboss.as.cli.RequestWithAttachments in project wildfly-core by wildfly.
the class CommandContextImpl method handleOperation.
private void handleOperation(ParsedCommandLine parsedLine) throws CommandFormatException, CommandLineException {
if (isBatchMode()) {
String line = parsedLine.getOriginalLine();
Batch batch = getBatchManager().getActiveBatch();
final ModelNode request = Util.toOperationRequest(this, parsedLine, batch.getAttachments());
StringBuilder op = new StringBuilder();
op.append(getNodePathFormatter().format(parsedLine.getAddress()));
op.append(line.substring(line.indexOf(':')));
DefaultBatchedCommand batchedCmd = new DefaultBatchedCommand(this, op.toString(), request, null);
batch.add(batchedCmd);
} else {
Attachments attachments = new Attachments();
final ModelNode op = Util.toOperationRequest(CommandContextImpl.this, parsedLine, attachments);
RequestWithAttachments req = new RequestWithAttachments(op, attachments);
set(Scope.REQUEST, "OP_REQ", req);
operationHandler.handle(this);
}
}
Aggregations