Fix parameters parsing in JobOperator and MetaDataInstanceFactory
Before this commit, the parsing of job parameters in JobOperator#start and MetaDataInstanceFactory#createJobExecution was accepting the comma separated key=value pairs format, which is incompatible with the new job parameters format introduced in v5. This commit updates the contract as well as the implementation of those APIs to be compatible with v5. Resolves #4253 Resolves #4301
This commit is contained in:
@@ -91,7 +91,8 @@ public interface JobOperator {
|
||||
Set<Long> getRunningExecutions(String jobName) throws NoSuchJobException;
|
||||
|
||||
/**
|
||||
* Get the {@link JobParameters} as an easily readable String.
|
||||
* Get the {@link JobParameters} as a human readable String (new line separated
|
||||
* key=value pairs).
|
||||
* @param executionId the id of an existing {@link JobExecution}
|
||||
* @return the job parameters that were used to launch the associated instance
|
||||
* @throws NoSuchJobExecutionException if the id was not associated with any
|
||||
@@ -102,8 +103,8 @@ public interface JobOperator {
|
||||
/**
|
||||
* Start a new instance of a job with the parameters specified.
|
||||
* @param jobName the name of the {@link Job} to launch
|
||||
* @param parameters the parameters to launch it with (comma or newline separated
|
||||
* name=value pairs)
|
||||
* @param parameters the parameters to launch it with (new line separated key=value
|
||||
* pairs)
|
||||
* @return the id of the {@link JobExecution} that is launched
|
||||
* @throws NoSuchJobException if there is no {@link Job} with the specified name
|
||||
* @throws JobInstanceAlreadyExistsException if a job instance with this name and
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,9 +60,9 @@ import org.springframework.batch.core.step.StepLocator;
|
||||
import org.springframework.batch.core.step.tasklet.StoppableTasklet;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -222,11 +222,7 @@ public class SimpleJobOperator implements JobOperator, InitializingBean {
|
||||
|
||||
Properties properties = this.jobParametersConverter.getProperties(jobExecution.getJobParameters());
|
||||
|
||||
List<String> keyValuePairs = new ArrayList<>();
|
||||
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
|
||||
keyValuePairs.add(entry.getKey() + "=" + entry.getValue());
|
||||
}
|
||||
return String.join(" ", keyValuePairs);
|
||||
return PropertiesConverter.propertiesToString(properties);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -319,14 +315,7 @@ public class SimpleJobOperator implements JobOperator, InitializingBean {
|
||||
logger.info("Checking status of job with name=" + jobName);
|
||||
}
|
||||
|
||||
Properties properties = new Properties();
|
||||
if (!parameters.isEmpty()) {
|
||||
String[] keyValuePairs = parameters.split(" ");
|
||||
for (String string : keyValuePairs) {
|
||||
String[] keyValuePair = string.split("=");
|
||||
properties.setProperty(keyValuePair[0], keyValuePair[1]);
|
||||
}
|
||||
}
|
||||
Properties properties = PropertiesConverter.stringToProperties(parameters);
|
||||
JobParameters jobParameters = jobParametersConverter.getJobParameters(properties);
|
||||
|
||||
if (jobRepository.isJobInstanceExists(jobName, jobParameters)) {
|
||||
|
||||
Reference in New Issue
Block a user