Skip to content

Commit

Permalink
[WFLY-5055] Remove the JobXmlResolverService as it's needed during de…
Browse files Browse the repository at this point in the history
…ployment processing. Using a services started in a DUP and consumed in a DUP is bad practice.
  • Loading branch information
jamezp committed Aug 5, 2015
1 parent 1690159 commit bf35b53
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 322 deletions.
Expand Up @@ -32,17 +32,6 @@ public static ServiceName batchEnvironmentServiceName(final DeploymentUnit deplo
return deploymentUnit.getServiceName().append("batch").append("environment"); return deploymentUnit.getServiceName().append("batch").append("environment");
} }


/**
* Creates a service name for the deployment unit to define the service.
*
* @param deploymentUnit the deployment unit to create the service name for
*
* @return the service name
*/
public static ServiceName jobXmlResolverServiceName(final DeploymentUnit deploymentUnit) {
return deploymentUnit.getServiceName().append("batch").append("job-xml");
}

/** /**
* Creates the service name used for the bean manager on the deployment. * Creates the service name used for the bean manager on the deployment.
* *
Expand Down
Expand Up @@ -60,11 +60,11 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
final JobOperatorService jobOperatorService = new JobOperatorService(moduleClassLoader); final JobOperatorService jobOperatorService = new JobOperatorService(moduleClassLoader);


// Get all the job XML service // Get all the job XML service
final JobXmlResolverService jobXmlResolverService = (JobXmlResolverService) phaseContext.getServiceRegistry().getService(BatchServiceNames.jobXmlResolverServiceName(deploymentUnit)).getValue(); final WildFlyJobXmlResolver jobXmlResolver = deploymentUnit.getAttachment(WildFlyJobXmlResolver.JOB_XML_RESOLVER);
// Process each job XML file // Process each job XML file
for (String jobXml : jobXmlResolverService.getJobXmlNames(moduleClassLoader)) { for (String jobXml : jobXmlResolver.getJobXmlNames(moduleClassLoader)) {
try { try {
final String jobName = jobXmlResolverService.resolveJobName(jobXml, moduleClassLoader); final String jobName = jobXmlResolver.resolveJobName(jobXml, moduleClassLoader);
// Add the job information to the service // Add the job information to the service
jobOperatorService.addAllowedJob(jobXml, jobName); jobOperatorService.addAllowedJob(jobXml, jobName);
BatchLogger.LOGGER.debugf("Added job XML %s with job name %s to allowed jobs for deployment %s", jobXml, jobName, deploymentUnit.getName()); BatchLogger.LOGGER.debugf("Added job XML %s with job name %s to allowed jobs for deployment %s", jobXml, jobName, deploymentUnit.getName());
Expand Down
Expand Up @@ -22,19 +22,14 @@


package org.wildfly.extension.batch.jberet.deployment; package org.wildfly.extension.batch.jberet.deployment;


import java.util.concurrent.ExecutorService;
import javax.enterprise.inject.spi.BeanManager; import javax.enterprise.inject.spi.BeanManager;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import java.io.IOException;
import java.util.concurrent.ExecutorService;


import org.jberet.repository.JobRepository; import org.jberet.repository.JobRepository;
import org.jberet.spi.BatchEnvironment; import org.jberet.spi.BatchEnvironment;
import org.jberet.spi.JobXmlResolver;
import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.ee.weld.WeldDeploymentMarker; import org.jboss.as.ee.weld.WeldDeploymentMarker;
import org.jboss.as.server.Services;
import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnit;
Expand All @@ -46,8 +41,6 @@
import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.value.ImmediateValue; import org.jboss.msc.value.ImmediateValue;
import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.VirtualFileFilter;
import org.wildfly.extension.batch.jberet.BatchServiceNames; import org.wildfly.extension.batch.jberet.BatchServiceNames;
import org.wildfly.extension.batch.jberet._private.BatchLogger; import org.wildfly.extension.batch.jberet._private.BatchLogger;
import org.wildfly.extension.batch.jberet._private.Capabilities; import org.wildfly.extension.batch.jberet._private.Capabilities;
Expand Down Expand Up @@ -96,7 +89,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);


// Create the batch environment // Create the batch environment
final BatchEnvironmentService service = new BatchEnvironmentService(moduleClassLoader, deploymentUnit.getName()); final BatchEnvironmentService service = new BatchEnvironmentService(moduleClassLoader, WildFlyJobXmlResolver.of(moduleClassLoader, deploymentUnit), deploymentUnit.getName());
final ServiceBuilder<BatchEnvironment> serviceBuilder = serviceTarget.addService(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), service); final ServiceBuilder<BatchEnvironment> serviceBuilder = serviceTarget.addService(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), service);


// Add a dependency to the thread-pool // Add a dependency to the thread-pool
Expand All @@ -117,34 +110,6 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
serviceBuilder.addDependency(BatchServiceNames.beanManagerServiceName(deploymentUnit), BeanManager.class, service.getBeanManagerInjector()); serviceBuilder.addDependency(BatchServiceNames.beanManagerServiceName(deploymentUnit), BeanManager.class, service.getBeanManagerInjector());
} }


// Get the root file
final VirtualFile root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
VirtualFile jobsDir;
// Only files in the META-INF/batch-jobs directory
if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
jobsDir = root.getChild("WEB-INF/classes/META-INF/batch-jobs");
} else {
jobsDir = root.getChild("META-INF/batch-jobs");
}
final JobXmlResolverService jobXmlResolverService;
if (jobsDir != null && jobsDir.exists()) {
try {
// Create the job XML resolver service with the files allowed to be used
jobXmlResolverService = new JobXmlResolverService(moduleClassLoader, jobsDir.getChildren(JobXmlFilter.INSTANCE));
} catch (IOException e) {
throw BatchLogger.LOGGER.errorProcessingBatchJobsDir(e);
}
} else {
// This is likely not a batch deployment, creates a no-op service
jobXmlResolverService = new JobXmlResolverService();
}
// Install the job XML resolver service
final ServiceBuilder<JobXmlResolver> jobXmlServiceBuilder = Services.addServerExecutorDependency(
serviceTarget.addService(BatchServiceNames.jobXmlResolverServiceName(deploymentUnit), jobXmlResolverService),
jobXmlResolverService.getExecutorServiceInjector(), false);
// Add a dependency to the job XML resolver service
serviceBuilder.addDependency(BatchServiceNames.jobXmlResolverServiceName(deploymentUnit), JobXmlResolver.class, service.getJobXmlResolverInjector());

// No deployment defined repository, use the default // No deployment defined repository, use the default
if (jobRepository == null) { if (jobRepository == null) {
final ServiceName defaultJobRepository = support.getCapabilityServiceName(Capabilities.DEFAULT_JOB_REPOSITORY_CAPABILITY.getName()); final ServiceName defaultJobRepository = support.getCapabilityServiceName(Capabilities.DEFAULT_JOB_REPOSITORY_CAPABILITY.getName());
Expand All @@ -157,22 +122,11 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
serviceBuilder.addDependency(RequestController.SERVICE_NAME, RequestController.class, service.getRequestControllerInjector()); serviceBuilder.addDependency(RequestController.SERVICE_NAME, RequestController.class, service.getRequestControllerInjector());
} }


jobXmlServiceBuilder.install();
serviceBuilder.install(); serviceBuilder.install();
} }
} }


@Override @Override
public void undeploy(DeploymentUnit context) { public void undeploy(DeploymentUnit context) {
} }

private static class JobXmlFilter implements VirtualFileFilter {

static final JobXmlFilter INSTANCE = new JobXmlFilter();

@Override
public boolean accepts(final VirtualFile file) {
return file.isFile() && file.getName().endsWith(".xml");
}
}
} }

This file was deleted.

0 comments on commit bf35b53

Please sign in to comment.