use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline 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.api.model.pipeline.Pipeline in project front50 by spinnaker.
the class PipelineController method checkForStalePipeline.
private void checkForStalePipeline(Pipeline pipeline, ValidatorErrors errors) {
Pipeline existingPipeline = pipelineDAO.findById(pipeline.getId());
Long storedUpdateTs = existingPipeline.getLastModified();
Long submittedUpdateTs = pipeline.getLastModified();
if (!submittedUpdateTs.equals(storedUpdateTs)) {
errors.reject("The submitted pipeline is stale. submitted updateTs " + submittedUpdateTs + " does not match stored updateTs " + storedUpdateTs);
}
}
use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline in project front50 by spinnaker.
the class PipelineController method listByApplication.
@PreAuthorize("hasPermission(#application, 'APPLICATION', 'READ')")
@RequestMapping(value = "{application:.+}", method = RequestMethod.GET)
public List<Pipeline> listByApplication(@PathVariable(value = "application") String application, @RequestParam(required = false, value = "refresh", defaultValue = "true") boolean refresh) {
List<Pipeline> pipelines = new ArrayList<>(pipelineDAO.getPipelinesByApplication(application, refresh));
pipelines.sort((p1, p2) -> {
if (p1.getIndex() != null && p2.getIndex() == null) {
return -1;
}
if (p1.getIndex() == null && p2.getIndex() != null) {
return 1;
}
if (p1.getIndex() != null && p2.getIndex() != null && !p1.getIndex().equals(p2.getIndex())) {
return p1.getIndex() - p2.getIndex();
}
return Optional.ofNullable(p1.getName()).orElse(p1.getId()).compareToIgnoreCase(Optional.ofNullable(p2.getName()).orElse(p2.getId()));
});
int i = 0;
for (Pipeline p : pipelines) {
p.setIndex(i);
i++;
}
return pipelines;
}
use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline in project front50 by spinnaker.
the class PipelineController method update.
@PreAuthorize("hasPermission(#pipeline.application, 'APPLICATION', 'WRITE')")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Pipeline update(@PathVariable final String id, @RequestParam(value = "staleCheck", required = false, defaultValue = "false") Boolean staleCheck, @RequestBody Pipeline pipeline) {
Pipeline existingPipeline = pipelineDAO.findById(id);
if (!pipeline.getId().equals(existingPipeline.getId())) {
throw new InvalidRequestException(format("The provided id %s doesn't match the pipeline id %s", pipeline.getId(), existingPipeline.getId()));
}
validatePipeline(pipeline, staleCheck);
pipeline.setName(pipeline.getName().trim());
pipeline.setLastModified(System.currentTimeMillis());
pipeline = ensureCronTriggersHaveIdentifier(pipeline);
pipelineDAO.update(id, pipeline);
return pipeline;
}
use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline in project front50 by spinnaker.
the class PipelineTemplateController method getDependentConfigs.
@VisibleForTesting
List<String> getDependentConfigs(String templateId, boolean recursive) {
List<String> dependentConfigIds = new ArrayList<>();
List<String> templateIds = convertAllTemplateIdsToSources(templateId, recursive);
pipelineDAO.all().stream().filter(pipeline -> pipeline.getType() != null && pipeline.getType().equals(TYPE_TEMPLATED)).forEach(templatedPipeline -> {
String source;
try {
TemplateConfiguration config = objectMapper.convertValue(templatedPipeline.getConfig(), TemplateConfiguration.class);
source = config.getPipeline().getTemplate().getSource();
} catch (Exception e) {
return;
}
if (source != null && containsAnyIgnoreCase(source, templateIds)) {
dependentConfigIds.add(templatedPipeline.getId());
}
});
return dependentConfigIds;
}
Aggregations