Java Code Examples for org.jboss.as.controller.operations.common.Util#getWriteAttributeOperation()

The following examples show how to use org.jboss.as.controller.operations.common.Util#getWriteAttributeOperation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HostXml_14.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Add the operation to add the local host definition.
 */
private ModelNode addLocalHost(final ModelNode address, final List<ModelNode> operationList, final String hostName) {

    String resolvedHost =  hostName != null ? hostName : defaultHostControllerName;

    // All further operations should modify the newly added host so the address passed in is updated.
    address.add(HOST, resolvedHost);

    // Add a step to setup the ManagementResourceRegistrations for the root host resource
    final ModelNode hostAddOp = new ModelNode();
    hostAddOp.get(OP).set(HostAddHandler.OPERATION_NAME); // /host=foo:add()
    hostAddOp.get(OP_ADDR).set(address);

    operationList.add(hostAddOp);

    // Add a step to store the HC name
    ModelNode nameValue = hostName == null ? new ModelNode() : new ModelNode(hostName);
    final ModelNode writeName = Util.getWriteAttributeOperation(address, NAME, nameValue);
    operationList.add(writeName);

    return hostAddOp;
}
 
Example 2
Source File: ManagedServerOperationsFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void convertApplicationClassificationConstraints(ModelNode model, ModelNode baseAddress, ModelNodeList updates) {
    PathAddress constraintAddress = PathAddress.pathAddress(baseAddress).append(CONSTRAINT, APPLICATION_CLASSIFICATION);
    if (model.hasDefined(TYPE)) {
        for (Property prop : model.get(TYPE).asPropertyList()) {
            PathAddress constraintTypeAddress = constraintAddress.append(TYPE, prop.getName());
            if (prop.getValue().hasDefined(CLASSIFICATION)) {
                for (Property classification : prop.getValue().get(CLASSIFICATION).asPropertyList()) {
                    PathAddress classificationAddress = constraintTypeAddress.append(CLASSIFICATION, classification.getName());
                    if (classification.getValue().hasDefined(CONFIGURED_APPLICATION)) {
                        ModelNode addOp = Util.getWriteAttributeOperation(classificationAddress, CONFIGURED_APPLICATION, classification.getValue().get(CONFIGURED_APPLICATION).asBoolean());
                        updates.add(addOp);
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: IOSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testThreadPoolAttrPropagation() throws Exception {
    KernelServices kernelServices = startKernelServices(getSubsystemXml());
    startXnioWorker(kernelServices);

    int coreThreads = 4; // default = 2
    int maxThreads = 64; // default = 128
    int keepAliveMillis = 5000; // default = 100 (0 in seconds)
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode maxThreadsOp = Util.getWriteAttributeOperation(addr, Constants.WORKER_TASK_MAX_THREADS, maxThreads);
    ModelNode coreThreadsOp = Util.getWriteAttributeOperation(addr, Constants.WORKER_TASK_CORE_THREADS, coreThreads);
    ModelNode keepAliveOp = Util.getWriteAttributeOperation(addr, Constants.WORKER_TASK_KEEPALIVE, keepAliveMillis);

    kernelServices.executeOperation(maxThreadsOp);
    kernelServices.executeOperation(coreThreadsOp);
    kernelServices.executeOperation(keepAliveOp);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName threadPoolName = new ObjectName("jboss.threads:name=\"default\",type=thread-pool");
    Assert.assertEquals(coreThreads, (int) mbs.getAttribute(threadPoolName, "CorePoolSize"));
    Assert.assertEquals(maxThreads, (int) mbs.getAttribute(threadPoolName, "MaximumPoolSize"));
    Assert.assertEquals(keepAliveMillis / 1000, (long) mbs.getAttribute(threadPoolName, "KeepAliveTimeSeconds"));
}
 
Example 4
Source File: HostXml_7.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Add the operation to add the local host definition.
 */
private ModelNode addLocalHost(final ModelNode address, final List<ModelNode> operationList, final String hostName) {

    String resolvedHost =  hostName != null ? hostName : defaultHostControllerName;

    // All further operations should modify the newly added host so the address passed in is updated.
    address.add(HOST, resolvedHost);

    // Add a step to setup the ManagementResourceRegistrations for the root host resource
    final ModelNode hostAddOp = new ModelNode();
    hostAddOp.get(OP).set(HostAddHandler.OPERATION_NAME); // /host=foo:add()
    hostAddOp.get(OP_ADDR).set(address);

    operationList.add(hostAddOp);

    // Add a step to store the HC name
    ModelNode nameValue = hostName == null ? new ModelNode() : new ModelNode(hostName);
    final ModelNode writeName = Util.getWriteAttributeOperation(address, NAME, nameValue);
    operationList.add(writeName);

    return hostAddOp;
}
 
Example 5
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleReject() throws Exception {
    //Set up the model
    resourceModel.get("reject").set(true);

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder().addRejectCheck(new RejectAttributeChecker.SimpleRejectAttributeChecker(ModelNode.TRUE), "reject").end();
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    //The rejection does not trigger for resource transformation
    Assert.assertTrue(model.hasDefined("reject"));

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("reject").set(true);
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertTrue(transformedAdd.rejectOperation(success()));

    ModelNode write = Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "reject", ModelNode.TRUE);
    OperationTransformer.TransformedOperation transformedWrite = transformOperation(write);
    Assert.assertTrue(transformedWrite.rejectOperation(success()));
}
 
Example 6
Source File: PoliciesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDefaultPolicyWriteIgnored() throws Exception {
    KernelServices services = standardSubsystemTest("custom-policy.xml", true);
    ModelNode write = Util.getWriteAttributeOperation(getPolicyAddress("custom-b"), "default-policy", "test");
    ModelNode response = services.executeOperation(write);
    assertEquals(response.toString(), "success", response.get("outcome").asString());
    assertFalse(response.toString(), response.has(RESPONSE_HEADERS, OPERATION_REQUIRES_RELOAD));
    assertFalse(response.toString(), response.has(RESPONSE_HEADERS, OPERATION_REQUIRES_RESTART));
    checkNoDefaultPolicy(services, "custom-b");
}
 
Example 7
Source File: AuditLogTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@After
public void turnOffSysylog() throws Exception {
    ModelNode op = Util.getWriteAttributeOperation(masterCoreLogggerAddress, ENABLED, ModelNode.FALSE);
    masterLifecycleUtil.executeForResult(op);

    op = Util.getWriteAttributeOperation(slaveCoreLogggerAddress, ENABLED, ModelNode.FALSE);
    slaveLifecycleUtil.executeForResult(op);

    op = Util.getWriteAttributeOperation(masterServerLoggerAddress, ENABLED, ModelNode.FALSE);
    masterLifecycleUtil.executeForResult(op);

    op = Util.getWriteAttributeOperation(slaveServerLoggerAddress, ENABLED, ModelNode.FALSE);
    slaveLifecycleUtil.executeForResult(op);
}
 
Example 8
Source File: InMemoryAuditReportSetupTask.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void tearDown(ManagementClient managementClient) throws Exception {
    ModelNode disableAuditLog = Util.getWriteAttributeOperation(AUDIT_LOG_LOGGER_ADDR, ENABLED, false);
    managementClient.getControllerClient().execute(disableAuditLog);
    ModelNode deactivateHandler = Util.createRemoveOperation(AUDIT_LOG_LOGGER_IN_MEMORY_HANDLER_ADDR);
    managementClient.getControllerClient().execute(deactivateHandler);
    ModelNode removeHandler = Util.createRemoveOperation(IN_MEMORY_HANDLER_ADDR);
    managementClient.getControllerClient().execute(removeHandler);
}
 
Example 9
Source File: HostXml_12.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 10
Source File: HostXml_10.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 11
Source File: DeploymentScannerNotificationUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testStartup() throws Exception {

    container.start();
    try {
        try (ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient()) {

            final File deploymentOne = new File(getDeployDir(), "deployment-one.jar");
            createDeployment(deploymentOne, "org.jboss.modules");

            // Add a new de
            addDeploymentScanner(client, 1000, false, true);
            try {
                // Wait until deployed ...
                long timeout = System.currentTimeMillis() + TimeoutUtil.adjust(30000);
                while (!exists(client, DEPLOYMENT_ONE) && System.currentTimeMillis() < timeout) {
                    Thread.sleep(100);
                }
                Assert.assertTrue(exists(client, DEPLOYMENT_ONE));
                Assert.assertEquals("OK", deploymentState(client, DEPLOYMENT_ONE));
                final Path oneDeployed = getDeployDirPath().resolve("deployment-one.jar.deployed");
                final Path oneUndeployed = getDeployDirPath().resolve("deployment-one.jar.undeployed");
                Assert.assertTrue(Files.deleteIfExists(oneDeployed));
                timeout = System.currentTimeMillis() + TimeoutUtil.adjust(30000);
                while (!Files.exists(oneUndeployed) && System.currentTimeMillis() < timeout) {
                    Thread.sleep(10);
                }
                Assert.assertFalse(Files.exists(oneDeployed));
                Assert.assertTrue(Files.exists(oneUndeployed));
                Assert.assertTrue(Files.exists(getDeployDirPath().resolve("deployment-one.jar")));
                Assert.assertFalse(exists(client, DEPLOYMENT_ONE));

                ModelNode disableScanner = Util.getWriteAttributeOperation(PathAddress.parseCLIStyleAddress("/subsystem=deployment-scanner/scanner=testScanner"), "scan-interval", 300000);
                ModelNode result = client.execute(disableScanner);
                assertEquals("Unexpected outcome of disabling the test deployment scanner: " + disableScanner, ModelDescriptionConstants.SUCCESS, result.get(OUTCOME).asString());

                deploy(client, deploymentOne);
                Assert.assertTrue(exists(client, DEPLOYMENT_ONE));
                Assert.assertEquals("OK", deploymentState(client, DEPLOYMENT_ONE));
                timeout = System.currentTimeMillis() + TimeoutUtil.adjust(30000);
                while (!Files.exists(oneDeployed) && System.currentTimeMillis() < timeout) {
                    Thread.sleep(10);
                }
                Assert.assertTrue(Files.exists(oneDeployed));
                Assert.assertFalse(Files.exists(oneUndeployed));
            } finally {
                removeDeploymentScanner(client);
                undeploy(client,"deployment-one.jar");
            }
        }
    } finally {
        container.stop();
    }
}
 
Example 12
Source File: HostXml_14.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 13
Source File: ConfigurationChangesHistoryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testAllConfigurationChanges() throws Exception {
    final ModelNode update = Util.getWriteAttributeOperation(ADDRESS,  "max-history", ALL_MAX_HISTORY_SIZE);
    getModelControllerClient().execute(update);
    final ModelNode listConfigurationChanges = Util.createOperation("list-changes", ADDRESS);
    List<ModelNode> changes = getManagementClient().executeForResult(listConfigurationChanges).asList();
    assertThat(changes.toString(), changes.size(), is(ALL_MAX_HISTORY_SIZE));
    for(ModelNode change : changes) {
        assertThat(change.hasDefined(OPERATION_DATE), is(true));
        assertThat(change.hasDefined(USER_ID), is(false));
        assertThat(change.hasDefined(DOMAIN_UUID), is(false));
        assertThat(change.hasDefined(ACCESS_MECHANISM), is(true));
        assertThat(change.get(ACCESS_MECHANISM).asString(), is("NATIVE"));
        assertThat(change.hasDefined(REMOTE_ADDRESS), is(true));
        assertThat(change.get(OPERATIONS).asList().size(), is(1));
    }

    ModelNode currentChange = changes.get(0);
    ModelNode currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION));
    assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
    currentChange = changes.get(1);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION));
    assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(FAILED));
    currentChange = changes.get(2);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(REMOVE));
    assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
    currentChange = changes.get(3);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(UNDEFINE_ATTRIBUTE_OPERATION));
    assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
    currentChange = changes.get(4);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(ADD));
    assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
}
 
Example 14
Source File: CapabilityReloadRequiredUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testCapabilityReloadEffects() throws IOException {
    // Change the interface to put its capability into r-r
    ModelNode op = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
    ModelNode steps = op.get(STEPS);
    steps.add(Util.getUndefineAttributeOperation(IFACE, LOOPBACK));
    steps.add(Util.getWriteAttributeOperation(IFACE, INET_ADDRESS, "${jboss.bind.address:127.0.0.1}"));
    assertStepRequiresReload(op);

    // Add the loc -- should get a restart-required header
    op = Util.createAddOperation(SUB);
    op.get("osb").set(WFCORE1106_OSB);
    assertStepRequiresReload(op);

    // reload
    ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient());

    // Change the l-o-c -- should *not* get a restart-required header
    op = Util.getWriteAttributeOperation(SUB, "osb", WFCORE1106_OSB2);

    assertStepDoesNotRequireReload(op);

    // Change the o-s-b to put its capability into r-r

    op = Util.getWriteAttributeOperation(OSB, SOURCE_PORT, 54321);
    assertStepRequiresReload(op);

    // Change the l-o-c -- should get a restart-required header
    op = Util.getWriteAttributeOperation(SUB, "osb", WFCORE1106_OSB);
    assertStepRequiresReload(op);

    // Remove the subsystem and osb
    op = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
    steps = op.get(STEPS);
    steps.add(Util.createRemoveOperation(SUB));
    steps.add(Util.createRemoveOperation(OSB));
    assertStepRequiresReload(op);

    // Re-add  -- should still get a restart-required header on SUB
    // because removing the o-s-b capability doesn't flush the need to reload
    // We also get a r-r header on the o-s-b add
    op = Util.createAddOperation(OSB);
    op.get(SOCKET_BINDING_REF).set(WFCORE1106);
    assertStepRequiresReload(op);
    op = Util.createAddOperation(SUB);
    op.get("osb").set(WFCORE1106_OSB);
    assertStepRequiresReload(op);

}
 
Example 15
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testCustomRejectChecker() throws Exception {
    //Set up the model
    resourceModel.get("reject").set(new ValueExpression("${expr}"));
    DontRejectChecker dontRejectChecker = new DontRejectChecker();
    CustomRejectExpressionsChecker rejectAttributeChecker = new CustomRejectExpressionsChecker();
    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
        builder.getAttributeBuilder()
            .addRejectCheck(dontRejectChecker, "reject")
            .addRejectCheck(rejectAttributeChecker, "reject")
            .end();
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    dontRejectChecker.called = false;
    rejectAttributeChecker.clear();
    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    //The rejection does not trigger for resource transformation
    //TODO this could be done if 'slave' is >= 7.2.0
    Assert.assertTrue(model.hasDefined("reject"));
    Assert.assertTrue(dontRejectChecker.called);
    Set<String> rejections = rejectAttributeChecker.getRejections();
    Assert.assertEquals(1, rejections.size());
    Assert.assertTrue(rejections.contains("reject"));

    dontRejectChecker.called = false;
    rejectAttributeChecker.clear();
    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("reject").set(new ValueExpression("${expr}"));
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertTrue(transformedAdd.rejectOperation(success()));
    Assert.assertTrue(dontRejectChecker.called);
    rejections = rejectAttributeChecker.getRejections();
    Assert.assertEquals(1, rejections.size());
    Assert.assertTrue(rejections.contains("reject"));


    dontRejectChecker.called = false;
    rejectAttributeChecker.clear();
    ModelNode write = Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "reject", new ModelNode().set(new ValueExpression("${expr}")));
    OperationTransformer.TransformedOperation transformedWrite = transformOperation(write);
    Assert.assertTrue(transformedWrite.rejectOperation(success()));
    Assert.assertTrue(dontRejectChecker.called);
    rejections = rejectAttributeChecker.getRejections();
    Assert.assertEquals(1, rejections.size());
    Assert.assertTrue(rejections.contains("reject"));

}
 
Example 16
Source File: StandaloneXml_10.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void setOrganization(final ModelNode address, final List<ModelNode> operationList, final ModelNode value) {
    if (value != null && value.isDefined() && value.asString().length() > 0) {
        final ModelNode update = Util.getWriteAttributeOperation(address, ORGANIZATION, value);
        operationList.add(update);
    }
}
 
Example 17
Source File: LegacyConfigurationChangesHistoryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Before
public void createConfigurationChanges() throws Exception {
    ManagementClient client = getManagementClient();
    final ModelNode add = Util.createAddOperation(PathAddress.pathAddress(ADDRESS));
    add.get(LegacyConfigurationChangeResourceDefinition.MAX_HISTORY.getName()).set(MAX_HISTORY_SIZE);
    client.executeForResult(add);
    // WFCORE-3995 sensitivity classification system property default configured-requires-read is false.
    // Need to write configured-requires-read before configured-requires-addressable
    ModelNode configureSensitivity = Util.getWriteAttributeOperation(SYSTEM_PROPERTY_CLASSIFICATION_ADDRESS, CONFIGURED_REQUIRES_READ, true);
    client.executeForResult(configureSensitivity);
    configureSensitivity = Util.getWriteAttributeOperation(SYSTEM_PROPERTY_CLASSIFICATION_ADDRESS, CONFIGURED_REQUIRES_ADDRESSABLE, true);
    client.executeForResult(configureSensitivity);
    ModelNode setAllowedOrigins = Util.createEmptyOperation("list-add", ALLOWED_ORIGINS_ADDRESS);
    setAllowedOrigins.get(NAME).set(ALLOWED_ORIGINS);
    setAllowedOrigins.get(VALUE).set("http://www.wildfly.org");
    client.executeForResult(setAllowedOrigins);
    ModelNode disableLogBoot = Util.getWriteAttributeOperation(AUDIT_LOG_ADDRESS, LOG_BOOT, false);
    client.executeForResult(disableLogBoot);
    //read
    client.executeForResult(Util.getReadAttributeOperation(ALLOWED_ORIGINS_ADDRESS, ALLOWED_ORIGINS));
    //invalid operation
    client.getControllerClient().execute(Util.getUndefineAttributeOperation(ALLOWED_ORIGINS_ADDRESS, "not-exists-attribute"));
    //invalid operation
    client.getControllerClient().execute(Util.getWriteAttributeOperation(ALLOWED_ORIGINS_ADDRESS, "not-exists-attribute", "123456"));
    //write operation, failed
    ModelNode setAllowedOriginsFails = Util.getWriteAttributeOperation(ALLOWED_ORIGINS_ADDRESS, ALLOWED_ORIGINS, "123456");//wrong type, expected is LIST, op list-add
    client.getControllerClient().execute(setAllowedOriginsFails);
    ModelNode setSystemProperty = Util.createAddOperation(SYSTEM_PROPERTY_ADDRESS);
    setSystemProperty.get(VALUE).set("changeConfig");
    client.getControllerClient().execute(setSystemProperty);
    ModelNode unsetAllowedOrigins = Util.getUndefineAttributeOperation(ALLOWED_ORIGINS_ADDRESS, ALLOWED_ORIGINS);
    client.getControllerClient().execute(unsetAllowedOrigins);
    ModelNode enableLogBoot = Util.getWriteAttributeOperation(AUDIT_LOG_ADDRESS, LOG_BOOT, true);
    client.getControllerClient().execute(enableLogBoot);
    ModelNode unsetSystemProperty = Util.createRemoveOperation(SYSTEM_PROPERTY_ADDRESS);
    client.getControllerClient().execute(unsetSystemProperty);
    ModelNode addInMemoryHandler = Util.createAddOperation(IN_MEMORY_HANDLER_ADDRESS);
    client.getControllerClient().execute(addInMemoryHandler);
    ModelNode editInMemoryHandler = Util.getWriteAttributeOperation(IN_MEMORY_HANDLER_ADDRESS, MAX_HISTORY, 50);
    client.getControllerClient().execute(editInMemoryHandler);
    ModelNode removeInMemoryHandler = Util.createRemoveOperation(IN_MEMORY_HANDLER_ADDRESS);
    client.getControllerClient().execute(removeInMemoryHandler);
}
 
Example 18
Source File: JmxAuditLogHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode createCoreAuditLogWriteAttributeOperation(String attr, boolean value) {
    return Util.getWriteAttributeOperation(PathAddress.pathAddress(
            CoreManagementResourceDefinition.PATH_ELEMENT,
            AccessAuditResourceDefinition.PATH_ELEMENT,
            AuditLogLoggerResourceDefinition.PATH_ELEMENT), attr, new ModelNode(value));
}
 
Example 19
Source File: HostXml_13.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 20
Source File: AbstractConfigurationChangesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void setConfigurationChangeMaxHistory(DomainClient client, PathElement prefix, int size) throws IOException, UnsuccessfulOperationException {
    PathAddress address = PathAddress.pathAddress().append(prefix).append(getAddress());
    ModelNode writeMaxHistorySize = Util.getWriteAttributeOperation(address, "max-history", size);
    executeForResult(client, writeMaxHistorySize);
    checkMaxHistorySize(client, size, prefix);
}