Skip to content

Commit

Permalink
Remove schedule. prefix from rest client and shell
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Renfro <grenfro@vmware.com>
  • Loading branch information
cppwfs committed Nov 11, 2024
1 parent 3cf889d commit cf4e581
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private List<ScheduleInfo> getSampleList() {
scheduleInfo.setScheduleName("FOO");
scheduleInfo.setTaskDefinitionName("BAR");
Map<String, String> props = new HashMap<>(1);
props.put("scheduler.AAA.spring.cloud.scheduler.cron.expression", "00 41 17 ? * *");
props.put("deployer.AAA.spring.cloud.scheduler.cron.expression", "00 41 17 ? * *");
scheduleInfo.setScheduleProperties(props);
result.add(scheduleInfo);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void createSchedule() throws Exception {
.queryParam("scheduleName", "myschedule")
.queryParam("taskDefinitionName", "mytaskname")
.queryParam("platform", "default")
.queryParam("properties", "scheduler.cron.expression=00 22 17 ? *")
.queryParam("properties", "deployer.cron.expression=00 22 17 ? *")
.queryParam("arguments", "--foo=bar"))
.andExpect(status().isCreated())
.andDo(this.documentationHandler.document(
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-dataflow-docs/src/main/asciidoc/tasks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ dataflow:>task schedule list
╔══════════════════════════╤════════════════════╤════════════════════════════════════════════════════╗
║ Schedule Name │Task Definition Name│ Properties ║
╠══════════════════════════╪════════════════════╪════════════════════════════════════════════════════╣
║mytaskschedule │mytask │spring.cloud.scheduler.cron.expression = */1 * * * *║
║mytaskschedule │mytask │spring.cloud.deployer.cron.expression = */1 * * * *
╚══════════════════════════╧════════════════════╧════════════════════════════════════════════════════╝
----
====
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
public class TaskSchedule implements AutoCloseable {

public static final String CRON_EXPRESSION_KEY = "scheduler.cron.expression";
public static final String CRON_EXPRESSION_KEY = "deployer.cron.expression";

private final String scheduleName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class DeploymentPropertiesUtils {
.compile("(\\s(?=" + "([^\\\"']*[\\\"'][^\\\"']*[\\\"'])*[^\\\"']*$))");


private static final String[] DEPLOYMENT_PROPERTIES_PREFIX ={"deployer", "app", "version", "scheduler", "spring.cloud.dataflow.task"};
private static final String[] DEPLOYMENT_PROPERTIES_PREFIX ={"deployer", "app", "version", "spring.cloud.dataflow.task"};

private DeploymentPropertiesUtils() {
// prevent instantiation
Expand Down Expand Up @@ -127,7 +127,7 @@ public static List<String> parseParamList(String s, String delimiter) {
// we have a key/value pair having '=', or malformed first pair
if (!startsWithDeploymentPropertyPrefix(candidate)) {
throw new IllegalArgumentException(
"Only deployment property keys starting with 'app.' or 'scheduler' or 'deployer.' or 'version.'" +
"Only deployment property keys starting with 'app.' or 'deployer.' or 'version.'" +
" allowed. Not " + candidate);
}
pairs.add(candidate);
Expand Down Expand Up @@ -286,9 +286,9 @@ public static void validateDeploymentProperties(Map<String, String> properties)
for (Entry<String, String> property : properties.entrySet()) {
String key = property.getKey();
if (!key.startsWith("app.") && !key.startsWith("deployer.")
&& !key.startsWith("scheduler.") && !key.startsWith("version.")) {
&& !key.startsWith("version.")) {
throw new IllegalArgumentException(
"Only deployment property keys starting with 'app.', 'deployer.' or, 'scheduler.' allowed, got '" + key + "'");
"Only deployment property keys starting with 'app.' or 'deployer.' allowed, got '" + key + "'");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ private static void assertArrays(String[] left, String[] right) {
@Test
void deploymentPropertiesParsing() {
Map<String, String> props = DeploymentPropertiesUtils.parse("app.foo.bar=v, app.foo.wizz=v2 , deployer.foo"
+ ".pot=fern, app.other.key = value , deployer.other.cow = meww, scheduler.other.key = baz");
+ ".pot=fern, app.other.key = value , deployer.other.cow = meww, deployer.other.key = baz");
assertThat(props.entrySet()).contains(entry("app.foo.bar", "v"));
assertThat(props.entrySet()).contains(entry("app.other.key", "value"));
assertThat(props.entrySet()).contains(entry("app.foo.wizz", "v2"));
assertThat(props.entrySet()).contains(entry("deployer.foo.pot", "fern"));
assertThat(props.entrySet()).contains(entry("deployer.other.cow", "meww"));
assertThat(props.entrySet()).contains(entry("scheduler.other.key", "baz"));
assertThat(props.entrySet()).contains(entry("deployer.other.key", "baz"));

props = DeploymentPropertiesUtils.parse("app.f=v");
assertThat(props.entrySet()).contains(entry("app.f", "v"));
Expand Down Expand Up @@ -87,7 +87,7 @@ void deploymentPropertiesParsing() {
fail("Illegal Argument Exception expected.");
}
catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("Only deployment property keys starting with 'app.' or 'scheduler' or 'deployer.' or 'version.' allowed. Not invalidkeyvalue");
assertThat(e.getMessage()).isEqualTo("Only deployment property keys starting with 'app.' or 'deployer.' or 'version.' allowed. Not invalidkeyvalue");
}

props = DeploymentPropertiesUtils.parse("deployer.foo=bar,invalidkeyvalue2");
Expand Down Expand Up @@ -125,7 +125,7 @@ void deploymentPropertiesParsing2() {
fail("Illegal Argument Exception expected.");
}
catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("Only deployment property keys starting with 'app.' or 'scheduler' or 'deployer.' or 'version.' allowed. Not a=b");
assertThat(e.getMessage()).isEqualTo("Only deployment property keys starting with 'app.' or 'deployer.' or 'version.' allowed. Not a=b");
}

props = DeploymentPropertiesUtils.parseArgumentList("a=b c=d", " ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void schedule(
AppDefinition revisedDefinition = TaskServiceUtils.mergeAndExpandAppProperties(taskDefinition, metadataResource,
appDeploymentProperties, visibleProperties);
DeploymentPropertiesUtils.validateDeploymentProperties(taskDeploymentProperties);
taskDeploymentProperties = extractAndQualifySchedulerProperties(taskDeploymentProperties);
taskDeploymentProperties = filterPrefixedProperties(taskDeploymentProperties);
deployerDeploymentProperties.putAll(taskDeploymentProperties);
scheduleName = validateScheduleNameForPlatform(launcher.getType(), scheduleName);
ScheduleRequest scheduleRequest = new ScheduleRequest(revisedDefinition,
Expand Down Expand Up @@ -501,22 +501,15 @@ private List<ScheduleInfo> limitScheduleInfoResultSize(
}

/**
* Retain only properties that are meant for the <em>scheduler</em> of a given task(those
* that start with {@code scheduler.}and qualify all
* property values with the {@code spring.cloud.scheduler.} prefix.
* Provided a filtered Map that removes entries prefixed with "app." or "deployer.".
*
* @param input the scheduler properties
* @return scheduler properties for the task
* @param input the properties
* @return deployer properties for the schedule
*/
@Deprecated
private static Map<String, String> extractAndQualifySchedulerProperties(Map<String, String> input) {
final String prefix = "scheduler.";
final int prefixLength = prefix.length();

private static Map<String, String> filterPrefixedProperties(Map<String, String> input) {
return new TreeMap<>(input).entrySet().stream()
.filter(kv -> kv.getKey().startsWith(prefix))
.collect(Collectors.toMap(kv -> "spring.cloud.deployer." + kv.getKey().substring(prefixLength), Map.Entry::getValue,
(fromWildcard, fromApp) -> fromApp));
.filter(kv -> (!kv.getKey().startsWith("deployer.") && !kv.getKey().startsWith("app.")))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

protected Resource getTaskResource(String taskDefinitionName, String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void createAndVerifySchedule(String scheduleName, String createdSchedule

repository.save(new TaskDefinition("testDefinition", "testApp"));
mockMvc.perform(post("/tasks/schedules").param("taskDefinitionName", "testDefinition")
.param("scheduleName", scheduleName).param("properties", "scheduler.cron.expression=* * * * *")
.param("scheduleName", scheduleName).param("properties", "deployer.testApp.cron.expression=* * * * *")
.accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated());
assertThat(simpleTestScheduler.list()).hasSize(1);
ScheduleInfo scheduleInfo = simpleTestScheduler.list().get(0);
Expand Down Expand Up @@ -253,7 +253,7 @@ private String createScheduleWithArguments(String arguments) throws Exception {
mockMvc.perform(post("/tasks/schedules").param("taskDefinitionName", "testDefinition")
.param("scheduleName", "mySchedule")
.param("properties",
"scheduler.cron.expression=* * * * *,app.testApp.prop1=foo,app.testApp.prop2.secret=kenny,deployer.*.prop1.secret=cartman,deployer.*.prop2.password=kyle")
"deployer.testApp.cron.expression=* * * * *,app.testApp.prop1=foo,app.testApp.prop2.secret=kenny,deployer.*.prop1.secret=cartman,deployer.*.prop2.password=kyle")
.param("arguments", arguments)
.accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated());
assertThat(simpleTestScheduler.list()).hasSize(1);
Expand Down Expand Up @@ -283,7 +283,7 @@ void createScheduleBadCron() throws Exception {
mockMvc.perform(post("/tasks/schedules").param("taskDefinitionName", "testDefinition")
.param("scheduleName", "myScheduleBadCron")
.param("properties",
"scheduler.cron.expression=" + SimpleTestScheduler.INVALID_CRON_EXPRESSION)
"deployer.testApp.cron.expression=" + SimpleTestScheduler.INVALID_CRON_EXPRESSION)
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isBadRequest());
}

Expand Down Expand Up @@ -339,7 +339,7 @@ private void createSampleSchedule(String scheduleName) {

private void createSampleSchedule(String taskDefinitionName, String scheduleName) {
Map<String, String> properties = new HashMap<>();
properties.put("scheduler.testApp." + SchedulerPropertyKeys.CRON_EXPRESSION, "* * * * *");
properties.put("deployer.testApp." + SchedulerPropertyKeys.CRON_EXPRESSION, "* * * * *");
schedulerService.schedule(scheduleName, taskDefinitionName, properties, new ArrayList<>(), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
@AutoConfigureTestDatabase(replace = Replace.ANY)
public class DefaultSchedulerServiceMultiplatformTests {

private static final String DATA_FLOW_SCHEDULER_PREFIX = "scheduler.";
private static final String DATA_FLOW_DEPLOYER_PREFIX = "deployer.demo.";

private static final String DEPLOYER_PREFIX = "spring.cloud.deployer.";

Expand Down Expand Up @@ -166,8 +166,8 @@ void setup() throws Exception {
initializeSuccessfulRegistry();

this.testProperties = new HashMap<>();
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "AAAA", "* * * * *");
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "EXPRESSION", "* * * * *");
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "AAAA", "* * * * *");
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "EXPRESSION", "* * * * *");
this.testProperties.put("version." + BASE_DEFINITION_NAME, "1.0.0");
this.resolvedProperties = new HashMap<>();
this.resolvedProperties.put(DEPLOYER_PREFIX + "AAAA", "* * * * *");
Expand Down Expand Up @@ -243,6 +243,11 @@ public void testScheduleWithLongName() {

@Test
void scheduleCTR() {
this.testProperties = new HashMap<>();
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "AAAA", "* * * * *");
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "EXPRESSION", "* * * * *");
this.testProperties.put("deployer.composed-task-runner." + "AAAA", "* * * * *");
this.testProperties.put("deployer.composed-task-runner." + "EXPRESSION", "* * * * *");
schedulerService.schedule(BASE_SCHEDULE_NAME, CTR_DEFINITION_NAME, this.testProperties, this.commandLineArgs, KUBERNETES_PLATFORM);
verifyScheduleExistsInScheduler(createScheduleInfo(BASE_SCHEDULE_NAME, CTR_DEFINITION_NAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
@AutoConfigureTestDatabase(replace = Replace.ANY)
public class DefaultSchedulerServiceTests {

private static final String DATA_FLOW_SCHEDULER_PREFIX = "scheduler.";
private static final String DATA_FLOW_DEPLOYER_PREFIX = "deployer.demo.";

private static final String SCHEDULER_PREFIX = "spring.cloud.deployer.";
private static final String DEPLOYER_PREFIX = "spring.cloud.deployer.";

private static final String BASE_SCHEDULE_NAME = "myTaskSchedule";

Expand Down Expand Up @@ -161,11 +161,11 @@ void setup() throws Exception{
initializeSuccessfulRegistry();

this.testProperties = new HashMap<>();
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "AAAA", "* * * * *");
this.testProperties.put(DATA_FLOW_SCHEDULER_PREFIX + "EXPRESSION", "* * * * *");
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "AAAA", "* * * * *");
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "EXPRESSION", "* * * * *");
this.resolvedProperties = new HashMap<>();
this.resolvedProperties.put(SCHEDULER_PREFIX + "AAAA", "* * * * *");
this.resolvedProperties.put(SCHEDULER_PREFIX + "EXPRESSION", "* * * * *");
this.resolvedProperties.put(DEPLOYER_PREFIX + "AAAA", "* * * * *");
this.resolvedProperties.put(DEPLOYER_PREFIX + "EXPRESSION", "* * * * *");
this.commandLineArgs = new ArrayList<>();
}

Expand Down Expand Up @@ -241,6 +241,11 @@ public void testScheduleWithLongName(){

@Test
void scheduleCTR(){
this.testProperties = new HashMap<>();
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "AAAA", "* * * * *");
this.testProperties.put(DATA_FLOW_DEPLOYER_PREFIX + "EXPRESSION", "* * * * *");
this.testProperties.put("deployer.composed-task-runner." + "AAAA", "* * * * *");
this.testProperties.put("deployer.composed-task-runner." + "EXPRESSION", "* * * * *");
schedulerService.schedule(BASE_SCHEDULE_NAME, CTR_DEFINITION_NAME, this.testProperties, Collections.singletonList("app.demo.0=foo=bar"));
verifyScheduleExistsInScheduler(createScheduleInfo(BASE_SCHEDULE_NAME, CTR_DEFINITION_NAME));
AuditActionType[] createActions = {AuditActionType.CREATE};
Expand Down
3 changes: 2 additions & 1 deletion whats-new.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ VersionInfoProperties versionInfoProperties, SecurityStateBean securityStateBean
* * Removed the `DefaultTaskExecutionInfoService` constructor that does not take the `composedTaskRunnerConfigurationProperties` parameter. Use the constructor that offers the `composedTaskRunnerConfigurationProperties` parameter.
* AggressiveShutdownStrategy & AggressiveShutdownWithNetworkCleanupStrategy deprecated classes have been removed. Use the KillDownShutdownStrategy class.
== Breaking Changes
Announce deprecated changes here
* Deprecated property prefix `scheduler.` has been removed when setting schedule properties for task applications. Use `deployer.` instead.


0 comments on commit cf4e581

Please sign in to comment.