Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 871b162

Browse files
cppwfstzolov
authored andcommitted
Task Status uses Job Exit Status for CTR launches
- TaskExecution view and lists now will check if entry is CTR, if so use, use the new logic. - Add taskExecutionStatus to TaskExecutionResource. Adjust DataFlowIT task tests Resolves #4457
1 parent c573509 commit 871b162

File tree

11 files changed

+244
-65
lines changed

11 files changed

+244
-65
lines changed

spring-cloud-dataflow-rest-resource/src/main/java/org/springframework/cloud/dataflow/rest/job/TaskJobExecutionRel.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,19 @@ public class TaskJobExecutionRel {
3838

3939
private final TaskManifest taskManifest;
4040

41-
/**
42-
* Constructor that establishes the relationship between a {@link TaskExecution} and
43-
* the Job Execution Ids of the jobs that were executed within it.
44-
*
45-
* @param taskExecution to be associated with the job execution ids.
46-
* @param jobExecutionIds to be associated with the task execution.
47-
*/
48-
public TaskJobExecutionRel(TaskExecution taskExecution, List<Long> jobExecutionIds) {
49-
this(taskExecution, jobExecutionIds, null);
50-
}
41+
private final TaskJobExecution composedTaskJobExecution;
5142

5243
/**
5344
* Constructor that establishes the relationship between a {@link TaskExecution} and
5445
* the Job Execution Ids of the jobs that were executed within it.
5546
*
5647
* @param taskExecution to be associated with the job execution ids.
5748
* @param jobExecutionIds to be associated with the task execution.
58-
* @param taskManifest to be associated with the task execution
49+
* @param taskManifest to be associated with the task execution.
50+
* @param composedTaskJobExecution to be associated with the task execution.
5951
*/
60-
public TaskJobExecutionRel(TaskExecution taskExecution, List<Long> jobExecutionIds, TaskManifest taskManifest) {
61-
Assert.notNull(taskExecution, "taskExecution must not be null");;
52+
public TaskJobExecutionRel(TaskExecution taskExecution, List<Long> jobExecutionIds, TaskManifest taskManifest, TaskJobExecution composedTaskJobExecution) {
53+
Assert.notNull(taskExecution, "taskExecution must not be null");
6254
this.taskExecution = taskExecution;
6355
this.taskManifest = taskManifest;
6456
if (jobExecutionIds == null) {
@@ -67,8 +59,10 @@ public TaskJobExecutionRel(TaskExecution taskExecution, List<Long> jobExecutionI
6759
else {
6860
this.jobExecutionIds = Collections.unmodifiableList(new ArrayList<>(jobExecutionIds));
6961
}
62+
this.composedTaskJobExecution = composedTaskJobExecution;
7063
}
7164

65+
7266
/**
7367
* @return the taskExecution for this relationship.
7468
*/
@@ -90,4 +84,8 @@ public List<Long> getJobExecutionIds() {
9084
public TaskManifest getTaskManifest() {
9185
return taskManifest;
9286
}
87+
88+
public TaskJobExecution getComposedTaskJobExecution() {
89+
return composedTaskJobExecution;
90+
}
9391
}

spring-cloud-dataflow-rest-resource/src/main/java/org/springframework/cloud/dataflow/rest/resource/TaskExecutionResource.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,11 +24,13 @@
2424

2525
import org.springframework.batch.core.JobExecution;
2626
import org.springframework.cloud.dataflow.core.TaskManifest;
27+
import org.springframework.cloud.dataflow.rest.job.TaskJobExecution;
2728
import org.springframework.cloud.dataflow.rest.job.TaskJobExecutionRel;
2829
import org.springframework.cloud.task.repository.TaskExecution;
2930
import org.springframework.hateoas.PagedModel;
3031
import org.springframework.hateoas.RepresentationModel;
3132
import org.springframework.util.Assert;
33+
import org.springframework.util.StringUtils;
3234

3335
/**
3436
* A HATEOAS representation of a TaskExecution.
@@ -113,6 +115,10 @@ public class TaskExecutionResource extends RepresentationModel<TaskExecutionReso
113115
*/
114116
private String platformName;
115117

118+
private String taskExecutionStatus;
119+
120+
private String composedTaskJobExecutionStatus;
121+
116122
public TaskExecutionResource() {
117123
arguments = new ArrayList<>();
118124
}
@@ -151,6 +157,9 @@ public TaskExecutionResource(TaskJobExecutionRel taskJobExecutionRel) {
151157
if(taskJobExecutionRel.getTaskManifest() != null) {
152158
this.platformName = taskJobExecutionRel.getTaskManifest().getPlatformName();
153159
}
160+
this.composedTaskJobExecutionStatus = (taskJobExecutionRel.getComposedTaskJobExecution() != null) ?
161+
taskJobExecutionRel.getComposedTaskJobExecution().getJobExecution().getExitStatus().getExitCode() :
162+
null;
154163
}
155164

156165
/**
@@ -159,7 +168,7 @@ public TaskExecutionResource(TaskJobExecutionRel taskJobExecutionRel) {
159168
*
160169
* @param taskExecution contains the {@link TaskExecution}
161170
*/
162-
public TaskExecutionResource(TaskExecution taskExecution) {
171+
public TaskExecutionResource(TaskExecution taskExecution, TaskJobExecution composedTaskJobExecution) {
163172
Assert.notNull(taskExecution, "taskExecution must not be null");
164173
this.executionId = taskExecution.getExecutionId();
165174
this.exitCode = taskExecution.getExitCode();
@@ -170,6 +179,9 @@ public TaskExecutionResource(TaskExecution taskExecution) {
170179
this.endTime = taskExecution.getEndTime();
171180
this.errorMessage = taskExecution.getErrorMessage();
172181
this.externalExecutionId = taskExecution.getExternalExecutionId();
182+
this.composedTaskJobExecutionStatus = (composedTaskJobExecution != null) ?
183+
composedTaskJobExecution.getJobExecution().getExitStatus().getExitCode() :
184+
null;
173185
}
174186

175187
/**
@@ -179,7 +191,7 @@ public TaskExecutionResource(TaskExecution taskExecution) {
179191
* @param taskExecution contains the {@link TaskExecution}
180192
* @param taskManifest contains the (@link TaskManifest}
181193
*/
182-
public TaskExecutionResource(TaskExecution taskExecution, TaskManifest taskManifest) {
194+
public TaskExecutionResource(TaskExecution taskExecution, TaskManifest taskManifest, TaskJobExecution composedTaskJobExecution) {
183195
Assert.notNull(taskExecution, "taskExecution must not be null");
184196
Assert.notNull(taskManifest, "taskManifest must not be null");
185197
this.executionId = taskExecution.getExecutionId();
@@ -194,6 +206,9 @@ public TaskExecutionResource(TaskExecution taskExecution, TaskManifest taskManif
194206
this.resourceUrl = taskManifest.getTaskDeploymentRequest().getResource().toString();
195207
this.appProperties = taskManifest.getTaskDeploymentRequest().getDefinition().getProperties();
196208
this.deploymentProperties = taskManifest.getTaskDeploymentRequest().getDeploymentProperties();
209+
this.composedTaskJobExecutionStatus = (composedTaskJobExecution != null) ?
210+
composedTaskJobExecution.getJobExecution().getExitStatus().getExitCode() :
211+
null;
197212
}
198213

199214
public long getExecutionId() {
@@ -264,6 +279,10 @@ public void setPlatformName(String platformName) {
264279
this.platformName = platformName;
265280
}
266281

282+
public void setTaskExecutionStatus(String taskExecutionStatus) {
283+
this.taskExecutionStatus = taskExecutionStatus;
284+
}
285+
267286
/**
268287
* Returns the calculated status of this {@link TaskExecution}.
269288
*
@@ -279,13 +298,23 @@ public void setPlatformName(String platformName) {
279298
* @return TaskExecutionStatus, never null
280299
*/
281300
public TaskExecutionStatus getTaskExecutionStatus() {
301+
if (StringUtils.hasText(this.taskExecutionStatus)) {
302+
return TaskExecutionStatus.valueOf(this.taskExecutionStatus);
303+
}
282304
if (this.startTime == null) {
283305
return TaskExecutionStatus.UNKNOWN;
284306
}
285307
if (this.endTime == null) {
286308
return TaskExecutionStatus.RUNNING;
287309
}
288310
else {
311+
if (this.composedTaskJobExecutionStatus != null) {
312+
return (this.composedTaskJobExecutionStatus.equals("ABANDONED") ||
313+
this.composedTaskJobExecutionStatus.equals("FAILED") ||
314+
this.composedTaskJobExecutionStatus.equals("STOPPED")) ?
315+
TaskExecutionStatus.ERROR : TaskExecutionStatus.COMPLETE;
316+
}
317+
289318
return (this.exitCode == null) ? TaskExecutionStatus.RUNNING :
290319
((this.exitCode == 0) ? TaskExecutionStatus.COMPLETE : TaskExecutionStatus.ERROR);
291320
}

spring-cloud-dataflow-rest-resource/src/test/java/org/springframework/cloud/dataflow/rest/resource/TaskExecutionResourceTests.java

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2018-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,10 @@
2222

2323
import org.junit.Test;
2424

25+
import org.springframework.batch.core.ExitStatus;
26+
import org.springframework.batch.core.JobExecution;
2527
import org.springframework.cloud.dataflow.core.TaskManifest;
28+
import org.springframework.cloud.dataflow.rest.job.TaskJobExecution;
2629
import org.springframework.cloud.dataflow.rest.job.TaskJobExecutionRel;
2730
import org.springframework.cloud.deployer.spi.core.AppDefinition;
2831
import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest;
@@ -50,27 +53,47 @@ public void testTaskExecutionStatusWithNoTaskExecutionSet() {
5053
@Test
5154
public void testTaskExecutionStatusWithNoStartTime() {
5255
final TaskExecution taskExecution = new TaskExecution();
53-
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution);
56+
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution, null);
5457
assertEquals(TaskExecutionStatus.UNKNOWN, taskExecutionResource.getTaskExecutionStatus());
5558
}
5659

5760
@Test
5861
public void testTaskExecutionStatusWithRunningTaskExecution() {
5962
final TaskExecution taskExecution = new TaskExecution();
6063
taskExecution.setStartTime(new Date());
61-
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution);
64+
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution, null);
6265
assertEquals(TaskExecutionStatus.RUNNING, taskExecutionResource.getTaskExecutionStatus());
6366
assertNull(taskExecutionResource.getExitCode());
6467
}
6568

6669
@Test
6770
public void testTaskExecutionStatusWithSuccessfulTaskExecution() {
71+
final TaskExecution taskExecution = getDefaultTaskExecution();
72+
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution, null);
73+
assertEquals(TaskExecutionStatus.COMPLETE, taskExecutionResource.getTaskExecutionStatus());
74+
}
75+
76+
@Test
77+
public void testCTRExecutionStatusWithSuccessfulJobExecution() {
78+
final TaskExecution taskExecution = getDefaultTaskExecution();
79+
JobExecution jobExecution = new JobExecution(1L);
80+
jobExecution.setExitStatus(ExitStatus.COMPLETED);
81+
TaskJobExecution taskJobExecution = new TaskJobExecution(taskExecution.getExecutionId(), jobExecution, true);
82+
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution, taskJobExecution);
83+
assertEquals(TaskExecutionStatus.COMPLETE, taskExecutionResource.getTaskExecutionStatus());
84+
}
85+
86+
@Test
87+
public void testCTRExecutionStatusWithFailedJobExecution() {
6888
final TaskExecution taskExecution = new TaskExecution();
6989
taskExecution.setStartTime(new Date());
7090
taskExecution.setEndTime(new Date());
7191
taskExecution.setExitCode(0);
72-
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution);
73-
assertEquals(TaskExecutionStatus.COMPLETE, taskExecutionResource.getTaskExecutionStatus());
92+
JobExecution jobExecution = new JobExecution(1L);
93+
jobExecution.setExitStatus(ExitStatus.FAILED);
94+
TaskJobExecution taskJobExecution = new TaskJobExecution(taskExecution.getExecutionId(), jobExecution, true);
95+
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution, taskJobExecution);
96+
assertEquals(TaskExecutionStatus.ERROR, taskExecutionResource.getTaskExecutionStatus());
7497
}
7598

7699
@Test
@@ -79,28 +102,46 @@ public void testTaskExecutionStatusWithFailedTaskExecution() {
79102
taskExecution.setStartTime(new Date());
80103
taskExecution.setEndTime(new Date());
81104
taskExecution.setExitCode(123);
82-
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution);
105+
final TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskExecution, null);
83106
assertEquals(TaskExecutionStatus.ERROR, taskExecutionResource.getTaskExecutionStatus());
84107
}
85108

86109
@Test
87110
public void testTaskExecutionForTaskExecutionRel() throws Exception{
88-
final TaskExecution taskExecution = new TaskExecution();
89-
taskExecution.setStartTime(new Date());
90-
taskExecution.setEndTime(new Date());
91-
taskExecution.setExitCode(0);
111+
final TaskExecution taskExecution = getDefaultTaskExecution();
92112
TaskManifest taskManifest = new TaskManifest();
93113
taskManifest.setPlatformName("testplatform");
94114
taskManifest.setTaskDeploymentRequest(new AppDeploymentRequest(new AppDefinition("testapp", Collections.emptyMap()), new UrlResource("http://foo")));
95-
TaskJobExecutionRel taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>(), taskManifest);
115+
TaskJobExecutionRel taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>(), taskManifest, null);
96116
TaskExecutionResource taskExecutionResource = new TaskExecutionResource(taskJobExecutionRel);
97117
assertEquals("testplatform", taskExecutionResource.getPlatformName());
98118
assertEquals(TaskExecutionStatus.COMPLETE, taskExecutionResource.getTaskExecutionStatus());
99-
taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>());
119+
taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>(), null, null);
120+
taskExecutionResource = new TaskExecutionResource(taskJobExecutionRel);
121+
assertNull(taskExecutionResource.getPlatformName());
122+
assertEquals(TaskExecutionStatus.COMPLETE, taskExecutionResource.getTaskExecutionStatus());
123+
JobExecution jobExecution = new JobExecution(1L, null, "foo");
124+
jobExecution.setExitStatus(ExitStatus.FAILED);
125+
126+
TaskJobExecution ctrTaskJobExecution = new TaskJobExecution(1, jobExecution, true);
127+
taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>(), null, ctrTaskJobExecution);
128+
taskExecutionResource = new TaskExecutionResource(taskJobExecutionRel);
129+
assertNull(taskExecutionResource.getPlatformName());
130+
assertEquals(TaskExecutionStatus.ERROR, taskExecutionResource.getTaskExecutionStatus());
131+
jobExecution.setExitStatus(ExitStatus.COMPLETED);
132+
ctrTaskJobExecution = new TaskJobExecution(1, jobExecution, true);
133+
taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>(), null, ctrTaskJobExecution);
100134
taskExecutionResource = new TaskExecutionResource(taskJobExecutionRel);
101135
assertNull(taskExecutionResource.getPlatformName());
102136
assertEquals(TaskExecutionStatus.COMPLETE, taskExecutionResource.getTaskExecutionStatus());
103137
}
104138

139+
private TaskExecution getDefaultTaskExecution() {
140+
final TaskExecution taskExecution = new TaskExecution();
141+
taskExecution.setStartTime(new Date());
142+
taskExecution.setEndTime(new Date());
143+
taskExecution.setExitCode(0);
144+
return taskExecution;
145+
}
105146

106147
}

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/DataFlowControllerAutoConfiguration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -263,10 +263,10 @@ public static class TaskEnabledConfiguration {
263263
public TaskExecutionController taskExecutionController(TaskExplorer explorer,
264264
TaskExecutionService taskExecutionService,
265265
TaskDefinitionRepository taskDefinitionRepository, TaskExecutionInfoService taskExecutionInfoService,
266-
TaskDeleteService taskDeleteService) {
266+
TaskDeleteService taskDeleteService, TaskJobService taskJobService) {
267267
return new TaskExecutionController(explorer, taskExecutionService, taskDefinitionRepository,
268268
taskExecutionInfoService,
269-
taskDeleteService);
269+
taskDeleteService, taskJobService);
270270
}
271271

272272
@Bean
@@ -276,8 +276,9 @@ public TaskPlatformController taskLauncherController(LauncherService launcherSer
276276

277277
@Bean
278278
@ConditionalOnMissingBean
279-
public TaskDefinitionAssemblerProvider taskDefinitionAssemblerProvider(TaskExecutionService taskExecutionService) {
280-
return new DefaultTaskDefinitionAssemblerProvider(taskExecutionService);
279+
public TaskDefinitionAssemblerProvider taskDefinitionAssemblerProvider(
280+
TaskExecutionService taskExecutionService, TaskJobService taskJobService, TaskExplorer taskExplorer) {
281+
return new DefaultTaskDefinitionAssemblerProvider(taskExecutionService, taskJobService, taskExplorer);
281282
}
282283

283284
@Bean

0 commit comments

Comments
 (0)