Java Code Examples for org.jboss.as.controller.client.ModelControllerClient#executeOperation()

The following examples show how to use org.jboss.as.controller.client.ModelControllerClient#executeOperation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseStreamTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void readLogFile(ModelNode opNode, ModelControllerClient client, boolean forServer) throws IOException {
    Operation op = OperationBuilder.create(opNode).build();
    OperationResponse response = null;
    try {
        response = client.executeOperation(op, OperationMessageHandler.DISCARD);

        ModelNode respNode = response.getResponseNode();
        System.out.println(respNode.toString());
        Assert.assertEquals(respNode.toString(), "success", respNode.get("outcome").asString());
        ModelNode result = respNode.get("result");
        Assert.assertEquals(respNode.toString(), ModelType.STRING, result.getType());
        List<? extends OperationResponse.StreamEntry> streams = response.getInputStreams();
        Assert.assertEquals(1, streams.size());
        processResponseStream(response, result.asString(), forServer, client == masterClient);

    } finally {
        StreamUtils.safeClose(response);
    }

}
 
Example 2
Source File: BaseOperationCommand.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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);
    }
}