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

Commit 996a660

Browse files
jvalkealDavid Turanski
authored andcommitted
Enhance local scheduler mock implementation
- Issue with current no-op local impl is that it throws error with UI just by going into a tasks and schedules page making UI side development more difficult. Error is java.lang.IllegalStateException: Could not find a default scheduler which is caused because existing `localScheduler` is not wired into a `Launcher`. - Locally use `localScheduler` from `LocalSchedulerAutoConfiguration` so that we can delay UI errors to a point where actual scheduling would then throw an error. This allows UI to so some meaninfull errors instead of a cryptic messages.
1 parent 9be5592 commit 996a660

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

spring-cloud-dataflow-autoconfigure/src/main/java/org/springframework/cloud/dataflow/autoconfigure/local/LocalSchedulerAutoConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.cloud.dataflow.autoconfigure.local;
1717

18+
import java.util.Collections;
1819
import java.util.List;
1920

2021
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -40,22 +41,22 @@ public Scheduler localScheduler() {
4041
return new Scheduler() {
4142
@Override
4243
public void schedule(ScheduleRequest scheduleRequest) {
43-
throw new UnsupportedOperationException("Interface is not implemented for schedule method.");
44+
throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
4445
}
4546

4647
@Override
4748
public void unschedule(String scheduleName) {
48-
throw new UnsupportedOperationException("Interface is not implemented for unschedule method.");
49+
throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
4950
}
5051

5152
@Override
5253
public List<ScheduleInfo> list(String taskDefinitionName) {
53-
throw new UnsupportedOperationException("Interface is not implemented for list method.");
54+
return Collections.emptyList();
5455
}
5556

5657
@Override
5758
public List<ScheduleInfo> list() {
58-
throw new UnsupportedOperationException("Interface is not implemented for list method.");
59+
return Collections.emptyList();
5960
}
6061
};
6162
}

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/features/LocalTaskPlatformFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.cloud.dataflow.core.TaskPlatform;
2424
import org.springframework.cloud.deployer.spi.local.LocalDeployerProperties;
2525
import org.springframework.cloud.deployer.spi.local.LocalTaskLauncher;
26+
import org.springframework.cloud.scheduler.spi.core.Scheduler;
2627
import org.springframework.util.StringUtils;
2728

2829
/**
@@ -31,9 +32,11 @@
3132
public class LocalTaskPlatformFactory extends AbstractTaskPlatformFactory<LocalPlatformProperties> {
3233

3334
private static final String PLATFORM_TYPE = "Local";
35+
private final Scheduler localScheduler;
3436

35-
public LocalTaskPlatformFactory(LocalPlatformProperties platformProperties) {
37+
public LocalTaskPlatformFactory(LocalPlatformProperties platformProperties, Scheduler localScheduler) {
3638
super(platformProperties, PLATFORM_TYPE);
39+
this.localScheduler = localScheduler;
3740
}
3841

3942
@Override
@@ -57,7 +60,7 @@ private Launcher createDefaultLauncher() {
5760

5861
private Launcher doCreateLauncher(String account, LocalDeployerProperties deployerProperties) {
5962
LocalTaskLauncher localTaskLauncher = new LocalTaskLauncher(deployerProperties);
60-
Launcher launcher = new Launcher(account, PLATFORM_TYPE, localTaskLauncher);
63+
Launcher launcher = new Launcher(account, PLATFORM_TYPE, localTaskLauncher, localScheduler);
6164
launcher.setDescription(prettyPrintLocalDeployerProperties(deployerProperties));
6265
return launcher;
6366
}

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/config/features/TaskConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.springframework.cloud.dataflow.server.service.impl.DefaultTaskSaveService;
5555
import org.springframework.cloud.dataflow.server.service.impl.TaskAppDeploymentRequestCreator;
5656
import org.springframework.cloud.dataflow.server.service.impl.TaskConfigurationProperties;
57+
import org.springframework.cloud.scheduler.spi.core.Scheduler;
5758
import org.springframework.cloud.task.repository.TaskExplorer;
5859
import org.springframework.cloud.task.repository.TaskRepository;
5960
import org.springframework.context.annotation.Bean;
@@ -103,9 +104,9 @@ public LauncherInitializationService launcherInitializationService(
103104
*/
104105
@Profile({"local", "default"})
105106
@Bean
106-
public TaskPlatform localTaskPlatform(LocalPlatformProperties localPlatformProperties) {
107+
public TaskPlatform localTaskPlatform(LocalPlatformProperties localPlatformProperties, Scheduler localScheduler) {
107108
TaskPlatform taskPlatform = new
108-
LocalTaskPlatformFactory(localPlatformProperties).createTaskPlatform();
109+
LocalTaskPlatformFactory(localPlatformProperties, localScheduler).createTaskPlatform();
109110
taskPlatform.setPrimary(true);
110111
return taskPlatform;
111112
}

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/config/features/LocalTaskPlatformFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class LocalTaskPlatformFactoryTests {
3434
@Test
3535
public void createsDefaultPlatform() {
3636
LocalPlatformProperties platformProperties = new LocalPlatformProperties();
37-
LocalTaskPlatformFactory taskPlatformFactory = new LocalTaskPlatformFactory(platformProperties);
37+
LocalTaskPlatformFactory taskPlatformFactory = new LocalTaskPlatformFactory(platformProperties, null);
3838
TaskPlatform taskPlatform = taskPlatformFactory.createTaskPlatform();
3939
assertThat(taskPlatform.getLaunchers()).hasSize(1);
4040
assertThat(taskPlatform.getName()).isEqualTo("Local");
@@ -48,7 +48,7 @@ public void createsDefaultPlatform() {
4848
public void createsConfiguredPlatform() {
4949
LocalPlatformProperties platformProperties = new LocalPlatformProperties();
5050
platformProperties.setAccounts(Collections.singletonMap("custom",new LocalDeployerProperties()));
51-
LocalTaskPlatformFactory taskPlatformFactory = new LocalTaskPlatformFactory(platformProperties);
51+
LocalTaskPlatformFactory taskPlatformFactory = new LocalTaskPlatformFactory(platformProperties, null);
5252
TaskPlatform taskPlatform = taskPlatformFactory.createTaskPlatform();
5353
assertThat(taskPlatform.getLaunchers()).hasSize(1);
5454
assertThat(taskPlatform.getName()).isEqualTo("Local");

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/TestConfig.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2018-2019 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.
@@ -16,10 +16,15 @@
1616
package org.springframework.cloud.dataflow.shell;
1717

1818
import java.util.ArrayList;
19+
import java.util.Collections;
20+
import java.util.List;
1921

2022
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2123
import org.springframework.cloud.dataflow.rest.client.config.DataFlowClientAutoConfiguration;
2224
import org.springframework.cloud.dataflow.server.EnableDataFlowServer;
25+
import org.springframework.cloud.scheduler.spi.core.ScheduleInfo;
26+
import org.springframework.cloud.scheduler.spi.core.ScheduleRequest;
27+
import org.springframework.cloud.scheduler.spi.core.Scheduler;
2328
import org.springframework.cloud.skipper.client.SkipperClient;
2429
import org.springframework.cloud.skipper.domain.AboutResource;
2530
import org.springframework.cloud.skipper.domain.Dependency;
@@ -41,6 +46,33 @@
4146
@Configuration
4247
public class TestConfig {
4348

49+
@Bean
50+
public Scheduler localScheduler() {
51+
// This is in auto-config package and we can depend on that, use same
52+
// dummy no-op impl here.
53+
return new Scheduler() {
54+
@Override
55+
public void schedule(ScheduleRequest scheduleRequest) {
56+
throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
57+
}
58+
59+
@Override
60+
public void unschedule(String scheduleName) {
61+
throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
62+
}
63+
64+
@Override
65+
public List<ScheduleInfo> list(String taskDefinitionName) {
66+
return Collections.emptyList();
67+
}
68+
69+
@Override
70+
public List<ScheduleInfo> list() {
71+
return Collections.emptyList();
72+
}
73+
};
74+
}
75+
4476
@Bean
4577
@Primary
4678
public SkipperClient skipperClientMock() {

0 commit comments

Comments
 (0)