Java Code Examples for org.jboss.as.controller.PathElement#isMultiTarget()

The following examples show how to use org.jboss.as.controller.PathElement#isMultiTarget() . 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: WildcardOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void assertMatchingAddress(PathAddress toMatch, ModelNode node, WildcardChecker wildcardChecker) {
    assertTrue(node.hasDefined(OP_ADDR));
    PathAddress testee = PathAddress.pathAddress(node.get(OP_ADDR));

    assertEquals(testee + " length matches " + toMatch, toMatch.size(), testee.size());
    for (int i = 0; i < toMatch.size(); i++) {
        PathElement matchElement = toMatch.getElement(i);
        PathElement testeeElement = testee.getElement(i);
        assertEquals(testee.toString(), matchElement.getKey(), testeeElement.getKey());
        // the /host=* registration can be returned as part of RRD, so we skip it.
        if (! (node.get(RESULT).has(DESCRIPTION) &&
            node.get(RESULT).get(DESCRIPTION).asString().contains("The root node of the host-level management model"))) {
            wildcardChecker.checkPathElement(testeeElement);
        }

        if (!matchElement.isWildcard()) {
            if (matchElement.isMultiTarget()) {
                boolean matched = false;
                for (String option : matchElement.getSegments()) {
                    if (option.equals(testeeElement.getValue())) {
                        matched = true;
                        break;
                    }
                }
                assertTrue(testeeElement + " value in " + matchElement.getValue(), matched);
            } else {
                assertEquals(matchElement.getValue(), testeeElement.getValue());
            }
        }
    }
}
 
Example 2
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 3
Source File: GlobalOperationHandlers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean isWFCORE621Needed(ImmutableManagementResourceRegistration registration, PathAddress remaining) {
    if (remaining.size() > 0) {
        PathElement pe = remaining.getElement(0);
        if (pe.isMultiTarget() && RUNNING_SERVER.equals(pe.getKey())) {
            // We only need this for WildFly 8 and earlier (including EAP 6),
            // so that's proxied controllers running kernel version 1.x or 2.x
            ModelVersion modelVersion = registration.getProxyController(PathAddress.EMPTY_ADDRESS).getKernelModelVersion();
            return modelVersion.getMajor() < 3;
        }
    }
    return false;
}
 
Example 4
Source File: AbstractModelResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerChild(final PathElement address, final Resource resource) {
    if(address.isMultiTarget()) {
        throw new IllegalArgumentException();
    }
    getOrCreateProvider(address.getKey()).register(address.getValue(), resource);
}
 
Example 5
Source File: AbstractModelResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerChild(final PathElement address, final int index, final Resource resource) {
    if(address.isMultiTarget()) {
        throw new IllegalArgumentException();
    }
    if (index >= 0 && !orderedChildTypes.contains(address.getKey())) {
        throw ControllerLogger.ROOT_LOGGER.indexedChildResourceRegistrationNotAvailable(address);
    }
    getOrCreateProvider(address.getKey()).register(address.getValue(), index, resource);
}
 
Example 6
Source File: HostControllerExecutionSupport.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a HostControllerExecutionSupport for a given operation.
 *
 *
 * @param context
 * @param operation the operation
 * @param hostName the name of the host executing the operation
 * @param domainModelProvider source for the domain model
 * @param ignoredDomainResourceRegistry registry of resource addresses that should be ignored
 * @throws OperationFailedException
 *
 * @return the HostControllerExecutionSupport
 */
public static HostControllerExecutionSupport create(OperationContext context, final ModelNode operation,
                                                    final String hostName,
                                                    final DomainModelProvider domainModelProvider,
                                                    final IgnoredDomainResourceRegistry ignoredDomainResourceRegistry,
                                                    final boolean isRemoteDomainControllerIgnoreUnaffectedConfiguration,
                                                    final ExtensionRegistry extensionRegistry) throws OperationFailedException {
    String targetHost = null;
    PathElement runningServerTarget = null;
    ModelNode runningServerOp = null;

    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    if (address.size() > 0) {
        PathElement first = address.getElement(0);
        if (HOST.equals(first.getKey()) && !first.isMultiTarget()) {
            targetHost = first.getValue();
            if (address.size() > 1 && RUNNING_SERVER.equals(address.getElement(1).getKey())) {
                runningServerTarget = address.getElement(1);
                ModelNode relativeAddress = new ModelNode().setEmptyList();
                for (int i = 2; i < address.size(); i++) {
                    PathElement element = address.getElement(i);
                    relativeAddress.add(element.getKey(), element.getValue());
                }
                runningServerOp = operation.clone();
                runningServerOp.get(OP_ADDR).set(relativeAddress);
            }
        }
    }

    HostControllerExecutionSupport result;


    if (targetHost != null && !hostName.equals(targetHost)) {
        // HostControllerExecutionSupport representing another host
        result = new IgnoredOpExecutionSupport(ignoredDomainResourceRegistry);
    }
    else if (runningServerTarget != null) {
        // HostControllerExecutionSupport representing a server op
        final Resource domainModel = domainModelProvider.getDomainModel();
        final Resource hostModel = domainModel.getChild(PathElement.pathElement(HOST, targetHost));
        if (runningServerTarget.isMultiTarget()) {
            return new DomainOpExecutionSupport(ignoredDomainResourceRegistry, operation, PathAddress.EMPTY_ADDRESS);
        } else {
            final String serverName = runningServerTarget.getValue();
            // TODO prevent NPE
            final String serverGroup = hostModel.getChild(PathElement.pathElement(SERVER_CONFIG, serverName)).getModel().require(GROUP).asString();
            final ServerIdentity serverIdentity = new ServerIdentity(targetHost, serverGroup, serverName);
            result = new DirectServerOpExecutionSupport(ignoredDomainResourceRegistry, serverIdentity, runningServerOp);
        }
    }
    else if (COMPOSITE.equals(operation.require(OP).asString())) {
        // Recurse into the steps to see what's required
        if (operation.hasDefined(STEPS)) {
            List<HostControllerExecutionSupport> parsedSteps = new ArrayList<HostControllerExecutionSupport>();
            for (ModelNode step : operation.get(STEPS).asList()) {
                // Propagate the caller-type=user header
                if (operation.hasDefined(OPERATION_HEADERS, CALLER_TYPE) && operation.get(OPERATION_HEADERS, CALLER_TYPE).asString().equals(USER)) {
                    step = step.clone();
                    step.get(OPERATION_HEADERS, CALLER_TYPE).set(USER);
                }
                parsedSteps.add(create(context, step, hostName, domainModelProvider, ignoredDomainResourceRegistry, isRemoteDomainControllerIgnoreUnaffectedConfiguration, extensionRegistry));
            }
            result = new MultiStepOpExecutionSupport(ignoredDomainResourceRegistry, parsedSteps);
        }
        else {
            // Will fail later
            result = new DomainOpExecutionSupport(ignoredDomainResourceRegistry, operation, address);
        }
    }
    else if (targetHost == null && isResourceExcluded(context, ignoredDomainResourceRegistry, isRemoteDomainControllerIgnoreUnaffectedConfiguration, domainModelProvider, hostName, address, extensionRegistry, operation)) {
        result = new IgnoredOpExecutionSupport(ignoredDomainResourceRegistry);
    }
    else {
        result = new DomainOpExecutionSupport(ignoredDomainResourceRegistry, operation, address);
    }

    return result;

}
 
Example 7
Source File: ResourceTransformationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ResourceTransformationContext addTransformedRecursiveResourceFromRoot(final PathAddress absoluteAddress, final PathAddress read, final Resource toAdd) {
    Resource model = this.root;
    Resource parent = null;
    if (absoluteAddress.size() > 0) {
        final Iterator<PathElement> i = absoluteAddress.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(absoluteAddress);
                } else {
                    parent = model;
                    model.registerChild(element, toAdd);
                    model = toAdd;
                    if (read.size() > 0) {
                        //We might be able to deal with this better in the future, but for now
                        //throw an error if the address was renamed and it was an ordered child type.
                        Set<String> parentOrderedChildren = parent.getOrderedChildTypes();
                        String readType = read.getLastElement().getKey();
                        if (parentOrderedChildren.contains(readType)) {
                            if (absoluteAddress.size() == 0 || !absoluteAddress.getLastElement().getKey().equals(readType)) {
                                throw ControllerLogger.ROOT_LOGGER.orderedChildTypeRenamed(read, absoluteAddress, readType, parentOrderedChildren);
                            }
                        }
                    }
                }
            } else {
                model = model.getChild(element);
                if (model == null) {
                    PathAddress ancestor = PathAddress.EMPTY_ADDRESS;
                    for (PathElement pe : absoluteAddress) {
                        ancestor = ancestor.append(pe);
                        if (element.equals(pe)) {
                            break;
                        }
                    }
                    throw ControllerLogger.ROOT_LOGGER.resourceNotFound(ancestor, absoluteAddress);
                }
            }
        }
    } else {
        //If this was the root address, replace the resource model
        model.writeModel(toAdd.getModel());
    }
    return new ResourceTransformationContextImpl(root, absoluteAddress, read, originalModel,
            transformerOperationAttachment, ignoredTransformationRegistry);
}