Search in sources :

Example 36 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 37 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) {
    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 < timeout) {
        try {
            ModelControllerClient liveClient = ModelControllerClient.Factory.create(serverAddress, serverPort);
            try {
                ModelNode result = liveClient.execute(operation);
                if ("running".equals(result.get(RESULT).asString())) {
                    return;
                }
            } catch (IOException e) {
            } finally {
                IoUtils.safeClose(liveClient);
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }
    fail("Live Server did not reload in the imparted time.");
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 38 with ModelControllerClient

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

the class CredentialStoreServerSetupTask method setup.

@Override
public void setup(ManagementClient managementClient, String s) throws Exception {
    final ModelControllerClient client = managementClient.getControllerClient();
    createCredentialStore(client);
    createAlias(client);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient)

Example 39 with ModelControllerClient

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

the class ResourceAdapterOperationsUnitTestCase method configureElytron.

@BeforeClass
public static void configureElytron() throws Exception {
    try (final ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {
        addAuth(client, "AuthCtxt");
        addAuth(client, "AuthCtxtAndApp");
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) BeforeClass(org.junit.BeforeClass)

Example 40 with ModelControllerClient

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

the class MessagingClientTestCase method doMessagingClient.

private void doMessagingClient(ClientSessionFactory sf) throws Exception {
    final String queueName = "queue.standalone";
    final ModelControllerClient client = managementClient.getControllerClient();
    // Check that the queue does not exists
    if (queueExists(queueName, sf)) {
        throw new IllegalStateException();
    }
    // Create a new core queue using the standalone client
    ModelNode op = new ModelNode();
    op.get("operation").set("add");
    op.get("address").add("subsystem", "messaging-activemq");
    op.get("address").add("server", "default");
    op.get("address").add("queue", queueName);
    op.get("queue-address").set(queueName);
    applyUpdate(op, client);
    // Check if the queue exists
    if (!queueExists(queueName, sf)) {
        throw new IllegalStateException();
    }
    ClientSession session = null;
    try {
        session = sf.createSession("guest", "guest", false, true, true, false, 1);
        ClientProducer producer = session.createProducer(queueName);
        ClientMessage message = session.createMessage(false);
        final String propName = "myprop";
        message.putStringProperty(propName, "Hello sent at " + new Date());
        producer.send(message);
        ClientConsumer messageConsumer = session.createConsumer(queueName);
        session.start();
        ClientMessage messageReceived = messageConsumer.receive(1000);
        assertNotNull("a message MUST have been received", messageReceived);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    op = new ModelNode();
    op.get("operation").set("remove");
    op.get("address").add("subsystem", "messaging-activemq");
    op.get("address").add("server", "default");
    op.get("address").add("queue", queueName);
    applyUpdate(op, client);
    // Check that the queue does not exists
    if (queueExists(queueName, sf)) {
        throw new IllegalStateException();
    }
}
Also used : IllegalStateException(javax.resource.spi.IllegalStateException) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ModelNode(org.jboss.dmr.ModelNode) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Date(java.util.Date)

Aggregations

ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)58 ModelNode (org.jboss.dmr.ModelNode)27 Test (org.junit.Test)21 ManagementClient (org.jboss.as.arquillian.container.ManagementClient)17 IOException (java.io.IOException)11 InSequence (org.jboss.arquillian.junit.InSequence)8 URL (java.net.URL)5 PathAddress (org.jboss.as.controller.PathAddress)5 Before (org.junit.Before)5 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)4 UnknownHostException (java.net.UnknownHostException)3 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)2 CommandContext (org.jboss.as.cli.CommandContext)2 CommandFormatException (org.jboss.as.cli.CommandFormatException)2 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)2 DefaultOperationRequestBuilder (org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)2 After (org.junit.After)2 BeforeClass (org.junit.BeforeClass)2