From 02068a73bba15524ec5383401a066cab80933f13 Mon Sep 17 00:00:00 2001 From: Corneil du Plessis Date: Mon, 11 Nov 2024 18:12:26 +0200 Subject: [PATCH] Back port of Task Thin Execution List and List By Name Updates api docs for tasks/thinexecutions/name and all HATEOAS links. Updates related tests for links. Update find by name to return 404 when task definition doesn't exist. Fixes #5995 --- .../config/DataFlowControllerAutoConfiguration.java | 4 ++-- .../controller/TaskExecutionThinController.java | 12 ++++++++++-- .../server/repository/TaskDefinitionRepository.java | 1 + .../server/configuration/JobDependencies.java | 4 ++-- .../server/configuration/TestDependencies.java | 4 ++-- .../controller/TaskExecutionControllerTests.java | 5 +++++ src/scripts/build-docs.sh | 4 ++-- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/DataFlowControllerAutoConfiguration.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/DataFlowControllerAutoConfiguration.java index 122f69ca91..57284eadca 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/DataFlowControllerAutoConfiguration.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/DataFlowControllerAutoConfiguration.java @@ -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) { + return new TaskExecutionThinController(aggregateTaskExplorer, taskDefinitionRepository, taskJobService); } @Bean diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java index 210911b3c3..da44e34c76 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionThinController.java @@ -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; @@ -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(); } @@ -68,6 +72,10 @@ public PagedModel listTasks(Pageable pageable, PagedR @ResponseStatus(HttpStatus.OK) public PagedModel retrieveTasksByName(@RequestParam("name") String taskName, Pageable pageable, PagedResourcesAssembler pagedAssembler) { + long tasks = this.taskDefinitionRepository.countByTaskName(taskName); + if(tasks == 0) { + throw new NoSuchTaskDefinitionException(taskName); + } Page page = this.explorer.findTaskExecutionsByName(taskName, pageable); taskJobService.populateComposeTaskRunnerStatus(page.getContent()); return pagedAssembler.toModel(page, resourceAssembler); diff --git a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/repository/TaskDefinitionRepository.java b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/repository/TaskDefinitionRepository.java index eb7464fae6..d67268bef5 100644 --- a/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/repository/TaskDefinitionRepository.java +++ b/spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/repository/TaskDefinitionRepository.java @@ -46,4 +46,5 @@ public interface TaskDefinitionRepository extends KeyValueRepository /dev/null || exit +SCDIR=$(realpath "$SCDIR/../..") +pushd "$SCDIR" || 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