Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit d803f83

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 #5705
1 parent 44f8757 commit d803f83

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
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.
@@ -321,7 +321,7 @@ public void schedule(
321321
deployerDeploymentProperties,
322322
commandLineArgs,
323323
scheduleName,
324-
getTaskResource(taskDefinitionName));
324+
getTaskResource(taskDefinitionName, version));
325325

326326
launcher.getScheduler().schedule(scheduleRequest);
327327

@@ -588,7 +588,7 @@ private static Map<String, String> extractAndQualifySchedulerProperties(Map<Stri
588588
(fromWildcard, fromApp) -> fromApp));
589589
}
590590

591-
protected Resource getTaskResource(String taskDefinitionName) {
591+
protected Resource getTaskResource(String taskDefinitionName, String version) {
592592
TaskDefinition taskDefinition = this.taskDefinitionRepository.findById(taskDefinitionName)
593593
.orElseThrow(() -> new NoSuchTaskDefinitionException(taskDefinitionName));
594594
AppRegistration appRegistration = null;
@@ -603,8 +603,14 @@ protected Resource getTaskResource(String taskDefinitionName) {
603603
}
604604
appRegistration = new AppRegistration(ComposedTaskRunnerConfigurationProperties.COMPOSED_TASK_RUNNER_NAME, ApplicationType.task, composedTaskUri);
605605
} else {
606-
appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(),
606+
if(version != null) {
607+
appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(),
608+
ApplicationType.task, version);
609+
}
610+
else {
611+
appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(),
607612
ApplicationType.task);
613+
}
608614
}
609615
Assert.notNull(appRegistration, "Unknown task app: " + taskDefinition.getRegisteredAppName());
610616
return this.registry.getAppResource(appRegistration);

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

+24-16
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;
@@ -75,6 +76,7 @@
7576
import static org.junit.jupiter.api.Assertions.assertThrows;
7677
import static org.mockito.ArgumentMatchers.any;
7778
import static org.mockito.ArgumentMatchers.anyString;
79+
import static org.mockito.ArgumentMatchers.eq;
7880
import static org.mockito.Mockito.mock;
7981
import static org.mockito.Mockito.verify;
8082
import static org.mockito.Mockito.when;
@@ -162,18 +164,13 @@ public class DefaultSchedulerServiceMultiplatformTests {
162164

163165
@BeforeEach
164166
public void setup() throws Exception {
165-
this.appRegistry.save("demo",
166-
ApplicationType.task,
167-
"1.0.0.",
168-
new URI("file:src/test/resources/apps/foo-task"),
169-
new URI("file:src/test/resources/apps/foo-task"),
170-
null);
171-
this.appRegistry.save("demo2",
172-
ApplicationType.task,
173-
"1.0.0",
174-
new URI("file:src/test/resources/apps/foo-task"),
175-
new URI("file:src/test/resources/apps/foo-task"),
176-
null);
167+
168+
when(this.appRegistry.find(
169+
eq("demo"), eq(ApplicationType.task), eq("1.0.0"))).thenReturn(new AppRegistration("demo",
170+
ApplicationType.task, new URI("file:src/test/resources/apps/foo-task")));
171+
when(this.appRegistry.find(
172+
eq("demo2"), eq(ApplicationType.task), eq("1.0.0"))).thenReturn(new AppRegistration("demo2",
173+
ApplicationType.task, new URI("file:src/test/resources/apps/foo-task")));
177174

178175
taskDefinitionRepository.save(new TaskDefinition(BASE_DEFINITION_NAME, "demo"));
179176
taskDefinitionRepository.save(new TaskDefinition(CTR_DEFINITION_NAME, "demo && demo2"));
@@ -182,7 +179,7 @@ public void setup() throws Exception {
182179
this.testProperties = new HashMap<>();
183180
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "AAAA", "* * * * *");
184181
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "EXPRESSION", "* * * * *");
185-
this.testProperties.put("version." + BASE_DEFINITION_NAME, "boot2");
182+
this.testProperties.put("version." + BASE_DEFINITION_NAME, "1.0.0");
186183
this.resolvedProperties = new HashMap<>();
187184
this.resolvedProperties.put(DEPLOYER_PREFIX + "AAAA", "* * * * *");
188185
this.resolvedProperties.put(DEPLOYER_PREFIX + "EXPRESSION", "* * * * *");
@@ -200,6 +197,13 @@ public void testSchedule() {
200197
verifyScheduleExistsInScheduler(createScheduleInfo(BASE_SCHEDULE_NAME));
201198
}
202199

200+
@Test
201+
public void testScheduleWithNoVersion() {
202+
this.testProperties.remove("version." + BASE_DEFINITION_NAME);
203+
schedulerService.schedule(BASE_SCHEDULE_NAME, BASE_DEFINITION_NAME, this.testProperties, this.commandLineArgs, KUBERNETES_PLATFORM);
204+
verifyScheduleExistsInScheduler(createScheduleInfo(BASE_SCHEDULE_NAME));
205+
}
206+
203207
@Test
204208
public void testScheduleWithLongNameOnKuberenetesPlatform() {
205209
assertThrows(IllegalArgumentException.class, () -> {
@@ -416,15 +420,19 @@ public void testScheduleWithCommandLineArguments() throws Exception {
416420
}
417421

418422
@Test
419-
public void testScheduleWithoutCommandLineArguments() {
423+
public void testScheduleWithoutCommandLineArguments() throws URISyntaxException {
420424
List<String> args = getCommandLineArguments(new ArrayList<>());
421425
assertThatCommandLineArgsHaveNonDefaultArgs(args, "--app.timestamp");
422426
}
423427

424-
private List<String> getCommandLineArguments(List<String> commandLineArguments) {
428+
private List<String> getCommandLineArguments(List<String> commandLineArguments) throws URISyntaxException {
425429
Scheduler mockScheduler = mock(SimpleTestScheduler.class);
426430
TaskDefinitionRepository mockTaskDefinitionRepository = mock(TaskDefinitionRepository.class);
427431
AppRegistryService mockAppRegistryService = mock(AppRegistryService.class);
432+
when(mockAppRegistryService.find(
433+
eq("timestamp"), eq(ApplicationType.task), eq("1.0.0"))).
434+
thenReturn(new AppRegistration("timestamp", ApplicationType.task,
435+
new URI("file:src/test/resources/apps/timestamp-task")));
428436

429437
AggregateExecutionSupport mockAggExecSupport = mock(AggregateExecutionSupport.class);
430438
when(mockAggExecSupport.findSchemaVersionTarget(anyString(), anyString(), any(TaskDefinition.class)))

0 commit comments

Comments
 (0)