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.
Update minimum supported version of client.

See spring-cloud#6062
  • Loading branch information
corneil committed Nov 12, 2024
1 parent 364414b commit 3f80045
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 51 deletions.
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";

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,17 +133,16 @@ public class TaskTemplate implements TaskOperations {
EXECUTIONS_INFO_RELATION,
PLATFORM_LIST_RELATION,
RETRIEVE_LOG,
VALIDATION_REL
VALIDATION_REL,
EXECUTIONS_CURRENT_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");
}
Assert.isTrue(VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion(version, VALIDATION_MIN_VERSION), () -> "Minimum Data Flow version required is " + VALIDATION_MIN_VERSION + " but got " + version);

this.aboutLink = resources.getLink("about").get();

Expand All @@ -158,9 +155,7 @@ public class TaskTemplate implements TaskOperations {
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();
}
this.executionsInfoLink = resources.getLink(EXECUTIONS_INFO_RELATION).orElse(null);
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 @@ -189,39 +184,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 @@ -47,21 +47,14 @@ void setup() {
restTemplate = mock(RestTemplate.class);
}

@Test
void oldDataFlow() {
validateExecutionLinkNotPresent("1.6.0");
}

@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 +64,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

0 comments on commit 3f80045

Please sign in to comment.