Search in sources :

Example 41 with OperationBuilder

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));
    }
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelNode(org.jboss.dmr.ModelNode) IOException(java.io.IOException)

Example 42 with OperationBuilder

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());
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelNode(org.jboss.dmr.ModelNode)

Example 43 with OperationBuilder

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);
    }
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) ModelNode(org.jboss.dmr.ModelNode) Before(org.junit.Before)

Aggregations

OperationBuilder (org.jboss.as.controller.client.OperationBuilder)43 ModelNode (org.jboss.dmr.ModelNode)42 Test (org.junit.Test)17 IOException (java.io.IOException)7 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)7 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)6 BeforeClass (org.junit.BeforeClass)6 Before (org.junit.Before)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 DefaultOperationRequestBuilder (org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)1 DomainClient (org.jboss.as.controller.client.helpers.domain.DomainClient)1 VaultSession (org.jboss.as.security.vault.VaultSession)1 VaultHandler (org.jboss.as.test.integration.security.common.VaultHandler)1 RetryTaskExecutor (org.jboss.as.test.shared.RetryTaskExecutor)1 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)1