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

The following examples show how to use org.springframework.cloud.deployer.spi.scheduler.CreateScheduleException. 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 6 votes vote down vote up
@Override
public void schedule(ScheduleRequest scheduleRequest) {
	scheduleRequest.setSchedulerProperties(mergeSchedulerProperties(scheduleRequest));
	if(scheduleRequest != null) {
		validateScheduleName(scheduleRequest);
	}
	try {
		createCronJob(scheduleRequest);
	}
	catch (KubernetesClientException e) {
		String invalidCronExceptionMessage = getExceptionMessageForField(e, SCHEDULE_EXPRESSION_FIELD_NAME);

		if (StringUtils.hasText(invalidCronExceptionMessage)) {
			throw new CreateScheduleException(invalidCronExceptionMessage, e);
		}

		throw new CreateScheduleException("Failed to create schedule " + scheduleRequest.getScheduleName(), e);
	}
}
 
Example #2
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidCron() {
	thrown.expect(CreateScheduleException.class);
	thrown.expectMessage("Illegal characters for this position: 'FOO'");

	Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

	mockAppResultsInAppList();
	AppDefinition definition = new AppDefinition("test-application-1", null);
	Map badCronMap = new HashMap<String, String>();
	badCronMap.put(CRON_EXPRESSION, BAD_CRON_EXPRESSION);

	ScheduleRequest request = new ScheduleRequest(definition, badCronMap, null, "test-schedule", resource);

	this.cloudFoundryAppScheduler.schedule(request);

	assertThat(((TestJobs) this.client.jobs()).getCreateJobResponse()).isNull();
}
 
Example #3
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccessJobCreateFailedSchedule() {
	thrown.expect(CreateScheduleException.class);

	Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

	mockAppResultsInAppList();
	AppDefinition definition = new AppDefinition("test-application-1", null);
	Map badCronMap = new HashMap<String, String>();
	badCronMap.put(CRON_EXPRESSION, CRON_EXPRESSION_FOR_SIX_MIN);
	ScheduleRequest request = new ScheduleRequest(definition, badCronMap, null, "test-schedule", resource);

	this.cloudFoundryAppScheduler.schedule(request);

	assertThat(((TestJobs) this.client.jobs()).getCreateJobResponse()).isNull();
}
 
Example #4
Source File: KubernetesScheduler.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
public void validateScheduleName(ScheduleRequest request) {
	if(request.getScheduleName() == null) {
		throw new CreateScheduleException("The name for the schedule request is null", null);
	}
	if(request.getScheduleName().length() > 52) {
		throw new CreateScheduleException(String.format("because Schedule Name: '%s' has too many characters.  Schedule name length must be 52 characters or less", request.getScheduleName()), null);
	}
	if(!Pattern.matches("^[a-z0-9]([-a-z0-9]*[a-z0-9])?$", request.getScheduleName())) {
		throw new CreateScheduleException("Invalid Format for Schedule Name. Schedule name can only contain lowercase letters, numbers 0-9 and hyphens.", null);
	}

}
 
Example #5
Source File: KubernetesSchedulerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test(expected = CreateScheduleException.class)
public void testMissingSchedule() {
	AppDefinition appDefinition = new AppDefinition(randomName(), null);
	ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, null, null, null, null, testApplication());

	scheduler.schedule(scheduleRequest);

	fail();
}
 
Example #6
Source File: KubernetesSchedulerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test(expected = CreateScheduleException.class)
public void testInvalidNameSchedule() {
	AppDefinition appDefinition = new AppDefinition("AAAAAA", null);
	ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, null, null, null, "AAAAA", testApplication());

	scheduler.schedule(scheduleRequest);

	fail();
}
 
Example #7
Source File: KubernetesSchedulerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test(expected = CreateScheduleException.class)
public void testInvalidCronSyntax() {
	Map<String, String> schedulerProperties = Collections.singletonMap(CRON_EXPRESSION, "1 2 3 4");

	AppDefinition appDefinition = new AppDefinition(randomName(), null);
	ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, schedulerProperties, null, null,
			randomName(), testApplication());

	scheduler.schedule(scheduleRequest);

	fail();
}
 
Example #8
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateSchedule() {
	ScheduleRequest request = createScheduleRequest();
	taskScheduler().schedule(request);
	ScheduleInfo scheduleInfo = new ScheduleInfo();
	scheduleInfo.setScheduleName(request.getScheduleName());

	this.expectedException.expect(CreateScheduleException.class);
	this.expectedException.expectMessage(String.format("Failed to create schedule %s", request.getScheduleName()));

	verifySchedule(scheduleInfo);
	taskScheduler().schedule(request);
}
 
Example #9
Source File: AbstractSchedulerIntegrationTests.java    From spring-cloud-deployer with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCronExpression() {
	final String INVALID_EXPRESSION = "BAD";
	String definitionName = randomName();
	String scheduleName = scheduleName() + definitionName;
	Map<String, String> properties = new HashMap<>(getSchedulerProperties());
	properties.put(SchedulerPropertyKeys.CRON_EXPRESSION, INVALID_EXPRESSION);
	AppDefinition definition = new AppDefinition(definitionName, properties);
	ScheduleRequest request = new ScheduleRequest(definition, properties, getDeploymentProperties(), getCommandLineArgs(), scheduleName, testApplication());
	this.expectedException.expect(CreateScheduleException.class);

	taskScheduler().schedule(request);
}
 
Example #10
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 #11
Source File: CloudFoundryAppSchedulerTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameTooLong() {
	thrown.expect(CreateScheduleException.class);
	thrown.expectMessage("Schedule can not be created because its name " +
			"'j1-scdf-itcouldbesaidthatthisislongtoowaytoo-oopsitcouldbesaidthatthisis" +
			"longtoowaytoo-oopsitcouldbesaidthatthisislongtoowaytoo-oopsitcouldbe" +
			"saidthatthisislongtoowaytoo-oopsitcouldbesaidthatthisislongtoowaytoo-" +
			"oopsitcouldbesaidthatthisislongtoowaytoo-oops12' has too many characters.  " +
			"Schedule name length must be 255 characters or less");

	Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar");

	mockAppResultsInAppList();
	AppDefinition definition = new AppDefinition("test-application-1", null);
	Map cronMap = new HashMap<String, String>();
	cronMap.put(CRON_EXPRESSION, DEFAULT_CRON_EXPRESSION);

	ScheduleRequest request = new ScheduleRequest(definition, cronMap, null,
			"j1-scdf-itcouldbesaidthatthisislongtoowaytoo-oopsitcouldbesaidthatthisis" +
					"longtoowaytoo-oopsitcouldbesaidthatthisislongtoowaytoo-oopsitcouldbe" +
					"saidthatthisislongtoowaytoo-oopsitcouldbesaidthatthisislongtoowaytoo-" +
					"oopsitcouldbesaidthatthisislongtoowaytoo-oops12", resource);

	this.cloudFoundryAppScheduler.schedule(request);

	assertThat(((TestJobs) this.client.jobs()).getCreateJobResponse()).isNull();
}
 
Example #12
Source File: DefaultSchedulerServiceMultiplatformTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test(expected = CreateScheduleException.class)
public void testDuplicate(){
	schedulerService.schedule(BASE_SCHEDULE_NAME + 1, BASE_DEFINITION_NAME,
			this.testProperties, this.commandLineArgs, KUBERNETES_PLATFORM);
	schedulerService.schedule(BASE_SCHEDULE_NAME + 1, BASE_DEFINITION_NAME,
			this.testProperties, this.commandLineArgs, KUBERNETES_PLATFORM);
}
 
Example #13
Source File: DefaultSchedulerServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test(expected = CreateScheduleException.class)
public void testDuplicate(){
	schedulerService.schedule(BASE_SCHEDULE_NAME + 1, BASE_DEFINITION_NAME,
			this.testProperties, this.commandLineArgs);
	schedulerService.schedule(BASE_SCHEDULE_NAME + 1, BASE_DEFINITION_NAME,
			this.testProperties, this.commandLineArgs);
}
 
Example #14
Source File: RestControllerAdvice.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
/**
 * Client did not formulate a correct request. Log the exception message at warn level
 * and stack trace as trace level. Return response status HttpStatus.BAD_REQUEST
 * (400).
 *
 * @param e one of the exceptions, {@link MissingServletRequestParameterException},
 * {@link UnsatisfiedServletRequestParameterException},
 * {@link MethodArgumentTypeMismatchException}, or
 * {@link InvalidStreamDefinitionException}
 * @return the error response in JSON format with media type
 * application/vnd.error+json
 */
@ExceptionHandler({ MissingServletRequestParameterException.class, HttpMessageNotReadableException.class,
		UnsatisfiedServletRequestParameterException.class, MethodArgumentTypeMismatchException.class,
		InvalidDateRangeException.class, CannotDeleteNonParentTaskExecutionException.class,
		InvalidStreamDefinitionException.class, CreateScheduleException.class, OffsetOutOfBoundsException.class,
		TaskExecutionMissingExternalIdException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public VndErrors onClientGenericBadRequest(Exception e) {
	String logref = logWarnLevelExceptionMessage(e);
	if (logger.isTraceEnabled()) {
		logTraceLevelStrackTrace(e);
	}

	String message = null;
	if (e instanceof MethodArgumentTypeMismatchException) {
		final MethodArgumentTypeMismatchException methodArgumentTypeMismatchException = (MethodArgumentTypeMismatchException) e;
		final Class<?> requiredType = methodArgumentTypeMismatchException.getRequiredType();

		final Class<?> enumType;

		if (requiredType.isEnum()) {
			enumType = requiredType;
		}
		else if (requiredType.isArray() && requiredType.getComponentType().isEnum()) {
			enumType = requiredType.getComponentType();
		}
		else {
			enumType = null;
		}

		if (enumType != null) {
			final String enumValues = StringUtils.arrayToDelimitedString(enumType.getEnumConstants(), ", ");
			message = String.format("The parameter '%s' must contain one of the following values: '%s'.", methodArgumentTypeMismatchException.getName(), enumValues);
		}
	}

	if (message == null) {
		message = getExceptionMessage(e);
	}

	return new VndErrors(logref, message);
}