Search in sources :

Example 1 with AliasEntry

use of org.jboss.as.controller.registry.AliasEntry in project wildfly by wildfly.

the class TransportResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = super.register(parent);
    new WriteAttributeStepHandler(new WriteThreadingAttributeStepHandlerDescriptor()) {

        @Override
        protected void validateUpdatedModel(OperationContext context, Resource model) throws OperationFailedException {
            // Add a new step to validate instead of doing it directly in this method.
            // This allows a composite op to change both attributes and then the
            // validation occurs after both have done their work.
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    ModelNode conf = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
                    // TODO doesn't cover the admin-only modes
                    if (context.getProcessType().isServer()) {
                        for (ThreadingAttribute attribute : EnumSet.allOf(ThreadingAttribute.class)) {
                            if (conf.hasDefined(attribute.getName())) {
                                // That is not supported.
                                throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.threadsAttributesUsedInRuntime());
                            }
                        }
                    }
                }
            }, OperationContext.Stage.MODEL);
        }
    }.register(registration);
    if (registration.getPathAddress().getLastElement().isWildcard()) {
        for (ThreadPoolResourceDefinition pool : EnumSet.allOf(ThreadPoolResourceDefinition.class)) {
            pool.register(registration);
        }
        parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {

            @Override
            public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
                PathAddress target = this.getTargetAddress();
                List<PathElement> result = new ArrayList<>(aliasAddress.size());
                for (int i = 0; i < aliasAddress.size(); ++i) {
                    PathElement element = aliasAddress.getElement(i);
                    if (i == target.size() - 1) {
                        final ModelNode operation = aliasContext.getOperation();
                        final String stackName;
                        if (ModelDescriptionConstants.ADD.equals(Operations.getName(operation)) && operation.hasDefined("type")) {
                            stackName = operation.get("type").asString();
                        } else {
                            Resource root = null;
                            try {
                                root = aliasContext.readResourceFromRoot(PathAddress.pathAddress(result));
                            } catch (Resource.NoSuchResourceException ignored) {
                            }
                            if (root == null) {
                                stackName = "*";
                            } else {
                                Set<String> names = root.getChildrenNames("transport");
                                if (names.size() > 1) {
                                    throw new AssertionError("There should be at most one child");
                                } else if (names.size() == 0) {
                                    stackName = "*";
                                } else {
                                    stackName = names.iterator().next();
                                }
                            }
                        }
                        result.add(PathElement.pathElement("transport", stackName));
                    } else if (i < target.size()) {
                        PathElement targetElement = target.getElement(i);
                        result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement);
                    } else {
                        result.add(element);
                    }
                }
                return PathAddress.pathAddress(result);
            }
        });
    }
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) EnumSet(java.util.EnumSet) Set(java.util.Set) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) WriteAttributeStepHandler(org.jboss.as.clustering.controller.WriteAttributeStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) List(java.util.List) AliasEntry(org.jboss.as.controller.registry.AliasEntry) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with AliasEntry

use of org.jboss.as.controller.registry.AliasEntry in project wildfly by wildfly.

the class ProxyConfigurationResourceDefinition method register.

@SuppressWarnings("deprecation")
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(EnumSet.complementOf(EnumSet.of(Attribute.SSL_CONTEXT))).addExtraParameters(Attribute.SSL_CONTEXT).addAttributeTranslation(DeprecatedAttribute.SIMPLE_LOAD_PROVIDER, SIMPLE_LOAD_PROVIDER_TRANSLATION).addAlias(DeprecatedAttribute.CONNECTOR, Attribute.LISTENER).addRequiredSingletonChildren(SimpleLoadProviderResourceDefinition.PATH).addCapabilities(Capability.class);
    registration.registerReadWriteAttribute(Attribute.SSL_CONTEXT.getDefinition(), null, new ReloadRequiredWriteAttributeHandler() {

        @Override
        protected void validateUpdatedModel(OperationContext context, Resource model) {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext ctx, ModelNode op) throws OperationFailedException {
                    if (model.hasChild(SSLResourceDefinition.PATH)) {
                        throw new OperationFailedException(ROOT_LOGGER.bothElytronAndLegacySslContextDefined());
                    }
                }
            }, OperationContext.Stage.MODEL);
        }
    });
    parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {

        @Override
        public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
            PathAddress rebuiltAddress = PathAddress.EMPTY_ADDRESS;
            for (PathElement pathElement : aliasAddress) {
                if (pathElement.equals(LEGACY_PATH)) {
                    try {
                        if (aliasContext.readResourceFromRoot(rebuiltAddress, false).hasChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey())) {
                            Set<Resource.ResourceEntry> children = aliasContext.readResourceFromRoot(rebuiltAddress, false).getChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey());
                            if (children.size() > 1 && !Operations.getOperationName(aliasContext.getOperation()).equals(AliasContext.RECURSIVE_GLOBAL_OP)) {
                                throw new IllegalStateException(ModClusterLogger.ROOT_LOGGER.legacyOperationsWithMultipleProxies());
                            }
                            PathAddress proxyPath = PathAddress.pathAddress(ProxyConfigurationResourceDefinition.pathElement(children.iterator().next().getName()));
                            rebuiltAddress = rebuiltAddress.append(proxyPath);
                        } else {
                            // handle :add
                            rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.pathElement("default"));
                        }
                    } catch (Resource.NoSuchResourceException ignore) {
                        // handle recursive-global-op
                        rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.WILDCARD_PATH);
                    }
                } else {
                    rebuiltAddress = rebuiltAddress.append(pathElement);
                }
            }
            return rebuiltAddress;
        }
    });
    if (registration.isRuntimeOnlyRegistrationValid()) {
        new OperationHandler<>(new ProxyOperationExecutor(this.executors), ProxyOperation.class).register(registration);
    }
    new ReloadRequiredResourceRegistration(descriptor).register(registration);
    new LegacyMetricOperationsRegistration().register(registration);
    new SimpleLoadProviderResourceDefinition().register(registration);
    new DynamicLoadProviderResourceDefinition().register(registration);
    new SSLResourceDefinition().register(registration);
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) EnumSet(java.util.EnumSet) Set(java.util.Set) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementResourceRegistration(org.jboss.as.clustering.controller.ManagementResourceRegistration) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ReloadRequiredResourceRegistration(org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration) AliasEntry(org.jboss.as.controller.registry.AliasEntry) ModelNode(org.jboss.dmr.ModelNode) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 3 with AliasEntry

use of org.jboss.as.controller.registry.AliasEntry in project wildfly by wildfly.

the class FilterDefinitions method registerChildren.

@Override
public void registerChildren(ManagementResourceRegistration resourceRegistration) {
    super.registerChildren(resourceRegistration);
    PathElement targetPe = RequestLimitHandler.INSTANCE.getPathElement();
    AliasEntry aliasEntry = new AliasEntry(resourceRegistration.getSubModel(PathAddress.pathAddress(targetPe))) {

        @Override
        public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
            PathElement pe = aliasAddress.getLastElement();
            return aliasAddress.getParent().append(PathElement.pathElement(targetPe.getKey(), pe.getValue()));
        }
    };
    resourceRegistration.registerAlias(PathElement.pathElement("connection-limit"), aliasEntry);
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) AliasEntry(org.jboss.as.controller.registry.AliasEntry)

Example 4 with AliasEntry

use of org.jboss.as.controller.registry.AliasEntry in project wildfly by wildfly.

the class ACLResourceDefinition method registerChildren.

@Override
public void registerChildren(ManagementResourceRegistration resourceRegistration) {
    super.registerChildren(resourceRegistration);
    ManagementResourceRegistration moduleReg = resourceRegistration.registerSubModel(new LoginModuleResourceDefinition(Constants.ACL_MODULE));
    // https://issues.jboss.org/browse/WFLY-2474 acl-module was wrongly called login-module in 7.2.0
    resourceRegistration.registerAlias(PathElement.pathElement(Constants.LOGIN_MODULE), new AliasEntry(moduleReg) {

        @Override
        public PathAddress convertToTargetAddress(PathAddress address, AliasContext aliasContext) {
            PathElement element = address.getLastElement();
            element = PathElement.pathElement(Constants.ACL_MODULE, element.getValue());
            return address.subAddress(0, address.size() - 1).append(element);
        }
    });
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) AliasEntry(org.jboss.as.controller.registry.AliasEntry)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)4 PathElement (org.jboss.as.controller.PathElement)4 AliasEntry (org.jboss.as.controller.registry.AliasEntry)4 EnumSet (java.util.EnumSet)2 Set (java.util.Set)2 OperationContext (org.jboss.as.controller.OperationContext)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)2 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)2 Resource (org.jboss.as.controller.registry.Resource)2 ModelNode (org.jboss.dmr.ModelNode)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ManagementResourceRegistration (org.jboss.as.clustering.controller.ManagementResourceRegistration)1 ReloadRequiredResourceRegistration (org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration)1 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)1 WriteAttributeStepHandler (org.jboss.as.clustering.controller.WriteAttributeStepHandler)1 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)1