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

The following examples show how to use org.jboss.as.controller.registry.Resource#hasChild() . 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: DeploymentResourceSupport.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Checks to see if a resource has already been registered for the specified address on the subsystem.
 *
 * @param subsystemName the name of the subsystem
 * @param address       the address to check
 *
 * @return {@code true} if the address exists on the subsystem otherwise {@code false}
 */
public boolean hasDeploymentSubModel(final String subsystemName, final PathAddress address) {
    final Resource root = deploymentUnit.getAttachment(DEPLOYMENT_RESOURCE);
    final PathElement subsystem = PathElement.pathElement(SUBSYSTEM, subsystemName);
    boolean found = false;
    if (root.hasChild(subsystem)) {
        if (address == PathAddress.EMPTY_ADDRESS) {
            return true;
        }
        Resource parent = root.getChild(subsystem);
        for (PathElement child : address) {
            if (parent.hasChild(child)) {
                found = true;
                parent = parent.getChild(child);
            } else {
                found = false;
                break;
            }
        }
    }
    return found;
}
 
Example 2
Source File: DeploymentRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void checkCanRemove(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String deploymentName = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();
    final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);

    if(root.hasChild(PathElement.pathElement(SERVER_GROUP))) {
        final List<String> badGroups = new ArrayList<String>();
        for(final Resource.ResourceEntry entry : root.getChildren(SERVER_GROUP)) {
            if(entry.hasChild(PathElement.pathElement(DEPLOYMENT, deploymentName))) {
                badGroups.add(entry.getName());
            }
        }

        if (badGroups.size() > 0) {
            throw new OperationFailedException(DomainControllerLogger.ROOT_LOGGER.cannotRemoveDeploymentInUse(deploymentName, badGroups));
        }
    }
}
 
Example 3
Source File: WorkerThreadPoolVsEndpointHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    ModelNode model = resource.getModel();
    boolean hasLegacy = false;
    if (forDomain) {
        for (final AttributeDefinition attribute : RemotingSubsystemRootResource.LEGACY_ATTRIBUTES) {
            if (model.hasDefined(attribute.getName())) {
                hasLegacy = true;
                break;
            }
        }
    }

    if (!hasLegacy && !resource.hasChild(RemotingEndpointResource.ENDPOINT_PATH)) {
        // User didn't configure either worker-thread-pool or endpoint. Add a default endpoint resource so
        // users can read the default config attribute values
        context.addResource(PathAddress.pathAddress(RemotingEndpointResource.ENDPOINT_PATH), Resource.Factory.create());
    }
}
 
Example 4
Source File: HandlerUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void checkNoOtherHandlerWithTheSameName(OperationContext context) throws OperationFailedException {
    final PathAddress address = context.getCurrentAddress();
    final PathAddress parentAddress = address.subAddress(0, address.size() - 1);
    final Resource resource = context.readResourceFromRoot(parentAddress);

    final PathElement element = address.getLastElement();
    final String handlerType = element.getKey();
    final String handlerName = element.getValue();

    for (String otherHandler: HANDLER_TYPES) {
        if (handlerType.equals(otherHandler)) {
            // we need to check other handler types for the same name
            continue;
        }
        final PathElement check = PathElement.pathElement(otherHandler, handlerName);
        if (resource.hasChild(check)) {
            throw DomainManagementLogger.ROOT_LOGGER.handlerAlreadyExists(check.getValue(), parentAddress.append(check));
        }
    }
}
 
Example 5
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void processServerGroup(final RequiredConfigurationHolder holder, final String group, final Resource domain, ExtensionRegistry extensionRegistry) {

        final PathElement groupElement = PathElement.pathElement(SERVER_GROUP, group);
        if (!domain.hasChild(groupElement)) {
            return;
        }
        final Resource serverGroup = domain.getChild(groupElement);
        final ModelNode model = serverGroup.getModel();

        if (model.hasDefined(SOCKET_BINDING_GROUP)) {
            final String socketBindingGroup = model.get(SOCKET_BINDING_GROUP).asString();
            processSocketBindingGroup(domain, socketBindingGroup, holder);
        }

        final String profile = model.get(PROFILE).asString();
        processProfile(domain, profile, holder, extensionRegistry);

    }
 
Example 6
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void processSocketBindingGroup(final Resource domain, final String socketBindingGroup, final RequiredConfigurationHolder holder) {
    final Set<String> socketBindingGroups = holder.socketBindings;

    if (socketBindingGroups.contains(socketBindingGroup)) {
        return;
    }
    socketBindingGroups.add(socketBindingGroup);
    final PathElement socketBindingGroupElement = PathElement.pathElement(SOCKET_BINDING_GROUP, socketBindingGroup);
    if (domain.hasChild(socketBindingGroupElement)) {
        final Resource resource = domain.getChild(socketBindingGroupElement);

        if (resource.getModel().hasDefined(INCLUDES)) {
            for (final ModelNode include : resource.getModel().get(INCLUDES).asList()) {
                processSocketBindingGroup(domain, include.asString(), holder);
            }
        }
    }
    ControllerLogger.ROOT_LOGGER.tracef("Recorded need for socket-binding-group %s", socketBindingGroup);
}
 
Example 7
Source File: AbstractOperationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void addResource(PathAddress relativeAddress, Resource toAdd) {
    Resource model = root;
    final Iterator<PathElement> i = operationAddress.append(relativeAddress).iterator();
    while (i.hasNext()) {
        final PathElement element = i.next();
        if (element.isMultiTarget()) {
            throw ControllerLogger.ROOT_LOGGER.cannotWriteTo("*");
        }
        if (!i.hasNext()) {
            if (model.hasChild(element)) {
                throw ControllerLogger.ROOT_LOGGER.duplicateResourceAddress(relativeAddress);
            } else {
                model.registerChild(element, toAdd);
                model = toAdd;
            }
        } else {
            model = model.getChild(element);
            if (model == null) {
                PathAddress ancestor = PathAddress.EMPTY_ADDRESS;
                for (PathElement pe : relativeAddress) {
                    ancestor = ancestor.append(pe);
                    if (element.equals(pe)) {
                        break;
                    }
                }
                throw ControllerLogger.ROOT_LOGGER.resourceNotFound(ancestor, relativeAddress);
            }
        }
    }
}
 
Example 8
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Resource requireChild(final Resource resource, final PathElement childPath, final PathAddress fullAddress) {
    if (resource.hasChild(childPath)) {
        return resource.requireChild(childPath);
    } else {
        PathAddress missing = PathAddress.EMPTY_ADDRESS;
        for (PathElement search : fullAddress) {
            missing = missing.append(search);
            if (search.equals(childPath)) {
                break;
            }
        }
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(missing);
    }
}
 
Example 9
Source File: GlobalOperationHandlers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void executeSingleTargetChild(PathAddress base, PathElement currentElement, PathAddress newRemaining, OperationContext context, boolean ignoreMissing) {
    final PathAddress next = base.append(currentElement);
    // Either require the child or a remote target
    final Resource resource = context.readResource(base, false);
    final ImmutableManagementResourceRegistration nr = context.getResourceRegistration().getSubModel(next);
    if (resource.hasChild(currentElement) || (nr != null && nr.isRemote())) {
        safeExecute(next, newRemaining, context, nr, ignoreMissing);
    }
    //if we are on the wrong host no need to do anything
    else if(!resource.hasChild(currentElement)) {
       throw new Resource.NoSuchResourceException(currentElement);
    }
}
 
Example 10
Source File: DeploymentResourceSupport.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Resource getOrCreate(final Resource parent, final PathElement element, final Resource desired) {
    synchronized (parent) {
        if (parent.hasChild(element)) {
            if (desired == null) {
                return parent.requireChild(element);
            } else {
                throw new IllegalStateException();
            }
        } else {
            return register(parent, element, desired);
        }
    }
}
 
Example 11
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 12
Source File: SyncModelOperationHandlerWrapper.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void processSocketBindingGroup(final Resource domain, final String name, final Set<String> socketBindings) {
    if (!socketBindings.contains(name)) {
        socketBindings.add(name);
        final PathElement pathElement = PathElement.pathElement(SOCKET_BINDING_GROUP, name);
        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()) {
                    processSocketBindingGroup(domain, include.asString(), socketBindings);
                }
            }
        }
    }
}
 
Example 13
Source File: SyncModelOperationHandlerWrapper.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void processProfile(final Resource domain, String profile, 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()) {
                    processProfile(domain, include.asString(), profiles);
                }
            }
        }
    }
}
 
Example 14
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 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: 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 17
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);
    }
}
 
Example 18
Source File: DeploymentReplaceHandler.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 {
    for (AttributeDefinition def : DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.values()) {
        def.validateOperation(operation);
    }
    String name = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(NAME).resolveModelAttribute(context, operation).asString();
    String toReplace = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(TO_REPLACE).resolveModelAttribute(context, operation).asString();

    if (name.equals(toReplace)) {
        throw ServerLogger.ROOT_LOGGER.cannotReplaceDeployment(OPERATION_NAME, NAME, TO_REPLACE,
                DeploymentRedeployHandler.OPERATION_NAME, DeploymentFullReplaceHandler.OPERATION_NAME);
    }

    final PathElement deployPath = PathElement.pathElement(DEPLOYMENT, name);
    final PathElement replacePath = PathElement.pathElement(DEPLOYMENT, toReplace);

    final Resource root = context.readResource(PathAddress.EMPTY_ADDRESS, false);
    if (! root.hasChild(replacePath)) {
        throw ServerLogger.ROOT_LOGGER.noSuchDeployment(toReplace);
    }

    final ModelNode replaceNode = context.readResourceForUpdate(PathAddress.pathAddress(replacePath)).getModel();
    final String replacedName = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, replaceNode).asString();

    ModelNode deployNode;
    String runtimeName;
    if (!root.hasChild(deployPath)) {
        if (!operation.hasDefined(CONTENT)) {
            throw ServerLogger.ROOT_LOGGER.noSuchDeployment(name);
        }
        // else -- the HostController handles a server group replace-deployment like an add, so we do too

        final ModelNode content = operation.require(CONTENT);
        // TODO: JBAS-9020: for the moment overlays are not supported, so there is a single content item
        final ModelNode contentItemNode = content.require(0);
        if (contentItemNode.hasDefined(HASH)) {
            byte[] hash = contentItemNode.require(HASH).asBytes();
            addFromHash(ModelContentReference.fromDeploymentName(name, hash));
        } else {
        }
        runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : replacedName;

        // Create the resource
        final Resource deployResource = context.createResource(PathAddress.pathAddress(deployPath));
        deployNode = deployResource.getModel();
        deployNode.get(RUNTIME_NAME).set(runtimeName);

        //TODO Assumes this can only be set by client
        deployNode.get(ModelDescriptionConstants.PERSISTENT).set(true);

        deployNode.get(CONTENT).set(content);

    } else {
        deployNode = context.readResourceForUpdate(PathAddress.pathAddress(deployPath)).getModel();
        if (ENABLED.resolveModelAttribute(context, deployNode).asBoolean()) {
            throw ServerLogger.ROOT_LOGGER.deploymentAlreadyStarted(toReplace);
        }
        runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : deployNode.require(RUNTIME_NAME).asString();
        deployNode.get(RUNTIME_NAME).set(runtimeName);
    }

    deployNode.get(ENABLED.getName()).set(true);
    replaceNode.get(ENABLED.getName()).set(false);

    final DeploymentHandlerUtil.ContentItem[] contents = getContents(deployNode.require(CONTENT));
    DeploymentHandlerUtil.replace(context, replaceNode, runtimeName, name, replacedName, vaultReader, contents);
}
 
Example 19
Source File: DeploymentResourceSupport.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Checks to see if a subsystem resource has already been registered for the deployment.
 *
 * @param subsystemName the name of the subsystem
 *
 * @return {@code true} if the subsystem exists on the deployment otherwise {@code false}
 */
public boolean hasDeploymentSubsystemModel(final String subsystemName) {
    final Resource root = deploymentUnit.getAttachment(DEPLOYMENT_RESOURCE);
    final PathElement subsystem = PathElement.pathElement(SUBSYSTEM, subsystemName);
    return root.hasChild(subsystem);
}
 
Example 20
Source File: DeploymentResourceSupport.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Checks to see if a resource has already been registered for the specified address on the subsystem.
 *
 * @param subsystemName the name of the subsystem
 * @param address       the address to check
 *
 * @return {@code true} if the address exists on the subsystem otherwise {@code false}
 */
public boolean hasDeploymentSubModel(final String subsystemName, final PathElement address) {
    final Resource root = deploymentUnit.getAttachment(DEPLOYMENT_RESOURCE);
    final PathElement subsystem = PathElement.pathElement(SUBSYSTEM, subsystemName);
    return root.hasChild(subsystem) && (address == null || root.getChild(subsystem).hasChild(address));
}