Search in sources :

Example 1 with OperationResponse

use of org.jboss.as.controller.client.OperationResponse in project wildfly by wildfly.

the class PrintDataTestCase method printData.

private void printData(Path file, boolean secret, boolean archive) throws Exception {
    ModelNode printDataOp = new ModelNode();
    printDataOp.get(OP_ADDR).add("subsystem", "messaging-activemq");
    printDataOp.get(OP_ADDR).add("server", "default");
    printDataOp.get(OP).set("print-data");
    printDataOp.get("secret").set(secret);
    printDataOp.get("archive").set(archive);
    OperationResponse response = managementClient.getControllerClient().executeOperation(Operation.Factory.create(printDataOp), OperationMessageHandler.logging);
    ModelNode result = response.getResponseNode();
    System.out.println("result = " + result);
    boolean success = SUCCESS.equals(result.get(OUTCOME).asString());
    if (success) {
        String uuid = result.get(RESULT).get("uuid").asString();
        try (InputStream in = response.getInputStream(uuid).getStream()) {
            Files.copy(in, file);
        }
    } else {
        throw new Exception("Operation failed " + result.get(FAILURE_DESCRIPTION));
    }
}
Also used : InputStream(java.io.InputStream) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse) NamingException(javax.naming.NamingException) IOException(java.io.IOException) JMSException(javax.jms.JMSException)

Example 2 with OperationResponse

use of org.jboss.as.controller.client.OperationResponse in project wildfly by wildfly.

the class ServerHelper method readLogFileFromModel.

public static List<JsonObject> readLogFileFromModel(final String logFileName, final String... addressPrefix) throws IOException {
    final Collection<String> addr = new ArrayList<>();
    if (addressPrefix != null) {
        Collections.addAll(addr, addressPrefix);
    }
    addr.add("subsystem");
    addr.add("logging");
    addr.add("log-file");
    addr.add(logFileName);
    final ModelNode address = Operations.createAddress(addr);
    final ModelNode op = Operations.createReadAttributeOperation(address, "stream");
    try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {
        final OperationResponse response = client.executeOperation(Operation.Factory.create(op), OperationMessageHandler.logging);
        final ModelNode result = response.getResponseNode();
        if (Operations.isSuccessfulOutcome(result)) {
            final OperationResponse.StreamEntry entry = response.getInputStream(Operations.readResult(result).asString());
            if (entry == null) {
                throw new RuntimeException(String.format("Failed to find entry with UUID %s for log file %s", Operations.readResult(result).asString(), logFileName));
            }
            final List<JsonObject> lines = new ArrayList<>();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(entry.getStream(), StandardCharsets.UTF_8))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    try (JsonReader jsonReader = Json.createReader(new StringReader(line))) {
                        lines.add(jsonReader.readObject());
                    }
                }
            }
            return lines;
        }
        throw new RuntimeException(String.format("Failed to read log file %s: %s", logFileName, Operations.getFailureDescription(result).asString()));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse)

Example 3 with OperationResponse

use of org.jboss.as.controller.client.OperationResponse in project wildfly by wildfly.

the class AbstractConfigTestCase method readLogFileFromModel.

private BufferedReader readLogFileFromModel(final String profileName, final String logFileName) throws IOException {
    final ModelNode address = createSubsystemAddress(profileName, "log-file", logFileName);
    final ModelNode op = Operations.createReadAttributeOperation(address, "stream");
    final OperationResponse response = client.getControllerClient().executeOperation(Operation.Factory.create(op), OperationMessageHandler.logging);
    final ModelNode result = response.getResponseNode();
    if (Operations.isSuccessfulOutcome(result)) {
        final OperationResponse.StreamEntry entry = response.getInputStream(Operations.readResult(result).asString());
        if (entry == null) {
            throw new RuntimeException(String.format("Failed to find entry with UUID %s for log file %s", Operations.readResult(result).asString(), logFileName));
        }
        return new BufferedReader(new InputStreamReader(entry.getStream(), StandardCharsets.UTF_8));
    }
    throw new RuntimeException(String.format("Failed to read log file %s: %s", logFileName, Operations.getFailureDescription(result).asString()));
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse)

Aggregations

OperationResponse (org.jboss.as.controller.client.OperationResponse)3 ModelNode (org.jboss.dmr.ModelNode)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1 JsonObject (javax.json.JsonObject)1 JsonReader (javax.json.JsonReader)1 NamingException (javax.naming.NamingException)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1