Skip to content

Commit

Permalink
fix(clouddriver): Fix NPE while searching for ancestor stage (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert committed Mar 22, 2018
1 parent 50710ea commit 4af35a7
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,17 @@ class ApplySourceServerGroupCapacityTask extends AbstractServerGroupTask {
ancestorStage.context.containsKey("sourceServerGroupCapacitySnapshot")
}

return ancestors ? ancestors[0] : stage.execution.stages.find {
Stage ancestor = (ancestors != null && !ancestors.isEmpty()) ? ancestors[0] : stage.execution.stages.find {
// find a synthetic sibling w/ 'sourceServerGroupCapacitySnapshot' in the event of there being no suitable
// ancestors (ie. rollback stages)
it.context.containsKey("sourceServerGroupCapacitySnapshot") && it.parentStageId == stage.parentStageId
}

if (ancestor == null) {
throw new CannotFindAncestorStage("No stages with sourceServerGroupCapacitySnapshot context defined in execution ${stage.execution.id}")
}

return ancestor
}

private static class DeployStageData extends StageData {
Expand Down Expand Up @@ -198,4 +204,10 @@ class ApplySourceServerGroupCapacityTask extends AbstractServerGroupTask {
Map<String, Object> context
Map<String, Long> sourceServerGroupCapacitySnapshot
}

private static class CannotFindAncestorStage extends IllegalStateException {
CannotFindAncestorStage(String message) {
super(message)
}
}
}

0 comments on commit 4af35a7

Please sign in to comment.