Skip to content

Commit

Permalink
Update Task Thin Executions list function for parity with 2.11.x
Browse files Browse the repository at this point in the history
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
  • Loading branch information
corneil authored and cppwfs committed Nov 14, 2024
1 parent 6c40236 commit bfa3c51
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -135,50 +133,37 @@ 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");
});
this.dataFlowServerVersion = dataFlowServerVersion;
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();
Expand Down Expand Up @@ -207,39 +192,16 @@ 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<String, String> properties, List<String> arguments) {
MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
String formattedProperties = DeploymentPropertiesUtils.format(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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");
}


Expand All @@ -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<TestResource> {

private final Map<String, Long> linksRequested = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit bfa3c51

Please sign in to comment.