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));
}
}
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()));
}
}
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()));
}
Aggregations