Java Code Examples for org.jboss.as.controller.registry.Resource#getChild()

The following examples show how to use org.jboss.as.controller.registry.Resource#getChild() . 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: ObjectNameAddressUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static PathAddress searchPathAddress(final PathAddress address, final Resource resource, final Map<String, String> properties) {
    if (properties.size() == 0) {
        return address;
    }
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        PathElement childElement = PathElement.pathElement(
                replaceEscapedCharactersInKey(entry.getKey()),
                replaceEscapedCharactersInValue(entry.getValue()));
        Resource child = resource.getChild(childElement);
        if (child != null) {
            Map<String, String> childProps = new HashMap<String, String>(properties);
            childProps.remove(entry.getKey());
            PathAddress foundAddr = searchPathAddress(address.append(childElement), child, childProps);
            if (foundAddr != null) {
                return foundAddr;
            }
        }
    }
    return null;
}
 
Example 2
Source File: RbacSanityCheckOperation.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
boolean doRoleMappingsExist() throws OperationFailedException {
    Resource authorizationResource = managementResource.getChild(PathElement.pathElement(ACCESS, AUTHORIZATION));
    Set<String> roleNames = authorizationResource.getChildrenNames(ROLE_MAPPING);
    for (String current : roleNames) {
        Resource roleResource = authorizationResource.getChild(PathElement.pathElement(ROLE_MAPPING, current));
        ModelNode roleModel = roleResource.getModel();
        if (roleModel.get(INCLUDE_ALL).isDefined() && roleModel.require(INCLUDE_ALL).asBoolean()) {
            return true;
        }

        if (roleResource.getChildren(INCLUDE).size() > 0) {
            return true;
        }
    }

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

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder().addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, "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(new ValueExpression("${expr}"));
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertTrue(transformedAdd.rejectOperation(success()));

    ModelNode write = Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "reject", new ModelNode().set(new ValueExpression("${expr}")));
    OperationTransformer.TransformedOperation transformedWrite = transformOperation(write);
    Assert.assertTrue(transformedWrite.rejectOperation(success()));
}
 
Example 4
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRenameAttribute() throws Exception {
    resourceModel.get("old").set("value");

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
        builder.getAttributeBuilder().addRename("old", "new").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();
    Assert.assertEquals(1, model.keys().size());
    Assert.assertEquals("value", model.get("new").asString());

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("old").set("value");
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertFalse(transformedAdd.rejectOperation(success()));
    Assert.assertFalse(transformedAdd.getTransformedOperation().hasDefined("old"));
    Assert.assertEquals("value", transformedAdd.getTransformedOperation().get("new").asString());


    checkWriteOp(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "old", new ModelNode("value")),
            "new", new ModelNode("value"));
}
 
Example 5
Source File: RecursiveDiscardAndRemoveTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRejectResource() throws Exception {
    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.rejectChildResource(DISCARDED_WILDCARD);
    builder.rejectChildResource(DISCARDED_SPECIFIC);
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    //Make sure the resource has none of the discarded children
    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    Assert.assertEquals(1, model.keys().size());
    Assert.assertEquals("test", model.get("subs").asString());

    //Sanity check that the subsystem works
    sanityTestNonDiscardedResource();

    //Check that the op gets rejected for the wildcard entry
    rejectResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_WILDCARD_ENTRY));

    //Check that the op gets rejected for the specific entry
    rejectResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_SPECIFIC));

    //Check that the op gets rejected for the wildcard entry child
    rejectResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_WILDCARD_ENTRY, DISCARDED_CHILD));

    //Check that the op gets rejected for the specific entry child
    rejectResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_SPECIFIC, DISCARDED_CHILD));
}
 
Example 6
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDiscardUndefined() throws Exception {
    //Set up the model
    resourceModel.get("discard");
    resourceModel.get("keep").set("here");

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
        builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.UNDEFINED, "discard", "keep").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();
    Assert.assertTrue(model.hasDefined("keep"));
    Assert.assertFalse(model.has("discard"));

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("discard");
    add.get("keep").set("here");
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertFalse(transformedAdd.rejectOperation(success()));
    Assert.assertTrue(transformedAdd.getTransformedOperation().hasDefined("keep"));
    Assert.assertFalse(transformedAdd.getTransformedOperation().has("discard"));

    checkOpDiscarded(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "discard", new ModelNode()));

    checkWriteOp(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "discard", new ModelNode("nothing")),
            "discard", new ModelNode("nothing"));
}
 
Example 7
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAddValue() throws Exception {
    resourceModel.get("old").set("existing");

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder().setValueConverter(new DefaultAttributeConverter() {
        @Override
        public void convertAttribute(PathAddress address, String name, ModelNode attributeValue, TransformationContext context) {
            attributeValue.set("extra");
        }
    }, "added").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();
    Assert.assertEquals(2, model.keys().size());
    Assert.assertEquals("existing", model.get("old").asString());
    Assert.assertEquals("extra", model.get("added").asString());

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("old").set("existing");
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertFalse(transformedAdd.rejectOperation(success()));
    Assert.assertEquals("existing", transformedAdd.getTransformedOperation().get("old").asString());
    Assert.assertEquals("extra", transformedAdd.getTransformedOperation().get("added").asString());

    //Can't write to this added attribute
}
 
Example 8
Source File: ChildRedirectTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testFixedRedirect() throws Exception {
    PathElement newChild = PathElement.pathElement("new-style", "lalala");
    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.addChildRedirection(CHILD_ONE, newChild);
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);

    Set<String> types = toto.getChildTypes();
    Assert.assertEquals(2, types.size());
    Assert.assertTrue(types.contains(CHILD_TWO.getKey()));
    Assert.assertTrue(types.contains(newChild.getKey()));

    Set<ResourceEntry> childEntries = toto.getChildren(CHILD_TWO.getKey());
    Assert.assertEquals(1, childEntries.size());
    Assert.assertEquals(CHILD_TWO, childEntries.iterator().next().getPathElement());

    childEntries = toto.getChildren(newChild.getKey());
    Assert.assertEquals(1, childEntries.size());
    Assert.assertEquals(newChild, childEntries.iterator().next().getPathElement());

    //Test operations get redirected
    final ModelNode addOp = Util.createAddOperation(PathAddress.pathAddress(PATH, CHILD_ONE));
    OperationTransformer.TransformedOperation txOp = transformOperation(ModelVersion.create(1), addOp.clone());
    Assert.assertFalse(txOp.rejectOperation(success()));
    final ModelNode expectedTx = Util.createAddOperation(PathAddress.pathAddress(PATH, newChild));
    Assert.assertEquals(expectedTx, txOp.getTransformedOperation());

    //Test operations in a composite get redirected
    final ModelNode composite = createComposite(addOp, addOp);
    txOp = transformOperation(ModelVersion.create(1), composite);
    Assert.assertFalse(txOp.rejectOperation(success()));
    Assert.assertEquals(createComposite(expectedTx, expectedTx), txOp.getTransformedOperation());

}
 
Example 9
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determine the relevant pieces of configuration which need to be included when processing the domain model.
 *
 * @param root                 the resource root
 * @param requiredConfigurationHolder    the resolution context
 * @param serverConfig         the server config
 * @param extensionRegistry    the extension registry
 */
static void processServerConfig(final Resource root, final RequiredConfigurationHolder requiredConfigurationHolder, final IgnoredNonAffectedServerGroupsUtil.ServerConfigInfo serverConfig, final ExtensionRegistry extensionRegistry) {

    final Set<String> serverGroups = requiredConfigurationHolder.serverGroups;
    final Set<String> socketBindings = requiredConfigurationHolder.socketBindings;

    String sbg = serverConfig.getSocketBindingGroup();
    if (sbg != null && !socketBindings.contains(sbg)) {
        processSocketBindingGroup(root, sbg, requiredConfigurationHolder);
    }

    final String groupName = serverConfig.getServerGroup();
    final PathElement groupElement = PathElement.pathElement(SERVER_GROUP, groupName);
    // Also check the root, since this also gets executed on the slave which may not have the server-group configured yet
    if (!serverGroups.contains(groupName) && root.hasChild(groupElement)) {

        final Resource serverGroup = root.getChild(groupElement);
        final ModelNode groupModel = serverGroup.getModel();
        serverGroups.add(groupName);

        // Include the socket binding groups
        if (groupModel.hasDefined(SOCKET_BINDING_GROUP)) {
            final String socketBindingGroup = groupModel.get(SOCKET_BINDING_GROUP).asString();
            processSocketBindingGroup(root, socketBindingGroup, requiredConfigurationHolder);
        }

        final String profileName = groupModel.get(PROFILE).asString();
        processProfile(root, profileName, requiredConfigurationHolder, extensionRegistry);
    }
}
 
Example 10
Source File: BasicResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testResourceTransformation() throws Exception {

    final ModelNode address = new ModelNode();
    address.add("toto", "testSubsystem");

    final ModelNode node = new ModelNode();
    node.get(ModelDescriptionConstants.OP).set("add");
    node.get(ModelDescriptionConstants.OP_ADDR).set(address);

    final OperationTransformer.TransformedOperation op = transformOperation(ModelVersion.create(1), node);
    Assert.assertNotNull(op);

    final Resource resource = transformResource(ModelVersion.create(1));

    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    final ModelNode model = toto.getModel();
    Assert.assertNotNull(toto);
    Assert.assertFalse(toto.hasChild(PathElement.pathElement("discard", "one")));
    Assert.assertFalse(toto.hasChild(CONFIGURATION_TEST));

    Assert.assertFalse(toto.hasChild(PathElement.pathElement("dynamic", "discard")));
    Assert.assertFalse(toto.hasChild(PathElement.pathElement("dynamic", "reject")));
    Resource dynamicKeep = toto.getChild(PathElement.pathElement("dynamic", "keep"));
    Assert.assertEquals("KEEP", dynamicKeep.getModel().get("attribute").asString());

    Assert.assertFalse(toto.hasChildren("dynamic-redirect-original")); //Make sure that we didn't keep the originals
    Assert.assertFalse(toto.hasChild(PathElement.pathElement("dynamic-redirect-new", "discard")));
    Assert.assertFalse(toto.hasChild(PathElement.pathElement("dynamic-redirect-new", "reject")));
    Resource dynamicRedirectKeep = toto.getChild(PathElement.pathElement("dynamic-redirect-new", "keep"));
    Assert.assertEquals("KEEP", dynamicRedirectKeep.getModel().get("attribute").asString());

    final Resource attResource = toto.getChild(PathElement.pathElement("attribute-resource", "test"));
    Assert.assertNotNull(attResource);
    final ModelNode attResourceModel = attResource.getModel();
    Assert.assertFalse(attResourceModel.get("test-resource").isDefined());  // check that the resource got removed
    Assert.assertTrue(attResourceModel.hasDefined("test-attribute"));
    Assert.assertTrue(attResource.hasChild(PathElement.pathElement("resource", "test")));
}
 
Example 11
Source File: JmxAuditLogHandlerReferenceResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean lookForResource(final Resource root, final PathAddress pathAddress) {
    Resource current = root;
    for (PathElement element : pathAddress) {
        current = current.getChild(element);
        if (current == null) {
            return false;
        }
    }
    return true;
}
 
Example 12
Source File: ReadContentHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    Resource resource = context.getOriginalRootResource();
    for(final PathElement element : address) {
        resource = resource.getChild(element);
    }
    byte[] content = resource.getModel().get(CONTENT).asBytes();
    final VirtualFile file = contentRepository.getContent(content);
    try {
        context.getResult().set(readFile(file));
    } catch (IOException e) {
        throw ServerLogger.ROOT_LOGGER.failedToLoadFile(file, e);
    }
}
 
Example 13
Source File: IgnoredNonAffectedServerGroupsUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processSocketBindingGroups(final Resource domainResource, final String name, final Set<String> socketBindingGroups) {
    if (!socketBindingGroups.contains(name)) {
        socketBindingGroups.add(name);
        final PathElement pathElement = PathElement.pathElement(SOCKET_BINDING_GROUP, name);
        if (domainResource.hasChild(pathElement)) {
            final Resource resource = domainResource.getChild(pathElement);
            final ModelNode model = resource.getModel();
            if (model.hasDefined(INCLUDES)) {
                for (final ModelNode include : model.get(INCLUDES).asList()) {
                    processSocketBindingGroups(domainResource, include.asString(), socketBindingGroups);
                }
            }
        }
    }
}
 
Example 14
Source File: ChainedTransformingDescription.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void copy(Resource src, Resource dest, PathAddress address) {
    PathAddress parentAddress = address.size() > 1 ? address.subAddress(0, address.size() - 1) : PathAddress.EMPTY_ADDRESS;
    PathElement childElement = address.getLastElement();
    Resource source = src.navigate(parentAddress);
    Resource destination = dest.navigate(parentAddress);
    Resource sourceChild = source.getChild(childElement);
    if (sourceChild != null) {
        Resource destChild = Resource.Factory.create();
        destination.registerChild(childElement, destChild);
        copy(sourceChild, destChild);
    }
    //copy(src, dest);
}
 
Example 15
Source File: IgnoredNonAffectedServerGroupsUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processProfiles(final Resource domain, final String profile, final Set<String> profiles) {
    if (!profiles.contains(profile)) {
        profiles.add(profile);
        final PathElement pathElement = PathElement.pathElement(PROFILE, profile);
        if (domain.hasChild(pathElement)) {
            final Resource resource = domain.getChild(pathElement);
            final ModelNode model = resource.getModel();
            if (model.hasDefined(INCLUDES)) {
                for (final ModelNode include : model.get(INCLUDES).asList()) {
                    processProfiles(domain, include.asString(), profiles);
                }
            }
        }
    }
}
 
Example 16
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAccessOtherValue() throws Exception {
    //Set up the model
    resourceModel.get("checked").set("test");
    resourceModel.get("other").set("value");

    VisibilityCheckerAndConverter checker = new VisibilityCheckerAndConverter();

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder()
        .addRejectCheck(checker, "checked")
        .setDiscard(checker, "checked")
        .setValueConverter(checker, "checked")
        .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("checked"));
    checker.checkValues("value");

    checker.reset();
    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("checked").set("test");
    add.get("other").set("value");
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertFalse(transformedAdd.rejectOperation(success()));
    checker.checkValues("value");

    checker.reset();
    ModelNode write = Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "checked", new ModelNode("test"));
    OperationTransformer.TransformedOperation transformedWrite = transformOperation(write);
    Assert.assertFalse(transformedWrite.rejectOperation(success()));
    checker.checkValues("value");
}
 
Example 17
Source File: RecursiveDiscardAndRemoveTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDiscardResource() throws Exception {
    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.discardChildResource(DISCARDED_WILDCARD);
    builder.discardChildResource(DISCARDED_SPECIFIC);
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    //Make sure the resource has none of the discarded children
    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    Assert.assertEquals(1, model.keys().size());
    Assert.assertEquals("test", model.get("subs").asString());

    //Sanity check that the subsystem works
    sanityTestNonDiscardedResource();

    //Check that the op gets discarded for the wildcard entry
    discardResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_WILDCARD_ENTRY));

    //Check that the op gets discarded for the specific entry
    discardResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_SPECIFIC));

    //Check that the op gets discarded for the wildcard entry child
    discardResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_WILDCARD_ENTRY, DISCARDED_CHILD));

    //Check that the op gets discarded for the specific entry child
    discardResourceOperationsTest(PathAddress.pathAddress(PATH, DISCARDED_SPECIFIC, DISCARDED_CHILD));
}
 
Example 18
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testConvertValue() throws Exception {
    resourceModel.get("value1").set("one");
    resourceModel.get("value2").set("two");

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder().setValueConverter(new DefaultAttributeConverter() {
        @Override
        public void convertAttribute(PathAddress address, String name, ModelNode attributeValue, TransformationContext context) {
            if (name.equals("value2") && attributeValue.asString().equals("two")) {
                attributeValue.set(1);
            }
        }
    }, "value1", "value2").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();
    Assert.assertEquals(2, model.keys().size());
    Assert.assertEquals("one", model.get("value1").asString());
    Assert.assertEquals(ModelType.INT, model.get("value2").getType());
    Assert.assertEquals(1, model.get("value2").asInt());

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("value1").set("one");
    add.get("value2").set("two");
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertFalse(transformedAdd.rejectOperation(success()));
    Assert.assertEquals("one", transformedAdd.getTransformedOperation().get("value1").asString());
    Assert.assertEquals(ModelType.INT, transformedAdd.getTransformedOperation().get("value2").getType());
    Assert.assertEquals(1, transformedAdd.getTransformedOperation().get("value2").asInt());

    checkWriteOp(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "value1", new ModelNode("value")),
            "value1", new ModelNode("value"));
    checkWriteOp(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "value2", new ModelNode("two")),
            "value2", new ModelNode(1));
}
 
Example 19
Source File: SyncModelServerStateTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void replaceRootDeployment(Resource root, String deploymentName, byte[] bytes) {
    Resource deployment = root.getChild(PathElement.pathElement(DEPLOYMENT, deploymentName));
    deployment.getModel().remove(CONTENT);
    setDeploymentBytes(deployment, bytes);
}
 
Example 20
Source File: ValidateAddressOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    ModelNode addr = VALUE_PARAM.validateOperation(operation);
    final PathAddress pathAddr = PathAddress.pathAddress(addr);
    Resource model = context.readResource(PathAddress.EMPTY_ADDRESS);
    final Iterator<PathElement> iterator = pathAddr.iterator();
    PathAddress current = PathAddress.EMPTY_ADDRESS;
    out: while(iterator.hasNext()) {
        final PathElement next = iterator.next();
        current = current.append(next);

        // Check if the registration is a proxy and dispatch directly
        final ImmutableManagementResourceRegistration registration = context.getResourceRegistration().getSubModel(current);

        if(registration != null && registration.isRemote()) {

            // If the target is a registered proxy return immediately
            if(! iterator.hasNext()) {
                break out;
            }

            // Create the proxy op
            final PathAddress newAddress = pathAddr.subAddress(current.size());
            final ModelNode newOperation = operation.clone();
            newOperation.get(OP_ADDR).set(current.toModelNode());
            newOperation.get(VALUE).set(newAddress.toModelNode());

            // On the DC the host=master is not a proxy but the validate-address is registered at the root
            // Otherwise delegate to the proxy handler
            final OperationStepHandler proxyHandler = registration.getOperationHandler(PathAddress.EMPTY_ADDRESS, OPERATION_NAME);
            if(proxyHandler != null) {
                context.addStep(newOperation, proxyHandler, OperationContext.Stage.MODEL, true);
                return;
            }

        } else if (model.hasChild(next)) {
            model = model.getChild(next);
        } else {
            // Invalid
            context.getResult().get(VALID).set(false);
            context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.childResourceNotFound(next));
            return;
        }
    }

    if (authorize(context, current, operation).getDecision() == Decision.DENY) {
        context.getResult().get(VALID).set(false);
        context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.managementResourceNotFoundMessage(current));
    } else {
        context.getResult().get(VALID).set(true);
    }
}