From bfa3c51eb6a48e5a70ed5ef8ec90141bca19d8b5 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 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. Update minimum supported version of client. See #6062 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. Update minimum supported version of client. See #6062 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. Update minimum supported version of client. See #6062 Revised TaskTemplate to retain order of link init in the constructor. 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. Update minimum supported version of client. Added test for invalid old version. See #6062 --- .../rest/documentation/ApiDocumentation.java | 2 +- .../dataflow/rest/client/TaskTemplate.java | 76 +++++-------------- .../rest/client/TaskTemplateTests.java | 20 ++--- .../TaskExecutionControllerTests.java | 6 ++ 4 files changed, 32 insertions(+), 72 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..be51914d2b 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 @@ -63,10 +63,8 @@ public class TaskTemplate implements TaskOperations { private static final String DEFINITION_RELATION = "tasks/definitions/definition"; - private static final String EXECUTIONS_CURRENT_RELATION_VERSION = "1.7.0"; + private static final String VALIDATION_MIN_VERSION = "3.0.0-SNAPSHOT"; - private static final String VALIDATION_RELATION_VERSION = "1.7.0"; - private static final String VALIDATION_THIN_TASK_VERSION = "2.11.3"; private static final String EXECUTIONS_RELATION = "tasks/executions"; private static final String THIN_EXECUTIONS_RELATION = "tasks/thinexecutions"; @@ -135,7 +133,11 @@ public class TaskTemplate implements TaskOperations { EXECUTIONS_INFO_RELATION, PLATFORM_LIST_RELATION, RETRIEVE_LOG, - VALIDATION_REL + VALIDATION_REL, + EXECUTIONS_CURRENT_RELATION, + THIN_EXECUTIONS_RELATION, + THIN_EXECUTIONS_BY_NAME_RELATION, + EXECUTION_LAUNCH_RELATION ).forEach(relation -> { Assert.isTrue(resources.getLink(relation).isPresent(), () -> relation + " relation is required"); }); @@ -143,42 +145,25 @@ public class TaskTemplate implements TaskOperations { this.restTemplate = restTemplate; String version = VersionUtils.getThreePartVersion(dataFlowServerVersion); - if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_RELATION_VERSION)) { - Assert.notNull(resources.getLink(VALIDATION_REL), ()-> VALIDATION_REL + " relation is required"); + if (StringUtils.hasText(version)) { + Assert.isTrue( + VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, + VALIDATION_MIN_VERSION), + () -> "Minimum Data Flow version required is " + VALIDATION_MIN_VERSION + " but got " + version); } - 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.executionsCurrentLink = resources.getLink(EXECUTIONS_CURRENT_RELATION).get(); this.aboutLink = resources.getLink("about").get(); this.definitionsLink = resources.getLink(DEFINITIONS_RELATION).get(); 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.thinExecutionsLink = resources.getLink(THIN_EXECUTIONS_RELATION).get(); + this.thinExecutionsByNameLink = resources.getLink(THIN_EXECUTIONS_BY_NAME_RELATION).get(); + this.executionLaunchLink = resources.getLink(EXECUTION_LAUNCH_RELATION).get(); this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME).get(); - if (resources.getLink(EXECUTIONS_INFO_RELATION).isPresent()) { - this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).get(); - } + this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).get(); this.validationLink = resources.getLink(VALIDATION_REL).get(); this.platformListLink = resources.getLink(PLATFORM_LIST_RELATION).get(); this.retrieveLogLink = resources.getLink(RETRIEVE_LOG).get(); @@ -207,16 +192,7 @@ public TaskDefinitionResource create(String name, String definition, String desc return restTemplate.postForObject(definitionsLink.expand().getHref(), values, TaskDefinitionResource.class); } - private boolean isNewServer() { - if(this.actualDataFlowServerCoreVersion == null) { - AboutResource aboutResource = restTemplate.getForObject(aboutLink.expand().getHref(), AboutResource.class); - Assert.notNull(aboutResource, "Expected about"); - this.actualDataFlowServerCoreVersion = aboutResource.getVersionInfo().getCore().getVersion(); - } - String v2_11_0 = VersionUtils.getThreePartVersion("2.11.0-SNAPSHOT"); - String serverVersion = VersionUtils.getThreePartVersion(this.actualDataFlowServerCoreVersion); - return VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(serverVersion, v2_11_0); - } + @Override public LaunchResponseResource launch(String name, Map properties, List arguments) { MultiValueMap values = new LinkedMultiValueMap<>(); @@ -224,22 +200,8 @@ public LaunchResponseResource launch(String name, Map properties String commandLineArguments = StringUtils.collectionToDelimitedString(arguments, " "); values.add("properties", formattedProperties); values.add("arguments", commandLineArguments); - if(isNewServer()) { - Assert.notNull(executionLaunchLink, "This version of SCDF doesn't support tasks/executions/launch"); - values.add("name", name); - String url = executionLaunchLink.expand(name).getHref(); - values.remove("name"); - return restTemplate.postForObject(url, values, LaunchResponseResource.class); - } else { - Long id = restTemplate.postForObject(executionByNameLink.expand(name).getHref(), values, Long.class, name); - if(id != null) { - LaunchResponseResource response = new LaunchResponseResource(); - response.setExecutionId(id); - return response; - } else { - throw new RuntimeException("Expected id"); - } - } + String url = executionLaunchLink.expand(name).getHref(); + return restTemplate.postForObject(url, values, LaunchResponseResource.class); } @Override diff --git a/spring-cloud-dataflow-rest-client/src/test/java/org/springframework/cloud/dataflow/rest/client/TaskTemplateTests.java b/spring-cloud-dataflow-rest-client/src/test/java/org/springframework/cloud/dataflow/rest/client/TaskTemplateTests.java index 1780c0ef0c..8d35a5e88e 100644 --- a/spring-cloud-dataflow-rest-client/src/test/java/org/springframework/cloud/dataflow/rest/client/TaskTemplateTests.java +++ b/spring-cloud-dataflow-rest-client/src/test/java/org/springframework/cloud/dataflow/rest/client/TaskTemplateTests.java @@ -28,6 +28,7 @@ import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.mock; /** @@ -46,22 +47,19 @@ class TaskTemplateTests { void setup() { restTemplate = mock(RestTemplate.class); } - @Test - void oldDataFlow() { - validateExecutionLinkNotPresent("1.6.0"); + void invalidVersion() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> validateExecutionLinkPresent("2.11.5")); } - @Test void minDataFlow() { - validateExecutionLinkPresent("1.7.0"); + validateExecutionLinkPresent("3.0.0"); } @Test void futureDataFlow() { - validateExecutionLinkPresent("1.8.0"); - validateExecutionLinkPresent("1.9.0"); - validateExecutionLinkPresent("2.0.0"); + validateExecutionLinkPresent("3.0.0"); } @@ -71,12 +69,6 @@ private void validateExecutionLinkPresent(String dataFlowVersion) { assertThat(testResource.isLinkRequested(CURRENT_TASK_EXECUTION_LINK)).isTrue(); } - private void validateExecutionLinkNotPresent(String version) { - TestResource testResource = new TestResource(); - new TaskTemplate(this.restTemplate, testResource, version); - assertThat(testResource.isLinkRequested(CURRENT_TASK_EXECUTION_LINK)).isFalse(); - } - public static class TestResource extends RepresentationModel { private final Map linksRequested = new HashMap<>(); 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))