Search in sources :

Example 1 with Operation

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

the class SubsystemOperationsTestCase method testRemoveThreadPool.

@Test
public void testRemoveThreadPool() throws Exception {
    final KernelServices kernelServices = boot(getSubsystemXml("/minimal-subsystem.xml"));
    final ModelNode address = createAddress(BatchSubsystemDefinition.THREAD_POOL_PATH);
    // Remove the thread pool
    final ModelNode removeOp = SubsystemOperations.createRemoveOperation(address);
    executeOperation(kernelServices, removeOp);
    // Reboot with a default thread pool
    String marshalledXml = kernelServices.getPersistedSubsystemXml();
    try {
        boot(marshalledXml);
        Assert.fail("Should be missing <thread-pool/>");
    } catch (XMLStreamException ignore) {
    }
    // Add back a thread-pool, must be named batch
    final ModelNode addOp = SubsystemOperations.createAddOperation(address);
    addOp.get("max-threads").set(10);
    final ModelNode keepAlive = addOp.get("keepalive-time");
    keepAlive.get("time").set(100L);
    keepAlive.get("unit").set(TimeUnit.MILLISECONDS.toString());
    executeOperation(kernelServices, addOp);
    // Get the serialized output and boot
    marshalledXml = kernelServices.getPersistedSubsystemXml();
    try {
        final KernelServices k = boot(marshalledXml);
        Assert.assertTrue(k.isSuccessfulBoot());
    } catch (XMLStreamException e) {
        final StringWriter writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer));
        Assert.fail("Failed to parse XML; " + writer.toString());
    }
    // Remove and add in a composite operation
    final Operation compositeOp = CompositeOperationBuilder.create().addStep(removeOp).addStep(addOp).build();
    executeOperation(kernelServices, compositeOp);
    // Get the serialized output and boot
    marshalledXml = kernelServices.getPersistedSubsystemXml();
    try {
        final KernelServices k = boot(marshalledXml);
        Assert.assertTrue(k.isSuccessfulBoot());
    } catch (XMLStreamException e) {
        final StringWriter writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer));
        Assert.fail("Failed to parse XML; " + writer.toString());
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) StringWriter(java.io.StringWriter) KernelServices(org.jboss.as.subsystem.test.KernelServices) Operation(org.jboss.as.controller.client.Operation) ModelNode(org.jboss.dmr.ModelNode) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with Operation

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

the class ClientCompatibilityUnitTestCase method test.

private void test(final ModelControllerClient client) throws Exception {
    try {
        final ModelNode operation = new ModelNode();
        operation.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_RESOURCE_OPERATION);
        operation.get(ModelDescriptionConstants.OP_ADDR).setEmptyList();
        // include a lot of garbage
        operation.get(ModelDescriptionConstants.RECURSIVE).set(true);
        operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(true);
        operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(true);
        final ModelNode result = client.execute(operation);
        Assert.assertEquals(operation.toString(), ModelDescriptionConstants.SUCCESS, result.get(ModelDescriptionConstants.OUTCOME).asString());
        final ModelNode deploy = new ModelNode();
        deploy.get(ModelDescriptionConstants.OP).set("add");
        deploy.get(ModelDescriptionConstants.OP_ADDR).add("deployment", "compat-test.war");
        deploy.get("content").get(0).get("input-stream-index").set(0);
        deploy.get("auto-start").set(true);
        final Operation o = OperationBuilder.create(deploy).addInputStream(deployment.as(ZipExporter.class).exportAsInputStream()).build();
        try {
            final ModelNode deployResult = client.execute(o);
            Assert.assertEquals(deployResult.toString(), ModelDescriptionConstants.SUCCESS, deployResult.get(ModelDescriptionConstants.OUTCOME).asString());
        } finally {
            final ModelNode undeploy = new ModelNode();
            undeploy.get(ModelDescriptionConstants.OP).set("remove");
            undeploy.get(ModelDescriptionConstants.OP_ADDR).add("deployment", "compat-test.war");
            try {
                client.execute(undeploy);
            } catch (IOException ignore) {
                ignore.printStackTrace();
            }
        }
    } finally {
        StreamUtils.safeClose(client);
    }
}
Also used : ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) Operation(org.jboss.as.controller.client.Operation) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with Operation

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

the class SubsystemOperationsTestCase method testAddRemoveThreadPool.

@Test
public void testAddRemoveThreadPool() throws Exception {
    final KernelServices kernelServices = boot(getSubsystemXml("/minimal-subsystem.xml"));
    final ModelNode address = createAddress("thread-pool", "test-pool");
    final ModelNode addOp = SubsystemOperations.createAddOperation(address);
    addOp.get("max-threads").set(10L);
    final ModelNode keepAlive = addOp.get("keepalive-time");
    keepAlive.get("time").set(100L);
    keepAlive.get("unit").set(TimeUnit.MILLISECONDS.toString());
    executeOperation(kernelServices, addOp);
    final ModelNode removeOp = SubsystemOperations.createRemoveOperation(address);
    executeOperation(kernelServices, removeOp);
    // Add one more time to test a composite operation
    executeOperation(kernelServices, addOp);
    // Remove and add in a composite operation
    final Operation compositeOp = CompositeOperationBuilder.create().addStep(removeOp).addStep(addOp).build();
    executeOperation(kernelServices, compositeOp);
}
Also used : KernelServices(org.jboss.as.subsystem.test.KernelServices) Operation(org.jboss.as.controller.client.Operation) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 4 with Operation

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

the class DeploymentOperationsTestCase method testDeploymentRollbackOnRuntimeFailure.

@Test
public void testDeploymentRollbackOnRuntimeFailure() throws Exception {
    final File deploymentOne = new File(deployDir, "deployment-one.jar");
    final File deploymentTwo = new File(deployDir, "deployment-two.jar");
    createDeployment(deploymentOne, "org.jboss.modules");
    createDeployment(deploymentTwo, "non.existing.dependency");
    final ModelNode composite = new ModelNode();
    composite.get(OP).set(COMPOSITE);
    composite.get(OPERATION_HEADERS).get(ROLLBACK_ON_RUNTIME_FAILURE).set(false);
    final ModelNode nested = composite.get(STEPS).setEmptyList().add();
    nested.get(OP).set(COMPOSITE);
    nested.get(OP_ADDR).setEmptyList();
    final ModelNode steps = nested.get(STEPS).setEmptyList();
    final ModelNode deployOne = steps.add();
    deployOne.get(OP).set(ADD);
    deployOne.get(OP_ADDR).set(DEPLOYMENT_ONE.toModelNode());
    deployOne.get(ENABLED).set(true);
    deployOne.get(CONTENT).add().get(INPUT_STREAM_INDEX).set(0);
    final ModelNode deployTwo = steps.add();
    deployTwo.get(OP).set(ADD);
    deployTwo.get(OP_ADDR).set(DEPLOYMENT_TWO.toModelNode());
    deployTwo.get(ENABLED).set(true);
    deployTwo.get(CONTENT).add().get(INPUT_STREAM_INDEX).set(1);
    final Operation operation = OperationBuilder.create(composite, true).addFileAsAttachment(deploymentOne).addFileAsAttachment(deploymentTwo).build();
    final ModelControllerClient client = getModelControllerClient();
    try {
        // Deploy
        final ModelNode overallResult = client.execute(operation);
        Assert.assertTrue(overallResult.asString(), SUCCESS.equals(overallResult.get(OUTCOME).asString()));
        final ModelNode result = overallResult.get(RESULT, "step-1");
        Assert.assertTrue(result.asString(), SUCCESS.equals(result.get(OUTCOME).asString()));
        final ModelNode step1 = result.get(RESULT, "step-1");
        Assert.assertEquals(SUCCESS, step1.get(OUTCOME).asString());
        final ModelNode step2 = result.get(RESULT, "step-2");
        Assert.assertEquals(FAILED, step2.get(OUTCOME).asString());
    } finally {
        safeClose(operation);
    }
    // Check if deployment-one and -two exist
    executeOperation(Util.createEmptyOperation(READ_RESOURCE_OPERATION, DEPLOYMENT_ONE));
    executeOperation(Util.createEmptyOperation(READ_RESOURCE_OPERATION, DEPLOYMENT_TWO));
    // do cleanup
    executeOperation(Util.createRemoveOperation(DEPLOYMENT_ONE));
    executeOperation(Util.createRemoveOperation(DEPLOYMENT_TWO));
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) Operation(org.jboss.as.controller.client.Operation) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File) Test(org.junit.Test)

Aggregations

Operation (org.jboss.as.controller.client.Operation)4 ModelNode (org.jboss.dmr.ModelNode)4 Test (org.junit.Test)3 KernelServices (org.jboss.as.subsystem.test.KernelServices)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)1