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

The following examples show how to use org.jboss.as.controller.registry.Resource#getChildTypes() . 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: RootResourceIterator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void doIterate(final Resource current, final PathAddress address) {
    boolean handleChildren = false;

    ObjectName resourceObjectName = action.onAddress(address);
    if (resourceObjectName != null &&
            (accessControlUtil == null || accessControlUtil.getResourceAccess(address, false).isAccessibleResource())) {
        handleChildren = action.onResource(resourceObjectName);
    }

    if (handleChildren) {
        for (String type : current.getChildTypes()) {
            if (current.hasChildren(type)) {
                for (ResourceEntry entry : current.getChildren(type)) {
                    final PathElement pathElement = entry.getPathElement();
                    final PathAddress childAddress = address.append(pathElement);
                    doIterate(entry, childAddress);
                }
            }
        }
    }
}
 
Example 2
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void describe(final PathAddress base, final Resource resource, List<ModelNode> nodes, boolean isRuntimeChange) {
    if (resource.isProxy() || resource.isRuntime()) {
        return; // ignore runtime and proxies
    } else if (base.size() >= 1 && base.getElement(0).getKey().equals(ModelDescriptionConstants.HOST)) {
        return; // ignore hosts
    }
    if (base.size() == 1) {
        newRootResources.add(base.getLastElement());
    }
    final ModelNode description = new ModelNode();
    description.get(DOMAIN_RESOURCE_ADDRESS).set(base.toModelNode());
    description.get(DOMAIN_RESOURCE_MODEL).set(resource.getModel());
    Set<String> orderedChildren = resource.getOrderedChildTypes();
    if (orderedChildren.size() > 0) {
        ModelNode orderedChildTypes = description.get(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY);
        for (String type : orderedChildren) {
            orderedChildTypes.add(type);
        }
    }
    nodes.add(description);
    for (final String childType : resource.getChildTypes()) {
        for (final Resource.ResourceEntry entry : resource.getChildren(childType)) {
            describe(base.append(entry.getPathElement()), entry, nodes, isRuntimeChange);
        }
    }
}
 
Example 3
Source File: ReadConfigAsFeaturesOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void describeChildren(final Resource resource, final ImmutableManagementResourceRegistration registration,
        final PathAddress address, OperationContext context,
        final AtomicReference<ModelNode> failureRef, final ModelNode results, ModelNode operation, Boolean nest) {
    for(String childType : resource.getChildTypes()) {
        for(Resource.ResourceEntry entry : resource.getChildren(childType)) {
            if(addressFilter != null && !addressFilter.accepts(address.append(entry.getPathElement()))) {
                continue;
            }
            final ImmutableManagementResourceRegistration childRegistration = registration.getSubModel(PathAddress.EMPTY_ADDRESS.append(entry.getPathElement()));
            if(childRegistration == null) {
                ControllerLogger.ROOT_LOGGER.debugf("Couldn't find a registration for %s at %s for resource %s at %s", entry.getPathElement().toString(), registration.getPathAddress().toCLIStyleString(), resource, address.toCLIStyleString());
                continue;
            }
            if(childRegistration.isRuntimeOnly() || childRegistration.isRemote() || childRegistration.isAlias()) {
                continue;
            }
            describeChildResource(entry, registration, address, context, failureRef, results, operation, nest);
        }
    }
}
 
Example 4
Source File: ResourceTransformationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void processChildren(final Resource resource) throws OperationFailedException {
    final Set<String> types = resource.getChildTypes();
    for (final String type : types) {
        for (final Resource.ResourceEntry child : resource.getChildren(type)) {
            processChild(child.getPathElement(), child);
        }
    }
}
 
Example 5
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) {
    dest.getModel().set(src.getModel());
    for (String type : src.getChildTypes()) {
        for (ResourceEntry entry : src.getChildren(type)) {
            Resource added = Resource.Factory.create();
            dest.registerChild(PathElement.pathElement(type, entry.getName()), added);
            copy(entry, added);
        }
    }
}
 
Example 6
Source File: GenericSubsystemDescribeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void describe(final OrderedChildTypesAttachment orderedChildTypesAttachment, final Resource resource,
                        final ModelNode address, ModelNode result, final ImmutableManagementResourceRegistration registration) {
    if(resource == null || registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime() || registration.isAlias()) {
        return;
    }

    final Set<PathElement> children;
    final Set<PathElement> defaultChildren = new LinkedHashSet<>();
    for (String type : resource.getChildTypes()) {
        for (String value : resource.getChildrenNames(type)) {
            defaultChildren.add(PathElement.pathElement(type, value));
        }
    }
    if (comparator == null) {
        children = defaultChildren;
    } else {
        children = new TreeSet<PathElement>(comparator);
        children.addAll(defaultChildren);
    }
    result.add(createAddOperation(orderedChildTypesAttachment, address, resource, children));
    for(final PathElement element : children) {
        final Resource child = resource.getChild(element);
        final ImmutableManagementResourceRegistration childRegistration = registration.getSubModel(PathAddress.pathAddress(element));
        if (childRegistration == null) {
            ControllerLogger.ROOT_LOGGER.debugf("No MRR exists for %s", registration.getPathAddress().append(element));
        } else {
            final ModelNode childAddress = address.clone();
            childAddress.add(element.getKey(), element.getValue());
            describe(orderedChildTypesAttachment, child, childAddress, result, childRegistration);
        }
    }
}
 
Example 7
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 8
Source File: AliasTransformerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testResourceTransformation() throws Exception {
    //We probably test this elsewhere, but make sure that only real (i.e. non-alias resources get transformed)
    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);

    Set<String> types = toto.getChildTypes();
    Assert.assertEquals(1, types.size());
    Assert.assertTrue(types.contains(LEGACY_CHILD.getKey()));
    Set<Resource.ResourceEntry> entries = toto.getChildren(LEGACY_CHILD.getKey());
    Assert.assertEquals(1, entries.size());
    Assert.assertNotNull(toto.getChild(PathElement.pathElement(LEGACY_CHILD.getKey(), "one")));
}
 
Example 9
Source File: OperationTransformationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode readModelRecursively(Resource resource) {
    ModelNode model = new ModelNode();
    model.set(resource.getModel().clone());

    for (String type : resource.getChildTypes()) {
        for (ResourceEntry entry : resource.getChildren(type)) {
            model.get(type, entry.getName()).set(readModelRecursively(entry));
        }
    }
    return model;
}
 
Example 10
Source File: ChildRedirectTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testWildcardRedirect() throws Exception {
    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.addChildRedirection(CHILD, NEW_CHILD);
    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(1, types.size());
    Assert.assertTrue(types.contains(NEW_CHILD.getKey()));

    Set<ResourceEntry> entries = toto.getChildren(NEW_CHILD.getKey());
    Assert.assertEquals(2, entries.size());

    PathElement[] expectedChildren = new PathElement[] {PathElement.pathElement(NEW_CHILD.getKey(), CHILD_ONE.getValue()), PathElement.pathElement(NEW_CHILD.getKey(), CHILD_TWO.getValue())};
    for (PathElement expectedChild : expectedChildren) {
        boolean found = false;
        for (ResourceEntry entry : entries) {
            if (entry.getPathElement().equals(expectedChild)) {
                found = true;
                break;
            }
        }
        Assert.assertTrue(found);
    }

    //Test operations get redirected
    final ModelNode addOp = Util.createAddOperation(PathAddress.pathAddress(PATH, CHILD));
    OperationTransformer.TransformedOperation txOp = transformOperation(ModelVersion.create(1), addOp.clone());
    Assert.assertFalse(txOp.rejectOperation(success()));
    final ModelNode expectedTx = Util.createAddOperation(PathAddress.pathAddress(PATH, NEW_CHILD));
    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());
}