Search in sources :

Example 61 with ModelControllerClient

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

the class WildflyDeploymentClient method getDeployments.

/**
 * @return The list of deployment names.
 *
 * @throws Exception
 */
public List<String> getDeployments() throws Exception {
    ModelControllerClient client = null;
    ModelNode response;
    List<String> result = new ArrayList<>();
    try {
        client = createControllerClient();
        ModelNode operation = new ModelNode();
        if (serverGroup != null) {
            operation.get(OP_ADDR).add(SERVER_GROUP, serverGroup);
        }
        operation.get(OP_ADDR).add(DEPLOYMENT, "*");
        operation.get(OP).set(READ_ATTRIBUTE_OPERATION);
        operation.get(NAME).set("name");
        response = createControllerClient().execute(operation);
        if (!isFailure(response)) {
            if (response.hasDefined(RESULT)) {
                List<ModelNode> nodes = response.get(RESULT).asList();
                for (ModelNode node : nodes) {
                    result.add(node.get(RESULT).asString());
                }
            }
        } else {
            checkResponse(response);
        }
        return result;
    } finally {
        safeClose(client);
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode)

Example 62 with ModelControllerClient

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

the class WildflyDeploymentClient method enableDeployment.

/**
 * @param deploymentName Unique identifier of the deployment to be enabled/disabled.
 *
 * @param enabled true if the deployment should be enabled, false if it should be disabled.
 *
 * @throws Exception
 */
public void enableDeployment(String deploymentName, boolean enabled) throws Exception {
    ModelControllerClient client = null;
    ModelNode response = null;
    try {
        client = createControllerClient();
        ModelNode operation = new ModelNode();
        if (enabled) {
            operation.get(OP).set(DEPLOYMENT_DEPLOY_OPERATION);
        } else {
            operation.get(OP).set(DEPLOYMENT_UNDEPLOY_OPERATION);
        }
        operation.get(OP_ADDR).add(DEPLOYMENT, deploymentName);
        response = client.execute(operation);
    } finally {
        safeClose(client);
        checkResponse(response);
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode)

Example 63 with ModelControllerClient

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

the class WildflyDriverManagementClient method getDeployedDrivers.

/**
 * Gets the definitions of the currently available drivers.
 */
public List<WildflyDriverDef> getDeployedDrivers() throws Exception {
    ModelNode operation = new ModelNode();
    operation.get(OP).set("installed-drivers-list");
    if (!isStandalone() && getReferenceServerHost() != null && getReferenceServerName() != null) {
        operation.get(OP_ADDR).add("host", getReferenceServerHost());
        operation.get(OP_ADDR).add("server", getReferenceServerName());
    }
    operation.get(OP_ADDR).add("subsystem", "datasources");
    ModelControllerClient client = null;
    List<WildflyDriverDef> drivers = new ArrayList<WildflyDriverDef>();
    try {
        client = createControllerClient();
        ModelNode response = client.execute(operation);
        WildflyDriverDef driver;
        String driverName;
        if (!isFailure(response)) {
            if (response.hasDefined(RESULT)) {
                List<ModelNode> nodes = response.get(RESULT).asList();
                for (ModelNode node : nodes) {
                    driver = new WildflyDriverDef();
                    driverName = node.get("driver-name").asString();
                    driver.setDriverName(driverName);
                    if (node.hasDefined("deployment-name")) {
                        driver.setDeploymentName(node.get("deployment-name").asString());
                    }
                    if (node.hasDefined("driver-module-name")) {
                        driver.setDriverModuleName(node.get("driver-module-name").asString());
                    }
                    if (node.hasDefined("module-slot")) {
                        driver.setModuleSlot(node.get("module-slot").asString());
                    }
                    if (node.hasDefined("driver-class-name")) {
                        driver.setDriverClass(node.get("driver-class-name").asString());
                    }
                    if (node.hasDefined("driver-datasource-class-name")) {
                        driver.setDataSourceClass(node.get("driver-datasource-class-name").asString());
                    }
                    if (node.hasDefined("driver-xa-datasource-class-name")) {
                        driver.setXaDataSourceClass(node.get("driver-xa-datasource-class-name").asString());
                    }
                    if (node.has("driver-major-version")) {
                        driver.setMayorVersion(node.get("driver-major-version").asInt());
                    }
                    if (node.has("driver-minor-version")) {
                        driver.setMayorVersion(node.get("driver-minor-version").asInt());
                    }
                    if (node.has("jdbc-compliant")) {
                        driver.setJdbcCompliant(node.get("jdbc-compliant").asBoolean());
                    }
                    drivers.add(driver);
                }
            }
        } else {
            checkResponse(response);
        }
    } finally {
        safeClose(client);
    }
    return drivers;
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode)

Example 64 with ModelControllerClient

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

the class WildflyDataSourceManagementClient method deleteDataSource.

/**
 * Deletes an existing data source.
 *
 * @param name the data source name.
 *
 * @throws Exception when the operation fails.
 */
public void deleteDataSource(String name) throws Exception {
    ModelNode operation = new ModelNode();
    operation.get(OP).set("remove");
    if (profile != null) {
        operation.get(OP_ADDR).add("profile", profile);
    }
    operation.get(OP_ADDR).add("subsystem", "datasources");
    operation.get(OP_ADDR).add("data-source", name);
    ModelControllerClient client = createControllerClient();
    ModelNode result = client.execute(operation);
    safeClose(client);
    checkResponse(result);
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode)

Example 65 with ModelControllerClient

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

the class WildflyDataSourceManagementClient method createDataSource.

/**
 * Creates a data source.
 */
public void createDataSource(WildflyDataSourceDef dataSourceDef) throws Exception {
    ModelNode operation = new ModelNode();
    operation.get(OP).set(ADD);
    if (profile != null) {
        operation.get(OP_ADDR).add("profile", profile);
    }
    operation.get(OP_ADDR).add("subsystem", "datasources");
    if (dataSourceDef.getName() != null) {
        operation.get(OP_ADDR).add("data-source", dataSourceDef.getName());
    }
    if (dataSourceDef.getJndi() != null) {
        operation.get(WildflyDataSourceAttributes.JNDI_NAME).set(dataSourceDef.getJndi());
    }
    if (dataSourceDef.getConnectionURL() != null) {
        operation.get(WildflyDataSourceAttributes.CONNECTION_URL).set(dataSourceDef.getConnectionURL());
    }
    if (dataSourceDef.getDriverName() != null) {
        operation.get(WildflyDataSourceAttributes.DRIVER_NAME).set(dataSourceDef.getDriverName());
    }
    if (dataSourceDef.getDriverClass() != null) {
        operation.get(WildflyDataSourceAttributes.DRIVER_CLASS).set(dataSourceDef.getDriverClass());
    }
    if (dataSourceDef.getDataSourceClass() != null) {
        operation.get(WildflyDataSourceAttributes.DATASOURCE_CLASS).set(dataSourceDef.getDataSourceClass());
    }
    if (dataSourceDef.getUser() != null) {
        operation.get(WildflyDataSourceAttributes.USER_NAME).set(dataSourceDef.getUser());
    }
    if (dataSourceDef.getPassword() != null) {
        operation.get(WildflyDataSourceAttributes.PASSWORD).set(dataSourceDef.getPassword());
    }
    operation.get(WildflyDataSourceAttributes.JTA).set(dataSourceDef.isUseJTA());
    operation.get(WildflyDataSourceAttributes.USE_CCM).set(dataSourceDef.isUseCCM());
    ModelControllerClient client = createControllerClient();
    ModelNode response = client.execute(new OperationBuilder(operation).build());
    safeClose(client);
    checkResponse(response);
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode)

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