Skip to content

Commit 365b478

Browse files
committed
Add support to allow user to set useJsonJobParameters for job relaunch via the shell.
Note: there are not tests for the shell update in this commit. This is because the current set of tests rely on @EnableDataflowServer which does not work. But before we fix @EnableDataflowServer we need to make sure we want to carry it forward per Issue spring-cloud#1040
1 parent 55bccb1 commit 365b478

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/JobOperations.java

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public interface JobOperations {
4242
*/
4343
void executionRestart(long id);
4444

45+
/**
46+
* Restarts a job by id
47+
*
48+
* @param id job execution id
49+
* @param useJsonJobParameters if true {@link org.springframework.batch.core.JobParameters} will be serialized to JSON.
50+
* Default is {@code Null} which will serialize the {@link org.springframework.batch.core.JobParameters}
51+
* to the default specified in SCDF's configuration.
52+
*/
53+
void executionRestart(long id, Boolean useJsonJobParameters);
54+
4555
/**
4656
* @return the list job executions without step executions known to the system.
4757
*/

spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/JobTemplate.java

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public void executionRestart(long id) {
117117
restTemplate.put(builder.toUriString(), null);
118118
}
119119

120+
@Override
121+
public void executionRestart(long id, Boolean useJsonJobParameters) {
122+
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(executionLink.expand(id).getHref()).queryParam("restart", "true")
123+
.queryParam("useJsonJobParameters", useJsonJobParameters);
124+
125+
restTemplate.put(builder.toUriString(), null);
126+
}
127+
120128
@Override
121129
public PagedModel<JobExecutionThinResource> executionThinList() {
122130
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(thinExecutionsLink.getHref()).queryParam("size", "2000");

spring-cloud-dataflow-shell-core/src/main/java/org/springframework/cloud/dataflow/shell/command/JobCommands.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,17 @@ public Table executionList(
107107
@ShellMethod(key = EXECUTION_RESTART, value = "Restart a failed job by jobExecutionId")
108108
@ShellMethodAvailability("availableWithViewRole")
109109
public String executionRestart(
110-
@ShellOption(help = "the job execution id") long id) {
111-
jobOperations().executionRestart(id);
110+
@ShellOption(help = "the job executiond id") long id,
111+
@ShellOption(value = "--useJsonJobParameters",
112+
help = "boolean value serialize job parameter as Json. " +
113+
"Default is null, meaning SCDF default will be used.",
114+
defaultValue = ShellOption.NULL) String useJsonJobParameters) {
115+
if(useJsonJobParameters == null) {
116+
jobOperations().executionRestart(id);
117+
}
118+
else {
119+
jobOperations().executionRestart(id, Boolean.valueOf(useJsonJobParameters));
120+
}
112121
return String.format("Restart request has been sent for job execution '%s'", id);
113122
}
114123

0 commit comments

Comments
 (0)