-
Notifications
You must be signed in to change notification settings - Fork 811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): Re-introduce executionEngine flag, add ExecutionEngineRunner that selects an underlying ExecutionRunner based on the specified ExecutionEngine #3984
Open
jonsie
wants to merge
1
commit into
spinnaker:master
Choose a base branch
from
jonsie:execution-engine
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would like docs on this. |
||
/** | ||
* 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!"))); | ||
Comment on lines
+70
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a subtype of |
||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get some docs on the method as well?