Skip to content
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): Allow ExecutionPreprocessor to discriminate on type #2881

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Map<String, Object> planPipeline(ContextParameterProcessor context
Map<String, Object> finalPipeline = pipeline;
List<ExecutionPreprocessor> preprocessors = pipelinePreprocessors
.stream()
.filter(p -> p.supports(finalPipeline))
.filter(p -> p.supports(finalPipeline, ExecutionPreprocessor.Type.PIPELINE))
.collect(Collectors.toList());
for (ExecutionPreprocessor pp : preprocessors) {
pipeline = pp.process(pipeline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.netflix.spinnaker.orca.preprocessors
import com.netflix.spinnaker.orca.config.DefaultApplicationConfigurationProperties
import com.netflix.spinnaker.orca.extensionpoint.pipeline.ExecutionPreprocessor
import org.springframework.stereotype.Component
import javax.annotation.Nonnull

/**
* Populates an Execution config payload with a default application value if one is not provided.
Expand All @@ -27,7 +28,8 @@ class DefaultApplicationExecutionPreprocessor(
private val properties: DefaultApplicationConfigurationProperties
) : ExecutionPreprocessor {

override fun supports(execution: MutableMap<String, Any>) = true
override fun supports(@Nonnull execution: MutableMap<String, Any>,
@Nonnull type: ExecutionPreprocessor.Type): Boolean = true

override fun process(execution: MutableMap<String, Any>): MutableMap<String, Any> {
if (!execution.containsKey("application")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ public interface ExecutionPreprocessor {
/**
* Returns whether or not the preprocess can handle the inbound execution.
*/
boolean supports(@Nonnull Map<String, Object> execution);
boolean supports(@Nonnull Map<String, Object> execution, @Nonnull Type type);

/**
* Allows modification of an execution configuration.
*/
@Nonnull Map<String, Object> process(@Nonnull Map<String, Object> execution);

enum Type {
PIPELINE,
ORCHESTRATION
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explicitly left a type off this to support cases where type isn't applicable. Maybe add an ANY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR passes in a Type at the call site so I think it's appropriate to be either PIPELINE or ORCHESTRATION (vs the preprocessor declaring what type it supports).

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class DependentPipelineStarter implements ApplicationContextAware {
//keep the trigger as the preprocessor removes it.
def expectedArtifacts = pipelineConfig.expectedArtifacts

for (ExecutionPreprocessor preprocessor : executionPreprocessors.findAll { it.supports(pipelineConfig) }) {
for (ExecutionPreprocessor preprocessor : executionPreprocessors.findAll {
it.supports(pipelineConfig, ExecutionPreprocessor.Type.PIPELINE)
}) {
pipelineConfig = preprocessor.process(pipelineConfig)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.netflix.spinnaker.orca.pipelinetemplate.v2schema.model.V2PipelineTemp
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import javax.annotation.Nonnull
import javax.annotation.PostConstruct

@Component("pipelineTemplatePreprocessor")
Expand All @@ -44,7 +45,8 @@ class PipelineTemplatePreprocessor

@PostConstruct fun confirmUsage() = log.info("Using ${javaClass.simpleName}")

override fun supports(execution: MutableMap<String, Any>) = true
override fun supports(@Nonnull execution: MutableMap<String, Any>,
@Nonnull type: ExecutionPreprocessor.Type): Boolean = true

override fun process(pipeline: MutableMap<String, Any>): MutableMap<String, Any> {
// TODO(jacobkiefer): We push the 'toplevel' v2 config into a 'config' field to play nice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ class OperationsController {
public Map parseAndValidatePipeline(Map pipeline, boolean resolveArtifacts) {
parsePipelineTrigger(executionRepository, buildService, pipeline, resolveArtifacts)

for (ExecutionPreprocessor preprocessor : executionPreprocessors.findAll { it.supports(pipeline) }) {
for (ExecutionPreprocessor preprocessor : executionPreprocessors.findAll {
it.supports(pipeline, ExecutionPreprocessor.Type.PIPELINE)
}) {
pipeline = preprocessor.process(pipeline)
}

Expand Down Expand Up @@ -407,9 +409,13 @@ class OperationsController {
applyStageRefIds(config)
}
injectPipelineOrigin(config)
for (ExecutionPreprocessor ep : executionPreprocessors) {
config = ep.process(config)

for (ExecutionPreprocessor preprocessor : executionPreprocessors.findAll {
it.supports(pipeline, ExecutionPreprocessor.Type.ORCHESTRATION)
}) {
config = preprocessor.process(pipeline)
}

def json = objectMapper.writeValueAsString(config)
log.info('requested task:{}', json)
def pipeline = executionLauncher.start(ORCHESTRATION, json)
Expand Down