Skip to content

Commit 6f97589

Browse files
author
Corneil du Plessis
authored
Added query for composed-task-runner status. (#5792)
* Added query for composed-task-runner status. #Fixes 5782 * Added index on task_execution parent_execution_id. Added check for taskExecutionStatus on task execution list. * Fix ctr status query. * Reduce minimum improvement to 2 times.
1 parent 872ee4c commit 6f97589

File tree

29 files changed

+241
-38
lines changed

29 files changed

+241
-38
lines changed

spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/AggregateDataFlowTaskExecutionQueryDao.java

+1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ public AggregateTaskExecution mapRow(ResultSet rs, int rowNum) throws SQLExcepti
581581
rs.getString("EXTERNAL_EXECUTION_ID"),
582582
parentExecutionId,
583583
null,
584+
null,
584585
schemaTarget
585586
);
586587
}

spring-cloud-dataflow-aggregate-task/src/main/java/org/springframework/cloud/dataflow/aggregate/task/impl/DefaultAggregateExecutionSupport.java

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public AggregateTaskExecution from(TaskExecution execution, String schemaTarget,
156156
execution.getExternalExecutionId(),
157157
execution.getParentExecutionId(),
158158
platformName,
159+
null,
159160
schemaTarget);
160161
}
161162
return null;

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public class TaskExecutionThinResource extends RepresentationModel<TaskExecution
7171

7272
private String taskExecutionStatus;
7373

74+
private String composedTaskJobExecutionStatus;
75+
7476
/**
7577
* @since 2.11.0
7678
*/
@@ -94,6 +96,7 @@ public TaskExecutionThinResource(AggregateTaskExecution aggregateTaskExecution)
9496
this.exitCode = aggregateTaskExecution.getExitCode();
9597
this.exitMessage = aggregateTaskExecution.getExitMessage();
9698
this.errorMessage = aggregateTaskExecution.getErrorMessage();
99+
this.composedTaskJobExecutionStatus = aggregateTaskExecution.getCtrTaskStatus();
97100
}
98101

99102
public long getExecutionId() {
@@ -187,6 +190,14 @@ public void setTaskExecutionStatus(String taskExecutionStatus) {
187190
this.taskExecutionStatus = taskExecutionStatus;
188191
}
189192

193+
public String getComposedTaskJobExecutionStatus() {
194+
return composedTaskJobExecutionStatus;
195+
}
196+
197+
public void setComposedTaskJobExecutionStatus(String composedTaskJobExecutionStatus) {
198+
this.composedTaskJobExecutionStatus = composedTaskJobExecutionStatus;
199+
}
200+
190201
/**
191202
* Returns the calculated status of this {@link TaskExecution}.
192203
*
@@ -211,7 +222,12 @@ public TaskExecutionStatus getTaskExecutionStatus() {
211222
if (this.endTime == null) {
212223
return TaskExecutionStatus.RUNNING;
213224
}
214-
225+
if (this.composedTaskJobExecutionStatus != null) {
226+
return (this.composedTaskJobExecutionStatus.equals("ABANDONED") ||
227+
this.composedTaskJobExecutionStatus.equals("FAILED") ||
228+
this.composedTaskJobExecutionStatus.equals("STOPPED")) ?
229+
TaskExecutionStatus.ERROR : TaskExecutionStatus.COMPLETE;
230+
}
215231
return (this.exitCode == null) ? TaskExecutionStatus.RUNNING :
216232
((this.exitCode == 0) ? TaskExecutionStatus.COMPLETE : TaskExecutionStatus.ERROR);
217233
}

spring-cloud-dataflow-schema-core/src/main/java/org/springframework/cloud/dataflow/schema/AggregateTaskExecution.java

+29-16
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public class AggregateTaskExecution {
8181
private String schemaTarget;
8282

8383
private String platformName;
84+
85+
private String ctrTaskStatus;
8486
/**
8587
* The arguments that were used for this task execution.
8688
*/
@@ -92,7 +94,8 @@ public AggregateTaskExecution() {
9294

9395
public AggregateTaskExecution(long executionId, Integer exitCode, String taskName,
9496
Date startTime, Date endTime, String exitMessage, List<String> arguments,
95-
String errorMessage, String externalExecutionId, Long parentExecutionId, String platformName, String schemaTarget) {
97+
String errorMessage, String externalExecutionId, Long parentExecutionId, String platformName,
98+
String ctrTaskStatus, String schemaTarget) {
9699

97100
Assert.notNull(arguments, "arguments must not be null");
98101
this.executionId = executionId;
@@ -107,14 +110,15 @@ public AggregateTaskExecution(long executionId, Integer exitCode, String taskNam
107110
this.parentExecutionId = parentExecutionId;
108111
this.schemaTarget = schemaTarget;
109112
this.platformName = platformName;
113+
this.ctrTaskStatus = ctrTaskStatus;
110114
}
111115

112116
public AggregateTaskExecution(long executionId, Integer exitCode, String taskName,
113117
Date startTime, Date endTime, String exitMessage, List<String> arguments,
114-
String errorMessage, String externalExecutionId, String platformName, String schemaTarget) {
118+
String errorMessage, String externalExecutionId, String platformName, String ctrTaskStatus, String schemaTarget) {
115119

116120
this(executionId, exitCode, taskName, startTime, endTime, exitMessage, arguments,
117-
errorMessage, externalExecutionId, null, platformName, schemaTarget);
121+
errorMessage, externalExecutionId, null, platformName, ctrTaskStatus, schemaTarget);
118122
}
119123

120124
public long getExecutionId() {
@@ -209,22 +213,31 @@ public void setPlatformName(String platformName) {
209213
this.platformName = platformName;
210214
}
211215

216+
public String getCtrTaskStatus() {
217+
return ctrTaskStatus;
218+
}
219+
220+
public void setCtrTaskStatus(String ctrTaskStatus) {
221+
this.ctrTaskStatus = ctrTaskStatus;
222+
}
223+
212224
@Override
213225
public String toString() {
214226
return "AggregateTaskExecution{" +
215-
"executionId=" + executionId +
216-
", parentExecutionId=" + parentExecutionId +
217-
", exitCode=" + exitCode +
218-
", taskName='" + taskName + '\'' +
219-
", startTime=" + startTime +
220-
", endTime=" + endTime +
221-
", exitMessage='" + exitMessage + '\'' +
222-
", externalExecutionId='" + externalExecutionId + '\'' +
223-
", errorMessage='" + errorMessage + '\'' +
224-
", schemaTarget='" + schemaTarget + '\'' +
225-
", platformName='" + platformName + '\'' +
226-
", arguments=" + arguments +
227-
'}';
227+
"executionId=" + executionId +
228+
", parentExecutionId=" + parentExecutionId +
229+
", exitCode=" + exitCode +
230+
", taskName='" + taskName + '\'' +
231+
", startTime=" + startTime +
232+
", endTime=" + endTime +
233+
", exitMessage='" + exitMessage + '\'' +
234+
", externalExecutionId='" + externalExecutionId + '\'' +
235+
", errorMessage='" + errorMessage + '\'' +
236+
", schemaTarget='" + schemaTarget + '\'' +
237+
", platformName='" + platformName + '\'' +
238+
", ctrTaskStatus='" + ctrTaskStatus + '\'' +
239+
", arguments=" + arguments +
240+
'}';
228241
}
229242

230243
public TaskExecution toTaskExecution() {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public TaskExecutionController taskExecutionController(
300300
}
301301

302302
@Bean
303-
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer) {
304-
return new TaskExecutionThinController(aggregateTaskExplorer);
303+
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskJobService taskJobService) {
304+
return new TaskExecutionThinController(aggregateTaskExplorer, taskJobService);
305305
}
306306

307307
@Bean

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.springframework.cloud.dataflow.aggregate.task.AggregateTaskExplorer;
1919
import org.springframework.cloud.dataflow.rest.resource.TaskExecutionThinResource;
2020
import org.springframework.cloud.dataflow.schema.AggregateTaskExecution;
21+
import org.springframework.cloud.dataflow.server.service.TaskJobService;
22+
import org.springframework.data.domain.Page;
2123
import org.springframework.data.domain.Pageable;
2224
import org.springframework.data.web.PagedResourcesAssembler;
2325
import org.springframework.hateoas.PagedModel;
@@ -26,6 +28,8 @@
2628
import org.springframework.http.HttpStatus;
2729
import org.springframework.web.bind.annotation.GetMapping;
2830
import org.springframework.web.bind.annotation.RequestMapping;
31+
import org.springframework.web.bind.annotation.RequestMethod;
32+
import org.springframework.web.bind.annotation.RequestParam;
2933
import org.springframework.web.bind.annotation.ResponseStatus;
3034
import org.springframework.web.bind.annotation.RestController;
3135

@@ -44,15 +48,29 @@ public class TaskExecutionThinController {
4448
private final AggregateTaskExplorer explorer;
4549
private final TaskExecutionThinResourceAssembler resourceAssembler;
4650

47-
public TaskExecutionThinController(AggregateTaskExplorer explorer) {
51+
private final TaskJobService taskJobService;
52+
53+
public TaskExecutionThinController(AggregateTaskExplorer explorer, TaskJobService taskJobService) {
4854
this.explorer = explorer;
55+
this.taskJobService = taskJobService;
4956
this.resourceAssembler = new TaskExecutionThinResourceAssembler();
5057
}
5158

5259
@GetMapping(produces = "application/json")
5360
@ResponseStatus(HttpStatus.OK)
5461
public PagedModel<TaskExecutionThinResource> listTasks(Pageable pageable, PagedResourcesAssembler<AggregateTaskExecution> pagedAssembler) {
55-
return pagedAssembler.toModel(explorer.findAll(pageable, true), resourceAssembler);
62+
Page<AggregateTaskExecution> page = explorer.findAll(pageable, true);
63+
taskJobService.populateComposeTaskRunnerStatus(page.getContent());
64+
return pagedAssembler.toModel(page, resourceAssembler);
65+
}
66+
67+
@RequestMapping(value = "", method = RequestMethod.GET, params = "name")
68+
@ResponseStatus(HttpStatus.OK)
69+
public PagedModel<TaskExecutionThinResource> retrieveTasksByName(@RequestParam("name") String taskName,
70+
Pageable pageable, PagedResourcesAssembler<AggregateTaskExecution> pagedAssembler) {
71+
Page<AggregateTaskExecution> page = this.explorer.findTaskExecutionsByName(taskName, pageable);
72+
taskJobService.populateComposeTaskRunnerStatus(page.getContent());
73+
return pagedAssembler.toModel(page, resourceAssembler);
5674
}
5775

5876
static class TaskExecutionThinResourceAssembler extends RepresentationModelAssemblerSupport<AggregateTaskExecution, TaskExecutionThinResource> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.cloud.dataflow.server.db.migration;
17+
18+
import java.util.Arrays;
19+
import java.util.List;
20+
21+
import org.springframework.cloud.dataflow.common.flyway.AbstractMigration;
22+
import org.springframework.cloud.dataflow.common.flyway.SqlCommand;
23+
24+
/**
25+
* Provide indexes to improve performance of finding child tasks.
26+
* @author Corneil du Plessis
27+
*/
28+
public abstract class AbstractCreateTaskParentIndexMigration extends AbstractMigration {
29+
protected static final String CREATE_TASK_PARENT_INDEX =
30+
"create index TASK_EXECUTION_PARENT_IX on TASK_EXECUTION(PARENT_EXECUTION_ID)";
31+
protected static final String CREATE_BOOT3_TASK_PARENT_INDEX =
32+
"create index BOOT3_TASK_EXECUTION_PARENT_IX on BOOT3_TASK_EXECUTION(PARENT_EXECUTION_ID)";
33+
34+
public AbstractCreateTaskParentIndexMigration() {
35+
super(null);
36+
}
37+
38+
@Override
39+
public List<SqlCommand> getCommands() {
40+
return Arrays.asList(
41+
SqlCommand.from(CREATE_TASK_PARENT_INDEX),
42+
SqlCommand.from(CREATE_BOOT3_TASK_PARENT_INDEX)
43+
);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.cloud.dataflow.server.db.migration.db2;
2+
3+
import org.springframework.cloud.dataflow.server.db.migration.AbstractCreateTaskParentIndexMigration;
4+
5+
public class V11__CreateTaskParentIndex extends AbstractCreateTaskParentIndexMigration {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.cloud.dataflow.server.db.migration.mariadb;
2+
3+
import org.springframework.cloud.dataflow.server.db.migration.AbstractCreateTaskParentIndexMigration;
4+
5+
public class V12__CreateTaskParentIndex extends AbstractCreateTaskParentIndexMigration {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.cloud.dataflow.server.db.migration.mysql;
2+
3+
import org.springframework.cloud.dataflow.server.db.migration.AbstractCreateTaskParentIndexMigration;
4+
5+
public class V12__CreateTaskParentIndex extends AbstractCreateTaskParentIndexMigration {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.cloud.dataflow.server.db.migration.oracle;
2+
3+
import org.springframework.cloud.dataflow.server.db.migration.AbstractCreateTaskParentIndexMigration;
4+
5+
public class V12__CreateTaskParentIndex extends AbstractCreateTaskParentIndexMigration {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.cloud.dataflow.server.db.migration.postgresql;
2+
3+
import org.springframework.cloud.dataflow.server.db.migration.AbstractCreateTaskParentIndexMigration;
4+
5+
public class V13__CreateTaskParentIndex extends AbstractCreateTaskParentIndexMigration {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.cloud.dataflow.server.db.migration.sqlserver;
2+
3+
import org.springframework.cloud.dataflow.server.db.migration.AbstractCreateTaskParentIndexMigration;
4+
5+
public class V11__CreateTaskParentIndex extends AbstractCreateTaskParentIndexMigration {
6+
7+
}

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/repository/AggregateJobQueryDao.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package org.springframework.cloud.dataflow.server.repository;
1717

1818

19+
import java.util.Collection;
1920
import java.util.Date;
20-
import java.util.List;
2121

2222
import org.springframework.batch.core.BatchStatus;
2323
import org.springframework.batch.core.JobInstance;
@@ -26,6 +26,7 @@
2626
import org.springframework.batch.core.launch.NoSuchJobInstanceException;
2727
import org.springframework.cloud.dataflow.rest.job.JobInstanceExecutions;
2828
import org.springframework.cloud.dataflow.rest.job.TaskJobExecution;
29+
import org.springframework.cloud.dataflow.schema.AggregateTaskExecution;
2930
import org.springframework.data.domain.Page;
3031
import org.springframework.data.domain.Pageable;
3132

@@ -60,4 +61,6 @@ public interface AggregateJobQueryDao {
6061

6162
JobInstance getJobInstance(long id, String schemaTarget) throws NoSuchJobInstanceException;
6263

64+
void populateCtrStatus(Collection<AggregateTaskExecution> aggregateTaskExecutions);
65+
6366
}

0 commit comments

Comments
 (0)