if (job.getInstanceCount() <= 0) {
throw new TaskDescriptionException("Shard count must be positive.");
}
JobConfiguration builder = job.newBuilder();
assertOwnerValidity(job.getOwner());
if (!JobKeys.isValid(job.getKey())) {
throw new TaskDescriptionException("Job key " + job.getKey() + " is invalid.");
}
if (!job.getKey().getRole().equals(job.getOwner().getRole())) {
throw new TaskDescriptionException("Role in job key must match job owner.");
}
if (!isGoodIdentifier(job.getKey().getRole())) {
throw new TaskDescriptionException(
"Job role contains illegal characters: " + job.getKey().getRole());
}
if (!isGoodIdentifier(job.getKey().getEnvironment())) {
throw new TaskDescriptionException(
"Job environment contains illegal characters: " + job.getKey().getEnvironment());
}
if (!isGoodIdentifier(job.getKey().getName())) {
throw new TaskDescriptionException(
"Job name contains illegal characters: " + job.getKey().getName());
}
builder.setTaskConfig(
validateAndPopulate(ITaskConfig.build(builder.getTaskConfig())).newBuilder());
// Only one of [service=true, cron_schedule] may be set.
if (!StringUtils.isEmpty(job.getCronSchedule()) && builder.getTaskConfig().isIsService()) {
throw new TaskDescriptionException(
"A service task may not be run on a cron schedule: " + builder);
}
return IJobConfiguration.build(builder);