-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Re-introduce executionEngine flag, add ExecutionEngineRun…
…ner that selects an underlying ExecutionRunner based on the specified ExecutionEngine
- Loading branch information
Showing
19 changed files
with
300 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
orca-api/src/main/java/com/netflix/spinnaker/orca/api/pipeline/models/ExecutionEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.netflix.spinnaker.orca.api.pipeline.models; | ||
|
||
public enum ExecutionEngine { | ||
/** | ||
* v2 is obsolete, but it is here as a failsafe in case it is present in a pipeline configuration | ||
* and needs to be deserialized. If v2 is specified, the default execution engine (v3) will be | ||
* used instead. | ||
*/ | ||
v2, | ||
|
||
/** v3 execution engine is the keiko execution engine. */ | ||
v3, | ||
|
||
/** v4 execution engine does not yet exist, early prototyping is underway. */ | ||
v4; | ||
|
||
public static ExecutionEngine DEFAULT = v3; | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/main/java/com/netflix/spinnaker/orca/api/pipeline/models/ExecutionEngineVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.netflix.spinnaker.orca.api.pipeline.models; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** Signals that the annotated element supports a specific {@link ExecutionEngine} version. */ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Documented | ||
public @interface ExecutionEngineVersion { | ||
ExecutionEngine value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
orca-core/src/main/java/com/netflix/spinnaker/orca/pipeline/ExecutionEngineRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.netflix.spinnaker.orca.pipeline; | ||
|
||
import com.netflix.spinnaker.kork.annotations.VisibleForTesting; | ||
import com.netflix.spinnaker.orca.api.pipeline.ExecutionRunner; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionEngine; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionEngineVersion; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution; | ||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Executes the {@link PipelineExecution} based on the specified {@link ExecutionEngine}. The {@link | ||
* ExecutionEngine} is expected to be specified via the {@link ExecutionEngineVersion} annotation. | ||
*/ | ||
public class ExecutionEngineRunner implements ExecutionRunner { | ||
|
||
private final List<ExecutionRunner> executionRunners; | ||
|
||
public ExecutionEngineRunner(List<ExecutionRunner> executionRunners) { | ||
this.executionRunners = executionRunners; | ||
} | ||
|
||
@Override | ||
public void start(@Nonnull PipelineExecution execution) { | ||
executionRunner(execution.getExecutionEngine()).start(execution); | ||
} | ||
|
||
@Override | ||
public void restart(@Nonnull PipelineExecution execution, @Nonnull String stageId) { | ||
executionRunner(execution.getExecutionEngine()).restart(execution, stageId); | ||
} | ||
|
||
@Override | ||
public void reschedule(@Nonnull PipelineExecution execution) { | ||
executionRunner(execution.getExecutionEngine()).reschedule(execution); | ||
} | ||
|
||
@Override | ||
public void unpause(@Nonnull PipelineExecution execution) { | ||
executionRunner(execution.getExecutionEngine()).unpause(execution); | ||
} | ||
|
||
@Override | ||
public void cancel( | ||
@Nonnull PipelineExecution execution, @Nonnull String user, @Nullable String reason) { | ||
executionRunner(execution.getExecutionEngine()).cancel(execution, user, reason); | ||
} | ||
|
||
@VisibleForTesting | ||
protected ExecutionRunner executionRunner(ExecutionEngine executionEngine) { | ||
return executionRunners.stream() | ||
.filter(it -> it.getClass().isAnnotationPresent(ExecutionEngineVersion.class)) | ||
.filter( | ||
it -> | ||
it.getClass().getAnnotation(ExecutionEngineVersion.class).value() | ||
== executionEngine) | ||
.findFirst() | ||
.orElseGet( | ||
() -> | ||
executionRunners.stream() | ||
.filter(it -> it.getClass().isAnnotationPresent(ExecutionEngineVersion.class)) | ||
.filter( | ||
it -> | ||
it.getClass().getAnnotation(ExecutionEngineVersion.class).value() | ||
== ExecutionEngine.DEFAULT) | ||
.findFirst() | ||
.orElseThrow( | ||
() -> | ||
new UnsupportedOperationException( | ||
"No execution engine runner found!"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...core/src/test/groovy/com/netflix/spinnaker/orca/pipeline/ExecutionEngineRunnerSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.netflix.spinnaker.orca.pipeline | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.ExecutionRunner | ||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionEngineVersion | ||
import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution | ||
import org.jetbrains.annotations.Nullable | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import javax.annotation.Nonnull | ||
|
||
import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionEngine.v2 | ||
import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionEngine.v3 | ||
import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionEngine.v4 | ||
|
||
class ExecutionEngineRunnerSpec extends Specification { | ||
|
||
@Unroll | ||
def "Finds the correct execution runner based on the execution engine"() { | ||
given: | ||
ExecutionEngineRunner executionEngineRunner = new ExecutionEngineRunner([new V3EngineRunner(), new V4EngineRunner()]) | ||
|
||
when: | ||
def runner = executionEngineRunner.executionRunner(supplied) | ||
|
||
then: | ||
runner.class == expected | ||
|
||
where: | ||
supplied | expected | ||
v2 | V3EngineRunner.class //v2 is obsolete, use v3 engine | ||
v3 | V3EngineRunner.class | ||
v4 | V4EngineRunner.class | ||
} | ||
|
||
@Unroll | ||
def "Throws UnsupportedOperationException when execution engine runner can not be found"() { | ||
given: | ||
ExecutionEngineRunner executionEngineRunner = new ExecutionEngineRunner([new UnsupportedRunner()]) | ||
|
||
when: | ||
executionEngineRunner.executionRunner(v3) | ||
|
||
then: | ||
thrown(UnsupportedOperationException) | ||
} | ||
} | ||
|
||
@ExecutionEngineVersion(v3) | ||
class V3EngineRunner implements ExecutionRunner { | ||
@Override | ||
void start(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void restart(@Nonnull PipelineExecution execution, @Nonnull String stageId) {} | ||
@Override | ||
void reschedule(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void unpause(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void cancel(@Nonnull PipelineExecution execution, @Nonnull String user, @Nullable String reason) {} | ||
} | ||
|
||
@ExecutionEngineVersion(v4) | ||
class V4EngineRunner implements ExecutionRunner { | ||
@Override | ||
void start(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void restart(@Nonnull PipelineExecution execution, @Nonnull String stageId) {} | ||
@Override | ||
void reschedule(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void unpause(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void cancel(@Nonnull PipelineExecution execution, @Nonnull String user, @Nullable String reason) {} | ||
} | ||
|
||
class UnsupportedRunner implements ExecutionRunner { | ||
@Override | ||
void start(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void restart(@Nonnull PipelineExecution execution, @Nonnull String stageId) {} | ||
@Override | ||
void reschedule(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void unpause(@Nonnull PipelineExecution execution) {} | ||
@Override | ||
void cancel(@Nonnull PipelineExecution execution, @Nonnull String user, @Nullable String reason) {} | ||
} |
Oops, something went wrong.