Skip to content

Commit

Permalink
refactor(model): unify stage types
Browse files Browse the repository at this point in the history
This gets rid of `PipelineStage`, `OrchestrationStage` and `AbstractStage` in favor of a single stage class. There's still a lot of horrible cruft glommed onto the `Stage` class that really has no business being in a value type but we can make improvements there down the road.
  • Loading branch information
robfletcher committed Mar 23, 2017
1 parent a97753c commit d3e5c9a
Show file tree
Hide file tree
Showing 168 changed files with 918 additions and 1,320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.front50.model.Application
import com.netflix.spinnaker.orca.front50.model.Front50Credential
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.PipelineStage
import com.netflix.spinnaker.orca.pipeline.model.Stage
import spock.lang.Specification
import spock.lang.Subject

Expand All @@ -48,7 +47,7 @@ class DeleteApplicationTaskSpec extends Specification {
}

when:
def taskResult = task.execute(new PipelineStage(new Pipeline(), "DeleteApplication", config))
def taskResult = task.execute(new Stage<>(new Pipeline(), "DeleteApplication", config))

then:
taskResult.status == ExecutionStatus.SUCCEEDED
Expand All @@ -63,7 +62,7 @@ class DeleteApplicationTaskSpec extends Specification {
}

when:
def taskResult = task.execute(new PipelineStage(new Pipeline(), "DeleteApplication", config))
def taskResult = task.execute(new Stage<>(new Pipeline(), "DeleteApplication", config))

then:
taskResult.status == ExecutionStatus.SUCCEEDED
Expand All @@ -80,7 +79,7 @@ class DeleteApplicationTaskSpec extends Specification {
}

when:
def taskResult = task.execute(new PipelineStage(new Pipeline(), "DeleteApplication", config))
def taskResult = task.execute(new Stage<>(new Pipeline(), "DeleteApplication", config))

then:
taskResult.stageOutputs.previousState == application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.front50.model.Application
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.PipelineStage
import spock.lang.Shared
import com.netflix.spinnaker.orca.pipeline.model.Stage
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Unroll
Expand Down Expand Up @@ -59,7 +58,7 @@ class UpsertApplicationTaskSpec extends Specification {
}

when:
def result = task.execute(new PipelineStage(new Pipeline(), "UpsertApplication", config))
def result = task.execute(new Stage<>(new Pipeline(), "UpsertApplication", config))

then:
result.status == ExecutionStatus.SUCCEEDED
Expand All @@ -84,7 +83,7 @@ class UpsertApplicationTaskSpec extends Specification {
}
when:
def result = task.execute(new PipelineStage(new Pipeline(), "UpsertApplication", config))
def result = task.execute(new Stage<>(new Pipeline(), "UpsertApplication", config))
then:
result.status == ExecutionStatus.SUCCEEDED
Expand All @@ -110,7 +109,7 @@ class UpsertApplicationTaskSpec extends Specification {
}

when:
def result = task.execute(new PipelineStage(new Pipeline(), "UpsertApplication", config))
def result = task.execute(new Stage<>(new Pipeline(), "UpsertApplication", config))

then:
result.stageOutputs.previousState == (initialState ?: [:])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.pipeline.model.DefaultTask
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.PipelineStage
import com.netflix.spinnaker.orca.pipeline.model.Stage
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
Expand Down Expand Up @@ -61,7 +61,7 @@ class VerifyApplicationHasNoDependenciesTaskSpec extends Specification {
task.objectMapper = new ObjectMapper()

and:
def stage = new PipelineStage(new Pipeline(), "VerifyApplication", config)
def stage = new Stage<>(new Pipeline(), "VerifyApplication", config)
stage.tasks = [new DefaultTask(name: "T1"), new DefaultTask(name: "T2")]

when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

package com.netflix.spinnaker.orca.bakery.pipeline

import groovy.time.TimeCategory
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.pipeline.model.AbstractStage
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.PipelineStage
import com.netflix.spinnaker.orca.pipeline.model.Stage
import groovy.time.TimeCategory
import spock.lang.Specification
import spock.lang.Unroll

Expand All @@ -34,7 +33,7 @@ class BakeStageSpec extends Specification {
}
def pipeline = pipelineBuilder.build()

def bakeStage = new PipelineStage(pipeline, "bake", "Bake!", bakeStageContext)
def bakeStage = new Stage<>(pipeline, "bake", "Bake!", bakeStageContext)
def builder = Spy(BakeStage, {
(0..1) * now() >> {
use([TimeCategory]) {
Expand Down Expand Up @@ -82,11 +81,11 @@ class BakeStageSpec extends Specification {
.withStage(BakeStage.PIPELINE_CONFIG_TYPE, "Bake", ["ami": 3])
.build()

def pipelineStage = new PipelineStage(pipeline, "bake")
def pipelineStage = new Stage<>(pipeline, "bake")
pipeline.stages.each {
it.status = ExecutionStatus.RUNNING
it.parentStageId = pipelineStage.parentStageId
((AbstractStage) it).id = pipelineStage.parentStageId
it.id = pipelineStage.parentStageId
}

when:
Expand All @@ -103,7 +102,7 @@ class BakeStageSpec extends Specification {
@Unroll
def "should return a different stage name when parallel flows are present"() {
given:
def stage = new PipelineStage(new Pipeline(), "type", stageName, [:])
def stage = new Stage<>(new Pipeline(), "type", stageName, [:])

expect:
new BakeStage().parallelStageName(stage, hasParallelFlows) == expectedStageName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.netflix.spinnaker.orca.bakery.api.Bake
import com.netflix.spinnaker.orca.bakery.api.BakeStatus
import com.netflix.spinnaker.orca.bakery.api.BakeryService
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.PipelineStage
import com.netflix.spinnaker.orca.pipeline.model.Stage
import retrofit.RetrofitError
import retrofit.client.Response
import rx.Observable
Expand Down Expand Up @@ -50,7 +50,7 @@ class CompletedBakeTaskSpec extends Specification {
}

and:
def stage = new PipelineStage(pipeline, "bake", [region: region, status: new BakeStatus(resourceId: bakeId)])
def stage = new Stage<>(pipeline, "bake", [region: region, status: new BakeStatus(resourceId: bakeId)])

when:
def result = task.execute(stage)
Expand All @@ -72,7 +72,7 @@ class CompletedBakeTaskSpec extends Specification {
}

and:
def stage = new PipelineStage(pipeline, "bake", [region: region, status: new BakeStatus(resourceId: bakeId)])
def stage = new Stage<>(pipeline, "bake", [region: region, status: new BakeStatus(resourceId: bakeId)])

when:
task.execute(stage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ package com.netflix.spinnaker.orca.bakery.tasks
import com.netflix.spinnaker.orca.bakery.api.BakeRequest
import com.netflix.spinnaker.orca.bakery.api.BakeStatus
import com.netflix.spinnaker.orca.bakery.api.BakeryService
import com.netflix.spinnaker.orca.bakery.api.BaseImage
import com.netflix.spinnaker.orca.jackson.OrcaObjectMapper
import com.netflix.spinnaker.orca.pipeline.model.*
import com.netflix.spinnaker.orca.pipeline.util.PackageType
import com.netflix.spinnaker.orca.pipeline.model.Orchestration
import com.netflix.spinnaker.orca.pipeline.model.OrchestrationStage
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.PipelineStage
import com.netflix.spinnaker.orca.pipeline.model.Stage
import retrofit.RetrofitError
import retrofit.client.Response
Expand Down Expand Up @@ -193,7 +188,7 @@ class CreateBakeTaskSpec extends Specification {

def setup() {
task.mapper = mapper
stage = new PipelineStage(pipeline, "bake", bakeConfig)
stage = new Stage<>(pipeline, "bake", bakeConfig)
}

def "creates a bake for the correct region"() {
Expand Down Expand Up @@ -248,7 +243,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo
Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
def bake
task.bakery = Mock(BakeryService) {
1 * createBake(*_) >> {
Expand Down Expand Up @@ -276,9 +271,9 @@ class CreateBakeTaskSpec extends Specification {
@Unroll
def "fails if pipeline trigger or context includes artifacts but no artifact for the bake package"() {
given:
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
bakeConfig.buildInfo = contextInfo
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Mock(BakeryService)
when:
Expand All @@ -300,16 +295,16 @@ class CreateBakeTaskSpec extends Specification {
@Unroll
def "fails if pipeline trigger and context includes artifacts have a different match"() {
given:
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: buildInfo]).build()
Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Mock(BakeryService)
bakeConfig.buildInfo = [
artifacts: [
[fileName: 'hodor_1.2_all.deb'],
[fileName: 'hodor-1.2.noarch.rpm'],
[fileName: 'hodor.1.2.nupkg']
]
]
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: buildInfo]).build()
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Mock(BakeryService)
when:
task.execute(stage)
Expand Down Expand Up @@ -354,7 +349,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo
Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Stub(BakeryService) {
createBake(*_) >> Observable.from(runningStatus)
}
Expand Down Expand Up @@ -384,7 +379,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo

Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Stub(BakeryService) {
createBake(*_) >> Observable.from(runningStatus)
}
Expand Down Expand Up @@ -412,7 +407,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo

Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Stub(BakeryService) {
createBake(*_) >> Observable.from(runningStatus)
}
Expand Down Expand Up @@ -440,7 +435,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo

Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Stub(BakeryService) {
createBake(*_) >> Observable.from(runningStatus)
}
Expand Down Expand Up @@ -468,7 +463,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo

Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Stub(BakeryService) {
createBake(*_) >> Observable.from(runningStatus)
}
Expand Down Expand Up @@ -498,7 +493,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo

Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Mock(BakeryService)
task.extractBuildDetails = true

Expand Down Expand Up @@ -531,7 +526,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo

Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Mock(BakeryService)

when:
Expand Down Expand Up @@ -563,7 +558,7 @@ class CreateBakeTaskSpec extends Specification {
Pipeline pipelineWithTrigger = new Pipeline.Builder().withTrigger([buildInfo: triggerInfo]).build()
bakeConfig.buildInfo = contextInfo

Stage stage = new PipelineStage(pipelineWithTrigger, "bake", bakeConfig)
Stage stage = new Stage<>(pipelineWithTrigger, "bake", bakeConfig)
task.bakery = Mock(BakeryService)

when:
Expand Down Expand Up @@ -591,7 +586,7 @@ class CreateBakeTaskSpec extends Specification {

def "cloudProviderType is propagated"() {
given:
Stage stage = new PipelineStage(new Pipeline(), "bake", bakeConfigWithCloudProviderType)
Stage stage = new Stage<>(new Pipeline(), "bake", bakeConfigWithCloudProviderType)
def bake
task.bakery = Mock(BakeryService) {
1 * createBake(*_) >> {
Expand Down Expand Up @@ -633,7 +628,7 @@ class CreateBakeTaskSpec extends Specification {

def "sets rebake query parameter if rebake flag is set in job context"() {
given:
Stage stage = new PipelineStage(new Pipeline(), "bake", bakeConfigWithRebake)
Stage stage = new Stage<>(new Pipeline(), "bake", bakeConfigWithRebake)
task.bakery = Mock(BakeryService)

when:
Expand All @@ -655,7 +650,7 @@ class CreateBakeTaskSpec extends Specification {
def "sets rebake query parameter to #queryParameter when trigger is #trigger"() {
given:
Pipeline pipeline = Pipeline.builder().withTrigger(trigger).build()
Stage pipelineStage = new PipelineStage(pipeline, "bake", bakeConfig)
Stage pipelineStage = new Stage<>(pipeline, "bake", bakeConfig)
task.bakery = Mock(BakeryService)

when:
Expand All @@ -673,7 +668,7 @@ class CreateBakeTaskSpec extends Specification {
0 * _

when:
task.execute(new OrchestrationStage(new Orchestration(), "bake", bakeConfig))
task.execute(new Stage<>(new Orchestration(), "bake", bakeConfig))

then:
1 * task.bakery.createBake(bakeConfig.region,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.bakery.api.BakeStatus
import com.netflix.spinnaker.orca.bakery.api.BakeryService
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.PipelineStage
import com.netflix.spinnaker.orca.pipeline.model.Stage
import rx.Observable
import spock.lang.Shared
import spock.lang.Specification
Expand All @@ -41,7 +41,7 @@ class MonitorBakeTaskSpec extends Specification {
def "should return #taskStatus if bake is #bakeState"() {
given:
def previousStatus = new BakeStatus(id: id, state: BakeStatus.State.PENDING)
def stage = new PipelineStage(pipeline, "bake", [region: "us-west-1", status: previousStatus])
def stage = new Stage<>(pipeline, "bake", [region: "us-west-1", status: previousStatus])

and:
task.bakery = Stub(BakeryService) {
Expand All @@ -68,7 +68,7 @@ class MonitorBakeTaskSpec extends Specification {
given:
def id = randomUUID().toString()
def previousStatus = new BakeStatus(id: id, state: BakeStatus.State.PENDING)
def stage = new PipelineStage(pipeline, "bake", [region: "us-west-1", status: previousStatus])
def stage = new Stage<>(pipeline, "bake", [region: "us-west-1", status: previousStatus])

and:
task.bakery = Stub(BakeryService) {
Expand All @@ -95,7 +95,7 @@ class MonitorBakeTaskSpec extends Specification {
def "outputs the updated bake status"() {
given:
def previousStatus = new BakeStatus(id: id, state: BakeStatus.State.PENDING)
def stage = new PipelineStage(pipeline, "bake", [region: "us-west-1", status: previousStatus])
def stage = new Stage<>(pipeline, "bake", [region: "us-west-1", status: previousStatus])

and:
task.bakery = Stub(BakeryService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.CloneServerGr
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.CreateServerGroupStage
import com.netflix.spinnaker.orca.pipeline.BranchingStageDefinitionBuilder
import com.netflix.spinnaker.orca.pipeline.TaskNode
import com.netflix.spinnaker.orca.pipeline.model.AbstractStage
import com.netflix.spinnaker.orca.pipeline.model.Execution
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.pipeline.model.Stage
Expand Down Expand Up @@ -118,7 +117,7 @@ class ParallelDeployStage implements BranchingStageDefinitionBuilder {
cluster.remove("stageEnabled")

// Parent stage can be deploy or cloneServerGroup.
((AbstractStage) stage).type = parentStage.type
stage.type = parentStage.type
stage.context.clusters = [cluster as Map<String, Object>]
}
}
Expand Down
Loading

0 comments on commit d3e5c9a

Please sign in to comment.