* @throws TaskDescriptionException If the task is invalid.
*/
public static ITaskConfig validateAndPopulate(ITaskConfig config)
throws TaskDescriptionException {
TaskConfig builder = config.newBuilder();
if (!builder.isSetRequestedPorts()) {
builder.setRequestedPorts(ImmutableSet.<String>of());
}
maybeFillLinks(builder);
if (!isGoodIdentifier(config.getJobName())) {
throw new TaskDescriptionException(
"Job name contains illegal characters: " + config.getJobName());
}
if (!isGoodIdentifier(config.getEnvironment())) {
throw new TaskDescriptionException(
"Environment contains illegal characters: " + config.getEnvironment());
}
if (config.isSetJob()) {
if (!JobKeys.isValid(config.getJob())) {
// Job key is set but invalid
throw new TaskDescriptionException("Job key " + config.getJob() + " is invalid.");
}
if (!config.getJob().getRole().equals(config.getOwner().getRole())) {
// Both owner and job key are set but don't match
throw new TaskDescriptionException("Role must match job owner.");
}
} else {
// TODO(maxim): Make sure both key and owner are populated to support older clients.
// Remove in 0.7.0. (AURORA-749).
// Job key is not set -> populate from owner, environment and name
assertOwnerValidity(config.getOwner());
builder.setJob(JobKeys.from(
config.getOwner().getRole(),
config.getEnvironment(),
config.getJobName()).newBuilder());
}
if (!builder.isSetExecutorConfig()) {
throw new TaskDescriptionException("Configuration may not be null");
}
// Maximize the usefulness of any thrown error message by checking required fields first.
for (RequiredFieldValidator<?> validator : REQUIRED_FIELDS_VALIDATORS) {