From 364414b668f864046b1e6d75e138643fbb85b6f0 Mon Sep 17 00:00:00 2001 From: Corneil du Plessis Date: Tue, 12 Nov 2024 10:25:10 +0200 Subject: [PATCH] Update Task Thin Executions list function for parity with 2.11.x Updated task thin executions link handing and added extra test for parity with 2.11.x See #6062 --- .../rest/documentation/ApiDocumentation.java | 2 +- .../dataflow/rest/client/TaskTemplate.java | 26 +++---------------- .../TaskExecutionControllerTests.java | 6 +++++ 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/ApiDocumentation.java b/spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/ApiDocumentation.java index 6c5ff8e895..17628b7566 100644 --- a/spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/ApiDocumentation.java +++ b/spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/ApiDocumentation.java @@ -222,7 +222,7 @@ 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").description("Link to the tasks/thinexecutions/name is templated"), + fieldWithPath("_links.tasks/thinexecutions/name.templated").type(JsonFieldType.BOOLEAN).optional().description("Link to the tasks/thinexecutions/name is templated"), fieldWithPath("_links.tasks/info/executions.href").description("Link to the tasks/info/executions"), fieldWithPath("_links.tasks/info/executions.templated").type(JsonFieldType.BOOLEAN).optional().description("Link tasks/info is templated"), diff --git a/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java b/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java index dd9f29b73a..840bc9dce3 100644 --- a/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java +++ b/spring-cloud-dataflow-rest-client/src/main/java/org/springframework/cloud/dataflow/rest/client/TaskTemplate.java @@ -146,12 +146,6 @@ public class TaskTemplate implements TaskOperations { if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_RELATION_VERSION)) { Assert.notNull(resources.getLink(VALIDATION_REL), ()-> VALIDATION_REL + " relation is required"); } - if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, EXECUTIONS_CURRENT_RELATION_VERSION)) { - Assert.isTrue(resources.getLink(EXECUTIONS_CURRENT_RELATION).isPresent(), ()-> EXECUTIONS_CURRENT_RELATION + " relation is required"); - this.executionsCurrentLink = resources.getLink(EXECUTIONS_CURRENT_RELATION).get(); - } else { - this.executionsCurrentLink = null; - } this.aboutLink = resources.getLink("about").get(); @@ -159,22 +153,10 @@ public class TaskTemplate implements TaskOperations { this.definitionLink = resources.getLink(DEFINITION_RELATION).get(); this.executionsLink = resources.getLink(EXECUTIONS_RELATION).get(); this.executionLink = resources.getLink(EXECUTION_RELATION).get(); - if(resources.getLink(THIN_EXECUTIONS_RELATION).isPresent()) { - this.thinExecutionsLink = resources.getLink(THIN_EXECUTIONS_RELATION).get(); - } else { - 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(resources.getLink(EXECUTION_LAUNCH_RELATION).isPresent()) { - this.executionLaunchLink = resources.getLink(EXECUTION_LAUNCH_RELATION).get(); - } else { - this.executionLaunchLink = null; - } + this.executionsCurrentLink = resources.getLink(EXECUTIONS_CURRENT_RELATION).orElse(null); + this.thinExecutionsLink = resources.getLink(THIN_EXECUTIONS_RELATION).orElse(null); + this.thinExecutionsByNameLink = resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).orElse(null); + this.executionLaunchLink = resources.getLink(EXECUTION_LAUNCH_RELATION).orElse(null); this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME).get(); if (resources.getLink(EXECUTIONS_INFO_RELATION).isPresent()) { this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).get(); diff --git a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionControllerTests.java b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionControllerTests.java index 3b24e2b22d..f403d409c0 100644 --- a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionControllerTests.java +++ b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/TaskExecutionControllerTests.java @@ -343,6 +343,12 @@ void getAllThinExecutions() throws Exception { } @Test void getThinExecutionsByName() 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))); mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", "nope").accept(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.page.totalElements", is(0))); mockMvc.perform(get("/tasks/thinexecutions").queryParam("name", "none").accept(MediaType.APPLICATION_JSON))