Skip to content

Commit

Permalink
fix(conditions): Make task conditional per config (spinnaker#2790)
Browse files Browse the repository at this point in the history
- s/@ConditionalOnBean/@ConditionalOnExpression
  • Loading branch information
jeyrschabu authored Mar 25, 2019
1 parent a8a08a9 commit 2ea8b02
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
package com.netflix.spinnaker.orca.clouddriver.pipeline;

import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.strategies.DeployStagePreProcessor;
import com.netflix.spinnaker.orca.conditions.ConditionSupplier;
import com.netflix.spinnaker.orca.kato.pipeline.support.StageData;
import com.netflix.spinnaker.orca.pipeline.WaitForConditionStage;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

Expand All @@ -33,7 +31,6 @@

@Component
@ConditionalOnExpression("${tasks.evaluateCondition.enabled:false}")
@ConditionalOnBean(value = ConditionSupplier.class)
public class ConditionAwareDeployStagePreprocessor implements DeployStagePreProcessor {
private final WaitForConditionStage waitForConditionStage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
Expand All @@ -41,17 +41,17 @@
import static com.netflix.spinnaker.orca.pipeline.WaitForConditionStage.WaitForConditionContext.*;

@Component
@ConditionalOnBean(ConditionSupplier.class)
@ConditionalOnExpression("${tasks.evaluateCondition.enabled:false}")
public class EvaluateConditionTask implements RetryableTask {
private static final Logger log = LoggerFactory.getLogger(EvaluateConditionTask.class);
private final ConditionConfigurationProperties conditionsConfigurationProperties;
private final List<ConditionSupplier> suppliers;
private final Optional<List<ConditionSupplier>> suppliers;
private final Clock clock;

@Autowired
public EvaluateConditionTask(
ConditionConfigurationProperties conditionsConfigurationProperties,
List<ConditionSupplier> suppliers,
Optional<List<ConditionSupplier>> suppliers,
Clock clock
) {
this.conditionsConfigurationProperties = conditionsConfigurationProperties;
Expand All @@ -73,7 +73,7 @@ public long getTimeout() {
@Override
public TaskResult execute(@Nonnull Stage stage) {
final WaitForConditionContext ctx = stage.mapTo(WaitForConditionContext.class);
if (ctx.getStatus() == Status.SKIPPED) {
if (ctx.getStatus() == Status.SKIPPED || !suppliers.isPresent()) {
return new TaskResult(ExecutionStatus.SUCCEEDED, Collections.singletonMap("status", Status.SKIPPED));
}

Expand All @@ -88,7 +88,7 @@ public TaskResult execute(@Nonnull Stage stage) {
}

try {
Set<Condition> conditions = suppliers
Set<Condition> conditions = suppliers.get()
.stream()
.flatMap(supplier -> supplier.getConditions(stage).stream()).filter(Objects::nonNull)
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class EvaluateConditionTaskSpec extends Specification {
@Subject
def task = new EvaluateConditionTask(
conditionsConfigurationProperties,
[conditionSupplier],
Optional.of([conditionSupplier]),
clock
)

Expand Down

0 comments on commit 2ea8b02

Please sign in to comment.