Search in sources :

Example 66 with ModelControllerClient

use of org.jboss.as.controller.client.ModelControllerClient in project kie-wb-common by kiegroup.

the class WildflyDataSourceManagementClient method getDataSources.

/**
 * Gets the definitions of the currently available data sources.
 */
public List<WildflyDataSourceDef> getDataSources() throws Exception {
    List<WildflyDataSourceDef> dataSources = new ArrayList<>();
    WildflyDataSourceDef dataSource;
    ModelNode response = null;
    ModelControllerClient client = null;
    try {
        client = createControllerClient();
        ModelNode operation = new ModelNode();
        // //profile=full/subsystem=datasources:read-children-resources(child-type=data-source)
        // /subsystem=datasources:read-children-resources(child-type=data-source)
        operation.get(OP).set("read-children-resources");
        operation.get("child-type").set("data-source");
        if (profile != null) {
            operation.get(OP_ADDR).add("profile", profile);
        }
        operation.get(OP_ADDR).add("subsystem", "datasources");
        response = client.execute(new OperationBuilder(operation).build());
        if (!isFailure(response)) {
            if (response.hasDefined(RESULT)) {
                List<ModelNode> nodes = response.get(RESULT).asList();
                Property property;
                ModelNode node;
                for (ModelNode resultNode : nodes) {
                    property = resultNode.asProperty();
                    node = property.getValue();
                    dataSource = new WildflyDataSourceDef();
                    dataSource.setName(property.getName());
                    dataSource.setJndi(node.get(WildflyDataSourceAttributes.JNDI_NAME).asString());
                    dataSource.setConnectionURL(node.get(WildflyDataSourceAttributes.CONNECTION_URL).asString());
                    dataSource.setDriverName(node.get(WildflyDataSourceAttributes.DRIVER_NAME).asString());
                    dataSource.setDriverClass(node.get(WildflyDataSourceAttributes.DRIVER_CLASS).asString());
                    dataSource.setDataSourceClass(node.get(WildflyDataSourceAttributes.DATASOURCE_CLASS).asString());
                    dataSource.setUser(node.get(WildflyDataSourceAttributes.USER_NAME).asString());
                    dataSource.setPassword(node.get(WildflyDataSourceAttributes.PASSWORD).asString());
                    dataSource.setUseJTA(node.get(WildflyDataSourceAttributes.JTA).asBoolean());
                    dataSource.setUseCCM(node.get(WildflyDataSourceAttributes.USE_CCM).asBoolean());
                    dataSources.add(dataSource);
                }
            }
        }
    } finally {
        safeClose(client);
        checkResponse(response);
    }
    return dataSources;
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 67 with ModelControllerClient

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

the class ModClusterSubsystemTestCase method testModClusterAddAndRemoveSequence.

@Test
public void testModClusterAddAndRemoveSequence() throws Exception {
    final CommandContext ctx = CLITestUtil.getCommandContext();
    final ModelControllerClient controllerClient = managementClient.getControllerClient();
    try {
        ctx.connectController();
        // Add the mod_cluster extension first (not in this profile by default)
        // n.b. extensions cannot be added in a batch
        ModelNode request = ctx.buildRequest("/extension=org.jboss.as.modcluster:add");
        ModelNode response = controllerClient.execute(request);
        String outcome = response.get("outcome").asString();
        Assert.assertEquals("Adding mod_cluster extension failed! " + response.toJSONString(false), SUCCESS, outcome);
        // Now lets execute subsystem add operation but we need to specify a connector
        ctx.getBatchManager().activateNewBatch();
        Batch b = ctx.getBatchManager().getActiveBatch();
        b.add(ctx.toBatchedCommand("/socket-binding-group=standard-sockets/socket-binding=modcluster:add(multicast-port=23364, multicast-address=224.0.1.105)"));
        b.add(ctx.toBatchedCommand("/subsystem=modcluster:add"));
        b.add(ctx.toBatchedCommand("/subsystem=modcluster/mod-cluster-config=configuration:add(connector=default, advertise-socket=modcluster)"));
        request = b.toRequest();
        b.clear();
        ctx.getBatchManager().discardActiveBatch();
        response = controllerClient.execute(request);
        outcome = response.get("outcome").asString();
        Assert.assertEquals("Adding mod_cluster subsystem failed! " + response.toJSONString(false), SUCCESS, outcome);
        // We need to reload the server here since the add operation leaves the server in 'reload-required' state
        ServerReload.executeReloadAndWaitForCompletion(managementClient);
        // Test subsystem remove
        request = ctx.buildRequest("/subsystem=modcluster:remove");
        response = controllerClient.execute(request);
        outcome = response.get("outcome").asString();
        Assert.assertEquals("Removing mod_cluster subsystem failed! " + response.toJSONString(false), SUCCESS, outcome);
        // Cleanup and remove the extension
        request = ctx.buildRequest("/extension=org.jboss.as.modcluster:remove");
        response = controllerClient.execute(request);
        outcome = response.get("outcome").asString();
        Assert.assertEquals("Removing mod_cluster extension failed! " + response.toJSONString(false), SUCCESS, outcome);
        // Cleanup socket binding
        request = ctx.buildRequest("/socket-binding-group=standard-sockets/socket-binding=modcluster:remove");
        response = controllerClient.execute(request);
        outcome = response.get("outcome").asString();
        Assert.assertEquals("Removing socket binding failed! " + response.toJSONString(false), SUCCESS, outcome);
        // Remove leaves the server in 'reload-required' state, we need to reload the server in order not to leave running services
        // around for subsequent tests
        ServerReload.executeReloadAndWaitForCompletion(managementClient);
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Batch(org.jboss.as.cli.batch.Batch) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 68 with ModelControllerClient

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

the class ConfigHttpPathTask method setup.

@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
    ModelControllerClient mgmtCli = managementClient.getControllerClient();
    addPropertiesConfigSource(mgmtCli, MP_OPENTRACING_CONFIG, MP_OPENTRACING_SERVER_OPERATION_NAME_PROVIDER, "http-path");
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient)

Example 69 with ModelControllerClient

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

the class FailoverTestCase method testBackupActivation.

@Test
public void testBackupActivation() throws Exception {
    ModelControllerClient client2 = createClient2();
    JMSOperations jmsOperations2 = JMSOperationsProvider.getInstance(client2);
    checkJMSQueue(jmsOperations2, jmsQueueName, false);
    InitialContext context1 = createJNDIContextFromServer1();
    sendAndReceiveMessage(context1, jmsQueueLookup);
    // send a message to server1 before it is stopped
    String text = "sent to server1, received from server2 (after failover)";
    sendMessage(context1, jmsQueueLookup, text);
    context1.close();
    testMasterInSyncWithReplica(createClient1());
    testSlaveInSyncWithReplica(client2);
    log.trace("===================");
    log.trace("STOP SERVER1...");
    log.trace("===================");
    container.stop(SERVER1);
    // let some time for the backup to detect the failure
    waitForHornetQServerActivation(jmsOperations2, true);
    checkJMSQueue(jmsOperations2, jmsQueueName, true);
    testSlaveOutOfSyncWithReplica(client2);
    InitialContext context2 = createJNDIContextFromServer2();
    // receive the message that was sent to server1 before failover occurs
    receiveMessage(context2, jmsQueueLookup, text);
    sendAndReceiveMessage(context2, jmsQueueLookup);
    String text2 = "sent to server2, received from server 1 (after failback)";
    sendMessage(context2, jmsQueueLookup, text2);
    context2.close();
    testSlaveOutOfSyncWithReplica(client2);
    log.trace("====================");
    log.trace("START SERVER1...");
    log.trace("====================");
    // restart the live server
    container.start(SERVER1);
    // let some time for the backup to detect the live node and failback
    ModelControllerClient client1 = createClient1();
    JMSOperations jmsOperations1 = JMSOperationsProvider.getInstance(client1);
    waitForHornetQServerActivation(jmsOperations1, true);
    checkHornetQServerStartedAndActiveAttributes(jmsOperations1, true, true);
    // let some time for the backup to detect the failure
    waitForHornetQServerActivation(jmsOperations2, false);
    // backup server has been restarted in passive mode
    checkHornetQServerStartedAndActiveAttributes(jmsOperations2, true, false);
    checkJMSQueue(jmsOperations2, jmsQueueName, false);
    context1 = createJNDIContextFromServer1();
    // receive the message that was sent to server2 before failback
    receiveMessage(context1, jmsQueueLookup, text2);
    // send & receive a message from server1
    sendAndReceiveMessage(context1, jmsQueueLookup);
    context1.close();
    testMasterInSyncWithReplica(client1);
    testSlaveInSyncWithReplica(client2);
    log.trace("=============================");
    log.trace("RETURN TO NORMAL OPERATION...");
    log.trace("=============================");
    log.trace("===================");
    log.trace("STOP SERVER2...");
    log.trace("===================");
    container.stop(SERVER2);
    testMasterOutOfSyncWithReplica(client1);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) JMSOperations(org.jboss.as.test.integration.common.jms.JMSOperations) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 70 with ModelControllerClient

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

the class FailoverTestCase method testBackupFailoverAfterFailback.

@Test
public void testBackupFailoverAfterFailback() throws Exception {
    ModelControllerClient client2 = createClient2();
    JMSOperations backupJMSOperations = JMSOperationsProvider.getInstance(client2);
    checkJMSQueue(backupJMSOperations, jmsQueueName, false);
    InitialContext context1 = createJNDIContextFromServer1();
    String text = "sent to server1, received from server2 (after failover)";
    sendMessage(context1, jmsQueueLookup, text);
    context1.close();
    testMasterInSyncWithReplica(createClient1());
    testSlaveInSyncWithReplica(client2);
    log.trace("############## 1 #############");
    // listSharedStoreDir();
    log.trace("===================");
    log.trace("STOP SERVER1...");
    log.trace("===================");
    container.stop(SERVER1);
    log.trace("############## 2 #############");
    // listSharedStoreDir();
    // let some time for the backup to detect the failure
    waitForHornetQServerActivation(backupJMSOperations, true);
    checkJMSQueue(backupJMSOperations, jmsQueueName, true);
    testSlaveOutOfSyncWithReplica(client2);
    InitialContext context2 = createJNDIContextFromServer2();
    // receive the message that was sent to server1 before failover occurs
    receiveMessage(context2, jmsQueueLookup, text);
    // send a message to server2 before server1 fails back
    String text2 = "sent to server2, received from server 1 (after failback)";
    sendMessage(context2, jmsQueueLookup, text2);
    context2.close();
    testSlaveOutOfSyncWithReplica(client2);
    log.trace("====================");
    log.trace("START SERVER1...");
    log.trace("====================");
    // restart the live server
    container.start(SERVER1);
    // let some time for the backup to detect the live node and failback
    ModelControllerClient client1 = createClient1();
    JMSOperations liveJMSOperations = JMSOperationsProvider.getInstance(client1);
    waitForHornetQServerActivation(liveJMSOperations, true);
    checkHornetQServerStartedAndActiveAttributes(liveJMSOperations, true, true);
    // let some time for the backup to detect the failure
    waitForHornetQServerActivation(backupJMSOperations, false);
    // backup server has been restarted in passive mode
    checkHornetQServerStartedAndActiveAttributes(backupJMSOperations, true, false);
    checkJMSQueue(backupJMSOperations, jmsQueueName, false);
    context1 = createJNDIContextFromServer1();
    // receive the message that was sent to server2 before failback
    receiveMessage(context1, jmsQueueLookup, text2);
    String text3 = "sent to server1, received from server2 (after 2nd failover)";
    // send a message to server1 before it is stopped a 2nd time
    sendMessage(context1, jmsQueueLookup, text3);
    context1.close();
    testMasterInSyncWithReplica(client1);
    testSlaveInSyncWithReplica(client2);
    log.trace("==============================");
    log.trace("STOP SERVER1 A 2ND TIME...");
    log.trace("==============================");
    // shutdown server1 a 2nd time
    container.stop(SERVER1);
    // let some time for the backup to detect the failure
    waitForHornetQServerActivation(backupJMSOperations, true);
    checkHornetQServerStartedAndActiveAttributes(backupJMSOperations, true, true);
    checkJMSQueue(backupJMSOperations, jmsQueueName, true);
    context2 = createJNDIContextFromServer2();
    // receive the message that was sent to server1 before failover occurs a 2nd time
    receiveMessage(context2, jmsQueueLookup, text3);
    context2.close();
    log.trace("====================");
    log.trace("START SERVER1 A 2ND TIME...");
    log.trace("====================");
    // restart the live server
    container.start(SERVER1);
    // let some time for the backup to detect the live node and failback
    client1 = createClient1();
    liveJMSOperations = JMSOperationsProvider.getInstance(client1);
    waitForHornetQServerActivation(liveJMSOperations, true);
    checkHornetQServerStartedAndActiveAttributes(liveJMSOperations, true, true);
    // let some time for the backup to detect the failure
    waitForHornetQServerActivation(backupJMSOperations, false);
    // backup server has been restarted in passive mode
    checkHornetQServerStartedAndActiveAttributes(backupJMSOperations, true, false);
    checkJMSQueue(backupJMSOperations, jmsQueueName, false);
    context1 = createJNDIContextFromServer1();
    // There should be no message to receive as it was consumed from the backup
    receiveNoMessage(context1, jmsQueueLookup);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) JMSOperations(org.jboss.as.test.integration.common.jms.JMSOperations) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

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