chore(cf): remove usage of task fail and throw an exception
MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/AbstractCloudFoundryLoadBalancerMappingOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/AbstractCloudFoundryLoadBalancerMappingOperation.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.RouteId;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.AbstractCloudFoundryServerGroupDescription;
@@ -47,35 +48,22 @@ public abstract class AbstractCloudFoundryLoadBalancerMappingOperation {
getTask().updateStatus(getPhase(), "Creating or updating load balancers");
- List<String> invalidRoutes = new ArrayList<>();
-
CloudFoundryClient client = description.getClient();
List<RouteId> routeIds = routes.stream()
.map(routePath -> {
RouteId routeId = client.getRoutes().toRouteId(routePath);
if (routeId == null) {
- invalidRoutes.add(routePath);
+ throw new IllegalArgumentException(routePath + "is an invalid route");
}
return routeId;
})
.filter(Objects::nonNull)
.collect(toList());
- for (String routePath : invalidRoutes) {
- getTask().updateStatus(getPhase(), "Invalid format or domain for load balancer '" + routePath + "'");
- }
-
- if (!invalidRoutes.isEmpty()) {
- getTask().fail();
- return false;
- }
-
for (RouteId routeId : routeIds) {
CloudFoundryLoadBalancer loadBalancer = client.getRoutes().createRoute(routeId, space.getId());
if (loadBalancer == null) {
- getTask().updateStatus(getPhase(), "Load balancer already exists in another organization and space");
- getTask().fail();
- return false;
+ throw new CloudFoundryApiException("Load balancer already exists in another organization and space");
}
getTask().updateStatus(getPhase(), "Mapping load balancer '" + loadBalancer.getName() + "' to " + description.getServerGroupName());
client.getApplications().mapRoute(serverGroupId, loadBalancer.getId());

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeleteCloudFoundryLoadBalancerAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeleteCloudFoundryLoadBalancerAtomicOperation.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.DeleteCloudFoundryLoadBalancerDescription;
import com.netflix.spinnaker.clouddriver.data.task.Task;
@@ -39,8 +40,7 @@ public class DeleteCloudFoundryLoadBalancerAtomicOperation implements AtomicOper
CloudFoundryClient client = description.getClient();
if (description.getLoadBalancer() == null) {
- getTask().updateStatus(PHASE, "Load balancer does not exist");
- getTask().fail();
+ throw new CloudFoundryApiException("Load balancer does not exist");
} else {
getTask().updateStatus(PHASE, "Deleting load balancer " + description.getLoadBalancer().getName());
client.getRoutes().deleteRoute(description.getLoadBalancer().getId());

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeployCloudFoundryServerGroupAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeployCloudFoundryServerGroupAtomicOperation.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.CloudFoundryServerGroupNameResolver;
@@ -98,9 +99,7 @@ public class DeployCloudFoundryServerGroupAtomicOperation
null, getTask(), description.getServerGroupName(), PHASE);
if (state != ProcessStats.State.RUNNING) {
- getTask().updateStatus(PHASE, "Failed to start '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
- getTask().fail();
- return null;
+ throw new CloudFoundryApiException("Failed to start '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
}
} else {
getTask().updateStatus(PHASE, "Stop state requested for '" + description.getServerGroupName());

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
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.ScaleCloudFoundryServerGroupDescription;
@@ -67,8 +68,7 @@ public class ScaleCloudFoundryServerGroupAtomicOperation implements AtomicOperat
(state == ProcessStats.State.DOWN && description.getCapacity().getDesired() == 0)) {
getTask().updateStatus(PHASE, "Resized '" + description.getServerGroupName() + "'");
} else {
- getTask().updateStatus(PHASE, "Failed to start '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
- getTask().fail();
+ throw new CloudFoundryApiException("Failed to start '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
}
return null;

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StartCloudFoundryServerGroupAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StartCloudFoundryServerGroupAtomicOperation.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.StartCloudFoundryServerGroupDescription;
@@ -54,9 +55,7 @@ public class StartCloudFoundryServerGroupAtomicOperation implements AtomicOperat
null, getTask(), description.getServerGroupName(), PHASE);
if (state != ProcessStats.State.RUNNING) {
- getTask().updateStatus(PHASE, "Failed to start '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
- getTask().fail();
- return null;
+ throw new CloudFoundryApiException("Failed to start '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
}
getTask().updateStatus(PHASE, "Started '" + description.getServerGroupName() + "'");

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperation.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.StopCloudFoundryServerGroupDescription;
@@ -52,9 +53,7 @@ public class StopCloudFoundryServerGroupAtomicOperation implements AtomicOperati
null, getTask(), description.getServerGroupName(), PHASE);
if (state != ProcessStats.State.DOWN) {
- getTask().updateStatus(PHASE, "Failed to stop '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
- getTask().fail();
- return null;
+ throw new CloudFoundryApiException("Failed to stop '" + description.getServerGroupName() + "' which instead " + describeProcessState(state));
}
getTask().updateStatus(PHASE, "Stopped '" + description.getServerGroupName() + "'");

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/TerminateCloudFoundryInstancesAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/TerminateCloudFoundryInstancesAtomicOperation.java
@@ -43,7 +43,6 @@ public class TerminateCloudFoundryInstancesAtomicOperation implements AtomicOper
getTask().updateStatus(PHASE, "Terminating " + instanceDescription());
final CloudFoundryClient client = description.getClient();
- boolean oneOrMoreFailed = false;
for (String instance : description.getInstanceIds()) {
try {
String serverGroupId = instance.substring(0, instance.lastIndexOf("-"));
@@ -51,15 +50,10 @@ public class TerminateCloudFoundryInstancesAtomicOperation implements AtomicOper
client.getApplications().deleteAppInstance(serverGroupId, instanceIndex);
getTask().updateStatus(PHASE, "Terminated " + instanceDescription());
} catch (CloudFoundryApiException e) {
- getTask().updateStatus(PHASE, "Failed to terminate '" + instance + "': " + e.getMessage());
- oneOrMoreFailed = true;
+ throw new CloudFoundryApiException("Failed to terminate '" + instance + "': " + e.getMessage());
}
}
- if (oneOrMoreFailed) {
- getTask().fail();
- }
-
return null;
}

MODIFY
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/UnmapLoadBalancersAtomicOperation.java
clouddriver-cloudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/UnmapLoadBalancersAtomicOperation.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.Routes;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.LoadBalancersDescription;
import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundryLoadBalancer;
@@ -47,33 +48,26 @@ public class UnmapLoadBalancersAtomicOperation
List<String> routeList = description.getRoutes();
if (routeList == null || routeList.size() == 0) {
- getTask().updateStatus(PHASE, "No load balancer specified");
- getTask().fail();
+ throw new CloudFoundryApiException("No load balancer specified");
} else {
Routes routes = description.getClient().getRoutes();
Map<String, Optional<CloudFoundryLoadBalancer>> lbMap = routeList.stream()
.collect(Collectors.toMap(uri -> uri, uri -> Optional.ofNullable(routes.find(routes.toRouteId(uri), description.getSpace().getId()))));
- AtomicReference<Boolean> failedUnmap = new AtomicReference<>(Boolean.FALSE);
routeList.forEach(uri -> {
if (!Routes.isValidRouteFormat(uri)) {
- getTask().updateStatus(PHASE, "Invalid format for load balancer '" + uri + "'");
- failedUnmap.set(Boolean.TRUE);
+ throw new CloudFoundryApiException("Invalid format for load balancer '" + uri + "'");
} else if (!lbMap.get(uri).isPresent()) {
- getTask().updateStatus(PHASE, "Load balancer '" + uri + "' does not exist");
- failedUnmap.set(Boolean.TRUE);
+ throw new CloudFoundryApiException("Load balancer '" + uri + "' does not exist");
}
});
- if (failedUnmap.get()) {
- getTask().fail();
- } else {
+
lbMap.forEach((uri, o) -> {
getTask().updateStatus(PHASE, "Unmapping load balancer '" + uri + "'");
o.ifPresent(lb -> routes.deleteRoute(lb.getId()));
getTask().updateStatus(PHASE, "Unmapped load balancer '" + uri + "'");
});
}
- }
return null;
}

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/AbstractCloudFoundryLoadBalancerMappingOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/AbstractCloudFoundryLoadBalancerMappingOperationTest.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.MockCloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.RouteId;
@@ -91,7 +92,7 @@ class AbstractCloudFoundryLoadBalancerMappingOperationTest {
}
@Test
- void mapRoutesShouldReturnFalseWhenInvalidRoutesAreFound() {
+ void mapRoutesShouldThrowAnExceptionWhenInvalidRoutesAreFound() {
AbstractCloudFoundryServerGroupDescription description = new AbstractCloudFoundryServerGroupDescription() {};
description.setClient(client);
description.setServerGroupName("sg-name");
@@ -100,12 +101,18 @@ class AbstractCloudFoundryLoadBalancerMappingOperationTest {
List<String> routeList = Collections.singletonList("road.to.nowhere");
- assertThat(operation.mapRoutes(description, routeList, null, null)).isFalse();
- assertThat(testTask.getHistory()).has(status("Invalid format or domain for load balancer 'road.to.nowhere'"), atIndex(2));
+ Exception exception = null;
+ try {
+ operation.mapRoutes(description, routeList, null, null);
+ } catch (IllegalArgumentException illegalArgumentException) {
+ exception = illegalArgumentException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("road.to.nowhereis an invalid route");
}
@Test
- void mapRoutesShouldReturnFalseWhenRoutesExistInOtherOrgSpace() {
+ void mapRoutesShouldThrowAnExceptionWhenRoutesExistInOtherOrgSpace() {
AbstractCloudFoundryServerGroupDescription description = new AbstractCloudFoundryServerGroupDescription() {};
description.setClient(client);
description.setServerGroupName("sg-name");
@@ -119,8 +126,14 @@ class AbstractCloudFoundryLoadBalancerMappingOperationTest {
List<String> routeList = Collections.singletonList("road.to.nowhere");
- assertThat(operation.mapRoutes(description, routeList, space, null)).isFalse();
- assertThat(testTask.getHistory()).has(status("Load balancer already exists in another organization and space"), atIndex(2));
+ Exception exception = null;
+ try {
+ operation.mapRoutes(description, routeList, space, null);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): Load balancer already exists in another organization and space");
}
private static class AbstractCloudFoundryAtomicOperationTestClass extends AbstractCloudFoundryLoadBalancerMappingOperation {

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeleteCloudFoundryLoadBalancerAtomicOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeleteCloudFoundryLoadBalancerAtomicOperationTest.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.DeleteCloudFoundryLoadBalancerDescription;
import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundryDomain;
import com.netflix.spinnaker.clouddriver.cloudfoundry.model.CloudFoundryLoadBalancer;
@@ -59,7 +60,13 @@ class DeleteCloudFoundryLoadBalancerAtomicOperationTest extends AbstractCloudFou
DeleteCloudFoundryLoadBalancerAtomicOperation op = new DeleteCloudFoundryLoadBalancerAtomicOperation(desc);
- assertThat(runOperation(op).getHistory())
- .has(status("Load balancer does not exist"), atIndex(1));
+ Exception exception = null;
+ try {
+ runOperation(op);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): Load balancer does not exist");
}
}

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeployCloudFoundryServerGroupAtomicOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/DeployCloudFoundryServerGroupAtomicOperationTest.java
@@ -18,6 +18,7 @@ package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
import com.netflix.spinnaker.clouddriver.cloudfoundry.artifacts.ArtifactCredentialsFromString;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.Applications;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.MockCloudFoundryClient;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
@@ -95,13 +96,17 @@ class DeployCloudFoundryServerGroupAtomicOperationTest extends AbstractCloudFoun
new DeployCloudFoundryServerGroupAtomicOperation(new PassThroughOperationPoller(), description, clusterProvider);
final Applications apps = getApplications(clusterProvider, ProcessStats.State.CRASHED);
+ Exception exception = null;
// When
- final DeploymentResult result = operation.operate(Lists.emptyList());
+ try {
+ operation.operate(Lists.emptyList());
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
//Then
- verifyInOrder(apps, () -> atLeastOnce());
-
- assertThat(testTask.getStatus().isFailed()).isTrue();
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): Failed to start 'app1-stack1-detail1-v000' which instead crashed");
}
@Test

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
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.ScaleCloudFoundryServerGroupDescription;
import com.netflix.spinnaker.clouddriver.helpers.OperationPoller;
import com.netflix.spinnaker.clouddriver.model.ServerGroup;
+import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import java.util.function.Supplier;
@@ -64,9 +66,14 @@ class ScaleCloudFoundryServerGroupAtomicOperationTest extends AbstractCloudFound
ScaleCloudFoundryServerGroupAtomicOperation op = new ScaleCloudFoundryServerGroupAtomicOperation(poller, desc);
- assertThat(runOperation(op).getHistory())
- .has(status("Resizing 'myapp'"), atIndex(1))
- .has(status("Failed to start 'myapp' which instead crashed"), atIndex(2));
+ Exception exception = null;
+ try {
+ runOperation(op);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): Failed to start 'myapp' which instead crashed");
}
@Test

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StartCloudFoundryServerGroupAtomicOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StartCloudFoundryServerGroupAtomicOperationTest.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.StartCloudFoundryServerGroupDescription;
import com.netflix.spinnaker.clouddriver.helpers.OperationPoller;
@@ -67,8 +68,13 @@ class StartCloudFoundryServerGroupAtomicOperationTest extends AbstractCloudFound
StartCloudFoundryServerGroupAtomicOperation op = new StartCloudFoundryServerGroupAtomicOperation(poller, desc);
- assertThat(runOperation(op).getHistory())
- .has(status("Starting 'myapp'"), atIndex(1))
- .has(status("Failed to start 'myapp' which instead crashed"), atIndex(2));
+ Exception exception = null;
+ try {
+ runOperation(op);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): Failed to start 'myapp' which instead crashed");
}
}

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/StopCloudFoundryServerGroupAtomicOperationTest.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.StopCloudFoundryServerGroupDescription;
import com.netflix.spinnaker.clouddriver.helpers.OperationPoller;
@@ -67,8 +68,13 @@ class StopCloudFoundryServerGroupAtomicOperationTest extends AbstractCloudFoundr
StopCloudFoundryServerGroupAtomicOperation op = new StopCloudFoundryServerGroupAtomicOperation(poller, desc);
- assertThat(runOperation(op).getHistory())
- .has(status("Stopping 'myapp'"), atIndex(1))
- .has(status("Failed to stop 'myapp' which instead is running"), atIndex(2));
+ Exception exception = null;
+ try {
+ runOperation(op);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): Failed to stop 'myapp' which instead is running");
}
}

MODIFY
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/UnmapLoadBalancersAtomicOperationTest.java
clouddriver-cloudfoundry/src/test/java/com/netflix/spinnaker/clouddriver/cloudfoundry/deploy/ops/UnmapLoadBalancersAtomicOperationTest.java
package com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.ops;
+import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryApiException;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.Routes;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.RouteId;
import com.netflix.spinnaker.clouddriver.cloudfoundry.deploy.description.LoadBalancersDescription;
@@ -51,16 +52,30 @@ class UnmapLoadBalancersAtomicOperationTest extends AbstractCloudFoundryAtomicOp
@Test
void operateWithNullRoutes() {
UnmapLoadBalancersAtomicOperation op = new UnmapLoadBalancersAtomicOperation(desc);
- assertThat(runOperation(op).getHistory())
- .has(status("No load balancer specified"), atIndex(2));
+
+ Exception exception = null;
+ try {
+ runOperation(op);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): No load balancer specified");
}
@Test
void operateWithEmptyRoutes() {
desc.setRoutes(Collections.emptyList());
UnmapLoadBalancersAtomicOperation op = new UnmapLoadBalancersAtomicOperation(desc);
- assertThat(runOperation(op).getHistory())
- .has(status("No load balancer specified"), atIndex(2));
+
+ Exception exception = null;
+ try {
+ runOperation(op);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): No load balancer specified");
}
@Test
@@ -70,9 +85,14 @@ class UnmapLoadBalancersAtomicOperationTest extends AbstractCloudFoundryAtomicOp
"bad.route 2.example.com"
).asJava());
UnmapLoadBalancersAtomicOperation op = new UnmapLoadBalancersAtomicOperation(desc);
- assertThat(runOperation(op).getHistory())
- .has(status("Load balancer 'bad.route-1.example.com' does not exist"), atIndex(2))
- .has(status("Invalid format for load balancer 'bad.route 2.example.com'"), atIndex(3));
+ Exception exception = null;
+ try {
+ runOperation(op);
+ } catch (CloudFoundryApiException cloudFoundryApiException) {
+ exception = cloudFoundryApiException;
+ }
+ assertThat(exception).isNotNull();
+ assertThat(exception.getMessage()).isEqualTo("Cloud Foundry API returned with error(s): Load balancer 'bad.route-1.example.com' does not exist");
}
@Test

chore(cf): remove usage of task fail and throw an exception (#3462)