From 6500bcf37c372774411a361ab971266ddbeba07f Mon Sep 17 00:00:00 2001 From: Daniel Peach Date: Fri, 25 Aug 2017 11:09:48 -0400 Subject: [PATCH] fix(pipeline_templates): notification inheritance (#1576) --- .../v1schema/V1SchemaExecutionGenerator.java | 21 ++++++++++- .../V1SchemaExecutionGeneratorSpec.groovy | 37 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java b/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java index ff0c697d2d..137a19d295 100644 --- a/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java +++ b/orca-pipelinetemplate/src/main/java/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGenerator.java @@ -46,14 +46,14 @@ public Map generate(PipelineTemplate template, TemplateConfigura pipeline.put("parallel", true); pipeline.put("limitConcurrent", true); pipeline.put("keepWaitingPipelines", false); - pipeline.put("notifications", Collections.emptyList()); } else { pipeline.put("parallel", c.getConcurrentExecutions().getOrDefault("parallel", true)); pipeline.put("limitConcurrent", c.getConcurrentExecutions().getOrDefault("limitConcurrent", true)); pipeline.put("keepWaitingPipelines", c.getConcurrentExecutions().getOrDefault("keepWaitingPipelines", false)); - pipeline.put("notifications", c.getNotifications()); } + addNotifications(pipeline, template, configuration); + pipeline.put("stages", template.getStages() .stream() .map(s -> { @@ -70,4 +70,21 @@ public Map generate(PipelineTemplate template, TemplateConfigura return pipeline; } + + private void addNotifications(Map pipeline, PipelineTemplate template, TemplateConfiguration configuration) { + if (configuration.getConfiguration().getInherit().contains("notifications")) { + pipeline.put( + "notifications", + TemplateMerge.mergeNamedContent( + template.getConfiguration().getNotifications(), + configuration.getConfiguration().getNotifications() + ) + ); + } else { + pipeline.put( + "notifications", + Optional.ofNullable(configuration.getConfiguration().getNotifications()).orElse(Collections.emptyList()) + ); + } + } } diff --git a/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGeneratorSpec.groovy b/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGeneratorSpec.groovy index 3b204c8e98..00077d44aa 100644 --- a/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGeneratorSpec.groovy +++ b/orca-pipelinetemplate/src/test/groovy/com/netflix/spinnaker/orca/pipelinetemplate/v1schema/V1SchemaExecutionGeneratorSpec.groovy @@ -84,6 +84,36 @@ class V1SchemaExecutionGeneratorSpec extends Specification { "124" | [application: 'orca'] || "124" } + @Unroll + def "should set notifications in execution json"() { + given: + PipelineTemplate template = getPipelineTemplate() + TemplateConfiguration configuration = new TemplateConfiguration( + pipeline: new PipelineDefinition([application: 'orca', pipelineConfigId: 'pipelineConfigId']), + configuration: new TemplateConfiguration.PipelineConfiguration( + inherit: inherit, + notifications: [ + new NamedHashMap().with { + put('name', 'configuration-notification') + put('address', 'email-from-configuration@spinnaker.io') + it + } + ] + ) + ) + + when: + def result = subject.generate(template, configuration, "pipelineConfigId") + + then: + result.notifications*.address == addresses + + where: + inherit || addresses + ['notifications'] || ['email-from-template@spinnaker.io', 'email-from-configuration@spinnaker.io'] + [] || ['email-from-configuration@spinnaker.io'] + } + private PipelineTemplate getPipelineTemplate() { new PipelineTemplate( id: 'simpleTemplate', @@ -99,6 +129,13 @@ class V1SchemaExecutionGeneratorSpec extends Specification { put('enabled', true) it } + ], + notifications: [ + new NamedHashMap().with { + put('name', 'template-notification') + put('address', 'email-from-template@spinnaker.io') + it + } ] ), stages: [