Skip to content

Commit

Permalink
fix(cf): cf rolling red black did not resize old SG correctly (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy Louie authored Oct 3, 2019
1 parent cb11ede commit 0d64a4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,13 @@ List<Stage> composeFlow(Stage stage) {
stages.add(disableStage);

// scale old back to original
ResizeStrategy.Capacity resetCapacity = new ResizeStrategy.Capacity();
resetCapacity.setMax(sourceCapacity.getMax());
resetCapacity.setMin(0);
resetCapacity.setDesired(0);
Map<String, Object> scaleSourceContext =
getScalingContext(
stage, cleanupConfig, baseContext, sourceCapacity, 100, source.getServerGroupName());
stage, cleanupConfig, baseContext, resetCapacity, 100, source.getServerGroupName());
scaleSourceContext.put("scaleStoppedServerGroup", true);
log.info(
"Adding `Grow source to 100% of original size` stage with context {} [executionId={}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CFRollingRedBlackStrategyTest {
}

@Test
void composeFlowWithDelayBeforeScaleDown() {
void composeFlowWithDelayBeforeScaleDown() throws IOException {
List<Object> targetPercentageList = Stream.of(50, 100).collect(Collectors.toList());
Map<String, Object> direct = new HashMap<>();
direct.put("instances", 4);
Expand All @@ -100,6 +100,8 @@ void composeFlowWithDelayBeforeScaleDown() {
new Execution(PIPELINE, "unit"), CreateServerGroupStage.PIPELINE_CONFIG_TYPE, context);
when(targetServerGroupResolver.resolve(any()))
.thenReturn(singletonList(new TargetServerGroup(Collections.emptyMap())));
when(resizeStrategySupport.getCapacity(any(), any(), any(), any()))
.thenReturn(new ResizeStrategy.Capacity(1, 1, 1));

List<Stage> stages = strategy.composeFlow(deployServerGroupStage);

Expand Down Expand Up @@ -142,6 +144,8 @@ void composeFlowWithDelayBeforeCleanup() {

when(targetServerGroupResolver.resolve(any()))
.thenReturn(singletonList(new TargetServerGroup(Collections.emptyMap())));
when(resizeStrategySupport.getCapacity(any(), any(), any(), any()))
.thenReturn(new ResizeStrategy.Capacity(1, 1, 1));

List<Stage> stages = strategy.composeFlow(deployServerGroupStage);

Expand Down Expand Up @@ -222,6 +226,8 @@ void composeFlowWithSourceAndManifestDirect() {
new Stage(
new Execution(PIPELINE, "unit"), CreateServerGroupStage.PIPELINE_CONFIG_TYPE, context);
ResizeStrategy.Capacity initialSourceCapacity = new ResizeStrategy.Capacity(8, 8, 8);
ResizeStrategy.Capacity resetOriginalCapacity =
new ResizeStrategy.Capacity(initialSourceCapacity.getMax(), 0, 0);

when(targetServerGroupResolver.resolve(any()))
.thenReturn(singletonList(new TargetServerGroup(Collections.emptyMap())));
Expand Down Expand Up @@ -261,7 +267,7 @@ void composeFlowWithSourceAndManifestDirect() {
initialSourceCapacity,
null,
null,
initialSourceCapacity);
resetOriginalCapacity);
assertThat(deployServerGroupStage.getContext().get("targetSize")).isNull();
assertThat(deployServerGroupStage.getContext().get("useSourceCapacity")).isNull();
assertThat(deployServerGroupStage.getContext().get("capacity")).isEqualTo(zeroCapacity);
Expand Down Expand Up @@ -342,6 +348,8 @@ void composeFlowWithSourceAndManifestArtifactConvertsManifestToDirect() throws I
context.put("source", createSource());
ResizeStrategy.Capacity resizeTo4Capacity = new ResizeStrategy.Capacity(4, 4, 4);
ResizeStrategy.Capacity initialSourceCapacity = new ResizeStrategy.Capacity(8, 8, 8);
ResizeStrategy.Capacity resetOriginalCapacity =
new ResizeStrategy.Capacity(initialSourceCapacity.getMax(), 0, 0);

Stage deployServerGroupStage = new Stage(new Execution(PIPELINE, "unit"), "type", context);
Artifact boundArtifactForStage = new Artifact();
Expand Down Expand Up @@ -386,7 +394,7 @@ void composeFlowWithSourceAndManifestArtifactConvertsManifestToDirect() throws I
initialSourceCapacity,
null,
null,
initialSourceCapacity);
resetOriginalCapacity);
assertThat(stages.stream().map(stage -> stage.getContext().get("scalePct")))
.containsExactly(null, 50, 50, 75, 25, 100, 0, null, null, 100);
assertThat(deployServerGroupStage.getContext().get("targetSize")).isNull();
Expand Down

0 comments on commit 0d64a4f

Please sign in to comment.