Search in sources :

Example 56 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class AddStepHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    PathAddress parentAddress = address.getParent();
    PathElement path = address.getLastElement();
    OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD);
    if (parentHandler instanceof DescribedAddStepHandler) {
        AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor();
        if (parentDescriptor.getRequiredChildren().contains(path)) {
            if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) {
                // If we are a required child resource of our parent, we need to remove the auto-created resource first
                context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
                context.addStep(operation, this, OperationContext.Stage.MODEL);
                return;
            }
        } else {
            Optional<PathElement> singletonPathResult = parentDescriptor.getRequiredSingletonChildren().stream().filter((PathElement requiredPath) -> requiredPath.getKey().equals(path.getKey()) && !requiredPath.getValue().equals(path.getValue())).findFirst();
            if (singletonPathResult.isPresent()) {
                PathElement singletonPath = singletonPathResult.get();
                if (context.readResourceFromRoot(parentAddress, false).hasChild(singletonPath)) {
                    // If there is a required singleton sibling resource, we need to remove it first
                    PathAddress singletonAddress = parentAddress.append(singletonPath);
                    context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
                    context.addStep(operation, this, OperationContext.Stage.MODEL);
                    return;
                }
            }
        }
    }
    super.execute(context, operation);
    if (this.requiresRuntime(context)) {
        this.descriptor.getRuntimeResourceRegistrations().forEach(registration -> context.addStep(registration, OperationContext.Stage.MODEL));
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress)

Example 57 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class SimpleAliasEntry method convertToTargetAddress.

@Override
public PathAddress convertToTargetAddress(PathAddress address, AliasContext aliasContext) {
    PathAddress target = this.getTargetAddress();
    List<PathElement> result = new ArrayList<>(address.size());
    for (int i = 0; i < address.size(); ++i) {
        PathElement element = address.getElement(i);
        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);
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList)

Example 58 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class EJB3RemoteServiceAdd method installRuntimeServices.

void installRuntimeServices(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final String clientMappingsClusterName = EJB3RemoteResourceDefinition.CLIENT_MAPPINGS_CLUSTER_NAME.resolveModelAttribute(context, model).asString();
    final String connectorName = EJB3RemoteResourceDefinition.CONNECTOR_REF.resolveModelAttribute(context, model).asString();
    final ServiceName remotingServerInfoServiceName = RemotingConnectorBindingInfoService.serviceName(connectorName);
    final String threadPoolName = EJB3RemoteResourceDefinition.THREAD_POOL_NAME.resolveModelAttribute(context, model).asString();
    final boolean executeInWorker = EJB3RemoteResourceDefinition.EXECUTE_IN_WORKER.resolveModelAttribute(context, model).asBoolean();
    final ServiceTarget target = context.getServiceTarget();
    // Install the client-mapping service for the remoting connector
    new EJBRemotingConnectorClientMappingsEntryProviderService(clientMappingsClusterName, remotingServerInfoServiceName).configure(context).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    new RegistryInstallerService(clientMappingsClusterName).configure(context).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    // Handle case where no infinispan subsystem exists or does not define an ejb cache-container
    Resource rootResource = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
    PathElement infinispanPath = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "infinispan");
    if (!rootResource.hasChild(infinispanPath) || !rootResource.getChild(infinispanPath).hasChild(PathElement.pathElement("cache-container", clientMappingsClusterName))) {
        // Install services that would normally be installed by this container/cache
        CapabilityServiceSupport support = context.getCapabilityServiceSupport();
        for (GroupBuilderProvider provider : ServiceLoader.load(LocalGroupBuilderProvider.class, LocalGroupBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> requirement.getServiceName(support, clientMappingsClusterName), clientMappingsClusterName)) {
                builder.configure(support).build(target).install();
            }
        }
        for (CacheBuilderProvider provider : ServiceLoader.load(LocalCacheBuilderProvider.class, LocalCacheBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> requirement.getServiceName(support, clientMappingsClusterName, null), clientMappingsClusterName, null)) {
                builder.configure(support).build(target).install();
            }
        }
    }
    final OptionMap channelCreationOptions = this.getChannelCreationOptions(context);
    // Install the EJB remoting connector service which will listen for client connections on the remoting channel
    // TODO: Externalize (expose via management API if needed) the version and the marshalling strategy
    final EJBRemoteConnectorService ejbRemoteConnectorService = new EJBRemoteConnectorService(channelCreationOptions);
    ServiceBuilder<EJBRemoteConnectorService> builder = target.addService(EJBRemoteConnectorService.SERVICE_NAME, ejbRemoteConnectorService);
    builder.addDependency(RemotingServices.SUBSYSTEM_ENDPOINT, Endpoint.class, ejbRemoteConnectorService.getEndpointInjector()).addDependency(remotingServerInfoServiceName, RemotingConnectorBindingInfoService.RemotingConnectorInfo.class, ejbRemoteConnectorService.getRemotingConnectorInfoInjectedValue()).addDependency(AssociationService.SERVICE_NAME, AssociationService.class, ejbRemoteConnectorService.getAssociationServiceInjector()).addDependency(TxnServices.JBOSS_TXN_REMOTE_TRANSACTION_SERVICE, RemotingTransactionService.class, ejbRemoteConnectorService.getRemotingTransactionServiceInjector()).addDependency(ControlledProcessStateService.SERVICE_NAME, ControlledProcessStateService.class, ejbRemoteConnectorService.getControlledProcessStateServiceInjector()).setInitialMode(ServiceController.Mode.ACTIVE);
    if (!executeInWorker) {
        builder.addDependency(EJB3SubsystemModel.BASE_THREAD_POOL_SERVICE_NAME.append(threadPoolName), ExecutorService.class, ejbRemoteConnectorService.getExecutorService());
    }
    builder.install();
}
Also used : LocalCacheBuilderProvider(org.wildfly.clustering.spi.LocalCacheBuilderProvider) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) ControlledProcessStateService(org.jboss.as.controller.ControlledProcessStateService) EJBRemotingConnectorClientMappingsEntryProviderService(org.jboss.as.ejb3.remote.EJBRemotingConnectorClientMappingsEntryProviderService) ServiceTarget(org.jboss.msc.service.ServiceTarget) RegistryInstallerService(org.jboss.as.ejb3.remote.RegistryInstallerService) RemotingConnectorBindingInfoService(org.jboss.as.remoting.RemotingConnectorBindingInfoService) Resource(org.jboss.as.controller.registry.Resource) AssociationService(org.jboss.as.ejb3.remote.AssociationService) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) PathElement(org.jboss.as.controller.PathElement) Endpoint(org.jboss.remoting3.Endpoint) ServiceName(org.jboss.msc.service.ServiceName) EJBRemoteConnectorService(org.jboss.as.ejb3.remote.EJBRemoteConnectorService) GroupBuilderProvider(org.wildfly.clustering.spi.GroupBuilderProvider) LocalGroupBuilderProvider(org.wildfly.clustering.spi.LocalGroupBuilderProvider) OptionMap(org.xnio.OptionMap) LocalCacheBuilderProvider(org.wildfly.clustering.spi.LocalCacheBuilderProvider) LocalGroupBuilderProvider(org.wildfly.clustering.spi.LocalGroupBuilderProvider)

Example 59 with PathElement

use of org.jboss.as.controller.PathElement 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)

Example 60 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class SecuritySubsystemParser method parseSecurityDomain.

private void parseSecurityDomain(List<ModelNode> list, XMLExtendedStreamReader reader, PathAddress parentAddress) throws XMLStreamException {
    ModelNode op = Util.createAddOperation();
    list.add(op);
    PathElement secDomainPath = null;
    EnumSet<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch(attribute) {
            case NAME:
                {
                    if (value == null || value.length() == 0) {
                        throw invalidAttributeValue(reader, i);
                    }
                    secDomainPath = PathElement.pathElement(SECURITY_DOMAIN, value);
                    break;
                }
            case CACHE_TYPE:
                {
                    SecurityDomainResourceDefinition.CACHE_TYPE.parseAndSetParameter(value, op, reader);
                    break;
                }
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (required.size() > 0) {
        throw missingRequired(reader, required);
    }
    final PathAddress address = parentAddress.append(secDomainPath);
    op.get(OP_ADDR).set(address.toModelNode());
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    moduleNames = new HashMap<String, Integer>();
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (!visited.add(element)) {
            throw unexpectedElement(reader);
        }
        switch(element) {
            case AUTHENTICATION:
                {
                    if (visited.contains(Element.AUTHENTICATION_JASPI)) {
                        throw SecurityLogger.ROOT_LOGGER.xmlStreamExceptionAuth(reader.getLocation());
                    }
                    parseAuthentication(list, address, reader);
                    break;
                }
            case AUTHORIZATION:
                {
                    parseAuthorization(list, address, reader);
                    break;
                }
            case ACL:
                {
                    parseACL(list, address, reader);
                    break;
                }
            case AUDIT:
                {
                    parseAudit(list, address, reader);
                    break;
                }
            case IDENTITY_TRUST:
                {
                    parseIdentityTrust(list, address, reader);
                    break;
                }
            case MAPPING:
                {
                    parseMapping(list, address, reader);
                    break;
                }
            case AUTHENTICATION_JASPI:
                {
                    if (visited.contains(Element.AUTHENTICATION)) {
                        throw SecurityLogger.ROOT_LOGGER.xmlStreamExceptionAuth(reader.getLocation());
                    }
                    parseAuthenticationJaspi(list, address, reader);
                    break;
                }
            case JSSE:
                {
                    parseJSSE(list, address, reader);
                    break;
                }
            default:
                {
                    throw unexpectedElement(reader);
                }
        }
    }
    moduleNames.clear();
}
Also used : PathElement(org.jboss.as.controller.PathElement) ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

PathElement (org.jboss.as.controller.PathElement)70 PathAddress (org.jboss.as.controller.PathAddress)35 ModelNode (org.jboss.dmr.ModelNode)32 Resource (org.jboss.as.controller.registry.Resource)24 OperationFailedException (org.jboss.as.controller.OperationFailedException)10 ServiceName (org.jboss.msc.service.ServiceName)10 Map (java.util.Map)9 ServiceTarget (org.jboss.msc.service.ServiceTarget)9 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)8 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)7 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)5 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)5 AbstractSubsystemBaseTest (org.jboss.as.subsystem.test.AbstractSubsystemBaseTest)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)4 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)4 OperationContext (org.jboss.as.controller.OperationContext)4 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)4 StatisticsPlugin (org.jboss.jca.core.spi.statistics.StatisticsPlugin)4