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

The following examples show how to use org.springframework.cloud.deployer.spi.scheduler.SchedulerException. 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: KubernetesScheduler.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public void unschedule(String scheduleName) {
	boolean unscheduled = this.client.batch().cronjobs().withName(scheduleName).delete();

	if (!unscheduled) {
		throw new SchedulerException("Failed to unschedule schedule " + scheduleName + " does not exist.");
	}
}
 
Example #2
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnScheduleNoEntry() {
	String definitionName = randomName();
	String scheduleName = scheduleName() + definitionName;

	this.expectedException.expect(SchedulerException.class);
	this.expectedException.expectMessage(String.format("Failed to unschedule schedule %s does not exist.",
			scheduleName));
	unscheduleTestSchedule(scheduleName);
}
 
Example #3
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Override
public List<ScheduleInfo> list() {
	List<ScheduleInfo> result = new ArrayList<>();
	for (int i = PCF_PAGE_START_NUM; i <= getJobPageCount(); i++) {
		List<ScheduleInfo> scheduleInfoPage = getSchedules(i)
				.collectList()
				.block(Duration.ofSeconds(schedulerProperties.getListTimeoutInSeconds()));
		if(scheduleInfoPage == null) {
			throw new SchedulerException(SCHEDULER_SERVICE_ERROR_MESSAGE);
		}
		result.addAll(scheduleInfoPage);
	}
	return result;
}
 
Example #4
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * Schedules the job for the application.
 * @param appName The name of the task app to be scheduled.
 * @param scheduleName the name of the schedule.
 * @param expression the cron expression.
 * @param command the command returned from the staging.
 */
private void scheduleTask(String appName, String scheduleName,
		String expression, String command) {
	logger.debug(String.format("Scheduling Task: ", appName));
	ScheduleJobResponse response = getApplicationByAppName(appName)
			.flatMap(abstractApplicationSummary -> {
				return this.client.jobs().create(CreateJobRequest.builder()
						.applicationId(abstractApplicationSummary.getId()) // App GUID
						.command(command)
						.name(scheduleName)
						.build());
			}).flatMap(createJobResponse -> {
		return this.client.jobs().schedule(ScheduleJobRequest.
				builder().
				jobId(createJobResponse.getId()).
				expression(expression).
				expressionType(ExpressionType.CRON).
				enabled(true).
				build());
	})
			.onErrorMap(e -> {
				if (e instanceof SSLException) {
					throw new CloudFoundryScheduleSSLException("Failed to schedule" + scheduleName, e);
				}
				else {
					throw new CreateScheduleException(scheduleName, e);
				}
			})
			.block(Duration.ofSeconds(schedulerProperties.getScheduleTimeoutInSeconds()));
	if(response == null) {
		throw new SchedulerException(SCHEDULER_SERVICE_ERROR_MESSAGE);
	}
}
 
Example #5
Source File: CloudFoundryAppScheduler.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the number of pages that can be returned when retrieving a list of jobs.
 * @return an int containing the number of available pages.
 */
private int getJobPageCount() {
	ListJobsResponse response = this.getSpace(this.properties.getSpace()).flatMap(requestSummary -> {
		return this.client.jobs().list(ListJobsRequest.builder()
				.spaceId(requestSummary.getId())
				.detailed(false).build());
	}).block();
	if(response == null) {
		throw new SchedulerException(SCHEDULER_SERVICE_ERROR_MESSAGE);
	}
	return response.getPagination().getTotalPages();
}
 
Example #6
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void testMissingScheduleDelete() {
	boolean exceptionFired = false;
	setupMockResults();
	try {
		this.cloudFoundryAppScheduler.unschedule("test-job-name-3");
	}
	catch (SchedulerException se) {
		assertThat(se.getMessage()).isEqualTo("Failed to unschedule schedule test-job-name-3 does not exist.");
		exceptionFired = true;
	}
	assertThat(exceptionFired).isTrue();
}
 
Example #7
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoServiceCreate() {
	thrown.expect(SchedulerException.class);
	thrown.expectMessage("Scheduler Service returned a null response.");
	Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

	mockAppResultsInAppList();
	AppDefinition definition = new AppDefinition("test-application-1", null);
	ScheduleRequest request = new ScheduleRequest(definition, getDefaultScheduleProperties(), null, "test-schedule", resource);

	this.noServiceCloudFoundryAppScheduler.schedule(request);
}
 
Example #8
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoServiceList() {
	thrown.expect(SchedulerException.class);
	thrown.expectMessage("Scheduler Service returned a null response.");
	this.noServiceCloudFoundryAppScheduler.list();
}
 
Example #9
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoServiceListSchedulesWithAppName() {
	thrown.expect(SchedulerException.class);
	thrown.expectMessage("Scheduler Service returned a null response.");
	this.noServiceCloudFoundryAppScheduler.list("test-application-2");
}