Improve JobOperator by reducing its scope to job operations only

Resolves #4833
This commit is contained in:
Mahmoud Ben Hassine
2025-05-07 23:00:18 +02:00
parent fc4a66516a
commit afdd842bc3
2 changed files with 39 additions and 11 deletions

View File

@@ -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<Long> 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<Long> 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<Long> 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<Long, String> getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException;
/**

View File

@@ -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:
*
* <ul>
* <li>{@link JobLauncher}
* <li>{@link JobExplorer}
* <li>{@link JobRepository}
* <li>{@link JobRegistry}
* </ul>
@@ -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<Long> 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<Long> getJobInstances(String jobName, int start, int count) throws NoSuchJobException {
List<Long> list = new ArrayList<>();
List<JobInstance> 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<Long> getRunningExecutions(String jobName) throws NoSuchJobException {
Set<Long> 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<Long, String> 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();