Search in sources :

Example 96 with ModelControllerClient

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

the class ServerReload method waitForLiveServerToReload.

private static void waitForLiveServerToReload(int timeout, String serverAddress, int serverPort) {
    int adjustedTimeout = TimeoutUtil.adjust(timeout);
    long start = System.currentTimeMillis();
    ModelNode operation = new ModelNode();
    operation.get(OP_ADDR).setEmptyList();
    operation.get(OP).set(READ_ATTRIBUTE_OPERATION);
    operation.get(NAME).set("server-state");
    while (System.currentTimeMillis() - start < adjustedTimeout) {
        // also reload generally takes longer than 100ms anyway
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        try {
            ModelControllerClient liveClient = ModelControllerClient.Factory.create(serverAddress, serverPort);
            try {
                ModelNode result = liveClient.execute(operation);
                if ("running".equals(result.get(RESULT).asString())) {
                    log.debugf("Server %s:%d was reloaded in %d milliseconds", serverAddress, serverPort, System.currentTimeMillis() - start);
                    return;
                }
            } catch (IOException e) {
            // ignore
            } finally {
                IoUtils.safeClose(liveClient);
            }
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }
    fail("Live Server did not reload in the imparted time of " + adjustedTimeout + "(" + timeout + ") milliseconds");
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 97 with ModelControllerClient

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

the class JdrRunner method obtainServerUUID.

private String obtainServerUUID() throws OperationFailedException {
    try {
        ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), UUID);
        operation.get(INCLUDE_RUNTIME).set(true);
        ModelControllerClient client = env.getClient();
        if (client == null) {
            client = env.getCli().getCommandContext().getModelControllerClient();
        }
        ModelNode result = client.execute(operation);
        if (Operations.isSuccessfulOutcome(result)) {
            return Operations.readResult(result).asString();
        }
        return null;
    } catch (IOException ex) {
        return null;
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 98 with ModelControllerClient

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

the class JdrRunner method obtainProductName.

private String obtainProductName() {
    try {
        ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), PRODUCT_NAME);
        operation.get(INCLUDE_RUNTIME).set(false);
        ModelControllerClient client = env.getClient();
        if (client == null) {
            client = env.getCli().getCommandContext().getModelControllerClient();
        }
        ModelNode result = client.execute(operation);
        if (Operations.isSuccessfulOutcome(result)) {
            return Operations.readResult(result).asString();
        }
        return "undefined";
    } catch (IOException e) {
        // In that case "undefined" is returned
        return "undefined";
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 99 with ModelControllerClient

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

the class JdrRunner method obtainProductVersion.

private String obtainProductVersion() {
    try {
        ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), PRODUCT_VERSION);
        operation.get(INCLUDE_RUNTIME).set(false);
        ModelControllerClient client = env.getClient();
        if (client == null) {
            client = env.getCli().getCommandContext().getModelControllerClient();
        }
        ModelNode result = client.execute(operation);
        if (Operations.isSuccessfulOutcome(result)) {
            return Operations.readResult(result).asString();
        }
        return "undefined";
    } catch (IOException e) {
        // In that case "undefined" is returned
        return "undefined";
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 100 with ModelControllerClient

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

the class DeleteJMSResourceHandler method buildRequestWithoutHeaders.

@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws OperationFormatException {
    try {
        if (!ctx.getParsedCommandLine().hasProperties()) {
            throw new OperationFormatException("Arguments are missing");
        }
    } catch (CommandFormatException e) {
        throw new OperationFormatException(e.getLocalizedMessage());
    }
    // String target = null;
    String jndiName = null;
    // TODO read server name from props
    String serverName = "default";
    String[] args = ctx.getArgumentsString().split("\\s+");
    int i = 0;
    while (i < args.length) {
        String arg = args[i++];
        if (arg.equals("--target")) {
        // if(i < args.length) {
        // target = args[i++];
        // }
        } else {
            jndiName = arg;
        }
    }
    if (jndiName == null) {
        throw new OperationFormatException("name is missing.");
    }
    ModelControllerClient client = ctx.getModelControllerClient();
    final String resource;
    if (Util.isTopic(client, jndiName)) {
        resource = "jms-topic";
    } else if (Util.isQueue(client, jndiName)) {
        resource = "jms-queue";
    } else if (Util.isConnectionFactory(client, jndiName)) {
        resource = "connection-factory";
    } else {
        throw new OperationFormatException("'" + jndiName + "' wasn't found among existing JMS resources.");
    }
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    builder.addNode("subsystem", "messaging");
    builder.addNode("server", serverName);
    builder.addNode(resource, jndiName);
    builder.setOperationName("remove");
    return builder.buildRequest();
}
Also used : OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) CommandFormatException(org.jboss.as.cli.CommandFormatException) DefaultOperationRequestBuilder(org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)

Aggregations

ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)106 ModelNode (org.jboss.dmr.ModelNode)61 Test (org.junit.Test)30 IOException (java.io.IOException)20 ManagementClient (org.jboss.as.arquillian.container.ManagementClient)19 PathAddress (org.jboss.as.controller.PathAddress)10 ArrayList (java.util.ArrayList)9 InSequence (org.jboss.arquillian.junit.InSequence)8 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 URL (java.net.URL)6 UnknownHostException (java.net.UnknownHostException)6 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)6 Before (org.junit.Before)6 WildFlyElytronProvider (org.wildfly.security.WildFlyElytronProvider)4 NamingException (javax.naming.NamingException)3 CommandContext (org.jboss.as.cli.CommandContext)3 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)3 After (org.junit.After)3 File (java.io.File)2 InitialContext (javax.naming.InitialContext)2