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

The following examples show how to use org.jboss.as.controller.PathElement#getKey() . 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: LdapConnectionPropertyResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private PropertyManipulator(OperationContext context, ModelNode operation) {
    PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));

    LdapConnectionManagerService service = null;
    String propertyName = null;

    for (PathElement current : address) {
        String currentKey = current.getKey();
        if (currentKey.equals(LDAP_CONNECTION)) {
            String connectionName = current.getValue();
            ServiceName svcName = LdapConnectionManagerService.ServiceUtil.createServiceName(connectionName);
            ServiceRegistry registry = context.getServiceRegistry(true);
            ServiceController<?> controller = registry.getService(svcName);
            service = LdapConnectionManagerService.class.cast(controller.getValue());
        } else if (currentKey.equals(PROPERTY)) {
            propertyName = current.getValue();
        }
    }

    this.service = service;
    this.propertyName = propertyName;
    this.isBooting = context.isBooting();
}
 
Example 2
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 3
Source File: OperationTransformerRegistry.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ResourceTransformerEntry resolveResourceTransformer(final Iterator<PathElement> iterator, final ResourceTransformerEntry inherited, final PlaceholderResolver placeholderResolver) {
    if(! iterator.hasNext()) {
        if(resourceTransformer == null) {
            return inherited;
        }
        return resourceTransformer;
    } else {
        final ResourceTransformerEntry inheritedEntry = resourceTransformer.inherited ? resourceTransformer : inherited;
        final PathElement element = iterator.next();
        final String key = element.getKey();
        SubRegistry registry = subRegistriesUpdater.get(this, key);
        if(registry == null) {
            return inherited;
        }
        return registry.resolveResourceTransformer(iterator, element.getValue(), inheritedEntry, placeholderResolver);
    }
}
 
Example 4
Source File: ReadFeatureDescriptionHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private PathAddress createAliasPathAddress(final ImmutableManagementResourceRegistration registration, PathAddress pa) {
    ImmutableManagementResourceRegistration registry = registration.getParent();
    List<PathElement> elements = new ArrayList<>();
    for (int i = pa.size() - 1; i >= 0; i--) {
        PathElement elt = pa.getElement(i);
        ImmutableManagementResourceRegistration childRegistration = registry.getSubModel(PathAddress.pathAddress(PathElement.pathElement(elt.getKey())));
        if (childRegistration == null) {
            elements.add(elt);
        } else {
            String value = "$" + elt.getKey();
            elements.add(PathElement.pathElement(elt.getKey(), value));
        }
        registry = registry.getParent();
    }
    Collections.reverse(elements);
    return PathAddress.pathAddress(elements.toArray(new PathElement[elements.size()]));
}
 
Example 5
Source File: HostInfo.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean isOperationExcluded(PathAddress address, String operationName) {

    if (address.size() > 0) {
        final PathElement element = address.getElement(0);
        final String type = element.getKey();
        final String name = element.getValue();
        final boolean domainExcluding = ignoreUnaffectedConfig && !hostDeclaredIgnoreUnaffected && requiredConfigurationHolder != null;
        switch (type) {
            case ModelDescriptionConstants.EXTENSION:
                return domainIgnoredExtensions != null && domainIgnoredExtensions.contains(element.getValue());
            case PROFILE:
                return domainExcluding
                        && ((CLONE.equals(operationName) && address.size() == 1)
                               || !requiredConfigurationHolder.getProfiles().contains(name));
            case SERVER_GROUP:
                return domainExcluding && !requiredConfigurationHolder.getServerGroups().contains(name);
            case SOCKET_BINDING_GROUP:
                return domainExcluding
                        && ((CLONE.equals(operationName) && address.size() == 1)
                        || !requiredConfigurationHolder.getSocketBindings().contains(name));
        }
    }
    return false;
}
 
Example 6
Source File: PathAddressFilter.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void addReject(final PathAddress address) {
    final Iterator<PathElement> i = address.iterator();
    Node node = this.node;
    while (i.hasNext()) {

        final PathElement element = i.next();
        final String elementKey = element.getKey();
        Node key = node.children.get(elementKey);
        if (key == null) {
            key = new Node(element.getKey());
            node.children.put(elementKey, key);
        }
        final String elementValue = element.getValue();
        Node value = key.children.get(elementValue);
        if (value == null) {
            value = new Node(elementValue);
            key.children.put(elementValue, value);
        }
        if (!i.hasNext()) {
            value.accept = false;
        }
    }
}
 
Example 7
Source File: ApplyExtensionsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Resource getResource(PathAddress resourceAddress, Resource rootResource, OperationContext context) {
    if(resourceAddress.size() == 0) {
        return rootResource;
    }
    Resource temp = rootResource;
    int idx = 0;
    for(PathElement element : resourceAddress) {
        temp = temp.getChild(element);
        if(temp == null) {
            if (idx == 0) {
                String type = element.getKey();
                if (type.equals(EXTENSION)) {
                    // Needs a specialized resource type
                    temp = new ExtensionResource(element.getValue(), extensionRegistry);
                    context.addResource(resourceAddress, temp);
                }
            }
            if (temp == null) {
                temp = context.createResource(resourceAddress);
            }
            break;
        }
        idx++;
    }
    return temp;
}
 
Example 8
Source File: PersistentResourceXMLParserTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String[] getAddress(PathAddress address) {
    String[] res = new String[(address.size() - 1) * 2];
    for (int i = 0; i < address.size() - 1; i++) {
        PathElement el = address.getElement(i + 1);
        res[i * 2] = el.getKey();
        res[(i * 2) + 1] = el.getValue();
    }
    return res;
}
 
Example 9
Source File: CapabilityScope.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Create a {@code CapabilityScope} appropriate for the given process type and address
 *
 * @param processType the type of process in which the {@code CapabilityScope} exists
 * @param address the address with which the {@code CapabilityScope} is associated
 */
public static CapabilityScope create(ProcessType processType, PathAddress address) {
    CapabilityScope context = CapabilityScope.GLOBAL;
    PathElement pe = processType.isServer() || address.size() == 0 ? null : address.getElement(0);
    if (pe != null) {
        String type = pe.getKey();
        switch (type) {
            case PROFILE: {
                context = address.size() == 1 ? ProfilesCapabilityScope.INSTANCE : new ProfileChildCapabilityScope(pe.getValue());
                break;
            }
            case SOCKET_BINDING_GROUP: {
                context = address.size() == 1 ? SocketBindingGroupsCapabilityScope.INSTANCE : new SocketBindingGroupChildScope(pe.getValue());
                break;
            }
            case HOST: {
                if (address.size() >= 2) {
                    PathElement hostElement = address.getElement(1);
                    final String hostType = hostElement.getKey();
                    switch (hostType) {
                        case SUBSYSTEM:
                        case SOCKET_BINDING_GROUP:
                            context = HostCapabilityScope.INSTANCE;
                            break;
                        case SERVER_CONFIG:
                            context = ServerConfigCapabilityScope.INSTANCE;
                    }
                }
                break;
            }
            case SERVER_GROUP :  {
                context = ServerGroupsCapabilityScope.INSTANCE;
                break;
            }
        }
    }
    return context;

}
 
Example 10
Source File: ConcreteResourceRegistration.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
void getNotificationDescriptions(final ListIterator<PathElement> iterator, final Map<String, NotificationEntry> providers, final boolean inherited) {

    if (!iterator.hasNext() ) {
        checkPermission();
        readLock.lock();
        try {
            if (notifications != null) {
                providers.putAll(notifications);
            }
        } finally {
            readLock.unlock();
        }
        if (inherited) {
            getInheritedNotifications(providers, true);
        }
        return;
    }
    final PathElement next = iterator.next();
    try {
        final String key = next.getKey();
        final NodeSubregistry subregistry = getSubregistry(key);
        if (subregistry != null) {
            subregistry.getNotificationDescriptions(iterator, next.getValue(), providers, inherited);
        }
    } finally {
        iterator.previous();
    }
}
 
Example 11
Source File: ConcreteResourceRegistration.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
void getOperationDescriptions(final ListIterator<PathElement> iterator, final Map<String, OperationEntry> providers, final boolean inherited) {

    if (!iterator.hasNext() ) {
        checkPermission();
        readLock.lock();
        try {
            if (operations != null) {
                providers.putAll(operations);
            }
        } finally {
            readLock.unlock();
        }
        if (inherited) {
            getInheritedOperations(providers, true);
        }
        return;
    }
    final PathElement next = iterator.next();
    try {
        final String key = next.getKey();
        final NodeSubregistry subregistry = getSubregistry(key);
        if (subregistry != null) {
            subregistry.getHandlers(iterator, next.getValue(), providers, inherited);
        }
    } finally {
        iterator.previous();
    }
}
 
Example 12
Source File: LoggingResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Resource removeChild(final PathElement address) {
    final String type = address.getKey();
    if (LogFileResourceDefinition.NAME.equals(type)) {
        throw LoggingLogger.ROOT_LOGGER.cannotRemoveResourceOfType(type);
    }
    return delegate.removeChild(address);
}
 
Example 13
Source File: LoggingResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerChild(PathElement address, int index, Resource resource) {
    final String type = address.getKey();
    if (LogFileResourceDefinition.NAME.equals(type)) {
        throw LoggingLogger.ROOT_LOGGER.cannotRegisterResourceOfType(type);
    }
    delegate.registerChild(address, index, resource);
}
 
Example 14
Source File: LoggingResource.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) {
    final String type = address.getKey();
    if (LogFileResourceDefinition.NAME.equals(type)) {
        throw LoggingLogger.ROOT_LOGGER.cannotRegisterResourceOfType(type);
    }
    delegate.registerChild(address, resource);
}
 
Example 15
Source File: DMRLocationResolver.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
private static boolean matches(int length, PathAddress pattern, PathAddress address) {
    for (int i = 0; i < length; i++) {
        PathElement otherElem = address.getElement(i);
        Property prop = new Property(otherElem.getKey(), new ModelNode(otherElem.getValue()));
        if (!pattern.getElement(i).matches(prop)) {
            return false;
        }
    }
    return true;
}
 
Example 16
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
     * Create the ResourceIgnoredTransformationRegistry when fetching missing content, only including relevant pieces
     * to a server-config.
     *
     * @param rc       the resolution context
     * @param delegate the delegate ignored resource transformation registry for manually ignored resources
     * @return
     */
    public static Transformers.ResourceIgnoredTransformationRegistry createServerIgnoredRegistry(final RequiredConfigurationHolder rc, final Transformers.ResourceIgnoredTransformationRegistry delegate) {
        return new Transformers.ResourceIgnoredTransformationRegistry() {
            @Override
            public boolean isResourceTransformationIgnored(PathAddress address) {
                final int length = address.size();
                if (length == 0) {
                    return false;
                } else if (length >= 1) {
                    if (delegate.isResourceTransformationIgnored(address)) {
                        return true;
                    }

                    final PathElement element = address.getElement(0);
                    final String type = element.getKey();
                    switch (type) {
                        case ModelDescriptionConstants.EXTENSION:
                            // Don't ignore extensions for now
                            return false;
//                            if (local) {
//                                return false; // Always include all local extensions
//                            } else if (rc.getExtensions().contains(element.getValue())) {
//                                return false;
//                            }
//                            break;
                        case ModelDescriptionConstants.PROFILE:
                            if (rc.getProfiles().contains(element.getValue())) {
                                return false;
                            }
                            break;
                        case ModelDescriptionConstants.SERVER_GROUP:
                            if (rc.getServerGroups().contains(element.getValue())) {
                                return false;
                            }
                            break;
                        case ModelDescriptionConstants.SOCKET_BINDING_GROUP:
                            if (rc.getSocketBindings().contains(element.getValue())) {
                                return false;
                            }
                            break;
                    }
                }
                return true;
            }
        };
    }
 
Example 17
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
     * Create the ResourceIgnoredTransformationRegistry for connection/reconnection process.
     *
     * @param hostInfo the host info
     * @param rc       the resolution context
     * @return
     */
    public static Transformers.ResourceIgnoredTransformationRegistry createHostIgnoredRegistry(final HostInfo hostInfo, final RequiredConfigurationHolder rc) {
        return new Transformers.ResourceIgnoredTransformationRegistry() {
            @Override
            public boolean isResourceTransformationIgnored(PathAddress address) {
                if (hostInfo.isResourceTransformationIgnored(address)) {
                    return true;
                }
                if (address.size() == 1 && hostInfo.isIgnoreUnaffectedConfig()) {
                    final PathElement element = address.getElement(0);
                    final String type = element.getKey();
                    switch (type) {
                        case ModelDescriptionConstants.EXTENSION:
                            // Don't ignore extensions for now
                            return false;
//                            if (local) {
//                                return false; // Always include all local extensions
//                            } else if (!rc.getExtensions().contains(element.getValue())) {
//                                return true;
//                            }
//                            break;
                        case PROFILE:
                            if (!rc.getProfiles().contains(element.getValue())) {
                                return true;
                            }
                            break;
                        case SERVER_GROUP:
                            if (!rc.getServerGroups().contains(element.getValue())) {
                                return true;
                            }
                            break;
                        case SOCKET_BINDING_GROUP:
                            if (!rc.getSocketBindings().contains(element.getValue())) {
                                return true;
                            }
                            break;
                    }
                }
                return false;
            }
        };
    }
 
Example 18
Source File: SyncServerStateOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
void checkContent(ModelNode operation, PathAddress operationAddress) {
    if (!operation.get(OP).asString().equals(ADD) || operationAddress.size() == 0) {
        return;
    }
    final PathElement firstElement = operationAddress.getElement(0);
    final String contentType = firstElement.getKey();
    if (contentType == null) {
        return;
    }
    if (operationAddress.size() == 1) {
        switch (contentType) {
            case DEPLOYMENT:
                final String deployment = firstElement.getValue();
                Set<ContentReference> hashes = deploymentHashes.get(deployment);
                if (hashes == null) {
                    hashes = new HashSet<>();
                    deploymentHashes.put(deployment, hashes);
                    for (ModelNode contentItem : operation.get(CONTENT).asList()) {
                        hashes.add(ModelContentReference.fromModelAddress(operationAddress, contentItem.get(HASH).asBytes()));
                        if (parameters.getHostControllerEnvironment().isBackupDomainFiles()) {
                            relevantDeployments.add(firstElement.getValue());
                        }
                    }
                }
                makeExistingDeploymentUpdatedAffected(firstElement, operation);
                break;
            case DEPLOYMENT_OVERLAY:
                break;
            case MANAGEMENT_CLIENT_CONTENT:
                if (firstElement.getValue().equals(ROLLOUT_PLANS)) {
                    updateRolloutPlans = true;
                    //This needs special handling. Drop the existing resource and add a new one
                    if (operation.hasDefined(HASH)) {
                        rolloutPlansHash = operation.get(HASH).asBytes();
                        requiredContent.add(ModelContentReference.fromModelAddress(operationAddress, rolloutPlansHash));
                    }
                }
                break;
            default:
                return;
        }
    } else if (operationAddress.size() == 2) {
        if( firstElement.getKey().equals(SERVER_GROUP) &&
            serversByGroup.containsKey(firstElement.getValue())) {
            PathElement secondElement = operationAddress.getElement(1);
            if (secondElement.getKey().equals(DEPLOYMENT)) {
                relevantDeployments.add(secondElement.getValue());
                affectedGroups.add(firstElement.getValue());
            }
        } else if (firstElement.getKey().equals(DEPLOYMENT_OVERLAY)) {
            requiredContent.add(ModelContentReference.fromModelAddress(operationAddress, operation.get(CONTENT).asBytes()));
        }
    }
    return;
}
 
Example 19
Source File: GlobalOperationHandlers.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void executeMultiTargetChildren(PathAddress base, PathElement currentElement, PathAddress newRemaining, OperationContext context, ImmutableManagementResourceRegistration registration, boolean ignoreMissing) {
    final String childType = currentElement.getKey().equals("*") ? null : currentElement.getKey();
    if (registration.isRemote()) {// || registration.isRuntimeOnly()) {
        // At least for proxies it should use the proxy operation handler
        throw new IllegalStateException();
    }

    final Set<PathElement> children = context.getResourceRegistration().getChildAddresses(base);
    if (children == null || children.isEmpty()) {
        throw new NoSuchResourceTypeException(base.append(currentElement));
    }

    boolean foundValid = false;
    PathAddress invalid = null;
    for (final PathElement path : children) {
        if (childType != null && !childType.equals(path.getKey())) {
            continue;
        }
        // matches /host=xxx/server=*/... address
        final boolean isHostWildcardServerAddress = base.size() > 0 && base.getLastElement().getKey().equals(HOST) && path.getKey().equals(RUNNING_SERVER) && path.isWildcard();
        if (isHostWildcardServerAddress && newRemaining.size() > 0) {
            //Trying to get e.g. /host=xxx/server=*/interface=public will fail, so make sure if there are remaining elements for
            //a /host=master/server=* that we don't attempt to get those
            continue;
        }
        final PathAddress next = base.append(path);
        final ImmutableManagementResourceRegistration nr = context.getResourceRegistration().getSubModel(next);
        try {
            execute(next, newRemaining, context, nr, ignoreMissing);
            foundValid = true;
        } catch (NoSuchResourceTypeException e) {
            if (!foundValid) {
                PathAddress failedAddr = e.getPathAddress();
                // Store the failed address for error reporting, but only if
                // 1) this is the first failure, or
                // 2) The size of the failed address is larger than the currently
                //    cached one, indicating there is some path that has a larger number
                //    of valid elements than the currently cached path. So we want to
                //    report that larger path
                if (invalid == null || failedAddr.size() > invalid.size()) {
                    PathAddress newBase = base.append(currentElement);
                    invalid = newBase.append(failedAddr.subAddress(newBase.size()));
                }
            }
        }
    }

    if (!foundValid) {
        if (invalid == null) {
            // No children matched currentElement
            invalid = base.append(currentElement);
        }
        throw new NoSuchResourceTypeException(invalid);
    }
}
 
Example 20
Source File: LoggingExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public int compare(final PathElement o1, final PathElement o2) {
    final String key1 = o1.getKey();
    final String key2 = o2.getKey();
    int result = key1.compareTo(key2);
    if (key1.equals(key2)) {
        // put the one already present first to preserve original order
        result = GREATER;
    } else {
        if (ModelDescriptionConstants.SUBSYSTEM.equals(key1)) {
            result = LESS;
        } else if (ModelDescriptionConstants.SUBSYSTEM.equals(key2)) {
            result = GREATER;
        } else if (CommonAttributes.LOGGING_PROFILE.equals(key1)) {
            result = LESS;
        } else if (CommonAttributes.LOGGING_PROFILE.equals(key2)) {
            result = GREATER;
        } else if (PatternFormatterResourceDefinition.NAME.equals(key1)) {
            result = LESS;
        } else if (PatternFormatterResourceDefinition.NAME.equals(key2)) {
            result = GREATER;
        } else if (CustomFormatterResourceDefinition.NAME.equals(key1)) {
            result = LESS;
        } else if (CustomFormatterResourceDefinition.NAME.equals(key2)) {
            result = GREATER;
        } else if (FilterResourceDefinition.NAME.equals(key1)) {
            result = LESS;
        } else if (FilterResourceDefinition.NAME.equals(key2)) {
            result = GREATER;
        } else if (RootLoggerResourceDefinition.NAME.equals(key1)) {
            result = GREATER;
        } else if (RootLoggerResourceDefinition.NAME.equals(key2)) {
            result = LESS;
        } else if (LoggerResourceDefinition.NAME.equals(key1)) {
            result = GREATER;
        } else if (LoggerResourceDefinition.NAME.equals(key2)) {
            result = LESS;
        } else if (AsyncHandlerResourceDefinition.NAME.equals(key1)) {
            result = GREATER;
        } else if (AsyncHandlerResourceDefinition.NAME.equals(key2)) {
            result = LESS;
        }
    }
    return result;
}