Search in sources :

Example 6 with Attachments

use of org.jboss.as.cli.Attachments in project wildfly-core by wildfly.

the class BaseOperationCommand method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    final ModelNode request = buildRequest(ctx);
    Attachments attachments = getAttachments(ctx);
    OperationBuilder builder = new OperationBuilder(request, true);
    for (String path : attachments.getAttachedFiles()) {
        builder.addFileAsAttachment(new File(path));
    }
    final ModelControllerClient client = ctx.getModelControllerClient();
    final OperationResponse operationResponse;
    try {
        operationResponse = client.executeOperation(builder.build(), OperationMessageHandler.DISCARD);
    } catch (Exception e) {
        throw new CommandLineException("Failed to perform operation", e);
    }
    try {
        final ModelNode response = operationResponse.getResponseNode();
        if (!Util.isSuccess(response)) {
            throw new CommandLineException(Util.getFailureDescription(response));
        }
        handleResponse(ctx, operationResponse, Util.COMPOSITE.equals(request.get(Util.OPERATION).asString()));
        operationResponse.close();
    } catch (IOException ex) {
        throw new CommandLineException("Failed to perform operation", ex);
    }
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse) Attachments(org.jboss.as.cli.Attachments) File(java.io.File) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandFormatException(org.jboss.as.cli.CommandFormatException) CommandLineException(org.jboss.as.cli.CommandLineException)

Aggregations

Attachments (org.jboss.as.cli.Attachments)6 ModelNode (org.jboss.dmr.ModelNode)4 File (java.io.File)3 IOException (java.io.IOException)3 CommandFormatException (org.jboss.as.cli.CommandFormatException)3 Batch (org.jboss.as.cli.batch.Batch)3 BatchManager (org.jboss.as.cli.batch.BatchManager)3 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)3 CommandException (org.aesh.command.CommandException)2 CommandLineException (org.jboss.as.cli.CommandLineException)2 Operation (org.jboss.as.controller.client.Operation)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 Executors (java.util.concurrent.Executors)1 Consumer (java.util.function.Consumer)1 Command (org.aesh.command.Command)1 CommandDefinition (org.aesh.command.CommandDefinition)1 CommandResult (org.aesh.command.CommandResult)1 Argument (org.aesh.command.option.Argument)1