From afdd842bc3e6d599e475f597f8becc12cc685fbd Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Wed, 7 May 2025 23:00:18 +0200 Subject: [PATCH] Improve JobOperator by reducing its scope to job operations only Resolves #4833 --- .../batch/core/launch/JobOperator.java | 34 ++++++++++++++++--- .../launch/support/SimpleJobOperator.java | 16 +++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java index ac36f6b42..e31e5b3c7 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java @@ -34,9 +34,7 @@ import org.springframework.batch.core.repository.JobRestartException; import org.springframework.lang.Nullable; /** - * Low level interface for inspecting and controlling jobs with access only to primitive - * and collection types. Suitable for a command-line client (e.g. that launches a new - * process for each operation), or a remote launcher like a JMX console. + * High level interface for operating batch jobs. * * @author Dave Syer * @author Mahmoud Ben Hassine @@ -53,7 +51,11 @@ public interface JobOperator extends JobLauncher { * this instance * @throws NoSuchJobInstanceException if the {@link JobInstance} associated with the * {@code instanceId} cannot be found. + * @deprecated Since 6.0 in favor of + * {@link org.springframework.batch.core.repository.JobRepository#getJobExecutions(JobInstance)}. + * Scheduled for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) List getExecutions(long instanceId) throws NoSuchJobInstanceException; /** @@ -65,7 +67,11 @@ public interface JobOperator extends JobLauncher { * @return the id values of the {@link JobInstance JobInstances} * @throws NoSuchJobException is thrown if no {@link JobInstance}s for the jobName * exist. + * @deprecated Since 6.0 in favor of + * {@link org.springframework.batch.core.repository.JobRepository#getJobInstances(String, int, int)}. + * Scheduled for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) List getJobInstances(String jobName, int start, int count) throws NoSuchJobException; /** @@ -73,9 +79,11 @@ public interface JobOperator extends JobLauncher { * @param jobParameters {@link JobParameters} parameters for the job instance. * @return the {@link JobInstance} with the given name and parameters, or * {@code null}. - * - * @since 5.0 + * @deprecated Since 6.0 in favor of + * {@link org.springframework.batch.core.repository.JobRepository#getJobInstance(String, JobParameters)}. + * Scheduled for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) @Nullable default JobInstance getJobInstance(String jobName, JobParameters jobParameters) { throw new UnsupportedOperationException(); @@ -88,7 +96,11 @@ public interface JobOperator extends JobLauncher { * @return the id values of the running {@link JobExecution} instances * @throws NoSuchJobException if there are no {@link JobExecution JobExecutions} with * that job name + * @deprecated Since 6.0 in favor of + * {@link org.springframework.batch.core.repository.JobRepository#findRunningJobExecutions(String)}. + * Scheduled for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) Set getRunningExecutions(String jobName) throws NoSuchJobException; /** @@ -98,7 +110,11 @@ public interface JobOperator extends JobLauncher { * @return the job parameters that were used to launch the associated instance * @throws NoSuchJobExecutionException if the id was not associated with any * {@link JobExecution} + * @deprecated Since 6.0 in favor of + * {@link org.springframework.batch.core.repository.JobRepository#getJobExecution(Long).getJobParameters()}. + * Scheduled for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) String getParameters(long executionId) throws NoSuchJobExecutionException; /** @@ -186,7 +202,11 @@ public interface JobOperator extends JobLauncher { * @return a String summarising the state of the job execution * @throws NoSuchJobExecutionException if there is no {@link JobExecution} with the * supplied id + * @deprecated Since 6.0 in favor of + * {@link org.springframework.batch.core.repository.JobRepository#getJobExecution(Long).toString()}. + * Scheduled for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) String getSummary(long executionId) throws NoSuchJobExecutionException; /** @@ -196,7 +216,11 @@ public interface JobOperator extends JobLauncher { * @return a map of step execution id to String summarising the state of the execution * @throws NoSuchJobExecutionException if there is no {@link JobExecution} with the * supplied id + * @deprecated Since 6.0 in favor of + * {@link org.springframework.batch.core.repository.JobRepository#getJobExecution(Long).getStepExecutions()}. + * Scheduled for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) Map getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java index bd8a46c7d..80b285db2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java @@ -42,10 +42,8 @@ import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.ListableJobLocator; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverter; -import org.springframework.batch.core.repository.explore.JobExplorer; import org.springframework.batch.core.launch.JobExecutionNotRunningException; import org.springframework.batch.core.launch.JobInstanceAlreadyExistsException; -import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.launch.NoSuchJobException; import org.springframework.batch.core.launch.NoSuchJobExecutionException; @@ -66,12 +64,10 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** - * Simple implementation of the JobOperator interface. Due to the amount of functionality - * the implementation is combining, the following dependencies are required: + * Simple implementation of the {@link JobOperator} interface. the following dependencies + * are required: * *
    - *
  • {@link JobLauncher} - *
  • {@link JobExplorer} *
  • {@link JobRepository} *
  • {@link JobRegistry} *
@@ -112,6 +108,7 @@ public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOpe * Public setter for the {@link JobParametersConverter}. * @param jobParametersConverter the {@link JobParametersConverter} to set */ + @Deprecated(since = "6.0", forRemoval = true) public void setJobParametersConverter(JobParametersConverter jobParametersConverter) { this.jobParametersConverter = jobParametersConverter; } @@ -125,6 +122,7 @@ public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOpe } @Override + @Deprecated(since = "6.0", forRemoval = true) public List getExecutions(long instanceId) throws NoSuchJobInstanceException { JobInstance jobInstance = jobRepository.getJobInstance(instanceId); if (jobInstance == null) { @@ -143,6 +141,7 @@ public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOpe } @Override + @Deprecated(since = "6.0", forRemoval = true) public List getJobInstances(String jobName, int start, int count) throws NoSuchJobException { List list = new ArrayList<>(); List jobInstances = jobRepository.getJobInstances(jobName, start, count); @@ -157,11 +156,13 @@ public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOpe @Override @Nullable + @Deprecated(since = "6.0", forRemoval = true) public JobInstance getJobInstance(String jobName, JobParameters jobParameters) { return this.jobRepository.getJobInstance(jobName, jobParameters); } @Override + @Deprecated(since = "6.0", forRemoval = true) public String getParameters(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); @@ -171,6 +172,7 @@ public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOpe } @Override + @Deprecated(since = "6.0", forRemoval = true) public Set getRunningExecutions(String jobName) throws NoSuchJobException { Set set = new LinkedHashSet<>(); for (JobExecution jobExecution : jobRepository.findRunningJobExecutions(jobName)) { @@ -183,6 +185,7 @@ public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOpe } @Override + @Deprecated(since = "6.0", forRemoval = true) public Map getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); @@ -194,6 +197,7 @@ public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOpe } @Override + @Deprecated(since = "6.0", forRemoval = true) public String getSummary(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); return jobExecution.toString();