Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meaningful message returned if schedule name too long #354

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import javax.validation.ConstraintViolationException;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Test;
Expand Down Expand Up @@ -228,6 +229,30 @@ public void testInvalidCronSyntax() {
fail();
}

@Test
public void testNameTooLong() {
final String baseScheduleName = "tencharlng-scdf-itcouldbesaidthatthisislongtoowaytoo";
Map<String, String> schedulerProperties = Collections.singletonMap(CRON_EXPRESSION, "0/10 * * * *");

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

//verify no validation fired.
scheduler.schedule(scheduleRequest);

scheduleRequest = new ScheduleRequest(appDefinition, schedulerProperties, null, null,
baseScheduleName + "1", testApplication());
try {
scheduler.schedule(scheduleRequest);
}
catch (CreateScheduleException createScheduleException) {
assertThat(createScheduleException.getMessage()).isEqualTo(String.format("Failed to create schedule because Schedule Name: '%s' has too many characters. Schedule name length must be 52 characters or less", baseScheduleName + "1"));
return;
}
fail();
}

@Test
public void testWithExecEntryPoint() {
KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties();
Expand Down