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

Commit 4ffd30d

Browse files
author
Corneil du Plessis
authored
Add support for sorting by SchemaTarget (#5617)
This commit adds support for sorting executions by schema target. Fixes #5615
1 parent 02d69bd commit 4ffd30d

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public class AggregateDataFlowTaskExecutionQueryDao implements DataflowTaskExecu
180180
validSortColumns.add("LAST_UPDATED");
181181
validSortColumns.add("EXTERNAL_EXECUTION_ID");
182182
validSortColumns.add("PARENT_EXECUTION_ID");
183+
validSortColumns.add("SCHEMA_TARGET");
183184
}
184185

185186
private final NamedParameterJdbcTemplate jdbcTemplate;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public class TaskExecutionController {
127127

128128
private static final List<String> allowedSorts = Arrays.asList("TASK_EXECUTION_ID", "START_TIME", "END_TIME",
129129
"TASK_NAME", "EXIT_CODE", "EXIT_MESSAGE", "ERROR_MESSAGE", "LAST_UPDATED", "EXTERNAL_EXECUTION_ID",
130-
"PARENT_EXECUTION_ID");
130+
"PARENT_EXECUTION_ID", "SCHEMA_TARGET");
131131

132132
/**
133133
* Creates a {@code TaskExecutionController} that retrieves Task Execution information

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionControllerTests.java

Lines changed: 9 additions & 1 deletion
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-2023 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.
@@ -107,6 +107,7 @@
107107
* @author David Turanski
108108
* @author Gunnar Hillert
109109
* @author Chris Bono
110+
* @author Corneil du Plessis
110111
*/
111112
@SpringBootTest(
112113
classes = { JobDependencies.class, TaskExecutionAutoConfiguration.class, DataflowAsyncAutoConfiguration.class,
@@ -637,6 +638,13 @@ void sorting() throws Exception {
637638
.andDo(print())
638639
.andExpect(status().isOk());
639640

641+
mockMvc.perform(get("/tasks/executions").param("sort", "SCHEMA_TARGET").accept(MediaType.APPLICATION_JSON))
642+
.andDo(print())
643+
.andExpect(status().isOk());
644+
mockMvc.perform(get("/tasks/executions").param("sort", "schema_target").accept(MediaType.APPLICATION_JSON))
645+
.andDo(print())
646+
.andExpect(status().isOk());
647+
640648
mockMvc.perform(get("/tasks/executions").param("sort", "WRONG_FIELD").accept(MediaType.APPLICATION_JSON))
641649
.andDo(print())
642650
.andExpect(status().is5xxServerError())

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/repository/TaskExecutionExplorerTests.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
package org.springframework.cloud.dataflow.server.repository;
1818

19+
import java.net.URI;
1920
import java.util.Date;
2021
import java.util.HashMap;
2122
import java.util.HashSet;
2223
import java.util.List;
2324
import java.util.Map;
2425
import java.util.Set;
26+
import java.util.stream.Collectors;
2527

2628
import javax.sql.DataSource;
2729

@@ -33,21 +35,30 @@
3335
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
3436
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
3537
import org.springframework.boot.test.context.SpringBootTest;
36-
import org.springframework.cloud.dataflow.aggregate.task.TaskDefinitionReader;
37-
import org.springframework.cloud.dataflow.schema.AggregateTaskExecution;
3838
import org.springframework.cloud.dataflow.aggregate.task.AggregateExecutionSupport;
3939
import org.springframework.cloud.dataflow.aggregate.task.AggregateTaskExplorer;
40+
import org.springframework.cloud.dataflow.aggregate.task.TaskDefinitionReader;
41+
import org.springframework.cloud.dataflow.core.AppRegistration;
42+
import org.springframework.cloud.dataflow.core.ApplicationType;
43+
import org.springframework.cloud.dataflow.core.TaskDefinition;
44+
import org.springframework.cloud.dataflow.registry.service.AppRegistryService;
45+
import org.springframework.cloud.dataflow.schema.AggregateTaskExecution;
46+
import org.springframework.cloud.dataflow.schema.AppBootSchemaVersion;
4047
import org.springframework.cloud.dataflow.schema.SchemaVersionTarget;
4148
import org.springframework.cloud.dataflow.schema.service.SchemaService;
4249
import org.springframework.cloud.dataflow.server.configuration.TaskServiceDependencies;
4350
import org.springframework.cloud.dataflow.server.repository.support.SchemaUtilities;
4451
import org.springframework.data.domain.PageRequest;
52+
import org.springframework.data.domain.Sort;
4553
import org.springframework.jdbc.core.JdbcTemplate;
4654
import org.springframework.test.annotation.DirtiesContext;
4755
import org.springframework.test.annotation.DirtiesContext.ClassMode;
4856
import org.springframework.test.context.junit.jupiter.SpringExtension;
4957

5058
import static org.assertj.core.api.Assertions.assertThat;
59+
import static org.mockito.ArgumentMatchers.any;
60+
import static org.mockito.ArgumentMatchers.eq;
61+
import static org.mockito.Mockito.when;
5162

5263
/**
5364
* @author Glenn Renfro
@@ -77,28 +88,38 @@ public class TaskExecutionExplorerTests {
7788
@Autowired
7889
private TaskDefinitionReader taskDefinitionReader;
7990

91+
@Autowired
92+
private AppRegistryService appRegistryService;
93+
94+
@Autowired
95+
private TaskDefinitionRepository definitionRepository;
96+
8097
@BeforeEach
8198
public void setup() throws Exception {
8299
template = new JdbcTemplate(dataSource);
83100
for (SchemaVersionTarget target : schemaService.getTargets().getSchemas()) {
84101
String prefix = target.getTaskPrefix();
85102
template.execute(SchemaUtilities.getQuery("DELETE FROM %PREFIX%EXECUTION", prefix));
86103
}
104+
TaskDefinition taskDefinition = new TaskDefinition("baz", "baz");
105+
definitionRepository.save(taskDefinition);
87106
}
88107

89108
@Test
90109
public void testInitializer() {
91110
for (SchemaVersionTarget target : schemaService.getTargets().getSchemas()) {
92111
String prefix = target.getTaskPrefix();
93-
int actual = template.queryForObject(SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION", prefix), Integer.class);
112+
int actual = template.queryForObject(
113+
SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION", prefix), Integer.class);
94114
assertThat(actual).isEqualTo(0);
95-
actual = template.queryForObject(SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION_PARAMS", prefix), Integer.class);
115+
actual = template.queryForObject(
116+
SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION_PARAMS", prefix), Integer.class);
96117
assertThat(actual).isEqualTo(0);
97118
}
98119
}
99120

100121
@Test
101-
public void testExplorerFindAll(){
122+
public void testExplorerFindAll() {
102123
final int ENTRY_COUNT = 4;
103124
insertTestExecutionDataIntoRepo(template, 3L, "foo");
104125
insertTestExecutionDataIntoRepo(template, 2L, "foo");
@@ -135,6 +156,20 @@ public void testExplorerFindByName() throws Exception {
135156
assertThat(taskExecution.getTaskName()).isEqualTo("fee");
136157
}
137158

159+
@Test
160+
public void testExplorerSort() throws Exception {
161+
when(appRegistryService.find(eq("baz"), any(ApplicationType.class))).thenReturn(new AppRegistration("baz", ApplicationType.task, "1.0.0", new URI("file://src/test/resources/register-all.txt"),null, AppBootSchemaVersion.BOOT3));
162+
insertTestExecutionDataIntoRepo(template, 3L, "foo");
163+
insertTestExecutionDataIntoRepo(template, 2L, "bar");
164+
insertTestExecutionDataIntoRepo(template, 1L, "baz");
165+
insertTestExecutionDataIntoRepo(template, 0L, "fee");
166+
167+
List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET"))).getContent();
168+
assertThat(resultList.size()).isEqualTo(4);
169+
List<Long> ids = resultList.stream().map(AggregateTaskExecution::getExecutionId).collect(Collectors.toList());
170+
assertThat(ids).containsExactly(0L, 2L, 3L, 1L);
171+
}
172+
138173
private void insertTestExecutionDataIntoRepo(JdbcTemplate template, long id, String taskName) {
139174
SchemaVersionTarget schemaVersionTarget = aggregateExecutionSupport.findSchemaVersionTarget(taskName, taskDefinitionReader);
140175
final String INSERT_STATEMENT = SchemaUtilities.getQuery("INSERT INTO %PREFIX%EXECUTION (task_execution_id, "

0 commit comments

Comments
 (0)