fix(cf): when scaling cf disabled SG we should use max capacity
MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperation.java
@@ -28,6 +28,7 @@ import com.netflix.spinnaker.clouddriver.helpers.OperationPoller;
import com.netflix.spinnaker.clouddriver.model.ServerGroup;
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
import java.util.List;
+import java.util.Optional;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@@ -48,11 +49,18 @@ public class ScaleCloudFoundryServerGroupAtomicOperation implements AtomicOperat
final CloudFoundryClient client = description.getClient();
ServerGroup.Capacity capacity = description.getCapacity();
+ boolean scaleStoppedInstance =
+ Optional.ofNullable(description.getScaleStoppedServerGroup()).orElse(false);
+ Integer numInstances =
+ Optional.ofNullable(capacity)
+ .map(c -> scaleStoppedInstance ? capacity.getMax() : capacity.getDesired())
+ .orElse(null);
+
client
.getApplications()
.scaleApplication(
description.getServerGroupId(),
- capacity == null ? null : capacity.getDesired(),
+ numInstances,
description.getMemory(),
description.getDiskQuota());

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/ScaleCloudFoundryServerGroupAtomicOperationTest.java
@@ -19,7 +19,9 @@ package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.atIndex;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
@@ -60,6 +62,25 @@ class ScaleCloudFoundryServerGroupAtomicOperationTest
.has(status("Resized 'myapp'"), atIndex(2));
}
+ @Test
+ void scaleForStoppedServerGroup() {
+ desc.setScaleStoppedServerGroup(true);
+ desc.setCapacity(ServerGroup.Capacity.builder().desired(2).min(2).max(3).build());
+ OperationPoller poller = mock(OperationPoller.class);
+
+ //noinspection unchecked
+ when(poller.waitForOperation(any(Supplier.class), any(), any(), any(), any(), any()))
+ .thenReturn(ProcessStats.State.RUNNING);
+
+ ScaleCloudFoundryServerGroupAtomicOperation op =
+ new ScaleCloudFoundryServerGroupAtomicOperation(poller, desc);
+
+ assertThat(runOperation(op).getHistory())
+ .has(status("Resizing 'myapp'"), atIndex(1))
+ .has(status("Resized 'myapp'"), atIndex(2));
+ verify(client.getApplications()).scaleApplication(any(), eq(3), any(), any());
+ }
+
@Test
void failedToScale() {
OperationPoller poller = mock(OperationPoller.class);

fix(cf): when scaling cf disabled SG we should use max capacity (#4067)