Skip to content

Commit

Permalink
Back port of Task Thin Execution List and List By Name
Browse files Browse the repository at this point in the history
Updates api docs for tasks/thinexecutions/name and all HATEOAS links. Updates related tests for links.

Fixes #5995
  • Loading branch information
corneil committed Nov 11, 2024
1 parent ad21f25 commit 2d6b7a3
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void index() throws Exception {
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"),
linkWithRel("tasks/logs").description("Retrieve the task application log"),
linkWithRel("tasks/thinexecutions").description("Returns thin Task executions"),
linkWithRel("tasks/thinexecutions/name").description("Returns all thin Task executions for a given Task name"),

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

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

fieldWithPath("_links.tasks/thinexecutions/name.href").description("Link to the tasks/thinexecutions/name"),
fieldWithPath("_links.tasks/thinexecutions/name.templated").type(JsonFieldType.BOOLEAN).optional().description("Link to the tasks/thinexecutions/name is templated"),

fieldWithPath("_links.tasks/schedules.href").description("Link to the tasks/executions/schedules"),
fieldWithPath("_links.tasks/schedules/instances.href").description("Link to the tasks/schedules/instances"),
fieldWithPath("_links.tasks/schedules/instances.templated").type(JsonFieldType.BOOLEAN).optional().description("Link tasks/schedules/instances is templated"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,29 @@ public void listTaskExecutionsByName() throws Exception {
subsectionWithPath("page").description("Pagination properties"))));
}

@Test
public void listTaskThinExecutionsByName() throws Exception {
this.mockMvc.perform(
get("/tasks/thinexecutions")
.param("name", "taskB")
.param("page", "0")
.param("size", "10")
)
.andExpect(status().isOk()).andDo(this.documentationHandler.document(
requestParameters(
parameterWithName("page")
.description("The zero-based page number (optional)"),
parameterWithName("size")
.description("The requested page size (optional)"),
parameterWithName("name")
.description("The name associated with the task execution")),
responseFields(
subsectionWithPath("_embedded.taskExecutionThinResourceList")
.description("Contains a collection of Task Executions/"),
subsectionWithPath("_links.self").description("Link to the task execution resource"),
subsectionWithPath("page").description("Pagination properties"))));
}

@Test
public void stopTask() throws Exception {
this.mockMvc.perform(
Expand Down
127 changes: 127 additions & 0 deletions spring-cloud-dataflow-docs/src/main/asciidoc/api-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,8 @@ The following topics provide more details:
* <<api-guide-resources-task-executions-stopping>>
* <<api-guide-resources-task-executions-list>>
* <<api-guide-resources-task-executions-list-by-name>>
* <<api-guide-resources-task-thin-executions-list>>
* <<api-guide-resources-task-thin-executions-list-by-name>>
* <<api-guide-resources-task-executions-detail>>
* <<api-guide-resources-task-executions-delete>>
* <<api-guide-resources-task-executions-current-count>>
Expand Down Expand Up @@ -2066,7 +2068,132 @@ include::{snippets}/task-executions-documentation/list-task-executions-by-name/c

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

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

The task executions endpoint lets you list all task executions with only top-level data.
The following topics provide more details:

* <<api-guide-resources-task-thin-executions-list-request-structure>>
* <<api-guide-resources-task-thin-executions-list-request-parameters>>
* <<api-guide-resources-task-thin-executions-list-example-request>>
* <<api-guide-resources-task-thin-executions-list-response-structure>>

[[api-guide-resources-task-thin-executions-list-request-structure]]
===== Request Structure

include::{snippets}/task-executions-documentation/list-task-thin-executions/http-request.adoc[]

[[api-guide-resources-task-thin-executions-list-request-parameters]]
===== Request Parameters

include::{snippets}/task-executions-documentation/list-task-thin-executions/query-parameters.adoc[]

[[api-guide-resources-task-thin-executions-list-example-request]]
===== Example Request

include::{snippets}/task-executions-documentation/list-task-thin-executions/curl-request.adoc[]

[[api-guide-resources-task-thin-executions-list-response-structure]]
===== Response Structure

include::{snippets}/task-executions-documentation/list-task-thin-executions/http-response.adoc[]

[[api-guide-resources-task-thin-executions-list-by-name]]
==== List All Task Thin Executions With a Specified Task Name

The task thin executions endpoint lets you list task executions with a specified task name.
The following topics provide more details:

* <<api-guide-resources-task-thin-executions-list-by-name-request-structure>>
* <<api-guide-resources-task-thin-executions-list-by-name-request-parameters>>
* <<api-guide-resources-task-thin-executions-list-by-name-example-request>>
* <<api-guide-resources-task-thin-executions-list-by-name-response-structure>>



[[api-guide-resources-task-thin-executions-list-by-name-request-structure]]
===== Request Structure

include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/http-request.adoc[]



[[api-guide-resources-task-thin-executions-list-by-name-request-parameters]]
===== Request Parameters

include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/query-parameters.adoc[]



[[api-guide-resources-task-thin-executions-list-by-name-example-request]]
===== Example Request

include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/curl-request.adoc[]

[[api-guide-resources-task-thin-executions-list-by-name-response-structure]]
===== Response Structure

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

[[api-guide-resources-task-thin-executions-list-request-structure]]
===== Request Structure

include::{snippets}/task-executions-documentation/list-task-thin-executions/http-request.adoc[]



[[api-guide-resources-task-thin-executions-list-request-parameters]]
===== Request Parameters

include::{snippets}/task-executions-documentation/list-task-thin-executions/request-parameters.adoc[]



[[api-guide-resources-task-thin-executions-list-example-request]]
===== Example Request

include::{snippets}/task-executions-documentation/list-task-thin-executions/curl-request.adoc[]



[[api-guide-resources-task-thin-executions-list-response-structure]]
===== Response Structure

include::{snippets}/task-executions-documentation/list-task-thin-executions/http-response.adoc[]



[[api-guide-resources-task-thin-executions-list-by-name]]
==== List All Task Thin Executions With a Specified Task Name

The task thin executions endpoint lets you list task executions with a specified task name.
The following topics provide more details:

* <<api-guide-resources-task-thin-executions-list-by-name-request-structure>>
* <<api-guide-resources-task-thin-executions-list-by-name-request-parameters>>
* <<api-guide-resources-task-thin-executions-list-by-name-example-request>>
* <<api-guide-resources-task-thin-executions-list-by-name-response-structure>>

[[api-guide-resources-task-thin-executions-list-by-name-request-structure]]
===== Request Structure

include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/http-request.adoc[]

[[api-guide-resources-task-thin-executions-list-by-name-request-parameters]]
===== Request Parameters

include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/request-parameters.adoc[]

[[api-guide-resources-task-thin-executions-list-by-name-example-request]]
===== Example Request

include::{snippets}/task-executions-documentation/list-task-thin-executions-by-name/curl-request.adoc[]

[[api-guide-resources-task-thin-executions-list-by-name-response-structure]]
===== Response Structure

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

[[api-guide-resources-task-executions-detail]]
==== Task Execution Detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public interface TaskOperations {
*/
PagedModel<TaskExecutionResource> executionListByTaskName(String taskName);

/**
* List task thin executions known to the system filtered by task name.
*
* @param taskName of the executions.
* @return the list of thin task executions known to the system.
*/
PagedModel<TaskExecutionThinResource> thinExecutionListByTaskName(String taskName);

/**
* Return the {@link TaskExecutionResource} for the id specified.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class TaskTemplate implements TaskOperations {

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

private static final String THIN_EXECUTIONS_BY_NAME_RELATION = "tasks/thinexecutions/name";

private static final String EXECUTIONS_CURRENT_RELATION = "tasks/executions/current";

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

private final Link thinExecutionsLink;

private final Link thinExecutionsByNameLink;

private final Link executionLink;

private final Link executionLaunchLink;
Expand Down Expand Up @@ -158,6 +162,11 @@ public class TaskTemplate implements TaskOperations {
this.thinExecutionsLink = null;
}

if(resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).isPresent()) {
this.thinExecutionsByNameLink = resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).get();
} else {
this.thinExecutionsByNameLink = null;
}
if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_TASK_LAUNCH_VERSION)) {
Assert.isTrue(resources.getLink(EXECUTION_LAUNCH_RELATION).isPresent(), () -> EXECUTION_LAUNCH_RELATION + " relation is required");
this.executionLaunchLink = resources.getLink(EXECUTION_LAUNCH_RELATION).get();
Expand Down Expand Up @@ -283,14 +292,23 @@ public TaskExecutionResource.Page executionList() {
}

@Override
public PagedModel<TaskExecutionThinResource> thinExecutionList() {
public TaskExecutionThinResource.Page thinExecutionList() {
if(thinExecutionsLink != null) {
return restTemplate.getForObject(thinExecutionsLink.getHref(), TaskExecutionThinResource.Page.class);
} else {
return restTemplate.getForObject(executionsLink.getHref(), TaskExecutionThinResource.Page.class);
}
}

@Override
public TaskExecutionThinResource.Page thinExecutionListByTaskName(String taskName) {
if(thinExecutionsByNameLink != null) {
return restTemplate.getForObject(thinExecutionsByNameLink.expand(taskName).getHref(), TaskExecutionThinResource.Page.class);
} else {
return restTemplate.getForObject(executionsLink.expand(taskName).getHref(), TaskExecutionThinResource.Page.class);
}
}

@Override
public TaskExecutionResource.Page executionListByTaskName(String taskName) {
return restTemplate.getForObject(executionByNameLink.expand(taskName).getHref(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public RootResource info() {
root.add(linkTo(methodOn(TasksInfoController.class).getInfo(null, null, null)).withRel("tasks/info/executions"));
root.add(linkTo(methodOn(TaskLogsController.class).getLog(null, null, null)).withRel("tasks/logs"));
root.add(linkTo(methodOn(TaskExecutionThinController.class).listTasks(null, null)).withRel("tasks/thinexecutions"));
root.add(linkTo(methodOn(TaskExecutionThinController.class).retrieveTasksByName(null, null, null)).withRel("tasks/thinexecutions/name"));
if (featuresProperties.isSchedulesEnabled()) {
root.add(entityLinks.linkToCollectionResource(ScheduleInfoResource.class).withRel("tasks/schedules"));
String scheduleTemplated = entityLinks.linkToCollectionResource(ScheduleInfoResource.class).getHref()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ void getAllThinExecutions() throws Exception {
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList", hasSize(4)));
}


@Test
void getThinExecutionsByTaskName() throws Exception {
mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", TASK_NAME_ORIG).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].executionId", containsInAnyOrder(2, 1)))
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].parentExecutionId", containsInAnyOrder(null, 1)))
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList[*].taskExecutionStatus", containsInAnyOrder("RUNNING", "RUNNING")))
.andExpect(jsonPath("$._embedded.taskExecutionThinResourceList", hasSize(2)));
}

@Test
void getCurrentExecutions() throws Exception {
when(taskLauncher.getRunningTaskExecutionCount()).thenReturn(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
"tasks/thinexecutions": {
"href":"http://localhost/tasks/thinexecutions"
},
"tasks/thinexecutions/name": {
"href":"http://localhost/tasks/thinexecutions/?name={name}",
"templated": true
},
"jobs/executions": {
"href": "http://localhost/jobs/executions"
},
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ if [ -z "$BASH_VERSION" ]; then
fi
SCDIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
SCDIR=$(realpath $SCDIR)
pushd "$SCDIR" > /dev/null || exit
pushd "$SCDIR/../.." > /dev/null || exit
./mvnw install -DskipTests -am -pl :spring-cloud-dataflow-classic-docs,:spring-cloud-dataflow-docs,:spring-cloud-skipper-server-core,:spring-cloud-skipper-docs -Pfull,docs
popd > /dev/null || exit

0 comments on commit 2d6b7a3

Please sign in to comment.