From ef91d0cc84893924a740442dc443420f6a1ca1c4 Mon Sep 17 00:00:00 2001 From: Rob Fletcher Date: Thu, 5 Apr 2018 16:36:22 -0700 Subject: [PATCH] chore(kayenta): use StageGraphBuilder.append where it's simpler --- ...TargetServerGroupLinearStageSupport.groovy | 24 +++++++------------ .../orca/mine/pipeline/CanaryStage.groovy | 5 ++-- .../com/netflix/spinnaker/orca/q/Stages.kt | 8 +++---- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/support/TargetServerGroupLinearStageSupport.groovy b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/support/TargetServerGroupLinearStageSupport.groovy index 153f4287ae..87dfc9ebc6 100644 --- a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/support/TargetServerGroupLinearStageSupport.groovy +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servergroup/support/TargetServerGroupLinearStageSupport.groovy @@ -151,19 +151,11 @@ abstract class TargetServerGroupLinearStageSupport implements StageDefinitionBui def targets = resolver.resolveByParams(params) def descriptionList = buildStaticTargetDescriptions(stage, targets) - descriptionList.inject(null) { Stage previous, Map description -> - if (previous == null) { - graph.add { - it.type = type - it.name = name - it.context = description - } - } else { - graph.connect(previous) { - it.type = type - it.name = name - it.context = description - } + descriptionList.each { Map description -> + graph.append { + it.type = type + it.name = name + it.context = description } } } @@ -180,15 +172,15 @@ abstract class TargetServerGroupLinearStageSupport implements StageDefinitionBui def singularLocationType = params.locations[0].singularType() def pluralLocationType = params.locations[0].pluralType() - def determineTargetServerGroups = graph.add { + graph.add { it.type = DetermineTargetServerGroupStage.PIPELINE_CONFIG_TYPE it.name = DetermineTargetServerGroupStage.PIPELINE_CONFIG_TYPE it.context.putAll(stage.context) it.context[pluralLocationType] = params.locations.collect { it.value } } - params.locations.inject(determineTargetServerGroups) { Stage previous, Location location -> - graph.connect(previous) { + params.locations.each { Location location -> + graph.append { it.type = type it.name = name it.context.putAll(stage.context) diff --git a/orca-mine/src/main/groovy/com/netflix/spinnaker/orca/mine/pipeline/CanaryStage.groovy b/orca-mine/src/main/groovy/com/netflix/spinnaker/orca/mine/pipeline/CanaryStage.groovy index 4a8afcc1ee..9f91e4cec3 100644 --- a/orca-mine/src/main/groovy/com/netflix/spinnaker/orca/mine/pipeline/CanaryStage.groovy +++ b/orca-mine/src/main/groovy/com/netflix/spinnaker/orca/mine/pipeline/CanaryStage.groovy @@ -21,7 +21,6 @@ import javax.annotation.Nonnull import com.netflix.frigga.autoscaling.AutoScalingGroupNameBuilder import com.netflix.spinnaker.kork.core.RetrySupport import com.netflix.spinnaker.orca.CancellableStage -import com.netflix.spinnaker.orca.CancellableStage.Result import com.netflix.spinnaker.orca.clouddriver.KatoService import com.netflix.spinnaker.orca.clouddriver.tasks.servergroup.DestroyServerGroupTask import com.netflix.spinnaker.orca.clouddriver.utils.OortHelper @@ -55,12 +54,12 @@ class CanaryStage implements StageDefinitionBuilder, CancellableStage { Map deployContext = canaryStageId + parent.context Map monitorContext = canaryStageId + [scaleUp: parent.context.scaleUp ?: [:]] - def deployCanaryStage = graph.add { + graph.append { it.type = deployCanaryStage.type it.name = "Deploy Canary" it.context = deployContext } - graph.connect(deployCanaryStage) { + graph.append { it.type = monitorCanaryStage.type it.name = "Monitor Canary" it.context = monitorContext diff --git a/orca-queue-tck/src/main/kotlin/com/netflix/spinnaker/orca/q/Stages.kt b/orca-queue-tck/src/main/kotlin/com/netflix/spinnaker/orca/q/Stages.kt index 4dbfbb4402..8f5a83c1d7 100644 --- a/orca-queue-tck/src/main/kotlin/com/netflix/spinnaker/orca/q/Stages.kt +++ b/orca-queue-tck/src/main/kotlin/com/netflix/spinnaker/orca/q/Stages.kt @@ -66,12 +66,12 @@ val stageWithSyntheticOnFailure = object : StageDefinitionBuilder { } override fun onFailureStages(stage: Stage, graph: StageGraphBuilder) { - val stage1 = graph.add { + graph.append { it.type = singleTaskStage.type it.name = "onFailure1" it.context = stage.context } - graph.connect(stage1) { + graph.append { it.type = singleTaskStage.type it.name = "onFailure2" it.context = stage.context @@ -103,12 +103,12 @@ val stageWithSyntheticAfter = object : StageDefinitionBuilder { } override fun afterStages(parent: Stage, graph: StageGraphBuilder) { - val first = graph.add { + graph.append { it.type = singleTaskStage.type it.name = "post1" it.context = parent.context } - graph.connect(first) { + graph.append { it.type = singleTaskStage.type it.name = "post2" it.context = parent.context