Search in sources :

Example 1 with TYPE_TEMPLATED

use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline.TYPE_TEMPLATED 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;
}
Also used : PipelineTemplate(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) PipelineDAO(com.netflix.spinnaker.front50.model.pipeline.PipelineDAO) PipelineTemplateDAO(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) BadRequestException(com.netflix.spinnaker.front50.exception.BadRequestException) InvalidEntityException(com.netflix.spinnaker.front50.exceptions.InvalidEntityException) TYPE_TEMPLATED(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline.TYPE_TEMPLATED) DuplicateEntityException(com.netflix.spinnaker.front50.exceptions.DuplicateEntityException) TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) SPINNAKER_PREFIX(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration.TemplateSource.SPINNAKER_PREFIX) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) ArrayList(java.util.ArrayList) TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) BadRequestException(com.netflix.spinnaker.front50.exception.BadRequestException) InvalidEntityException(com.netflix.spinnaker.front50.exceptions.InvalidEntityException) DuplicateEntityException(com.netflix.spinnaker.front50.exceptions.DuplicateEntityException) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with TYPE_TEMPLATED

use of com.netflix.spinnaker.front50.api.model.pipeline.Pipeline.TYPE_TEMPLATED in project front50 by spinnaker.

the class V2PipelineTemplateController method getDependentConfigs.

@VisibleForTesting
List<String> getDependentConfigs(String templateId) {
    List<String> dependentConfigIds = new ArrayList<>();
    String prefixedId = SPINNAKER_PREFIX + templateId;
    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 && source.equalsIgnoreCase(prefixedId)) {
            dependentConfigIds.add(templatedPipeline.getId());
        }
    });
    return dependentConfigIds;
}
Also used : PipelineTemplate(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate) PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) PipelineDAO(com.netflix.spinnaker.front50.model.pipeline.PipelineDAO) PipelineTemplateDAO(com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO) MessageDigest(java.security.MessageDigest) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Hex(org.apache.commons.codec.binary.Hex) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) BadRequestException(com.netflix.spinnaker.front50.exception.BadRequestException) Map(java.util.Map) InvalidEntityException(com.netflix.spinnaker.front50.exceptions.InvalidEntityException) TYPE_TEMPLATED(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline.TYPE_TEMPLATED) DuplicateEntityException(com.netflix.spinnaker.front50.exceptions.DuplicateEntityException) TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TreeMap(java.util.TreeMap) SPINNAKER_PREFIX(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration.TemplateSource.SPINNAKER_PREFIX) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) ArrayList(java.util.ArrayList) TemplateConfiguration(com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) BadRequestException(com.netflix.spinnaker.front50.exception.BadRequestException) InvalidEntityException(com.netflix.spinnaker.front50.exceptions.InvalidEntityException) DuplicateEntityException(com.netflix.spinnaker.front50.exceptions.DuplicateEntityException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Pipeline (com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)2 TYPE_TEMPLATED (com.netflix.spinnaker.front50.api.model.pipeline.Pipeline.TYPE_TEMPLATED)2 BadRequestException (com.netflix.spinnaker.front50.exception.BadRequestException)2 DuplicateEntityException (com.netflix.spinnaker.front50.exceptions.DuplicateEntityException)2 InvalidEntityException (com.netflix.spinnaker.front50.exceptions.InvalidEntityException)2 InvalidRequestException (com.netflix.spinnaker.front50.exceptions.InvalidRequestException)2 PipelineDAO (com.netflix.spinnaker.front50.model.pipeline.PipelineDAO)2 PipelineTemplate (com.netflix.spinnaker.front50.model.pipeline.PipelineTemplate)2 PipelineTemplateDAO (com.netflix.spinnaker.front50.model.pipeline.PipelineTemplateDAO)2 TemplateConfiguration (com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration)2 SPINNAKER_PREFIX (com.netflix.spinnaker.front50.model.pipeline.TemplateConfiguration.TemplateSource.SPINNAKER_PREFIX)2 NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 PathVariable (org.springframework.web.bind.annotation.PathVariable)2