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

The following examples show how to use org.jboss.as.controller.registry.Resource#registerChild() . 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: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Resource getAuthorizationResource(PathAddress address) {
    Resource model = this.managementModel.getRootResource();
    for (PathElement element : address) {
        // Allow wildcard navigation for the last element
        if (element.isWildcard()) {
            model = Resource.Factory.create();
            final Set<Resource.ResourceEntry> children = model.getChildren(element.getKey());
            for (final Resource.ResourceEntry entry : children) {
                model.registerChild(entry.getPathElement(), entry);
            }
        } else {
            model = model.getChild(element);
            if (model == null) {
                return Resource.Factory.create();
            }
        }
    }
    return model;
}
 
Example 2
Source File: HostModelJvmModelTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected ModelInitializer getModelInitializer() {
    return new ModelInitializer() {
        @Override
        public void populateModel(Resource rootResource) {
            //Register the host resource that will be the parent of the jvm
            rootResource.registerChild(PARENT, Resource.Factory.create());
        }
    };
}
 
Example 3
Source File: TestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void initCoreModel(Resource rootResource, ManagementResourceRegistration rootRegistration, Resource modelControllerResource) {
    VersionModelInitializer.registerRootResource(rootResource, null);
    Resource managementResource = Resource.Factory.create();
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.MANAGEMENT), managementResource);
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.SERVICE_CONTAINER), Resource.Factory.create());
    managementResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.ACCESS, ModelDescriptionConstants.AUTHORIZATION),
            AccessAuthorizationResourceDefinition.createResource(authorizer.getWritableAuthorizerConfiguration()));
    rootResource.registerChild(ServerEnvironmentResourceDescription.RESOURCE_PATH, Resource.Factory.create());
    pathManagerService.addPathManagerResources(rootResource);
}
 
Example 4
Source File: SyncModelServerStateTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void registerServerGroupDeploymentOverlay(Resource root, String groupName, String overlayName, String deploymentName) {
    Resource group = root.requireChild(PathElement.pathElement(SERVER_GROUP, groupName));
    Resource overlay = Resource.Factory.create();
    group.registerChild(PathElement.pathElement(DEPLOYMENT_OVERLAY, overlayName), overlay);
    Resource deployment = Resource.Factory.create();
    deployment.getModel().setEmptyObject();
    overlay.registerChild(PathElement.pathElement(DEPLOYMENT, deploymentName), deployment);
}
 
Example 5
Source File: FindNonProgressingOpUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Resource assemble(Resource... ops) {
    Resource result = Resource.Factory.create(true);
    for (int i = 0; i < ops.length; i++) {
        result.registerChild(PathElement.pathElement(ACTIVE_OPERATION, String.valueOf(i)), ops[i]);
    }
    return result;

}
 
Example 6
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
Resource readResourceFromRoot(ManagementModel managementModel, PathAddress address, boolean recursive) {
    //
    // TODO double check authorization checks for this!
    //
    Resource model = managementModel.getRootResource();
    final Iterator<PathElement> iterator = address.iterator();
    while(iterator.hasNext()) {
        final PathElement element = iterator.next();
        // Allow wildcard navigation for the last element
        if(element.isWildcard() && ! iterator.hasNext()) {
            final Set<Resource.ResourceEntry> children = model.getChildren(element.getKey());
            if(children.isEmpty()) {
                final PathAddress parent = address.subAddress(0, address.size() -1);
                final Set<String> childrenTypes = managementModel.getRootResourceRegistration().getChildNames(parent);
                if(! childrenTypes.contains(element.getKey())) {
                    throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
                }
                // Return an empty model
                return Resource.Factory.create();
            }
            model = Resource.Factory.create();
            for(final Resource.ResourceEntry entry : children) {
                model.registerChild(entry.getPathElement(), entry);
            }
        } else {
            model = requireChild(model, element, address);
        }
    }
    if(recursive) {
        return model.clone();
    } else {
        return model.shallowCopy();
    }
}
 
Example 7
Source File: SyncServerStateOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Set<String> pullDownContent(final Resource domainRootResource) {
    // Make sure we have all needed deployment and management client content
    for (final String id : relevantDeployments) {
        final Set<ContentReference> hashes = deploymentHashes.remove(id);
        if (hashes != null) {
            requiredContent.addAll(hashes);
        }
    }
    for (final ContentReference reference : requiredContent) {
        parameters.getFileRepository().getDeploymentFiles(reference);
        parameters.getContentRepository().addContentReference(reference);
    }

    if (updateRolloutPlans) {
        final PathElement rolloutPlansElement = PathElement.pathElement(MANAGEMENT_CLIENT_CONTENT, ROLLOUT_PLANS);
        final Resource existing = domainRootResource.removeChild(rolloutPlansElement);
        if (existing != null) {
            final ModelNode hashNode = existing.getModel().get(HASH);
            if (hashNode.isDefined()) {
                removedContent.add(
                        new ContentReference(PathAddress.pathAddress(rolloutPlansElement).toCLIStyleString(), hashNode.asBytes()));
            }
        }
        ManagedDMRContentTypeResource rolloutPlansResource =
                new ManagedDMRContentTypeResource(PathAddress.pathAddress(rolloutPlansElement), ROLLOUT_PLAN,
                        rolloutPlansHash, parameters.getContentRepository());
        domainRootResource.registerChild(rolloutPlansElement, rolloutPlansResource);
    }

    final Set<String> servers = new HashSet<>();
    for (String group : affectedGroups) {
        if (serversByGroup.containsKey(group)) {
            servers.addAll(serversByGroup.get(group));
        }
    }
    return servers;
}
 
Example 8
Source File: AbstractOrderedChildResourceSyncModelTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Resource createChildResource(Resource parent, String childType, String value, int index) {
    Resource resource = registerExtraChildren ? Resource.Factory.create(false, Collections.singleton(EXTRA_CHILD.getKey())) : Resource.Factory.create();
    resource.getModel().get(ATTR.getName()).set(value.toUpperCase(Locale.ENGLISH));
    if (index < 0) {
        parent.registerChild(PathElement.pathElement(childType, value.toLowerCase(Locale.ENGLISH)), resource);
    } else {
        parent.registerChild(PathElement.pathElement(childType, value.toLowerCase(Locale.ENGLISH)), index, resource);
    }
    return resource;
}
 
Example 9
Source File: SyncModelServerStateTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void registerRootDeployment(Resource root, String deploymentName, byte[] bytes) {
    Resource deployment = Resource.Factory.create();
    deployment.getModel().get(NAME).set(deploymentName);
    deployment.getModel().get(RUNTIME_NAME).set(deploymentName);
    setDeploymentBytes(deployment, bytes);
    root.registerChild(PathElement.pathElement(DEPLOYMENT, deploymentName), deployment);
}
 
Example 10
Source File: SocketBindingGroupIncludesHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
MockOperationContext getOperationContextForSocketBindingIncludes(final PathAddress operationAddress, RootResourceInitializer initializer) {
    final Resource root = createRootResource();
    Resource socketBindingGroupThree = Resource.Factory.create();
    root.registerChild(PathElement.pathElement(SOCKET_BINDING_GROUP, "binding-three"), socketBindingGroupThree);

    Resource socketBindingGroupFour = Resource.Factory.create();
    root.registerChild(PathElement.pathElement(SOCKET_BINDING_GROUP, "binding-four"), socketBindingGroupFour);

    Resource socketBindingGroupFive = Resource.Factory.create();
    root.registerChild(PathElement.pathElement(SOCKET_BINDING_GROUP, "binding-five"), socketBindingGroupFive);

    initializer.addAdditionalResources(root);
    return new MockOperationContext(root, false, operationAddress, false);
}
 
Example 11
Source File: HostServerSpecifiedPathsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected ModelInitializer createEmptyModelInitalizer() {
    return new ModelInitializer() {
        @Override
        public void populateModel(Resource rootResource) {
            Resource host = Resource.Factory.create();
            rootResource.registerChild(PARENT.getLastElement(), host);
            ModelNode serverConfig = new ModelNode();
            serverConfig.get(GROUP).set("test");
            Resource server1 = Resource.Factory.create();
            server1.writeModel(serverConfig);
            host.registerChild(getPathsParent().getLastElement(), server1);
        }
    };
}
 
Example 12
Source File: HostInfoUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testIgnoredResources() {

    LocalHostControllerInfoImpl lch = new MockLocalHostControllerInfo(new ControlledProcessState(true), "test");
    ProductConfig productConfig = new ProductConfig(null, null, "main");
    IgnoredDomainResourceRegistry ignoredRegistry = new IgnoredDomainResourceRegistry(lch);

    Resource parent = ignoredRegistry.getRootResource();
    PathElement wildcardPE = PathElement.pathElement(ModelDescriptionConstants.IGNORED_RESOURCE_TYPE, "wildcard");
    parent.registerChild(wildcardPE, new IgnoreDomainResourceTypeResource("wildcard", new ModelNode(), Boolean.TRUE));
    PathElement listPE = PathElement.pathElement(ModelDescriptionConstants.IGNORED_RESOURCE_TYPE, "list");
    parent.registerChild(listPE, new IgnoreDomainResourceTypeResource("list", new ModelNode().add("ignored"), Boolean.FALSE));
    PathElement nullWildcardPE = PathElement.pathElement(ModelDescriptionConstants.IGNORED_RESOURCE_TYPE, "nullWildcard");
    parent.registerChild(nullWildcardPE, new IgnoreDomainResourceTypeResource("nullWildcard", new ModelNode().add("ignored"), null));
    PathElement emptyPE = PathElement.pathElement(ModelDescriptionConstants.IGNORED_RESOURCE_TYPE, "empty");
    parent.registerChild(emptyPE, new IgnoreDomainResourceTypeResource("empty", new ModelNode(), null));

    // Do some sanity checking on IgnoredDomainResourceRegistry
    Assert.assertTrue(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("wildcard", "ignored"))));
    Assert.assertTrue(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("list", "ignored"))));
    Assert.assertFalse(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("list", "used"))));
    Assert.assertTrue(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("nullWildcard", "ignored"))));
    Assert.assertFalse(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("nullWildcard", "used"))));
    Assert.assertFalse(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("empty", "ignored"))));
    Assert.assertFalse(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("empty", "used"))));
    Assert.assertFalse(ignoredRegistry.isResourceExcluded(PathAddress.pathAddress(PathElement.pathElement("random", "ignored"))));

    ModelNode model = HostInfo.createLocalHostHostInfo(lch, productConfig, ignoredRegistry, Resource.Factory.create());

    HostInfo testee = HostInfo.fromModelNode(model);

    Assert.assertTrue(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("wildcard", "ignored"))));
    Assert.assertTrue(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("list", "ignored"))));
    Assert.assertFalse(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("list", "used"))));
    Assert.assertTrue(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("nullWildcard", "ignored"))));
    Assert.assertFalse(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("nullWildcard", "used"))));
    Assert.assertFalse(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("empty", "ignored"))));
    Assert.assertFalse(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("empty", "used"))));
    Assert.assertFalse(testee.isResourceTransformationIgnored(PathAddress.pathAddress(PathElement.pathElement("random", "ignored"))));

}
 
Example 13
Source File: ReadResourceWithRuntimeResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testReadResourceWithNoRuntimeResource() throws Exception {
    ModelNode operation = createOperation(READ_RESOURCE_OPERATION, "subsystem", "mysubsystem");
    // use a recursive operations as we are interested by the /susbsystem=mysubsystem's children
    operation.get(RECURSIVE).set(true);

    // read-resource(include-runtime=false) must not return the resource=B child
    operation.get(INCLUDE_RUNTIME).set(false);
    operation.get(PROXIES).set(true);
    ModelNode result = executeForResult(operation);
    assertEquals(1, result.keys().size());
    ModelNode children = result.get("resource");
    assertEquals(2, children.keys().size());
    assertTrue(children.keys().contains("A"));
    assertFalse(children.keys().contains("B"));
    assertTrue(children.keys().contains("C"));

    // read-resource(include-runtime=true) returns the resource=B child (and its attribute)
    // even though it not defined in the model
    operation.get(INCLUDE_RUNTIME).set(true);
    operation.get(PROXIES).set(true);
    result = executeForResult(operation);
    assertEquals(1, result.keys().size());
    children = result.get("resource");
    assertEquals(2, children.keys().size());
    assertTrue(children.keys().contains("A"));
    assertFalse(children.keys().contains("B"));
    assertTrue(children.keys().contains("C"));

    // Now add the "B" resource
    Resource res = managementModel.getRootResource().requireChild(MockProxyController.ADDRESS.getElement(0));
    res.registerChild(PathElement.pathElement("resource", "B"), Resource.Factory.create(true));
    result = executeForResult(operation);
    assertEquals(1, result.keys().size());
    children = result.get("resource");
    assertEquals(3, children.keys().size());
    assertTrue(children.keys().contains("A"));
    assertTrue(children.keys().contains("B"));
    assertTrue(children.keys().contains("C"));
    ModelNode resourceB = children.get("B");
    assertEquals(-1, resourceB.get("attr").asLong());
}
 
Example 14
Source File: ReadMasterDomainModelHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testResourceTransformation() throws Exception {
    Resource resourceRoot = Resource.Factory.create();
    TransformerRegistry registry = TransformerRegistry.Factory.create();
    ManagementResourceRegistration resourceRegistration = ManagementResourceRegistration.Factory.forProcessType(ProcessType.EMBEDDED_SERVER).createRegistration(ROOT);

    final Resource extension = Resource.Factory.create();
    extension.getModel().get("attr").set("value");
    resourceRoot.registerChild(PathElement.pathElement("extension", "not-ignored"), extension);

    final Resource ignoredExtension = Resource.Factory.create();
    ignoredExtension.getModel().get("attr").set("value");
    resourceRoot.registerChild(PathElement.pathElement("extension", "ignored"), ignoredExtension);

    resourceRoot.registerChild(PathElement.pathElement("profile", "not-ignored"), createProfile());
    resourceRoot.registerChild(PathElement.pathElement("profile", "ignored"), createProfile());

    ModelNode original = Resource.Tools.readModel(resourceRoot);
    Assert.assertEquals("value", original.get("extension", "not-ignored", "attr").asString());
    Assert.assertEquals("value", original.get("extension", "ignored", "attr").asString());
    Assert.assertEquals("value", original.get("profile", "not-ignored", "subsystem", "thingy", "attr").asString());
    Assert.assertEquals("value", original.get("profile", "ignored", "subsystem", "thingy", "attr").asString());


    ModelNode hostInfo = new ModelNode();
    hostInfo.get(NAME).set("kabirs-macbook-pro.local");
    hostInfo.get(RELEASE_VERSION).set("8.0.0.Alpha1-SNAPSHOT");
    hostInfo.get(RELEASE_CODENAME).set("TBD");
    hostInfo.get(MANAGEMENT_MAJOR_VERSION).set(1);
    hostInfo.get(MANAGEMENT_MINOR_VERSION).set(4);
    hostInfo.get(MANAGEMENT_MICRO_VERSION).set(0);
    hostInfo.get(IGNORED_RESOURCES, PROFILE, WILDCARD);
    hostInfo.get(IGNORED_RESOURCES, PROFILE, NAMES).add("ignored");
    hostInfo.get(IGNORED_RESOURCES, EXTENSION, WILDCARD);
    hostInfo.get(IGNORED_RESOURCES, EXTENSION, NAMES).add("ignored");
    hostInfo.get(IGNORE_UNUSED_CONFIG).set(false);
    hostInfo.get(INITIAL_SERVER_GROUPS).setEmptyObject();
    hostInfo.get("domain-connection-id").set(1361470170404L);

    Resource transformedResource = transformResource(registry, resourceRoot, resourceRegistration, HostInfo.fromModelNode(hostInfo));
    ModelNode transformed = Resource.Tools.readModel(transformedResource);

    Assert.assertEquals("value", transformed.get("extension", "not-ignored", "attr").asString());
    Assert.assertFalse(transformed.get("extension").hasDefined("ignored"));
    Assert.assertEquals("value", transformed.get("profile", "not-ignored", "subsystem", "thingy", "attr").asString());
    Assert.assertFalse(transformed.get("profile").hasDefined("ignored"));
}
 
Example 15
Source File: ServerService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void initModel(ManagementModel managementModel, Resource modelControllerResource) {
    Resource rootResource = managementModel.getRootResource();
    // TODO maybe make creating of empty nodes part of the MNR description
    Resource managementResource = Resource.Factory.create(); // TODO - Can we get a Resource direct from CoreManagementResourceDefinition?
    managementResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.SERVICE, ModelDescriptionConstants.MANAGEMENT_OPERATIONS), modelControllerResource);
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.MANAGEMENT), managementResource);
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.SERVICE_CONTAINER), Resource.Factory.create());
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.MODULE_LOADING), PlaceholderResource.INSTANCE);
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.CAPABILITY_REGISTRY), Resource.Factory.create());
    managementResource.registerChild(AccessAuthorizationResourceDefinition.PATH_ELEMENT, AccessAuthorizationResourceDefinition.createResource(authorizer.getWritableAuthorizerConfiguration()));
    rootResource.registerChild(ServerEnvironmentResourceDescription.RESOURCE_PATH, Resource.Factory.create());
    ((PathManagerService)injectedPathManagerService.getValue()).addPathManagerResources(rootResource);

    VersionModelInitializer.registerRootResource(rootResource, configuration.getServerEnvironment() != null ? configuration.getServerEnvironment().getProductConfig() : null);

    // Platform MBeans
    rootResource.registerChild(PlatformMBeanConstants.ROOT_PATH, new RootPlatformMBeanResource());

    final RuntimeCapabilityRegistry capabilityRegistry = managementModel.getCapabilityRegistry();
    capabilityRegistry.registerCapability(
            new RuntimeCapabilityRegistration(PATH_MANAGER_CAPABILITY, CapabilityScope.GLOBAL, new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));
    capabilityRegistry.registerCapability(
            new RuntimeCapabilityRegistration(EXECUTOR_CAPABILITY, CapabilityScope.GLOBAL, new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));
    capabilityRegistry.registerCapability(
            new RuntimeCapabilityRegistration(SUSPEND_CONTROLLER_CAPABILITY, CapabilityScope.GLOBAL, new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));
    capabilityRegistry.registerCapability(
            new RuntimeCapabilityRegistration(PROCESS_STATE_NOTIFIER_CAPABILITY, CapabilityScope.GLOBAL, new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));
    capabilityRegistry.registerCapability(
            new RuntimeCapabilityRegistration(EXTERNAL_MODULE_CAPABILITY, CapabilityScope.GLOBAL,new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));
    capabilityRegistry.registerCapability(
            new RuntimeCapabilityRegistration(CONSOLE_AVAILABILITY_CAPABILITY, CapabilityScope.GLOBAL, new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));

    // Record the core capabilities with the root MRR so reads of it will show it as their provider
    // This also gets them recorded as 'possible capabilities' in the capability registry
    ManagementResourceRegistration rootRegistration = managementModel.getRootResourceRegistration();
    rootRegistration.registerCapability(PATH_MANAGER_CAPABILITY);
    rootRegistration.registerCapability(EXECUTOR_CAPABILITY);
    rootRegistration.registerCapability(SUSPEND_CONTROLLER_CAPABILITY);
    rootRegistration.registerCapability(PROCESS_STATE_NOTIFIER_CAPABILITY);
    rootRegistration.registerCapability(EXTERNAL_MODULE_CAPABILITY);
    rootRegistration.registerCapability(CONSOLE_AVAILABILITY_CAPABILITY);
}
 
Example 16
Source File: HostVaultTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void populateModel(Resource rootResource) {
    Resource host = Resource.Factory.create();
    rootResource.registerChild(PathElement.pathElement(HOST, "master"), host);
}
 
Example 17
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a resource based on the result of the {@code ReadMasterDomainModelHandler}.
 *
 * @param result        the operation result
 * @param extensions    set to track extensions
 * @return the resource
 */
static Resource createResourceFromDomainModelOp(final ModelNode result, final Set<String> extensions) {
    final Resource root = Resource.Factory.create();
    for (ModelNode model : result.asList()) {

        final PathAddress resourceAddress = PathAddress.pathAddress(model.require(DOMAIN_RESOURCE_ADDRESS));

        if (resourceAddress.size() == 1) {
            final PathElement element = resourceAddress.getElement(0);
            if (element.getKey().equals(EXTENSION)) {
                if (!extensions.contains(element.getValue())) {
                    extensions.add(element.getValue());
                }
            }
        }

        Resource resource = root;
        final Iterator<PathElement> i = resourceAddress.iterator();
        if (!i.hasNext()) { //Those are root attributes
            resource.getModel().set(model.require(DOMAIN_RESOURCE_MODEL));
        }
        while (i.hasNext()) {
            final PathElement e = i.next();

            if (resource.hasChild(e)) {
                resource = resource.getChild(e);
            } else {
                /*
                {
                    "domain-resource-address" => [
                        ("profile" => "test"),
                        ("subsystem" => "test")
                    ],
                    "domain-resource-model" => {},
                    "domain-resource-properties" => {"ordered-child-types" => ["ordered-child"]}
                }*/
                final Resource nr;
                if (model.hasDefined(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY)) {
                    List<ModelNode> list = model.get(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY).asList();
                    Set<String> orderedChildTypes = new HashSet<String>(list.size());
                    for (ModelNode type : list) {
                        orderedChildTypes.add(type.asString());
                    }
                    nr = Resource.Factory.create(false, orderedChildTypes);
                } else {
                    nr = Resource.Factory.create();
                }
                resource.registerChild(e, nr);
                resource = nr;
            }

            if (!i.hasNext()) {
                resource.getModel().set(model.require(DOMAIN_RESOURCE_MODEL));
            }
        }
    }
    return root;
}
 
Example 18
Source File: ReadFeatureDescriptionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void initModel(ManagementModel managementModel) {
    registration = managementModel.getRootResourceRegistration();

    // register root attr and capability
    ModelOnlyWriteAttributeHandler writeHandler = new ModelOnlyWriteAttributeHandler();
    registration.registerReadWriteAttribute(new SimpleAttributeDefinitionBuilder(NAME, ModelType.STRING).build(), null, writeHandler);
    registration.registerCapability(RuntimeCapability.Builder.of(ROOT_CAPABILITY_NAME).build());
    registration.registerCapability(RuntimeCapability.Builder.of(DYNAMIC_CAPABILITY_NAME, true).build());

    // register extension with child subsystem
    Resource extensionRes = Resource.Factory.create();
    extensionRes.registerChild(PathElement.pathElement(SUBSYSTEM, TEST_SUBSYSTEM), Resource.Factory.create());
    managementModel.getRootResource().registerChild(PathElement.pathElement(EXTENSION, TEST_EXTENSION), extensionRes);

    // subsystem=testsubsystem
    ManagementResourceRegistration subsysRegistration =
            registration.registerSubModel(new SimpleResourceDefinition(
                    new SimpleResourceDefinition.Parameters(PathElement.pathElement(SUBSYSTEM, TEST_SUBSYSTEM),
                            NonResolvingResourceDescriptionResolver.INSTANCE)));
    subsysRegistration.registerCapability(RuntimeCapability.Builder.of("subsystem-capability").build());

    // resource=main-resource
    ManagementResourceRegistration mainResourceRegistration =
            subsysRegistration.registerSubModel(new MainResourceDefinition(
                    PathElement.pathElement(RESOURCE, MAIN_RESOURCE),
                        NonResolvingResourceDescriptionResolver.INSTANCE));

    // resource=referencing-resource
    subsysRegistration.registerSubModel(new ReferencingResourceDefinition(PathElement.pathElement(RESOURCE, REFERENCING_RESOURCE),
            NonResolvingResourceDescriptionResolver.INSTANCE));

    // register runtime resource
    subsysRegistration.registerSubModel(new SimpleResourceDefinition(
            new SimpleResourceDefinition.Parameters(PathElement.pathElement(RESOURCE, RUNTIME_RESOURCE),
                    NonResolvingResourceDescriptionResolver.INSTANCE)
                    .setRuntime()));

    // register another resource that is marked as not-a-feature
    subsysRegistration.registerSubModel(new SimpleResourceDefinition(
            new SimpleResourceDefinition.Parameters(PathElement.pathElement(RESOURCE, NON_FEATURE_RESOURCE),
                    NonResolvingResourceDescriptionResolver.INSTANCE)
                    .setFeature(false)));

    // register resource "test=storage-resource" with attribute "test", so that the "test" parameter will need to be
    // remapped to "test-feature"
    subsysRegistration.registerSubModel(new TestResourceDefinition(PathElement.pathElement(TEST, SPECIAL_NAMES_RESOURCE),
                    NonResolvingResourceDescriptionResolver.INSTANCE));

    registration.registerAlias(PathElement.pathElement("alias", "alias-to-resource"), new AliasEntry(mainResourceRegistration) {
        @Override
        public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
            return getTargetAddress();
        }
    });
}
 
Example 19
Source File: CoreManagementResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void registerDomainResource(Resource parent, AccessConstraintUtilizationRegistry registry) {
    Resource coreManagement = Resource.Factory.create();
    coreManagement.registerChild(AccessAuthorizationResourceDefinition.PATH_ELEMENT,
            AccessAuthorizationResourceDefinition.createResource(registry));
    parent.registerChild(PATH_ELEMENT, coreManagement);
}
 
Example 20
Source File: HostSystemPropertyTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void populateModel(Resource rootResource) {
    Resource host = Resource.Factory.create();
    rootResource.registerChild(PARENT.getElement(0), host);
}