Skip to content

Commit

Permalink
fix(provider/cf): handle error when route exists in other org/space (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelchio authored and jkschneider committed Dec 20, 2018
1 parent b1a949b commit 12c9dd8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ boolean mapRoutes(@Nullable List<String> routes, CloudFoundrySpace space, String
}

for (RouteId routeId : routeIds) {
CloudFoundryLoadBalancer loadBalancer = client.getRoutes().find(routeId, space.getId());
CloudFoundryLoadBalancer loadBalancer = client.getRoutes().createRoute(routeId, space.getId());
if (loadBalancer == null) {
loadBalancer = client.getRoutes().createRoute(routeId, space.getId());
getTask().updateStatus(PHASE, "Load balancer already exists in another organization and space");
getTask().fail();
return false;
}
getTask().updateStatus(PHASE, "Mapping load balancer '" + loadBalancer.getName() + "' to " + description.getServerGroupName());
client.getApplications().mapRoute(serverGroupId, loadBalancer.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void mapRoutesShouldReturnTrueWhenRoutesAreValid() {
organization(org).
build()).
build();
when(client.getRoutes().find(any(), anyString())).thenReturn(loadBalancer);
when(client.getRoutes().createRoute(any(RouteId.class), anyString())).thenReturn(loadBalancer);

List<String> routeList = Collections.singletonList("road.to.nowhere");

Expand All @@ -117,6 +117,24 @@ void mapRoutesShouldReturnFalseWhenInvalidRoutesAreFound() {
assertThat(testTask.getHistory()).has(status("Invalid format or domain for route 'road.to.nowhere'"), atIndex(2));
}

@Test
void mapRoutesShouldReturnFalseWhenRoutesExistInOtherOrgSpace() {
DeployCloudFoundryServerGroupDescription description = new DeployCloudFoundryServerGroupDescription();
description.setClient(client);
description.setServerGroupName("sg-name");

CloudFoundryOrganization org = CloudFoundryOrganization.builder().id("org-id").name("org-name").build();
CloudFoundrySpace space = CloudFoundrySpace.builder().id("space-id").name("space-name").organization(org).build();

DeployCloudFoundryServerGroupAtomicOperation operation = new DeployCloudFoundryServerGroupAtomicOperation(null, description, null);
when(client.getRoutes().toRouteId(anyString())).thenReturn(new RouteId("road.to.nowhere", null, null, "domain-guid"));

List<String> routeList = Collections.singletonList("road.to.nowhere");

assertThat(operation.mapRoutes(routeList, space, null)).isFalse();
assertThat(testTask.getHistory()).has(status("Load balancer already exists in another organization and space"), atIndex(2));
}

@Test
void executeOperation() {
// Given
Expand Down

0 comments on commit 12c9dd8

Please sign in to comment.