use of com.netflix.spinnaker.front50.model.pipeline.V2TemplateConfiguration in project front50 by spinnaker.
the class PipelineController method validatePipeline.
/**
* Ensure basic validity of the pipeline. Invalid pipelines will raise runtime exceptions.
*
* @param pipeline The Pipeline to validate
*/
private void validatePipeline(final Pipeline pipeline, Boolean staleCheck) {
// Pipelines must have an application and a name
if (StringUtils.isAnyBlank(pipeline.getApplication(), pipeline.getName())) {
throw new InvalidEntityException("A pipeline requires name and application fields");
}
// Check if pipeline type is templated
if (TYPE_TEMPLATED.equals(pipeline.getType())) {
PipelineTemplateDAO templateDAO = getTemplateDAO();
// Check templated pipelines to ensure template is valid
String source;
switch(pipeline.getSchema()) {
case "v2":
V2TemplateConfiguration v2Config = objectMapper.convertValue(pipeline, V2TemplateConfiguration.class);
source = v2Config.getTemplate().getReference();
break;
default:
TemplateConfiguration v1Config = objectMapper.convertValue(pipeline.getConfig(), TemplateConfiguration.class);
source = v1Config.getPipeline().getTemplate().getSource();
break;
}
// Check if template id which is after :// is in the store
if (source.startsWith(SPINNAKER_PREFIX)) {
String templateId = source.substring(SPINNAKER_PREFIX.length());
try {
templateDAO.findById(templateId);
} catch (NotFoundException notFoundEx) {
throw new BadRequestException("Configured pipeline template not found", notFoundEx);
}
}
}
checkForDuplicatePipeline(pipeline.getApplication(), pipeline.getName().trim(), pipeline.getId());
final ValidatorErrors errors = new ValidatorErrors();
pipelineValidators.forEach(it -> it.validate(pipeline, errors));
if (staleCheck && !Strings.isNullOrEmpty(pipeline.getId()) && pipeline.getLastModified() != null) {
checkForStalePipeline(pipeline, errors);
}
if (errors.hasErrors()) {
String message = errors.getAllErrorsMessage();
throw new ValidationException(message, errors.getAllErrors());
}
}
Aggregations