Search in sources :

Example 11 with WeldCapability

use of org.jboss.as.weld.WeldCapability in project wildfly by wildfly.

the class MicroProfileFaultToleranceDependenciesProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    Optional<WeldCapability> weldCapability = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class);
    if (weldCapability.isPresent() && weldCapability.get().isPartOfWeldDeployment(deploymentUnit) && MicroProfileFaultToleranceMarker.hasMicroProfileFaultToleranceAnnotations(deploymentUnit)) {
        MicroProfileFaultToleranceMarker.mark(deploymentUnit);
        ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
        ModuleLoader moduleLoader = Module.getBootModuleLoader();
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, "org.eclipse.microprofile.fault-tolerance.api", false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, "org.wildfly.microprofile.fault-tolerance-smallrye.executor", false, false, true, false));
    }
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) WeldCapability(org.jboss.as.weld.WeldCapability) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 12 with WeldCapability

use of org.jboss.as.weld.WeldCapability in project wildfly by wildfly.

the class MicroProfileFaultToleranceDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!MicroProfileFaultToleranceMarker.isMarked(deploymentUnit)) {
        return;
    }
    // Weld Extension
    CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    WeldCapability weldCapability;
    try {
        weldCapability = support.getCapabilityRuntimeAPI(Capabilities.WELD_CAPABILITY_NAME, WeldCapability.class);
    } catch (CapabilityServiceSupport.NoSuchCapabilityException e) {
        throw new IllegalStateException();
    }
    weldCapability.registerExtensionInstance(new FaultToleranceExtension(), deploymentUnit);
}
Also used : FaultToleranceExtension(io.smallrye.faulttolerance.FaultToleranceExtension) WeldCapability(org.jboss.as.weld.WeldCapability) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 13 with WeldCapability

use of org.jboss.as.weld.WeldCapability in project wildfly by wildfly.

the class BatchEnvironmentProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.hasAttachment(Attachments.MODULE)) {
        BatchLogger.LOGGER.tracef("Processing deployment '%s' for the batch environment.", deploymentUnit.getName());
        // Configure and attach the job resolver for all deployments
        final WildFlyJobXmlResolver jobXmlResolver = WildFlyJobXmlResolver.forDeployment(deploymentUnit);
        // Skip the rest of the processing for EAR's, only sub-deployments need an environment configured
        if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit))
            return;
        // Get the class loader
        final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        final ClassLoader moduleClassLoader = module.getClassLoader();
        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        JobRepository jobRepository = null;
        String jobRepositoryName = null;
        String dataSourceName = null;
        String jobExecutorName = null;
        Boolean restartJobsOnResume = null;
        // Check for a deployment descriptor
        BatchEnvironmentMetaData metaData = deploymentUnit.getAttachment(BatchAttachments.BATCH_ENVIRONMENT_META_DATA);
        if (metaData == null) {
            // Check the parent
            final DeploymentUnit parent = deploymentUnit.getParent();
            if (parent != null) {
                metaData = parent.getAttachment(BatchAttachments.BATCH_ENVIRONMENT_META_DATA);
            }
        }
        if (metaData != null) {
            jobRepository = metaData.getJobRepository();
            jobRepositoryName = metaData.getJobRepositoryName();
            dataSourceName = metaData.getDataSourceName();
            jobExecutorName = metaData.getExecutorName();
            restartJobsOnResume = metaData.getRestartJobsOnResume();
        }
        final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        final String deploymentName = deploymentUnit.getName();
        // Create the job operator service used interact with a deployments batch job
        final JobOperatorService jobOperatorService = new JobOperatorService(restartJobsOnResume, deploymentName, jobXmlResolver);
        // Create the batch environment
        final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final NamespaceContextSelector namespaceContextSelector = eeModuleDescription == null ? null : eeModuleDescription.getNamespaceContextSelector();
        final BatchEnvironmentService service = new BatchEnvironmentService(moduleClassLoader, jobXmlResolver, deploymentName, namespaceContextSelector);
        final ServiceBuilder<SecurityAwareBatchEnvironment> serviceBuilder = serviceTarget.addService(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), service);
        // Add a dependency to the thread-pool
        if (jobExecutorName != null) {
            // Register the named thread-pool capability
            serviceBuilder.addDependency(Capabilities.THREAD_POOL_CAPABILITY.getCapabilityServiceName(jobExecutorName), JobExecutor.class, service.getJobExecutorInjector());
        }
        // Register the required services
        serviceBuilder.addDependency(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getCapabilityServiceName(), BatchConfiguration.class, service.getBatchConfigurationInjector());
        // Ensure local transaction support is started
        serviceBuilder.requires(support.getCapabilityServiceName(Capabilities.LOCAL_TRANSACTION_PROVIDER_CAPABILITY));
        final ServiceName artifactFactoryServiceName = BatchServiceNames.batchArtifactFactoryServiceName(deploymentUnit);
        final ArtifactFactoryService artifactFactoryService = new ArtifactFactoryService();
        final ServiceBuilder<ArtifactFactory> artifactFactoryServiceBuilder = serviceTarget.addService(artifactFactoryServiceName, artifactFactoryService);
        // Register the bean manager if this is a Jakarta Contexts and Dependency Injection deployment
        if (support.hasCapability(WELD_CAPABILITY_NAME)) {
            final WeldCapability api = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get();
            if (api.isPartOfWeldDeployment(deploymentUnit)) {
                BatchLogger.LOGGER.tracef("Adding BeanManager service dependency for deployment %s", deploymentUnit.getName());
                api.addBeanManagerService(deploymentUnit, artifactFactoryServiceBuilder, artifactFactoryService.getBeanManagerInjector());
            }
        }
        artifactFactoryServiceBuilder.install();
        serviceBuilder.addDependency(artifactFactoryServiceName, WildFlyArtifactFactory.class, service.getArtifactFactoryInjector());
        if (jobRepositoryName != null) {
            // Register a named job repository
            serviceBuilder.addDependency(support.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), jobRepositoryName), JobRepository.class, service.getJobRepositoryInjector());
        } else if (dataSourceName != null) {
            // Register a jdbc job repository with data-source
            final JdbcJobRepositoryService jdbcJobRepositoryService = new JdbcJobRepositoryService();
            final ServiceName jobRepositoryServiceName = support.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), deploymentName);
            final ServiceBuilder<JobRepository> jobRepositoryServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(jobRepositoryServiceName, jdbcJobRepositoryService), jdbcJobRepositoryService.getExecutorServiceInjector()).addDependency(support.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY, dataSourceName), DataSource.class, jdbcJobRepositoryService.getDataSourceInjector());
            jobRepositoryServiceBuilder.install();
            serviceBuilder.addDependency(jobRepositoryServiceName, JobRepository.class, service.getJobRepositoryInjector());
        } else if (jobRepository != null) {
            // Use the job repository as defined in the deployment descriptor
            service.getJobRepositoryInjector().setValue(new ImmediateValue<>(jobRepository));
        }
        if (rcPresent) {
            serviceBuilder.addDependency(RequestController.SERVICE_NAME, RequestController.class, service.getRequestControllerInjector());
        }
        // Install the batch environment service
        serviceBuilder.install();
        // Install the JobOperatorService
        ServiceName jobOperatorServiceName = BatchServiceNames.jobOperatorServiceName(deploymentUnit);
        Services.addServerExecutorDependency(serviceTarget.addService(jobOperatorServiceName, jobOperatorService).addDependency(support.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName()), BatchConfiguration.class, jobOperatorService.getBatchConfigurationInjector()).addDependency(support.getCapabilityServiceName(Capabilities.SUSPEND_CONTROLLER_CAPABILITY), SuspendController.class, jobOperatorService.getSuspendControllerInjector()).addDependency(support.getCapabilityServiceName(Capabilities.PROCESS_STATE_NOTIFIER_CAPABILITY), ProcessStateNotifier.class, jobOperatorService.getProcessStateInjector()).addDependency(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), SecurityAwareBatchEnvironment.class, jobOperatorService.getBatchEnvironmentInjector()), jobOperatorService.getExecutorServiceInjector()).install();
        // Add the JobOperatorService to the deployment unit
        deploymentUnit.putAttachment(BatchAttachments.JOB_OPERATOR, jobOperatorService);
        deploymentUnit.addToAttachmentList(DEPLOYMENT_COMPLETE_SERVICES, jobOperatorServiceName);
        // Add the JobOperator to the context selector
        selector.registerContext(moduleClassLoader, JobOperatorContext.create(jobOperatorService));
    }
}
Also used : JobRepository(org.jberet.repository.JobRepository) NamespaceContextSelector(org.jboss.as.naming.context.NamespaceContextSelector) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) BatchConfiguration(org.wildfly.extension.batch.jberet.BatchConfiguration) ServiceTarget(org.jboss.msc.service.ServiceTarget) JdbcJobRepositoryService(org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryService) WeldCapability(org.jboss.as.weld.WeldCapability) ProcessStateNotifier(org.jboss.as.controller.ProcessStateNotifier) DataSource(javax.sql.DataSource) ArtifactFactory(org.jberet.spi.ArtifactFactory) ServiceName(org.jboss.msc.service.ServiceName) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 14 with WeldCapability

use of org.jboss.as.weld.WeldCapability in project wildfly by wildfly.

the class HibernateValidatorDeploymentUnitProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    if (support.hasCapability(WELD_CAPABILITY_NAME) && support.hasCapability(BEAN_VALIDATION_CAPABILITY)) {
        try {
            final WeldCapability weldCapability = support.getCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class);
            weldCapability.registerExtensionInstance(new EjbProxyNormalizerCdiExtension(), deploymentUnit);
        } catch (CapabilityServiceSupport.NoSuchCapabilityException e) {
            Assert.unreachableCode();
        }
    }
}
Also used : EjbProxyNormalizerCdiExtension(org.jboss.as.ejb3.validator.EjbProxyNormalizerCdiExtension) WeldCapability(org.jboss.as.weld.WeldCapability) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 15 with WeldCapability

use of org.jboss.as.weld.WeldCapability in project wildfly by wildfly.

the class ReactiveMessagingDependencyProcessor method ignorePrecalulatedJandex.

@SuppressWarnings("deprecation")
private void ignorePrecalulatedJandex(DeploymentUnit deploymentUnit, String... modules) {
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    if (support.hasCapability(WELD_CAPABILITY_NAME)) {
        WeldCapability weld = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get();
        weld.ignorePrecalculatedJandexForModules(deploymentUnit, modules);
    }
}
Also used : WeldCapability(org.jboss.as.weld.WeldCapability) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Aggregations

WeldCapability (org.jboss.as.weld.WeldCapability)16 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)15 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)13 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)5 ModuleLoader (org.jboss.modules.ModuleLoader)5 ModuleDependency (org.jboss.as.server.deployment.module.ModuleDependency)3 Module (org.jboss.modules.Module)3 ServiceName (org.jboss.msc.service.ServiceName)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 FaultToleranceExtension (io.smallrye.faulttolerance.FaultToleranceExtension)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 DataSource (javax.sql.DataSource)1 JobRepository (org.jberet.repository.JobRepository)1 ArtifactFactory (org.jberet.spi.ArtifactFactory)1 ProcessStateNotifier (org.jboss.as.controller.ProcessStateNotifier)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 EjbProxyNormalizerCdiExtension (org.jboss.as.ejb3.validator.EjbProxyNormalizerCdiExtension)1 BeanManagerAfterDeploymentValidation (org.jboss.as.jpa.beanmanager.BeanManagerAfterDeploymentValidation)1 NamespaceContextSelector (org.jboss.as.naming.context.NamespaceContextSelector)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1