Search in sources :

Example 56 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class DistributableWebDeploymentDependencyProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    DeploymentUnit unit = context.getDeploymentUnit();
    WarMetaData warMetaData = unit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    SharedSessionManagerConfig sharedConfig = unit.getAttachment(SharedSessionManagerConfig.ATTACHMENT_KEY);
    if (((warMetaData != null) && (warMetaData.getMergedJBossWebMetaData() != null && warMetaData.getMergedJBossWebMetaData().getDistributable() != null)) || ((sharedConfig != null) && sharedConfig.isDistributable())) {
        CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        DistributableWebDeploymentConfiguration config = unit.getAttachment(CONFIGURATION_KEY);
        String name = (config != null) ? config.getSessionManagementName() : null;
        DistributableSessionManagementProvider management = (name == null) && (config != null) ? config.getSessionManagement() : null;
        List<String> immutableClasses = (config != null) ? config.getImmutableClasses() : Collections.emptyList();
        for (String immutableClass : immutableClasses) {
            unit.addToAttachmentList(DistributableSessionManagementProvider.IMMUTABILITY_ATTACHMENT_KEY, immutableClass);
        }
        if (management != null) {
            LOGGER.debugf("%s will use a deployment-specific distributable session management provider", unit.getName());
            ServiceTarget target = context.getServiceTarget();
            DeploymentUnit parentUnit = unit.getParent();
            String deploymentName = (parentUnit != null) ? parentUnit.getName() + "." + unit.getName() : unit.getName();
            ServiceName serviceName = WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, deploymentName);
            ServiceBuilder<?> builder = target.addService(serviceName);
            Consumer<DistributableSessionManagementProvider> injector = builder.provides(serviceName);
            Service service = Service.newInstance(injector, management);
            builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
            context.addDependency(serviceName, DistributableSessionManagementProvider.ATTACHMENT_KEY);
        } else {
            if (name != null) {
                LOGGER.debugf("%s will use the '%s' distributable session management provider", unit.getName(), name);
            } else {
                LOGGER.debugf("%s will use the default distributable session management provider", unit.getName());
            }
            context.addDependency(WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, name), DistributableSessionManagementProvider.ATTACHMENT_KEY);
        }
    }
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) WarMetaData(org.jboss.as.web.common.WarMetaData) DistributableSessionManagementProvider(org.wildfly.clustering.web.session.DistributableSessionManagementProvider) Service(org.jboss.msc.Service) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) SharedSessionManagerConfig(org.jboss.as.web.session.SharedSessionManagerConfig) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 57 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class UndertowDistributableServerRuntimeHandler method execute.

@Override
public void execute(OperationContext context, String serverName) {
    SupplierDependency<RoutingProvider> provider = getRoutingProvider(context, serverName);
    if (provider != null) {
        ServiceTarget target = context.getServiceTarget();
        CapabilityServiceSupport support = context.getCapabilityServiceSupport();
        SupplierDependency<Server> server = new ServiceSupplierDependency<>(UndertowUnaryRequirement.SERVER.getServiceName(context, serverName));
        SupplierDependency<String> route = new FunctionSupplierDependency<>(server, Server::getRoute);
        Consumer<ServiceTarget> installer = new Consumer<ServiceTarget>() {

            @Override
            public void accept(ServiceTarget target) {
                for (CapabilityServiceConfigurator configurator : provider.get().getServiceConfigurators(serverName, route)) {
                    configurator.configure(support).build(target).install();
                }
            }
        };
        ServiceName name = ServiceName.JBOSS.append("clustering", "web", "undertow", "routing", serverName);
        provider.register(target.addService(name)).setInstance(new ChildTargetService(installer)).install();
    }
}
Also used : RoutingProvider(org.wildfly.clustering.web.routing.RoutingProvider) FunctionSupplierDependency(org.wildfly.clustering.service.FunctionSupplierDependency) Server(org.wildfly.extension.undertow.Server) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) Consumer(java.util.function.Consumer) ServiceName(org.jboss.msc.service.ServiceName)

Example 58 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class RaOperationUtil method activate.

public static void activate(OperationContext context, String raName, String archiveName) throws OperationFailedException {
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> inactiveRaController = registry.getService(ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(archiveName));
    final CapabilityServiceSupport support = context.getCapabilityServiceSupport();
    if (inactiveRaController == null) {
        inactiveRaController = registry.getService(ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(raName));
        if (inactiveRaController == null) {
            throw ConnectorLogger.ROOT_LOGGER.RARNotYetDeployed(raName);
        }
    }
    InactiveResourceAdapterDeploymentService.InactiveResourceAdapterDeployment inactive = (InactiveResourceAdapterDeploymentService.InactiveResourceAdapterDeployment) inactiveRaController.getValue();
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
    Activation raxml = (Activation) RaxmlController.getValue();
    RaServicesFactory.createDeploymentService(inactive.getRegistration(), inactive.getConnectorXmlDescriptor(), inactive.getModule(), inactive.getServiceTarget(), archiveName, inactive.getDeploymentUnitServiceName(), inactive.getDeployment(), raxml, inactive.getResource(), registry, support);
}
Also used : InactiveResourceAdapterDeploymentService(org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 59 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class DataSourceDefinitionInjectionSource method getResourceValue.

// --- //
@Override
public void getResourceValue(ResolutionContext context, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfiguration = new AgroalConnectionFactoryConfigurationSupplier();
    try {
        Class<?> providerClass = phaseContext.getDeploymentUnit().getAttachment(MODULE).getClassLoader().loadClass(className);
        if (providerClass != null && !DataSource.class.isAssignableFrom(providerClass) && !Driver.class.isAssignableFrom(providerClass)) {
            throw AgroalLogger.SERVICE_LOGGER.invalidDeploymentConnectionProvider();
        }
        connectionFactoryConfiguration.connectionProviderClass(providerClass);
    } catch (ClassNotFoundException e) {
        throw AgroalLogger.SERVICE_LOGGER.loadClassDeploymentException(e, className);
    }
    for (Map.Entry<String, String> property : properties.entrySet()) {
        connectionFactoryConfiguration.jdbcProperty(property.getKey(), property.getValue());
    }
    if (databaseName != null && !databaseName.isEmpty()) {
        connectionFactoryConfiguration.jdbcProperty(DATABASE_NAME_PROP, databaseName);
    }
    if (description != null && !description.isEmpty()) {
        connectionFactoryConfiguration.jdbcProperty(DESCRIPTION_PROP, description);
    }
    if (serverName != null && !serverName.isEmpty()) {
        connectionFactoryConfiguration.jdbcProperty(SERVER_NAME_PROP, serverName);
    }
    if (portNumber >= 0) {
        connectionFactoryConfiguration.jdbcProperty(PORT_NUMBER_PROP, Integer.toString(portNumber));
    }
    if (loginTimeout >= 0) {
        connectionFactoryConfiguration.jdbcProperty(LOGIN_TIMEOUT_PROP, Integer.toString(loginTimeout));
    }
    if (maxStatements >= 0) {
        connectionFactoryConfiguration.jdbcProperty(MAX_STATEMENTS_PROP, Integer.toString(maxStatements));
    }
    if (url != null && !url.isEmpty()) {
        connectionFactoryConfiguration.jdbcUrl(url);
    }
    if (user != null && !user.isEmpty()) {
        connectionFactoryConfiguration.principal(new NamePrincipal(user));
    }
    if (password != null && !password.isEmpty()) {
        connectionFactoryConfiguration.credential(new SimplePassword(password));
    }
    connectionFactoryConfiguration.jdbcTransactionIsolation(AgroalConnectionFactoryConfiguration.TransactionIsolation.fromLevel(isolationLevel));
    AgroalConnectionPoolConfigurationSupplier connectionPoolConfiguration = new AgroalConnectionPoolConfigurationSupplier();
    connectionPoolConfiguration.connectionFactoryConfiguration(connectionFactoryConfiguration);
    if (initialPoolSize >= 0) {
        connectionPoolConfiguration.initialSize(initialPoolSize);
    }
    if (minPoolSize >= 0) {
        connectionPoolConfiguration.minSize(minPoolSize);
    }
    if (maxPoolSize >= 0) {
        connectionPoolConfiguration.maxSize(maxPoolSize);
    }
    if (maxIdleTime >= 0) {
        connectionPoolConfiguration.reapTimeout(Duration.ofSeconds(maxIdleTime));
    }
    AgroalDataSourceConfigurationSupplier dataSourceConfiguration = new AgroalDataSourceConfigurationSupplier();
    dataSourceConfiguration.connectionPoolConfiguration(connectionPoolConfiguration);
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    ServiceName dataSourceServiceName = DATASOURCE_DEFINITION_SERVICE_PREFIX.append(bindInfo.getBinderServiceName().getCanonicalName());
    // This is the service responsible for the JNDI binding, with a dependency on the datasource service that acts as a ManagedReferenceFactory and is used as the injection source
    BinderService binderService = new BinderService(bindInfo.getBindName(), this);
    phaseContext.getServiceTarget().addService(bindInfo.getBinderServiceName(), binderService).addDependency(dataSourceServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
    ServiceBuilder svcBuilder = phaseContext.getServiceTarget().addService(dataSourceServiceName);
    Supplier<TransactionSynchronizationRegistry> tsrSupplier = null;
    if (transactional) {
        CapabilityServiceSupport css = phaseContext.getDeploymentUnit().getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        ServiceName tsrName = css.getCapabilityServiceName("org.wildfly.transactions.transaction-synchronization-registry");
        // noinspection unchecked
        tsrSupplier = (Supplier<TransactionSynchronizationRegistry>) svcBuilder.requires(tsrName);
    }
    DataSourceDefinitionService dataSourceService = new DataSourceDefinitionService(bindInfo, transactional, dataSourceConfiguration, tsrSupplier);
    svcBuilder.setInstance(dataSourceService).install();
    serviceBuilder.requires(bindInfo.getBinderServiceName());
    serviceBuilder.addDependency(dataSourceServiceName, ManagedReferenceFactory.class, injector);
}
Also used : AgroalDataSourceConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier) NamePrincipal(io.agroal.api.security.NamePrincipal) AgroalConnectionFactoryConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalConnectionFactoryConfigurationSupplier) DataSource(javax.sql.DataSource) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) BinderService(org.jboss.as.naming.service.BinderService) AgroalConnectionPoolConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalConnectionPoolConfigurationSupplier) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) SimplePassword(io.agroal.api.security.SimplePassword) Map(java.util.Map) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 60 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class EJBComponentDescription method addRemoteTransactionsDependency.

/**
 * Adds a dependency for the ComponentConfiguration on the remote transaction service if the EJB exposes at least one remote view
 */
protected void addRemoteTransactionsDependency() {
    this.getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration componentConfiguration) throws DeploymentUnitProcessingException {
            if (this.hasRemoteView((EJBComponentDescription) description)) {
                // add a dependency on local transaction service
                componentConfiguration.getCreateDependencies().add(new DependencyConfigurator<EJBComponentCreateService>() {

                    @Override
                    public void configureDependency(ServiceBuilder<?> serviceBuilder, EJBComponentCreateService ejbComponentCreateService) throws DeploymentUnitProcessingException {
                        CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
                        // add dependency on the remote transaction service
                        serviceBuilder.requires(support.getCapabilityServiceName(REMOTE_TRANSACTION_SERVICE_CAPABILITY_NAME));
                    }
                });
            }
        }

        /**
         * Returns true if the passed EJB component description has at least one remote view
         * @param ejbComponentDescription
         * @return
         */
        private boolean hasRemoteView(final EJBComponentDescription ejbComponentDescription) {
            final Set<ViewDescription> views = ejbComponentDescription.getViews();
            for (final ViewDescription view : views) {
                if (!(view instanceof EJBViewDescription)) {
                    continue;
                }
                final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
                if (viewType == MethodIntf.REMOTE || viewType == MethodIntf.HOME) {
                    return true;
                }
            }
            return false;
        }
    });
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) Set(java.util.Set) HashSet(java.util.HashSet) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ViewDescription(org.jboss.as.ee.component.ViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration)

Aggregations

CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)74 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)39 ServiceName (org.jboss.msc.service.ServiceName)36 ServiceTarget (org.jboss.msc.service.ServiceTarget)23 WeldCapability (org.jboss.as.weld.WeldCapability)19 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)18 Module (org.jboss.modules.Module)16 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)14 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)10 HashMap (java.util.HashMap)9 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)9 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)8 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)8 ValidatorFactory (javax.validation.ValidatorFactory)7 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)7 HashSet (java.util.HashSet)6 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)6 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)6 ModelNode (org.jboss.dmr.ModelNode)6 ModuleLoader (org.jboss.modules.ModuleLoader)6