Skip to content

Commit

Permalink
fix(pipeline_template): Catch template load errors on pipeline save (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert authored Sep 6, 2017
1 parent c2a4d72 commit b1a8a56
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.orca.front50.PipelineModelMutator;
import com.netflix.spinnaker.orca.pipelinetemplate.exceptions.TemplateLoaderException;
import com.netflix.spinnaker.orca.pipelinetemplate.loader.TemplateLoader;
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.NamedHashMap;
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.PipelineTemplate;
Expand All @@ -27,6 +28,8 @@
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.render.RenderContext;
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.render.RenderUtil;
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.render.Renderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
Expand All @@ -39,6 +42,8 @@
*/
public class TemplatedPipelineModelMutator implements PipelineModelMutator {

private final static Logger log = LoggerFactory.getLogger(TemplatedPipelineModelMutator.class);

private final ObjectMapper pipelineTemplateObjectMapper;
private final TemplateLoader templateLoader;
private final Renderer renderer;
Expand All @@ -65,7 +70,9 @@ public void mutate(Map<String, Object> pipeline) {
// Dynamically sourced templates don't support configuration inheritance.
if (!sourceContainsExpressions(configuration)) {
template = getPipelineTemplate(configuration);
applyConfigurationsFromTemplate(configuration.getConfiguration(), template.getConfiguration(), pipeline);
if (template != null) {
applyConfigurationsFromTemplate(configuration.getConfiguration(), template.getConfiguration(), pipeline);
}
}

mapPipelineConfigId(pipeline, configuration);
Expand Down Expand Up @@ -173,7 +180,11 @@ private boolean sourceContainsExpressions(TemplateConfiguration configuration) {
}

private PipelineTemplate getPipelineTemplate(TemplateConfiguration configuration) {
List<PipelineTemplate> templates = templateLoader.load(configuration.getPipeline().getTemplate());
return TemplateMerge.merge(templates);
try {
return TemplateMerge.merge(templateLoader.load(configuration.getPipeline().getTemplate()));
} catch (TemplateLoaderException e) {
log.error("Could not load template: {}", configuration.getPipeline().getTemplate(), e);
return null;
}
}
}

0 comments on commit b1a8a56

Please sign in to comment.