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

Commit d7ff312

Browse files
author
Corneil du Plessis
authored
Add task thin executions by name and fix missing docs
This commit is a back port of "Add task thin executions by name and fix missing docs" (#5994). - changes TaskTemplate to use task/thinexecutions instead of task/executions - adds task thin executions by name - updates api-guide.adoc with links to generated documentation - modifies TaskCommands to use thin executions since it provides the data required. Resolves #5995
1 parent 4377909 commit d7ff312

File tree

14 files changed

+226
-19
lines changed

14 files changed

+226
-19
lines changed

spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/ApiDocumentation.java

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void index() throws Exception {
124124
linkWithRel("tasks/platforms").description("Provides platform accounts for launching tasks. The results can be filtered to show the platforms that support scheduling by adding a request parameter of 'schedulesEnabled=true"),
125125
linkWithRel("tasks/logs").description("Retrieve the task application log"),
126126
linkWithRel("tasks/thinexecutions").description("Returns thin Task executions"),
127+
linkWithRel("tasks/thinexecutions/name").description("Returns all thin Task executions for a given Task name"),
127128

128129
linkWithRel("schema/versions").description("List of Spring Boot related schemas"),
129130
linkWithRel("schema/targets").description("List of schema targets"),
@@ -234,6 +235,9 @@ public void index() throws Exception {
234235

235236
fieldWithPath("_links.tasks/thinexecutions.href").description("Link to the tasks/thinexecutions"),
236237

238+
fieldWithPath("_links.tasks/thinexecutions/name.href").description("Link to the tasks/thinexecutions/name"),
239+
fieldWithPath("_links.tasks/thinexecutions/name.templated").type(JsonFieldType.BOOLEAN).optional().description("Link to the tasks/thinexecutions/name is templated"),
240+
237241
fieldWithPath("_links.tasks/schedules.href").description("Link to the tasks/executions/schedules"),
238242
fieldWithPath("_links.tasks/schedules/instances.href").description("Link to the tasks/schedules/instances"),
239243
fieldWithPath("_links.tasks/schedules/instances.templated").type(JsonFieldType.BOOLEAN).optional().description("Link tasks/schedules/instances is templated"),

spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/TaskExecutionsDocumentation.java

+23
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,29 @@ public void listTaskExecutionsByName() throws Exception {
314314
subsectionWithPath("page").description("Pagination properties"))));
315315
}
316316

317+
@Test
318+
public void listTaskThinExecutionsByName() throws Exception {
319+
this.mockMvc.perform(
320+
get("/tasks/thinexecutions")
321+
.param("name", "taskB")
322+
.param("page", "0")
323+
.param("size", "10")
324+
)
325+
.andExpect(status().isOk()).andDo(this.documentationHandler.document(
326+
requestParameters(
327+
parameterWithName("page")
328+
.description("The zero-based page number (optional)"),
329+
parameterWithName("size")
330+
.description("The requested page size (optional)"),
331+
parameterWithName("name")
332+
.description("The name associated with the task execution")),
333+
responseFields(
334+
subsectionWithPath("_embedded.taskExecutionThinResourceList")
335+
.description("Contains a collection of Task Executions/"),
336+
subsectionWithPath("_links.self").description("Link to the task execution resource"),
337+
subsectionWithPath("page").description("Pagination properties"))));
338+
}
339+
317340
@Test
318341
public void stopTask() throws Exception {
319342
this.mockMvc.perform(

spring-cloud-dataflow-docs/src/main/asciidoc/api-guide.adoc

+127
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,8 @@ The following topics provide more details:
18621862
* <<api-guide-resources-task-executions-stopping>>
18631863
* <<api-guide-resources-task-executions-list>>
18641864
* <<api-guide-resources-task-executions-list-by-name>>
1865+
* <<api-guide-resources-task-thin-executions-list>>
1866+
* <<api-guide-resources-task-thin-executions-list-by-name>>
18651867
* <<api-guide-resources-task-executions-detail>>
18661868
* <<api-guide-resources-task-executions-delete>>
18671869
* <<api-guide-resources-task-executions-current-count>>
@@ -2066,7 +2068,132 @@ include::{snippets}/task-executions-documentation/list-task-executions-by-name/c
20662068

20672069
include::{snippets}/task-executions-documentation/list-task-executions-by-name/http-response.adoc[]
20682070

2071+
[[api-guide-resources-task-thin-executions-list]]
2072+
==== List All Task Thin Executions
20692073

2074+
The task executions endpoint lets you list all task executions with only top-level data.
2075+
The following topics provide more details:
2076+
2077+
* <<api-guide-resources-task-thin-executions-list-request-structure>>
2078+
* <<api-guide-resources-task-thin-executions-list-request-parameters>>
2079+
* <<api-guide-resources-task-thin-executions-list-example-request>>
2080+
* <<api-guide-resources-task-thin-executions-list-response-structure>>
2081+
2082+
[[api-guide-resources-task-thin-executions-list-request-structure]]
2083+
===== Request Structure
2084+
2085+
include::{snippets}/task-executions-documentation/list-task-thin-executions/http-request.adoc[]
2086+
2087+
[[api-guide-resources-task-thin-executions-list-request-parameters]]
2088+
===== Request Parameters
2089+
2090+
include::{snippets}/task-executions-documentation/list-task-thin-executions/query-parameters.adoc[]
2091+
2092+
[[api-guide-resources-task-thin-executions-list-example-request]]
2093+
===== Example Request
2094+
2095+
include::{snippets}/task-executions-documentation/list-task-thin-executions/curl-request.adoc[]
2096+
2097+
[[api-guide-resources-task-thin-executions-list-response-structure]]
2098+
===== Response Structure
2099+
2100+
include::{snippets}/task-executions-documentation/list-task-thin-executions/http-response.adoc[]
2101+
2102+
[[api-guide-resources-task-thin-executions-list-by-name]]
2103+
==== List All Task Thin Executions With a Specified Task Name
2104+
2105+
The task thin executions endpoint lets you list task executions with a specified task name.
2106+
The following topics provide more details:
2107+
2108+
* <<api-guide-resources-task-thin-executions-list-by-name-request-structure>>
2109+
* <<api-guide-resources-task-thin-executions-list-by-name-request-parameters>>
2110+
* <<api-guide-resources-task-thin-executions-list-by-name-example-request>>
2111+
* <<api-guide-resources-task-thin-executions-list-by-name-response-structure>>
2112+
2113+
2114+
2115+
[[api-guide-resources-task-thin-executions-list-by-name-request-structure]]
2116+
===== Request Structure
2117+
2118+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/http-request.adoc[]
2119+
2120+
2121+
2122+
[[api-guide-resources-task-thin-executions-list-by-name-request-parameters]]
2123+
===== Request Parameters
2124+
2125+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/query-parameters.adoc[]
2126+
2127+
2128+
2129+
[[api-guide-resources-task-thin-executions-list-by-name-example-request]]
2130+
===== Example Request
2131+
2132+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/curl-request.adoc[]
2133+
2134+
[[api-guide-resources-task-thin-executions-list-by-name-response-structure]]
2135+
===== Response Structure
2136+
2137+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/http-response.adoc[]
2138+
2139+
[[api-guide-resources-task-thin-executions-list-request-structure]]
2140+
===== Request Structure
2141+
2142+
include::{snippets}/task-executions-documentation/list-task-thin-executions/http-request.adoc[]
2143+
2144+
2145+
2146+
[[api-guide-resources-task-thin-executions-list-request-parameters]]
2147+
===== Request Parameters
2148+
2149+
include::{snippets}/task-executions-documentation/list-task-thin-executions/request-parameters.adoc[]
2150+
2151+
2152+
2153+
[[api-guide-resources-task-thin-executions-list-example-request]]
2154+
===== Example Request
2155+
2156+
include::{snippets}/task-executions-documentation/list-task-thin-executions/curl-request.adoc[]
2157+
2158+
2159+
2160+
[[api-guide-resources-task-thin-executions-list-response-structure]]
2161+
===== Response Structure
2162+
2163+
include::{snippets}/task-executions-documentation/list-task-thin-executions/http-response.adoc[]
2164+
2165+
2166+
2167+
[[api-guide-resources-task-thin-executions-list-by-name]]
2168+
==== List All Task Thin Executions With a Specified Task Name
2169+
2170+
The task thin executions endpoint lets you list task executions with a specified task name.
2171+
The following topics provide more details:
2172+
2173+
* <<api-guide-resources-task-thin-executions-list-by-name-request-structure>>
2174+
* <<api-guide-resources-task-thin-executions-list-by-name-request-parameters>>
2175+
* <<api-guide-resources-task-thin-executions-list-by-name-example-request>>
2176+
* <<api-guide-resources-task-thin-executions-list-by-name-response-structure>>
2177+
2178+
[[api-guide-resources-task-thin-executions-list-by-name-request-structure]]
2179+
===== Request Structure
2180+
2181+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/http-request.adoc[]
2182+
2183+
[[api-guide-resources-task-thin-executions-list-by-name-request-parameters]]
2184+
===== Request Parameters
2185+
2186+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/request-parameters.adoc[]
2187+
2188+
[[api-guide-resources-task-thin-executions-list-by-name-example-request]]
2189+
===== Example Request
2190+
2191+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/curl-request.adoc[]
2192+
2193+
[[api-guide-resources-task-thin-executions-list-by-name-response-structure]]
2194+
===== Response Structure
2195+
2196+
include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/http-response.adoc[]
20702197

20712198
[[api-guide-resources-task-executions-detail]]
20722199
==== Task Execution Detail

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

+8
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ public interface TaskOperations {
123123
*/
124124
PagedModel<TaskExecutionResource> executionListByTaskName(String taskName);
125125

126+
/**
127+
* List task thin executions known to the system filtered by task name.
128+
*
129+
* @param taskName of the executions.
130+
* @return the list of thin task executions known to the system.
131+
*/
132+
PagedModel<TaskExecutionThinResource> thinExecutionListByTaskName(String taskName);
133+
126134
/**
127135
* Return the {@link TaskExecutionResource} for the id specified.
128136
*

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

+23-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.cloud.dataflow.schema.SchemaVersionTarget;
4040
import org.springframework.core.ParameterizedTypeReference;
4141
import org.springframework.hateoas.Link;
42-
import org.springframework.hateoas.PagedModel;
4342
import org.springframework.hateoas.RepresentationModel;
4443
import org.springframework.http.HttpMethod;
4544
import org.springframework.util.Assert;
@@ -71,11 +70,14 @@ public class TaskTemplate implements TaskOperations {
7170
private static final String VALIDATION_THIN_TASK_VERSION = "2.11.3";
7271

7372
private static final String VALIDATION_TASK_LAUNCH_VERSION = "2.11.0";
73+
private static final String VALIDATION_TASK_THIN_BY_NAME = "2.11.6";
7474

7575
private static final String EXECUTIONS_RELATION = "tasks/executions";
7676

7777
private static final String THIN_EXECUTIONS_RELATION = "tasks/thinexecutions";
7878

79+
private static final String THIN_EXECUTIONS_BY_NAME_RELATION = "tasks/thinexecutions/name";
80+
7981
private static final String EXECUTIONS_CURRENT_RELATION = "tasks/executions/current";
8082

8183
private static final String EXECUTION_RELATION = "tasks/executions/execution";
@@ -102,6 +104,8 @@ public class TaskTemplate implements TaskOperations {
102104

103105
private final Link thinExecutionsLink;
104106

107+
private final Link thinExecutionsByNameLink;
108+
105109
private final Link executionLink;
106110

107111
private final Link executionLaunchLink;
@@ -150,13 +154,18 @@ public class TaskTemplate implements TaskOperations {
150154
this.validationLink = null;
151155
}
152156

153-
// TODO early 2.11.3-SNAPSHOT version didn't have this. Remove && resources.getLink(THIN_EXECUTIONS_RELATION).isPresent() when releasing 2.11.3
154-
if(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_THIN_TASK_VERSION) && resources.getLink(THIN_EXECUTIONS_RELATION).isPresent()) {
157+
if(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_THIN_TASK_VERSION)) {
155158
Assert.isTrue(resources.getLink(THIN_EXECUTIONS_RELATION).isPresent(), () -> THIN_EXECUTIONS_RELATION + " relation is required");
156159
this.thinExecutionsLink = resources.getLink(THIN_EXECUTIONS_RELATION).get();
157160
} else {
158161
this.thinExecutionsLink = null;
159162
}
163+
if(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_TASK_THIN_BY_NAME)) {
164+
Assert.isTrue(resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).isPresent(), () -> THIN_EXECUTIONS_BY_NAME_RELATION + " relation is required");
165+
this.thinExecutionsByNameLink = resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).get();
166+
} else {
167+
this.thinExecutionsByNameLink = null;
168+
}
160169

161170
if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_TASK_LAUNCH_VERSION)) {
162171
Assert.isTrue(resources.getLink(EXECUTION_LAUNCH_RELATION).isPresent(), () -> EXECUTION_LAUNCH_RELATION + " relation is required");
@@ -283,18 +292,26 @@ public TaskExecutionResource.Page executionList() {
283292
}
284293

285294
@Override
286-
public PagedModel<TaskExecutionThinResource> thinExecutionList() {
295+
public TaskExecutionThinResource.Page thinExecutionList() {
287296
if(thinExecutionsLink != null) {
288297
return restTemplate.getForObject(thinExecutionsLink.getHref(), TaskExecutionThinResource.Page.class);
289298
} else {
290299
return restTemplate.getForObject(executionsLink.getHref(), TaskExecutionThinResource.Page.class);
291300
}
292301
}
293302

303+
@Override
304+
public TaskExecutionThinResource.Page thinExecutionListByTaskName(String taskName) {
305+
if(thinExecutionsByNameLink != null) {
306+
return restTemplate.getForObject(thinExecutionsByNameLink.expand(taskName).getHref(), TaskExecutionThinResource.Page.class);
307+
} else {
308+
return restTemplate.getForObject(executionByNameLink.expand(taskName).getHref(), TaskExecutionThinResource.Page.class);
309+
}
310+
}
311+
294312
@Override
295313
public TaskExecutionResource.Page executionListByTaskName(String taskName) {
296-
return restTemplate.getForObject(executionByNameLink.expand(taskName).getHref(),
297-
TaskExecutionResource.Page.class);
314+
return restTemplate.getForObject(executionByNameLink.expand(taskName).getHref(), TaskExecutionResource.Page.class);
298315
}
299316

300317
@Override

spring-cloud-dataflow-rest-client/src/test/java/org/springframework/cloud/dataflow/rest/client/TaskTemplateTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ public void testOldDataFlow() {
5454

5555
@Test
5656
public void testMinDataFlow() {
57-
validateExecutionLinkPresent("1.7.0");
57+
validateExecutionLinkPresent("2.10.0");
5858
}
5959

6060
@Test
6161
public void testFutureDataFlow() {
62-
validateExecutionLinkPresent("1.8.0");
63-
validateExecutionLinkPresent("1.9.0");
64-
validateExecutionLinkPresent("2.0.0");
62+
validateExecutionLinkPresent("2.11.6");
6563
}
6664

6765

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, TaskJobService taskJobService) {
304-
return new TaskExecutionThinController(aggregateTaskExplorer, taskJobService);
303+
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
304+
return new TaskExecutionThinController(aggregateTaskExplorer, taskDefinitionRepository, taskJobService);
305305
}
306306

307307
@Bean

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

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public RootResource info() {
159159
root.add(linkTo(methodOn(TasksInfoController.class).getInfo(null, null, null)).withRel("tasks/info/executions"));
160160
root.add(linkTo(methodOn(TaskLogsController.class).getLog(null, null, null)).withRel("tasks/logs"));
161161
root.add(linkTo(methodOn(TaskExecutionThinController.class).listTasks(null, null)).withRel("tasks/thinexecutions"));
162+
root.add(linkTo(methodOn(TaskExecutionThinController.class).retrieveTasksByName(null, null, null)).withRel("tasks/thinexecutions/name"));
162163
if (featuresProperties.isSchedulesEnabled()) {
163164
root.add(entityLinks.linkToCollectionResource(ScheduleInfoResource.class).withRel("tasks/schedules"));
164165
String scheduleTemplated = entityLinks.linkToCollectionResource(ScheduleInfoResource.class).getHref()

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

+10-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.repository.NoSuchTaskDefinitionException;
22+
import org.springframework.cloud.dataflow.server.repository.TaskDefinitionRepository;
2123
import org.springframework.cloud.dataflow.server.service.TaskJobService;
2224
import org.springframework.data.domain.Page;
2325
import org.springframework.data.domain.Pageable;
@@ -46,13 +48,15 @@
4648
public class TaskExecutionThinController {
4749

4850
private final AggregateTaskExplorer explorer;
51+
private final TaskDefinitionRepository taskDefinitionRepository;
4952
private final TaskExecutionThinResourceAssembler resourceAssembler;
5053

5154
private final TaskJobService taskJobService;
5255

53-
public TaskExecutionThinController(AggregateTaskExplorer explorer, TaskJobService taskJobService) {
56+
public TaskExecutionThinController(AggregateTaskExplorer explorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
5457
this.explorer = explorer;
55-
this.taskJobService = taskJobService;
58+
this.taskDefinitionRepository = taskDefinitionRepository;
59+
this.taskJobService = taskJobService;
5660
this.resourceAssembler = new TaskExecutionThinResourceAssembler();
5761
}
5862

@@ -68,6 +72,10 @@ public PagedModel<TaskExecutionThinResource> listTasks(Pageable pageable, PagedR
6872
@ResponseStatus(HttpStatus.OK)
6973
public PagedModel<TaskExecutionThinResource> retrieveTasksByName(@RequestParam("name") String taskName,
7074
Pageable pageable, PagedResourcesAssembler<AggregateTaskExecution> pagedAssembler) {
75+
long tasks = this.taskDefinitionRepository.countByTaskName(taskName);
76+
if(tasks == 0) {
77+
throw new NoSuchTaskDefinitionException(taskName);
78+
}
7179
Page<AggregateTaskExecution> page = this.explorer.findTaskExecutionsByName(taskName, pageable);
7280
taskJobService.populateComposeTaskRunnerStatus(page.getContent());
7381
return pagedAssembler.toModel(page, resourceAssembler);

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

+1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ public interface TaskDefinitionRepository extends KeyValueRepository<TaskDefinit
4646
*/
4747
TaskDefinition findByTaskName(String name);
4848

49+
long countByTaskName(String taskName);
4950
}

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/configuration/JobDependencies.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ public TaskExecutionController taskExecutionController(
244244
}
245245

246246
@Bean
247-
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskJobService taskJobService) {
248-
return new TaskExecutionThinController(aggregateTaskExplorer, taskJobService);
247+
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
248+
return new TaskExecutionThinController(aggregateTaskExplorer, taskDefinitionRepository, taskJobService);
249249
}
250250

251251
@Bean

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/configuration/TestDependencies.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ public TaskExecutionController taskExecutionController(
550550
);
551551
}
552552
@Bean
553-
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer explorer, TaskJobService taskJobService) {
554-
return new TaskExecutionThinController(explorer, taskJobService);
553+
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer explorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
554+
return new TaskExecutionThinController(explorer, taskDefinitionRepository, taskJobService);
555555
}
556556

557557
@Bean

0 commit comments

Comments
 (0)