|
1 | 1 | /*
|
2 |
| - * Copyright 2014 Netflix, Inc. |
| 2 | + * Copyright 2024 Netflix, Inc. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
6 | 6 | * You may obtain a copy of the License at
|
7 | 7 | *
|
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 | *
|
10 | 10 | * Unless required by applicable law or agreed to in writing, software
|
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
|
27 | 27 | @Component
|
28 | 28 | public class WaitForCapacityMatchTask extends AbstractInstancesCheckTask {
|
29 | 29 |
|
| 30 | + private final ServerGroupProperties serverGroupProperties; |
| 31 | + |
| 32 | + public WaitForCapacityMatchTask(ServerGroupProperties serverGroupProperties) { |
| 33 | + this.serverGroupProperties = serverGroupProperties; |
| 34 | + } |
| 35 | + |
30 | 36 | @Override
|
31 | 37 | protected Map<String, List<String>> getServerGroups(StageExecution stage) {
|
32 | 38 | return (Map<String, List<String>>) stage.getContext().get("deploy.server.groups");
|
@@ -88,27 +94,37 @@ protected boolean hasSucceeded(
|
88 | 94 | desired = capacity.getDesired();
|
89 | 95 | }
|
90 | 96 |
|
91 |
| - Integer targetDesiredSize = |
92 |
| - Optional.ofNullable((Number) context.get("targetDesiredSize")) |
93 |
| - .map(Number::intValue) |
94 |
| - .orElse(null); |
95 |
| - |
96 |
| - splainer.add( |
97 |
| - String.format( |
98 |
| - "checking if capacity matches (desired=%s, target=%s current=%s)", |
99 |
| - desired, targetDesiredSize == null ? "none" : targetDesiredSize, instances.size())); |
100 |
| - if (targetDesiredSize != null && targetDesiredSize != 0) { |
101 |
| - // `targetDesiredSize` is derived from `targetHealthyDeployPercentage` and if present, |
102 |
| - // then scaling has succeeded if the number of instances is greater than this value. |
103 |
| - if (instances.size() < targetDesiredSize) { |
| 97 | + if (serverGroupProperties.getResize().isMatchInstancesSize()) { |
| 98 | + splainer.add( |
| 99 | + "checking if capacity matches (desired=${desired}, instances.size()=${instances.size()}) "); |
| 100 | + if (desired == null || desired != instances.size()) { |
104 | 101 | splainer.add(
|
105 |
| - "short-circuiting out of WaitForCapacityMatchTask because targetDesired and current capacity don't match"); |
| 102 | + "short-circuiting out of WaitForCapacityMatchTask because expected and current capacity don't match}"); |
106 | 103 | return false;
|
107 | 104 | }
|
108 |
| - } else if (desired == null || desired != instances.size()) { |
| 105 | + } else { |
| 106 | + Integer targetDesiredSize = |
| 107 | + Optional.ofNullable((Number) context.get("targetDesiredSize")) |
| 108 | + .map(Number::intValue) |
| 109 | + .orElse(null); |
| 110 | + |
109 | 111 | splainer.add(
|
110 |
| - "short-circuiting out of WaitForCapacityMatchTask because expected and current capacity don't match"); |
111 |
| - return false; |
| 112 | + String.format( |
| 113 | + "checking if capacity matches (desired=%s, target=%s current=%s)", |
| 114 | + desired, targetDesiredSize == null ? "none" : targetDesiredSize, instances.size())); |
| 115 | + if (targetDesiredSize != null && targetDesiredSize != 0) { |
| 116 | + // `targetDesiredSize` is derived from `targetHealthyDeployPercentage` and if present, |
| 117 | + // then scaling has succeeded if the number of instances is greater than this value. |
| 118 | + if (instances.size() < targetDesiredSize) { |
| 119 | + splainer.add( |
| 120 | + "short-circuiting out of WaitForCapacityMatchTask because targetDesired and current capacity don't match"); |
| 121 | + return false; |
| 122 | + } |
| 123 | + } else if (desired == null || desired != instances.size()) { |
| 124 | + splainer.add( |
| 125 | + "short-circuiting out of WaitForCapacityMatchTask because expected and current capacity don't match"); |
| 126 | + return false; |
| 127 | + } |
112 | 128 | }
|
113 | 129 |
|
114 | 130 | boolean disabled = Boolean.TRUE.equals(serverGroup.getDisabled());
|
|
0 commit comments