Search in sources :

Example 81 with ServiceTarget

use of org.jboss.msc.service.ServiceTarget in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method addPuService.

/**
     * Add one PU service per top level deployment that represents
     *
     *
     * @param phaseContext
     * @param puList
     * @param startEarly
     * @param platform
     * @throws DeploymentUnitProcessingException
     *
     */
private static void addPuService(final DeploymentPhaseContext phaseContext, final ArrayList<PersistenceUnitMetadataHolder> puList, final boolean startEarly, final Platform platform) throws DeploymentUnitProcessingException {
    if (puList.size() > 0) {
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final Collection<ComponentDescription> components = eeModuleDescription.getComponentDescriptions();
        if (module == null) {
            // Unresolved OSGi bundles would not have a module attached
            ROOT_LOGGER.failedToGetModuleAttachment(deploymentUnit);
            return;
        }
        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        final ModuleClassLoader classLoader = module.getClassLoader();
        for (PersistenceUnitMetadataHolder holder : puList) {
            setAnnotationIndexes(holder, deploymentUnit);
            for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
                // only start the persistence unit if JPA_CONTAINER_MANAGED is true
                String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED);
                boolean deployPU = (jpaContainerManaged == null ? true : Boolean.parseBoolean(jpaContainerManaged));
                if (deployPU) {
                    final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder = getPersistenceProviderDeploymentHolder(deploymentUnit);
                    final PersistenceProvider provider = lookupProvider(pu, persistenceProviderDeploymentHolder, deploymentUnit);
                    final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, deploymentUnit, provider, platform);
                    final boolean twoPhaseBootStrapCapable = (adaptor instanceof TwoPhaseBootstrapCapable) && Configuration.allowTwoPhaseBootstrap(pu);
                    if (startEarly) {
                        if (twoPhaseBootStrapCapable) {
                            deployPersistenceUnitPhaseOne(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, adaptor);
                        } else if (false == Configuration.needClassFileTransformer(pu)) {
                            // will start later when startEarly == false
                            ROOT_LOGGER.tracef("persistence unit %s in deployment %s is configured to not need class transformer to be set, no class rewriting will be allowed", pu.getPersistenceUnitName(), deploymentUnit.getName());
                        } else {
                            // we need class file transformer to work, don't allow cdi bean manager to be access since that
                            // could cause application classes to be loaded (workaround by setting jboss.as.jpa.classtransformer to false).  WFLY-1463
                            final boolean allowCdiBeanManagerAccess = false;
                            deployPersistenceUnit(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, startEarly, provider, adaptor, allowCdiBeanManagerAccess);
                        }
                    } else {
                        // !startEarly
                        if (twoPhaseBootStrapCapable) {
                            deployPersistenceUnitPhaseTwo(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, provider, adaptor);
                        } else if (false == Configuration.needClassFileTransformer(pu)) {
                            final boolean allowCdiBeanManagerAccess = true;
                            // PUs that have Configuration.JPA_CONTAINER_CLASS_TRANSFORMER = false will start during INSTALL phase
                            deployPersistenceUnit(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, startEarly, provider, adaptor, allowCdiBeanManagerAccess);
                        }
                    }
                } else {
                    ROOT_LOGGER.tracef("persistence unit %s in deployment %s is not container managed (%s is set to false)", pu.getPersistenceUnitName(), deploymentUnit.getName(), Configuration.JPA_CONTAINER_MANAGED);
                }
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ServiceTarget(org.jboss.msc.service.ServiceTarget) PersistenceProvider(javax.persistence.spi.PersistenceProvider) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata) Module(org.jboss.modules.Module) PersistenceProviderDeploymentHolder(org.jboss.as.jpa.config.PersistenceProviderDeploymentHolder) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) TwoPhaseBootstrapCapable(org.jipijapa.plugin.spi.TwoPhaseBootstrapCapable) PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 82 with ServiceTarget

use of org.jboss.msc.service.ServiceTarget in project wildfly by wildfly.

the class NodeServiceActivator method activate.

@Override
public void activate(ServiceActivatorContext context) {
    ServiceTarget target = context.getServiceTarget();
    try {
        SingletonServiceBuilderFactory factory = (SingletonServiceBuilderFactory) context.getServiceRegistry().getRequiredService(ServiceName.parse(SingletonDefaultCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY.resolve(CONTAINER_NAME))).awaitValue();
        install(target, factory, DEFAULT_SERVICE_NAME, 1);
        install(target, factory, QUORUM_SERVICE_NAME, 2);
    } catch (InterruptedException e) {
        throw new ServiceRegistryException(e);
    }
}
Also used : SingletonServiceBuilderFactory(org.wildfly.clustering.singleton.SingletonServiceBuilderFactory) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceRegistryException(org.jboss.msc.service.ServiceRegistryException)

Example 83 with ServiceTarget

use of org.jboss.msc.service.ServiceTarget in project wildfly by wildfly.

the class HandlerAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String name = address.getLastElement().getValue();
    final HandlerService service = new HandlerService(handler.createHandler(context, model), name);
    final ServiceTarget target = context.getServiceTarget();
    ServiceBuilder<HttpHandler> builder = target.addService(UndertowService.HANDLER.append(name), service).setInitialMode(ServiceController.Mode.ON_DEMAND);
    final RuntimeCapability newCapability = Handler.CAPABILITY.fromBaseCapability(name);
    if (context.hasOptionalCapability(Handler.REQUEST_CONTROLLER, newCapability.getName(), null)) {
        builder.addDependency(RequestController.SERVICE_NAME, RequestController.class, service.getRequestControllerInjectedValue());
    }
    builder.install();
}
Also used : HttpHandler(io.undertow.server.HttpHandler) RuntimeCapability(org.jboss.as.controller.capability.RuntimeCapability) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget)

Example 84 with ServiceTarget

use of org.jboss.msc.service.ServiceTarget in project wildfly by wildfly.

the class FilterAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String name = address.getLastElement().getValue();
    final FilterService service = new FilterService(handler, getResolvedModel(context, model));
    final ServiceTarget target = context.getServiceTarget();
    target.addService(UndertowService.FILTER.append(name), service).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget)

Example 85 with ServiceTarget

use of org.jboss.msc.service.ServiceTarget 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 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();
            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 BatchEnvironmentService service = new BatchEnvironmentService(moduleClassLoader, jobXmlResolver, deploymentName);
        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(support.getCapabilityServiceName(Capabilities.THREAD_POOL_CAPABILITY.getName(), jobExecutorName), JobExecutor.class, service.getJobExecutorInjector());
        }
        // Register the required services
        serviceBuilder.addDependency(support.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName()), BatchConfiguration.class, service.getBatchConfigurationInjector());
        serviceBuilder.addDependency(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER, TransactionManager.class, service.getTransactionManagerInjector());
        // Register the bean manager if this is a CDI deployment
        if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
            BatchLogger.LOGGER.tracef("Adding BeanManager service dependency for deployment %s", deploymentUnit.getName());
            serviceBuilder.addDependency(BatchServiceNames.beanManagerServiceName(deploymentUnit), BeanManager.class, service.getBeanManagerInjector());
        }
        // No deployment defined repository, use the default
        if (jobRepositoryName != null) {
            // Register a named job repository
            serviceBuilder.addDependency(support.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), jobRepositoryName), JobRepository.class, service.getJobRepositoryInjector());
        } else {
            // 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
        Services.addServerExecutorDependency(serviceTarget.addService(BatchServiceNames.jobOperatorServiceName(deploymentUnit), jobOperatorService).addDependency(support.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName()), BatchConfiguration.class, jobOperatorService.getBatchConfigurationInjector()).addDependency(SuspendController.SERVICE_NAME, SuspendController.class, jobOperatorService.getSuspendControllerInjector()).addDependency(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), SecurityAwareBatchEnvironment.class, jobOperatorService.getBatchEnvironmentInjector()), jobOperatorService.getExecutorServiceInjector(), false).install();
        // Add the JobOperatorService to the deployment unit
        deploymentUnit.putAttachment(BatchAttachments.JOB_OPERATOR, jobOperatorService);
        // Add the JobOperator to the context selector
        selector.registerContext(moduleClassLoader, JobOperatorContext.create(jobOperatorService));
    }
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) JobRepository(org.jberet.repository.JobRepository) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) SuspendController(org.jboss.as.server.suspend.SuspendController) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ServiceTarget (org.jboss.msc.service.ServiceTarget)108 ServiceName (org.jboss.msc.service.ServiceName)57 PathAddress (org.jboss.as.controller.PathAddress)30 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)26 ModelNode (org.jboss.dmr.ModelNode)26 Module (org.jboss.modules.Module)18 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)15 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)11 ContextNames (org.jboss.as.naming.deployment.ContextNames)11 Resource (org.jboss.as.controller.registry.Resource)10 BinderService (org.jboss.as.naming.service.BinderService)10 AbstractDeploymentChainStep (org.jboss.as.server.AbstractDeploymentChainStep)10 DeploymentProcessorTarget (org.jboss.as.server.DeploymentProcessorTarget)10 PathElement (org.jboss.as.controller.PathElement)9 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)9 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)9 ServiceController (org.jboss.msc.service.ServiceController)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5