Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back port of Task Thin Execution List and List By Name #6062

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
onobc marked this conversation as resolved.
Show resolved Hide resolved

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"),
onobc marked this conversation as resolved.
Show resolved Hide resolved

fieldWithPath("_links.tasks/schedules.href").description("Link to the tasks/executions/schedules"),
onobc marked this conversation as resolved.
Show resolved Hide resolved
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>>
onobc marked this conversation as resolved.
Show resolved Hide resolved
* <<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 @@ -39,7 +39,6 @@
import org.springframework.cloud.dataflow.schema.SchemaVersionTarget;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.http.HttpMethod;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -71,11 +70,14 @@ public class TaskTemplate implements TaskOperations {
private static final String VALIDATION_THIN_TASK_VERSION = "2.11.3";

private static final String VALIDATION_TASK_LAUNCH_VERSION = "2.11.0";
private static final String VALIDATION_TASK_THIN_BY_NAME = "2.11.6";

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

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 @@ -150,13 +154,18 @@ public class TaskTemplate implements TaskOperations {
this.validationLink = null;
}

// TODO early 2.11.3-SNAPSHOT version didn't have this. Remove && resources.getLink(THIN_EXECUTIONS_RELATION).isPresent() when releasing 2.11.3
onobc marked this conversation as resolved.
Show resolved Hide resolved
if(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_THIN_TASK_VERSION) && resources.getLink(THIN_EXECUTIONS_RELATION).isPresent()) {
if(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_THIN_TASK_VERSION)) {
Assert.isTrue(resources.getLink(THIN_EXECUTIONS_RELATION).isPresent(), () -> THIN_EXECUTIONS_RELATION + " relation is required");
this.thinExecutionsLink = resources.getLink(THIN_EXECUTIONS_RELATION).get();
} else {
this.thinExecutionsLink = null;
}
if(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_TASK_THIN_BY_NAME)) {
Assert.isTrue(resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).isPresent(), () -> THIN_EXECUTIONS_BY_NAME_RELATION + " relation is required");
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");
Expand Down Expand Up @@ -283,18 +292,26 @@ public TaskExecutionResource.Page executionList() {
}

@Override
public PagedModel<TaskExecutionThinResource> thinExecutionList() {
public TaskExecutionThinResource.Page thinExecutionList() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature change? Seems breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result is the same type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if they are the same let's leave it as is since this is a simple backport on what will be a patch release. What is the value in changing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other uses on tasks/execution uses the .Page I noticed when comparing the various tasks/executions and tasks/thinexecutions controller methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot cleaner as a result return restTemplate.getForObject(executionsLink.getHref(), TaskExecutionThinResource.Page.class);

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 {
onobc marked this conversation as resolved.
Show resolved Hide resolved
return restTemplate.getForObject(executionByNameLink.expand(taskName).getHref(), TaskExecutionThinResource.Page.class);
}
}

@Override
public TaskExecutionResource.Page executionListByTaskName(String taskName) {
return restTemplate.getForObject(executionByNameLink.expand(taskName).getHref(),
TaskExecutionResource.Page.class);
return restTemplate.getForObject(executionByNameLink.expand(taskName).getHref(), TaskExecutionResource.Page.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ public void testOldDataFlow() {

@Test
public void testMinDataFlow() {
validateExecutionLinkPresent("1.7.0");
validateExecutionLinkPresent("2.10.0");
}

@Test
public void testFutureDataFlow() {
validateExecutionLinkPresent("1.8.0");
validateExecutionLinkPresent("1.9.0");
validateExecutionLinkPresent("2.0.0");
validateExecutionLinkPresent("2.11.6");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ public TaskExecutionController taskExecutionController(
}

@Bean
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskJobService taskJobService) {
return new TaskExecutionThinController(aggregateTaskExplorer, taskJobService);
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
onobc marked this conversation as resolved.
Show resolved Hide resolved
return new TaskExecutionThinController(aggregateTaskExplorer, taskDefinitionRepository, taskJobService);
}

@Bean
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()) {
onobc marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -18,6 +18,8 @@
import org.springframework.cloud.dataflow.aggregate.task.AggregateTaskExplorer;
import org.springframework.cloud.dataflow.rest.resource.TaskExecutionThinResource;
import org.springframework.cloud.dataflow.schema.AggregateTaskExecution;
import org.springframework.cloud.dataflow.server.repository.NoSuchTaskDefinitionException;
import org.springframework.cloud.dataflow.server.repository.TaskDefinitionRepository;
import org.springframework.cloud.dataflow.server.service.TaskJobService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -46,13 +48,15 @@
public class TaskExecutionThinController {

private final AggregateTaskExplorer explorer;
private final TaskDefinitionRepository taskDefinitionRepository;
private final TaskExecutionThinResourceAssembler resourceAssembler;

private final TaskJobService taskJobService;

public TaskExecutionThinController(AggregateTaskExplorer explorer, TaskJobService taskJobService) {
public TaskExecutionThinController(AggregateTaskExplorer explorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
this.explorer = explorer;
this.taskJobService = taskJobService;
this.taskDefinitionRepository = taskDefinitionRepository;
this.taskJobService = taskJobService;
this.resourceAssembler = new TaskExecutionThinResourceAssembler();
}

Expand All @@ -68,6 +72,10 @@ public PagedModel<TaskExecutionThinResource> listTasks(Pageable pageable, PagedR
@ResponseStatus(HttpStatus.OK)
public PagedModel<TaskExecutionThinResource> retrieveTasksByName(@RequestParam("name") String taskName,
Pageable pageable, PagedResourcesAssembler<AggregateTaskExecution> pagedAssembler) {
long tasks = this.taskDefinitionRepository.countByTaskName(taskName);
if(tasks == 0) {
throw new NoSuchTaskDefinitionException(taskName);
}
Page<AggregateTaskExecution> page = this.explorer.findTaskExecutionsByName(taskName, pageable);
taskJobService.populateComposeTaskRunnerStatus(page.getContent());
return pagedAssembler.toModel(page, resourceAssembler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ public interface TaskDefinitionRepository extends KeyValueRepository<TaskDefinit
*/
TaskDefinition findByTaskName(String name);

long countByTaskName(String taskName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public TaskExecutionController taskExecutionController(
}

@Bean
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskJobService taskJobService) {
return new TaskExecutionThinController(aggregateTaskExplorer, taskJobService);
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer aggregateTaskExplorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
return new TaskExecutionThinController(aggregateTaskExplorer, taskDefinitionRepository, taskJobService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ public TaskExecutionController taskExecutionController(
);
}
@Bean
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer explorer, TaskJobService taskJobService) {
return new TaskExecutionThinController(explorer, taskJobService);
public TaskExecutionThinController taskExecutionThinController(AggregateTaskExplorer explorer, TaskDefinitionRepository taskDefinitionRepository, TaskJobService taskJobService) {
return new TaskExecutionThinController(explorer, taskDefinitionRepository, taskJobService);
}

@Bean
Expand Down
Loading
Loading