Skip to content

Commit

Permalink
Reverted deleted methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kkotula committed Mar 9, 2023
1 parent 8c66585 commit 4573ba5
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository;
import com.netflix.spinnaker.security.AuthenticatedRequest;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -120,6 +124,63 @@ public PipelineExecution restartStage(@Nonnull String executionId, @Nonnull Stri
return execution;
}

public PipelineExecution restartStage(
@Nonnull String executionId, @Nonnull String stageId, Map restartDetails) {
PipelineExecution execution = repository.retrieve(ExecutionType.PIPELINE, executionId);
execution = updatePreconditionStageExpression(restartDetails, execution);
if (repository.handlesPartition(execution.getPartition())) {
runner.restart(execution, stageId);
} else {
log.info(
"Not pushing queue message action='restart' for execution with foreign partition='{}'",
execution.getPartition());
repository.restartStage(executionId, stageId);
}
return execution;
}

private PipelineExecution updatePreconditionStageExpression(
Map restartDetails, PipelineExecution execution) {
List<Map> preconditionList = getPreconditionsFromStage(restartDetails);
if (preconditionList.isEmpty()) {
return execution;
}

for (StageExecution stage : execution.getStages()) {
if (stage.getType() != null && stage.getType().equalsIgnoreCase("checkPreconditions")) {
if (stage.getContext().get("preconditions") != null) {
stage.getContext().replace("preconditions", preconditionList);
repository.storeStage(stage);
log.info("Updated preconditions for CheckPreconditions stage");
}
}
}
return execution;
}

private List<Map> getPreconditionsFromStage(Map restartDetails) {
List<Map> preconditionList = new ArrayList();
Map pipelineConfigMap = new HashMap(restartDetails);

List<String> keysToRetain = new ArrayList();
keysToRetain.add("stages");

pipelineConfigMap.keySet().retainAll(keysToRetain);

Map<String, List<Map>> pipelineStageMap = new HashMap(pipelineConfigMap);

if (pipelineStageMap != null && !pipelineStageMap.isEmpty()) {
List<Map> pipelineStageList = pipelineStageMap.get(keysToRetain.get(0));
for (Map stageMap : pipelineStageList) {
if (stageMap.get("type").toString().equalsIgnoreCase("checkPreconditions")) {
preconditionList = (List<Map>) stageMap.get("preconditions");
log.info("Retrieved preconditions for CheckPreconditions stage");
}
}
}
return preconditionList;
}

private PipelineExecution doInternal(
Consumer<PipelineExecution> runnerAction,
Runnable repositoryAction,
Expand Down

0 comments on commit 4573ba5

Please sign in to comment.