-
Notifications
You must be signed in to change notification settings - Fork 807
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
18 changed files
with
302 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
16 changes: 16 additions & 0 deletions
16
.../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,16 @@ | ||
package com.netflix.spinnaker.orca.api.pipeline.models; | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution.ExecutionEngine; | ||
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
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
package com.netflix.spinnaker.orca.pipeline; | ||
|
||
import static com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution.DEFAULT_EXECUTION_ENGINE; | ||
|
||
import com.netflix.spinnaker.kork.annotations.VisibleForTesting; | ||
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 com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution.ExecutionEngine; | ||
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() | ||
== DEFAULT_EXECUTION_ENGINE) | ||
.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.PipelineExecution.ExecutionEngine.v2 | ||
import static com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution.ExecutionEngine.v3 | ||
import static com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution.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.