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