Search in sources :

Example 1 with JobRepository

use of org.jberet.repository.JobRepository in project wildfly by wildfly.

the class BatchDeploymentDescriptorParser_1_0 method parse.

@Override
public BatchEnvironmentMetaData parse(final XMLExtendedStreamReader reader, final DeploymentUnit deploymentUnit) throws XMLStreamException {
    JobRepository jobRepository = null;
    String jobRepositoryName = null;
    String jobExecutorName = null;
    Boolean restartJobsOnResume = null;
    boolean empty = true;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final String localName = reader.getLocalName();
        final Element element = Element.forName(localName);
        // Process the job repository
        if (element == Element.JOB_REPOSITORY) {
            // Only one repository can be defined
            if (jobRepository != null || jobRepositoryName != null) {
                BatchLogger.LOGGER.multipleJobRepositoriesFound();
            } else {
                if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                    final String name = reader.getLocalName();
                    final Element jobRepositoryElement = Element.forName(name);
                    if (jobRepositoryElement == Element.IN_MEMORY) {
                        ParseUtils.requireNoContent(reader);
                        jobRepository = new InMemoryRepository();
                    } else if (jobRepositoryElement == Element.NAMED) {
                        jobRepositoryName = readRequiredAttribute(reader, Attribute.NAME);
                        ParseUtils.requireNoContent(reader);
                    } else {
                        throw ParseUtils.unexpectedElement(reader);
                    }
                }
                // Log an error indicating the job-repository is empty, but continue as normal
                if (jobRepository == null && jobRepositoryName == null) {
                    BatchLogger.LOGGER.emptyJobRepositoryElement(deploymentUnit.getName());
                }
            }
            ParseUtils.requireNoContent(reader);
        } else if (element == Element.THREAD_POOL) {
            // Only thread-pool's defined on the subsystem are allowed to be referenced
            jobExecutorName = readRequiredAttribute(reader, Attribute.NAME);
            ParseUtils.requireNoContent(reader);
        } else if (element == Element.RESTART_JOBS_ON_RESUME) {
            restartJobsOnResume = Boolean.valueOf(readRequiredAttribute(reader, Attribute.VALUE));
            ParseUtils.requireNoContent(reader);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        empty = false;
    }
    if (empty) {
        // An empty tag was found. A null value will result in the subsystem default being used.
        BatchLogger.LOGGER.debugf("An empty batch element in the deployment descriptor was found for %s.", deploymentUnit.getName());
        return null;
    }
    return new BatchEnvironmentMetaData(jobRepository, jobRepositoryName, jobExecutorName, restartJobsOnResume);
}
Also used : InMemoryRepository(org.jberet.repository.InMemoryRepository) Element(org.wildfly.extension.batch.jberet.Element) JobRepository(org.jberet.repository.JobRepository)

Example 2 with JobRepository

use of org.jberet.repository.JobRepository 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)

Example 3 with JobRepository

use of org.jberet.repository.JobRepository in project wildfly by wildfly.

the class BatchEnvironmentService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    BatchLogger.LOGGER.debugf("Creating batch environment; %s", classLoader);
    final BatchConfiguration batchConfiguration = batchConfigurationInjector.getValue();
    // Find the job executor to use
    JobExecutor jobExecutor = jobExecutorInjector.getOptionalValue();
    if (jobExecutor == null) {
        jobExecutor = batchConfiguration.getDefaultJobExecutor();
    }
    // Find the job repository to use
    JobRepository jobRepository = jobRepositoryInjector.getOptionalValue();
    if (jobRepository == null) {
        jobRepository = batchConfiguration.getDefaultJobRepository();
    }
    this.batchEnvironment = new WildFlyBatchEnvironment(beanManagerInjector.getOptionalValue(), jobExecutor, transactionManagerInjector.getValue(), jobRepository, jobXmlResolver);
    final RequestController requestController = requestControllerInjector.getOptionalValue();
    if (requestController != null) {
        // Create the entry point
        controlPoint = requestController.getControlPoint(deploymentName, "batch-executor-service");
    } else {
        controlPoint = null;
    }
}
Also used : BatchConfiguration(org.wildfly.extension.batch.jberet.BatchConfiguration) JobExecutor(org.jberet.spi.JobExecutor) RequestController(org.wildfly.extension.requestcontroller.RequestController) JobRepository(org.jberet.repository.JobRepository)

Aggregations

JobRepository (org.jberet.repository.JobRepository)3 InMemoryRepository (org.jberet.repository.InMemoryRepository)1 JobExecutor (org.jberet.spi.JobExecutor)1 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 SuspendController (org.jboss.as.server.suspend.SuspendController)1 Module (org.jboss.modules.Module)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 BatchConfiguration (org.wildfly.extension.batch.jberet.BatchConfiguration)1 Element (org.wildfly.extension.batch.jberet.Element)1 RequestController (org.wildfly.extension.requestcontroller.RequestController)1