org.springframework.cloud.deployer.spi.scheduler.Scheduler Java Examples

The following examples show how to use org.springframework.cloud.deployer.spi.scheduler.Scheduler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesTaskPlatformFactory.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public Launcher createLauncher(String account) {
	KubernetesDeployerProperties kubernetesProperties = this.platformProperties.accountProperties(account);
	ContainerFactory containerFactory = new DefaultContainerFactory(
			this.platformProperties.accountProperties(account));
	KubernetesClient kubernetesClient =
			KubernetesClientFactory.getKubernetesClient(this.platformProperties.accountProperties(account));

	KubernetesTaskLauncher kubernetesTaskLauncher = new KubernetesTaskLauncher(
			kubernetesProperties, kubernetesClient, containerFactory);

	Scheduler scheduler = getScheduler(schedulerProperties, kubernetesClient);
	Launcher launcher = new Launcher(account, KUBERNETES_PLATFORM_TYPE, kubernetesTaskLauncher, scheduler);

	launcher.setDescription(
			String.format("master url = [%s], namespace = [%s], api version = [%s]",
					kubernetesClient.getMasterUrl(), kubernetesClient.getNamespace(),
					kubernetesClient.getApiVersion()));

	return launcher;
}
 
Example #2
Source File: TestConfig.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
public Scheduler localScheduler() {
	// This is in auto-config package and we can depend on that, use same
	// dummy no-op impl here.
	return new Scheduler() {
		@Override
		public void schedule(ScheduleRequest scheduleRequest) {
			throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
		}

		@Override
		public void unschedule(String scheduleName) {
			throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
		}

		@Override
		public List<ScheduleInfo> list(String taskDefinitionName) {
			return Collections.emptyList();
		}

		@Override
		public List<ScheduleInfo> list() {
			return Collections.emptyList();
		}
	};
}
 
Example #3
Source File: LocalDataflowResource.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public Scheduler localScheduler() {
	return new Scheduler() {
		@Override
		public void schedule(ScheduleRequest scheduleRequest) {
			throw new UnsupportedOperationException("Interface is not implemented for schedule method.");
		}

		@Override
		public void unschedule(String scheduleName) {
			throw new UnsupportedOperationException("Interface is not implemented for unschedule method.");
		}

		@Override
		public List<ScheduleInfo> list(String taskDefinitionName) {
			throw new UnsupportedOperationException("Interface is not implemented for list method.");
		}

		@Override
		public List<ScheduleInfo> list() {
			throw new UnsupportedOperationException("Interface is not implemented for list method.");
		}
	};
}
 
Example #4
Source File: BaseDocumentation.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
public Scheduler localTestScheduler() {
	return new Scheduler() {
		@Override
		public void schedule(ScheduleRequest scheduleRequest) {
			throw new UnsupportedOperationException("Interface is not implemented for schedule method.");
		}

		@Override
		public void unschedule(String scheduleName) {
			throw new UnsupportedOperationException("Interface is not implemented for unschedule method.");
		}

		@Override
		public List<ScheduleInfo> list(String taskDefinitionName) {
			throw new UnsupportedOperationException("Interface is not implemented for list method.");
		}

		@Override
		public List<ScheduleInfo> list() {
			return getSampleList();
		}
	};
}
 
Example #5
Source File: LocalSchedulerAutoConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public Scheduler localScheduler() {
	return new Scheduler() {
		@Override
		public void schedule(ScheduleRequest scheduleRequest) {
			throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
		}

		@Override
		public void unschedule(String scheduleName) {
			throw new UnsupportedOperationException("Scheduling is not implemented for local platform.");
		}

		@Override
		public List<ScheduleInfo> list(String taskDefinitionName) {
			return Collections.emptyList();
		}

		@Override
		public List<ScheduleInfo> list() {
			return Collections.emptyList();
		}
	};
}
 
Example #6
Source File: DefaultSchedulerServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private List<String> getCommandLineArguments(List<String> commandLineArguments) {
	Scheduler mockScheduler = mock(SimpleTestScheduler.class);
	TaskDefinitionRepository mockTaskDefinitionRepository = mock(TaskDefinitionRepository.class);
	AppRegistryService mockAppRegistryService = mock(AppRegistryService.class);

	Launcher launcher = new Launcher("default", "defaultType", null, mockScheduler);
	List<Launcher> launchers = new ArrayList<>();
	launchers.add(launcher);
	List<TaskPlatform> taskPlatform = Collections.singletonList(new TaskPlatform("testTaskPlatform", launchers));
	SchedulerService mockSchedulerService = new DefaultSchedulerService(mock(CommonApplicationProperties.class),
			taskPlatform, mockTaskDefinitionRepository, mockAppRegistryService, mock(ResourceLoader.class),
			this.taskConfigurationProperties, mock(DataSourceProperties.class), "uri",
			mock(ApplicationConfigurationMetadataResolver.class), mock(SchedulerServiceProperties.class),
			mock(AuditRecordService.class));

	TaskDefinition taskDefinition = new TaskDefinition(BASE_DEFINITION_NAME, "timestamp");

	when(mockTaskDefinitionRepository.findById(BASE_DEFINITION_NAME)).thenReturn(Optional.of(taskDefinition));
	when(mockAppRegistryService.getAppResource(any())).thenReturn(new DockerResource("springcloudtask/timestamp-task:latest"));
	when(mockAppRegistryService.find(taskDefinition.getRegisteredAppName(), ApplicationType.task))
			.thenReturn(new AppRegistration());
	mockSchedulerService.schedule(BASE_SCHEDULE_NAME, BASE_DEFINITION_NAME, this.testProperties,
			commandLineArguments, null);

	ArgumentCaptor<ScheduleRequest> scheduleRequestArgumentCaptor = ArgumentCaptor.forClass(ScheduleRequest.class);
	verify(mockScheduler).schedule(scheduleRequestArgumentCaptor.capture());

	return scheduleRequestArgumentCaptor.getValue().getCommandlineArguments();
}
 
Example #7
Source File: DefaultSchedulerServiceMultiplatformTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskPlatform taskCFPlatform(Scheduler scheduler) {
	Launcher launcher = new Launcher(KUBERNETES_PLATFORM, "Kubernetes", Mockito.mock(TaskLauncher.class), scheduler);
	List<Launcher> launchers = new ArrayList<>();
	launchers.add(launcher);
	TaskPlatform taskPlatform = new TaskPlatform(KUBERNETES_PLATFORM, launchers);
	return taskPlatform;
}
 
Example #8
Source File: KubernetesTaskPlatformFactory.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Scheduler getScheduler(Optional<KubernetesSchedulerProperties> kubernetesSchedulerProperties,
		KubernetesClient kubernetesClient) {
	Scheduler scheduler = null;

	if (schedulesEnabled) {
		KubernetesSchedulerProperties schedulerProperties = kubernetesSchedulerProperties
				.orElseGet(KubernetesSchedulerProperties::new);
		scheduler = new KubernetesScheduler(kubernetesClient, schedulerProperties);
	}

	return scheduler;
}
 
Example #9
Source File: SpringCloudSchedulerIntegrationTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public Scheduler scheduler(ReactorSchedulerClient client,
		CloudFoundryOperations operations,
		CloudFoundryConnectionProperties properties,
		TaskLauncher taskLauncher,
		CloudFoundrySchedulerProperties schedulerProperties) {
	return new CloudFoundryAppScheduler(client, operations, properties,
			(CloudFoundryTaskLauncher) taskLauncher,
			schedulerProperties);
}
 
Example #10
Source File: DefaultSchedulerServiceMultiplatformTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private List<String> getCommandLineArguments(List<String> commandLineArguments) {
	Scheduler mockScheduler = mock(SimpleTestScheduler.class);
	TaskDefinitionRepository mockTaskDefinitionRepository = mock(TaskDefinitionRepository.class);
	AppRegistryService mockAppRegistryService = mock(AppRegistryService.class);

	Launcher launcher = new Launcher("default", "defaultType", null, mockScheduler);
	List<Launcher> launchers = new ArrayList<>();
	launchers.add(launcher);
	List<TaskPlatform> taskPlatform = Collections.singletonList(new TaskPlatform("testTaskPlatform", launchers));
	SchedulerService mockSchedulerService = new DefaultSchedulerService(mock(CommonApplicationProperties.class),
			taskPlatform, mockTaskDefinitionRepository, mockAppRegistryService, mock(ResourceLoader.class),
			this.taskConfigurationProperties, mock(DataSourceProperties.class), "uri",
			mock(ApplicationConfigurationMetadataResolver.class), mock(SchedulerServiceProperties.class),
			mock(AuditRecordService.class));

	TaskDefinition taskDefinition = new TaskDefinition(BASE_DEFINITION_NAME, "timestamp");

	when(mockTaskDefinitionRepository.findById(BASE_DEFINITION_NAME)).thenReturn(Optional.of(taskDefinition));
	when(mockAppRegistryService.getAppResource(any())).thenReturn(new DockerResource("springcloudtask/timestamp-task:latest"));
	when(mockAppRegistryService.find(taskDefinition.getRegisteredAppName(), ApplicationType.task))
			.thenReturn(new AppRegistration());
	mockSchedulerService.schedule(BASE_SCHEDULE_NAME, BASE_DEFINITION_NAME, this.testProperties,
			commandLineArguments, null);

	ArgumentCaptor<ScheduleRequest> scheduleRequestArgumentCaptor = ArgumentCaptor.forClass(ScheduleRequest.class);
	verify(mockScheduler).schedule(scheduleRequestArgumentCaptor.capture());

	return scheduleRequestArgumentCaptor.getValue().getCommandlineArguments();
}
 
Example #11
Source File: SchedulerPerPlatformTest.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalSchedulerEnabled() {
	assertFalse("K8s should be disabled", context.getEnvironment().containsProperty("kubernetes_service_host"));
	assertFalse("CF should be disabled", CloudPlatform.CLOUD_FOUNDRY.isActive(context.getEnvironment()));

	Scheduler scheduler = context.getBean(Scheduler.class);

	assertNotNull(scheduler);
	assertTrue(scheduler.getClass().getName().contains("LocalSchedulerAutoConfiguration"));
}
 
Example #12
Source File: TaskConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * The default profile is active when no other profiles are active. This is configured so
 * that several tests will pass without having to explicitly enable the local profile.
 * @param localPlatformProperties the local platform properties
 * @param localScheduler the local scheduler
 *
 * @return the task platform
 */
@Profile({ "local", "default" })
@Bean
public TaskPlatform localTaskPlatform(LocalPlatformProperties localPlatformProperties,
		@Nullable Scheduler localScheduler) {
	TaskPlatform taskPlatform = new LocalTaskPlatformFactory(localPlatformProperties, localScheduler)
			.createTaskPlatform();
	taskPlatform.setPrimary(true);
	return taskPlatform;
}
 
Example #13
Source File: TaskPlatformControllerTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Before
public void setupMockMVC() {
	this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
			.defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)).build();
	Launcher launcher = new Launcher("default", "local", taskLauncher);
	Launcher cfLauncher = new Launcher("cf", "Cloud Foundry", mock(TaskLauncher.class));
	Launcher cfLauncherWithScheduler = new Launcher("cfsched", "Cloud Foundry", mock(TaskLauncher.class), mock(Scheduler.class));
	this.launcherRepository.save(launcher);
	this.launcherRepository.save(cfLauncher);
	this.launcherRepository.save(cfLauncherWithScheduler);
}
 
Example #14
Source File: TaskServiceDependencies.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public Scheduler scheduler() {
	return new SimpleTestScheduler();
}
 
Example #15
Source File: LocalTaskPlatformFactory.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
public LocalTaskPlatformFactory(LocalPlatformProperties platformProperties, Scheduler localScheduler) {
	super(platformProperties, LOCAL_PLATFORM_TYPE);
	this.localScheduler = localScheduler;
}
 
Example #16
Source File: DataFlowServerConfigurationTests.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public Scheduler scheduler() {
	return mock(Scheduler.class);
}
 
Example #17
Source File: DefaultEnvironmentPostProcessorTests.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public Scheduler scheduler() {
	return mock(Scheduler.class);
}
 
Example #18
Source File: Launcher.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
public Launcher(String name, String type, TaskLauncher taskLauncher, Scheduler scheduler) {
	this.name = name;
	this.type = type;
	this.taskLauncher = taskLauncher;
	this.scheduler = scheduler;
}
 
Example #19
Source File: Launcher.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
public Scheduler getScheduler() {
	return scheduler;
}
 
Example #20
Source File: Launcher.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
public void setScheduler(Scheduler scheduler) {
	this.scheduler = scheduler;
}
 
Example #21
Source File: TestDependencies.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
Scheduler scheduler() {
	return new SimpleTestScheduler();
}
 
Example #22
Source File: KubernetesSchedulerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Override
protected Scheduler provideScheduler() {
	return this.scheduler;
}
 
Example #23
Source File: SchedulerPerPlatformTest.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Test(expected = NoSuchBeanDefinitionException.class)
public void testLocalSchedulerEnabled() {
	assertFalse(context.getEnvironment().containsProperty("kubernetes_service_host"));
	assertFalse(CloudPlatform.CLOUD_FOUNDRY.isActive(context.getEnvironment()));
	context.getBean(Scheduler.class);
}
 
Example #24
Source File: SpringCloudSchedulerIntegrationTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Override
protected Scheduler provideScheduler() {
	return this.scheduler;
}
 
Example #25
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 4 votes vote down vote up
public SchedulerWrapper(Scheduler wrapped) {
	this.wrapped = wrapped;
}
 
Example #26
Source File: KubernetesSchedulerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Bean
public Scheduler scheduler(KubernetesClient kubernetesClient) {
	return new KubernetesScheduler(kubernetesClient, kubernetesSchedulerProperties);
}
 
Example #27
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 2 votes vote down vote up
/**
 * To be implemented by subclasses, which should return the instance of Scheduler that needs
 * to be tested. Can be used if subclasses decide to add additional implementation-specific tests.
 */
protected abstract Scheduler provideScheduler();
 
Example #28
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 2 votes vote down vote up
/**
 * Subclasses should call this method to interact with the Scheduler under test.
 * Returns a wrapper around the scheduler returned by {@link #provideScheduler()}, that keeps
 * track of which tasks have been scheduled and unscheduled.
 */
protected Scheduler taskScheduler() {
	return this.schedulerWrapper;
}