use of org.jboss.as.controller.client.OperationBuilder in project wildfly by wildfly.
the class WSAttributesChangesTestCase method applyUpdate.
private static ModelNode applyUpdate(final ModelControllerClient client, final ModelNode update, final boolean expectReloadRequired) throws Exception {
final ModelNode result = client.execute(new OperationBuilder(update).build());
if (result.hasDefined(OUTCOME) && SUCCESS.equals(result.get(OUTCOME).asString())) {
if (expectReloadRequired) {
Assert.assertTrue(result.hasDefined(RESPONSE_HEADERS));
ModelNode responseHeaders = result.get(RESPONSE_HEADERS);
Assert.assertTrue(responseHeaders.hasDefined(OPERATION_REQUIRES_RELOAD));
Assert.assertEquals("true", responseHeaders.get(OPERATION_REQUIRES_RELOAD).asString());
} else {
Assert.assertFalse(result.hasDefined(RESPONSE_HEADERS));
}
return result;
} else if (result.hasDefined(FAILURE_DESCRIPTION)) {
throw new Exception(result.get(FAILURE_DESCRIPTION).toString());
} else {
throw new Exception("Operation not successful; outcome = " + result.get(OUTCOME));
}
}
use of org.jboss.as.controller.client.OperationBuilder in project wildfly by wildfly.
the class ExplodedDeploymentOverlayTestCase method updateDeployment.
private void updateDeployment(String file, String targetPath) throws IOException, MgmtOperationException {
final ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("add-content");
final ModelNode addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT, "exploded-test.war");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
ModelNode updatedFile = new ModelNode();
updatedFile.get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);
updatedFile.get("target-path").set(targetPath);
op.get(ModelDescriptionConstants.CONTENT).add(updatedFile);
OperationBuilder builder = new OperationBuilder(op, true);
builder.addInputStream(ExplodedDeploymentOverlayTestCase.class.getResourceAsStream(file));
ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build());
}
use of org.jboss.as.controller.client.OperationBuilder in project wildfly by wildfly.
the class ExplodedDeploymentOverlayTestCase method setup.
@Before
public void setup() throws Exception {
ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
//add an override that will not be linked via a wildcard
//add the content
op = new ModelNode();
ModelNode addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY);
addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);
OperationBuilder builder = new OperationBuilder(op, true);
builder.addInputStream(ExplodedDeploymentOverlayTestCase.class.getResourceAsStream("override.xml"));
ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build());
//add the non-wildcard link
op = new ModelNode();
addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY);
addr.add(ModelDescriptionConstants.DEPLOYMENT, "exploded-test.war");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
//add the deployment overlay that will be linked via wildcard
op = new ModelNode();
op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
op = new ModelNode();
addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);
addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.BYTES).set(FileUtils.readFile(ExplodedDeploymentOverlayTestCase.class, "wildcard-override.xml").getBytes());
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
op = new ModelNode();
addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);
addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/classes/wildcard-new-file");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);
builder = new OperationBuilder(op, true);
builder.addInputStream(ExplodedDeploymentOverlayTestCase.class.getResourceAsStream("wildcard-new-file"));
ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build());
//add the wildcard link
op = new ModelNode();
addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);
addr.add(ModelDescriptionConstants.DEPLOYMENT, "*.war");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
//Deploy exploded deployement
addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT, "exploded-test.war");
op = new ModelNode();
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION);
op.get(ModelDescriptionConstants.NAME).set("content[0]");
ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
if (!result.hasDefined(ModelDescriptionConstants.ARCHIVE) || result.get(ModelDescriptionConstants.ARCHIVE).asBoolean(true)) {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UNDEPLOY);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("explode");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
op = new ModelNode();
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.DEPLOY);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
}
}
Aggregations