Skip to content

Commit 17804c7

Browse files
committed
User needs ability to specify app version when creating schedule
This update allows user to specify version.label=<version.number> Tests were also updated because the original settings assumed that the appregistry was real instance instead of being mocked. Thus the find would always return null. And in this case the tests returned a false positive. Now that the mocks are in place it excercises all the code. Also added explicit test if user does not set the version number. Some of the tests do this, but wanted an explicit test to verify this. resolves spring-cloud#5705
1 parent 0248a28 commit 17804c7

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultSchedulerService.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2023 the original author or authors.
2+
* Copyright 2018-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -297,7 +297,7 @@ public void schedule(
297297
deployerDeploymentProperties,
298298
commandLineArgs,
299299
scheduleName,
300-
getTaskResource(taskDefinitionName));
300+
getTaskResource(taskDefinitionName, version));
301301

302302
launcher.getScheduler().schedule(scheduleRequest);
303303

@@ -526,7 +526,7 @@ private static Map<String, String> extractAndQualifySchedulerProperties(Map<Stri
526526
(fromWildcard, fromApp) -> fromApp));
527527
}
528528

529-
protected Resource getTaskResource(String taskDefinitionName) {
529+
protected Resource getTaskResource(String taskDefinitionName, String version) {
530530
TaskDefinition taskDefinition = this.taskDefinitionRepository.findById(taskDefinitionName)
531531
.orElseThrow(() -> new NoSuchTaskDefinitionException(taskDefinitionName));
532532
AppRegistration appRegistration = null;
@@ -541,8 +541,14 @@ protected Resource getTaskResource(String taskDefinitionName) {
541541
}
542542
appRegistration = new AppRegistration(ComposedTaskRunnerConfigurationProperties.COMPOSED_TASK_RUNNER_NAME, ApplicationType.task, composedTaskUri);
543543
} else {
544-
appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(),
544+
if(version != null) {
545+
appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(),
546+
ApplicationType.task, version);
547+
}
548+
else {
549+
appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(),
545550
ApplicationType.task);
551+
}
546552
}
547553
Assert.notNull(appRegistration, "Unknown task app: " + taskDefinition.getRegisteredAppName());
548554
return this.registry.getAppResource(appRegistration);

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/DefaultSchedulerServiceMultiplatformTests.java

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.cloud.dataflow.server.service.impl;
1818

1919
import java.net.URI;
20+
import java.net.URISyntaxException;
2021
import java.util.ArrayList;
2122
import java.util.Collections;
2223
import java.util.HashMap;
@@ -73,6 +74,7 @@
7374
import static org.assertj.core.api.Assertions.assertThat;
7475
import static org.mockito.ArgumentMatchers.any;
7576
import static org.mockito.ArgumentMatchers.anyString;
77+
import static org.mockito.ArgumentMatchers.eq;
7678
import static org.mockito.Mockito.mock;
7779
import static org.mockito.Mockito.verify;
7880
import static org.mockito.Mockito.when;
@@ -155,25 +157,20 @@ public class DefaultSchedulerServiceMultiplatformTests {
155157

156158
@Before
157159
public void setup() throws Exception {
158-
this.appRegistry.save("demo",
159-
ApplicationType.task,
160-
"1.0.0.",
161-
new URI("file:src/test/resources/apps/foo-task"),
162-
new URI("file:src/test/resources/apps/foo-task"));
163-
this.appRegistry.save("demo2",
164-
ApplicationType.task,
165-
"1.0.0",
166-
new URI("file:src/test/resources/apps/foo-task"),
167-
new URI("file:src/test/resources/apps/foo-task"));
168-
160+
when(this.appRegistry.find(
161+
eq("demo"), eq(ApplicationType.task), eq("1.0.0"))).thenReturn(new AppRegistration("demo",
162+
ApplicationType.task, new URI("file:src/test/resources/apps/foo-task")));
163+
when(this.appRegistry.find(
164+
eq("demo2"), eq(ApplicationType.task), eq("1.0.0"))).thenReturn(new AppRegistration("demo2",
165+
ApplicationType.task, new URI("file:src/test/resources/apps/foo-task")));
169166
taskDefinitionRepository.save(new TaskDefinition(BASE_DEFINITION_NAME, "demo"));
170167
taskDefinitionRepository.save(new TaskDefinition(CTR_DEFINITION_NAME, "demo && demo2"));
171168
initializeSuccessfulRegistry();
172169

173170
this.testProperties = new HashMap<>();
174171
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "AAAA", "* * * * *");
175172
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "EXPRESSION", "* * * * *");
176-
this.testProperties.put("version." + BASE_DEFINITION_NAME, "boot2");
173+
this.testProperties.put("version." + BASE_DEFINITION_NAME, "1.0.0");
177174
this.resolvedProperties = new HashMap<>();
178175
this.resolvedProperties.put(DEPLOYER_PREFIX + "AAAA", "* * * * *");
179176
this.resolvedProperties.put(DEPLOYER_PREFIX + "EXPRESSION", "* * * * *");
@@ -191,6 +188,13 @@ public void testSchedule() {
191188
verifyScheduleExistsInScheduler(createScheduleInfo(BASE_SCHEDULE_NAME));
192189
}
193190

191+
@Test
192+
public void testScheduleWithNoVersion() {
193+
this.testProperties.remove("version." + BASE_DEFINITION_NAME);
194+
schedulerService.schedule(BASE_SCHEDULE_NAME, BASE_DEFINITION_NAME, this.testProperties, this.commandLineArgs, KUBERNETES_PLATFORM);
195+
verifyScheduleExistsInScheduler(createScheduleInfo(BASE_SCHEDULE_NAME));
196+
}
197+
194198
@Test(expected = IllegalArgumentException.class)
195199
public void testScheduleWithLongNameOnKuberenetesPlatform() {
196200
getMockedKubernetesSchedulerService().schedule(BASE_SCHEDULE_NAME +
@@ -397,15 +401,19 @@ public void testScheduleWithCommandLineArguments() throws Exception {
397401
}
398402

399403
@Test
400-
public void testScheduleWithoutCommandLineArguments() {
404+
public void testScheduleWithoutCommandLineArguments() throws URISyntaxException {
401405
List<String> args = getCommandLineArguments(new ArrayList<>());
402406
assertThatCommandLineArgsHaveNonDefaultArgs(args, "--app.timestamp", new String[0]);
403407
}
404408

405-
private List<String> getCommandLineArguments(List<String> commandLineArguments) {
409+
private List<String> getCommandLineArguments(List<String> commandLineArguments) throws URISyntaxException {
406410
Scheduler mockScheduler = mock(SimpleTestScheduler.class);
407411
TaskDefinitionRepository mockTaskDefinitionRepository = mock(TaskDefinitionRepository.class);
408412
AppRegistryService mockAppRegistryService = mock(AppRegistryService.class);
413+
when(mockAppRegistryService.find(
414+
eq("timestamp"), eq(ApplicationType.task), eq("1.0.0"))).
415+
thenReturn(new AppRegistration("timestamp", ApplicationType.task,
416+
new URI("file:src/test/resources/apps/timestamp-task")));
409417

410418

411419
Launcher launcher = new Launcher("default", "defaultType", null, mockScheduler);

0 commit comments

Comments
 (0)