use of com.netflix.spinnaker.front50.exception.ValidationException in project front50 by spinnaker.
the class PluginInfoService method validate.
private void validate(PluginInfo pluginInfo) {
Errors errors = new GenericValidationErrors(pluginInfo);
validators.forEach(v -> v.validate(pluginInfo, errors));
if (errors.hasErrors()) {
throw new ValidationException(errors);
}
}
use of com.netflix.spinnaker.front50.exception.ValidationException 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());
}
}
use of com.netflix.spinnaker.front50.exception.ValidationException in project front50 by spinnaker.
the class ApplicationService method validate.
private void validate(Application application) {
ApplicationValidationErrors errors = new ApplicationValidationErrors(application);
validators.forEach(v -> v.validate(application, errors));
if (errors.hasErrors()) {
throw new ValidationException(errors);
}
}
Aggregations