Skip to content

Commit 072ca8d

Browse files
author
Steve Powell
committed
Merge 124537911-check-route-no-host to master
[Completes #124537911]
2 parents c62b599 + a019d59 commit 072ca8d

File tree

6 files changed

+70
-40
lines changed

6 files changed

+70
-40
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v2/routes/ReactorRoutes.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.cloudfoundry.util.ExceptionUtils;
4040
import reactor.core.publisher.Mono;
4141

42+
import java.util.Optional;
43+
4244
/**
4345
* The Reactor-based implementation of {@link Routes}
4446
*/
@@ -74,7 +76,12 @@ public Mono<DeleteRouteResponse> delete(DeleteRouteRequest request) {
7476

7577
@Override
7678
public Mono<Boolean> exists(RouteExistsRequest request) {
77-
return get(request, Boolean.class, builder -> builder.pathSegment("v2", "routes", "reserved", "domain", request.getDomainId(), "host", request.getHost()))
79+
return get(request, Boolean.class,
80+
builder -> {
81+
builder.pathSegment("v2", "routes", "reserved", "domain", request.getDomainId());
82+
Optional.ofNullable(request.getHost()).ifPresent(host -> builder.pathSegment("host", host));
83+
return builder;
84+
})
7885
.defaultIfEmpty(true)
7986
.otherwise(ExceptionUtils.statusCode(CF_NOT_FOUND), t -> Mono.just(false));
8087
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v2/routes/_RouteExistsRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ abstract class _RouteExistsRequest {
3636
/**
3737
* The host
3838
*/
39+
@Nullable
3940
@JsonIgnore
4041
abstract String getHost();
4142

cloudfoundry-client/src/test/java/org/cloudfoundry/client/v2/routes/RouteExistsRequestTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,13 @@ public final class RouteExistsRequestTest {
2323
@Test(expected = IllegalStateException.class)
2424
public void noDomainId() {
2525
RouteExistsRequest.builder()
26-
.host("test-host")
27-
.build();
28-
}
29-
30-
@Test(expected = IllegalStateException.class)
31-
public void noHost() {
32-
RouteExistsRequest.builder()
33-
.domainId("test-domain-id")
3426
.build();
3527
}
3628

3729
@Test
3830
public void valid() {
3931
RouteExistsRequest.builder()
4032
.domainId("test-domain-id")
41-
.host("test-host")
4233
.build();
4334
}
4435

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/routes/_CheckRouteRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ abstract class _CheckRouteRequest {
3333
/**
3434
* The host of the route
3535
*/
36+
@Nullable
3637
abstract String getHost();
3738

3839
/**

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/routes/CheckRouteRequestTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,13 @@ public final class CheckRouteRequestTest {
2323
@Test(expected = IllegalStateException.class)
2424
public void noDomain() {
2525
CheckRouteRequest.builder()
26-
.host("test-host")
27-
.build();
28-
}
29-
30-
@Test(expected = IllegalStateException.class)
31-
public void noHost() {
32-
CheckRouteRequest.builder()
33-
.domain("test-domain")
3426
.build();
3527
}
3628

3729
@Test
3830
public void valid() {
3931
CheckRouteRequest.builder()
4032
.domain("test-domain")
41-
.host("test-host")
4233
.build();
4334
}
4435

integration-test/src/test/java/org/cloudfoundry/operations/RoutesTest.java

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
import org.cloudfoundry.operations.applications.ApplicationHealthCheck;
2121
import org.cloudfoundry.operations.applications.PushApplicationRequest;
2222
import org.cloudfoundry.operations.domains.CreateDomainRequest;
23+
import org.cloudfoundry.operations.domains.CreateSharedDomainRequest;
2324
import org.cloudfoundry.operations.routes.CheckRouteRequest;
2425
import org.cloudfoundry.operations.routes.CreateRouteRequest;
2526
import org.cloudfoundry.operations.routes.DeleteRouteRequest;
2627
import org.cloudfoundry.operations.routes.ListRoutesRequest;
2728
import org.cloudfoundry.operations.routes.MapRouteRequest;
2829
import org.cloudfoundry.operations.routes.Route;
2930
import org.cloudfoundry.operations.routes.UnmapRouteRequest;
31+
import org.junit.Ignore;
3032
import org.junit.Test;
3133
import org.springframework.beans.factory.annotation.Autowired;
3234
import org.springframework.core.io.ClassPathResource;
@@ -68,13 +70,30 @@ public void checkFalse() {
6870
.assertEquals(false));
6971
}
7072

73+
@Ignore("Awaiting resolution of https://github.com/cloudfoundry/cloud_controller_ng/issues/650")
7174
@Test
72-
public void checkTrue() {
75+
public void checkTruePrivateDomainNoHost() {
7376
String domainName = getDomainName();
7477
String hostName = getHostName();
7578
String path = getPath();
7679

77-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
80+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
81+
.then(this.cloudFoundryOperations.routes()
82+
.check(CheckRouteRequest.builder()
83+
.domain(domainName)
84+
.path(path)
85+
.build()))
86+
.subscribe(testSubscriber()
87+
.assertEquals(true));
88+
}
89+
90+
@Test
91+
public void checkTrueSharedDomain() {
92+
String domainName = getDomainName();
93+
String hostName = getHostName();
94+
String path = getPath();
95+
96+
createSharedDomainAndRoute(this.cloudFoundryOperations, this.spaceName, domainName, hostName, path)
7897
.then(this.cloudFoundryOperations.routes()
7998
.check(CheckRouteRequest.builder()
8099
.domain(domainName)
@@ -91,7 +110,7 @@ public void create() {
91110
String hostName = getHostName();
92111
String path = getPath();
93112

94-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
113+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
95114
.then(this.cloudFoundryOperations.routes()
96115
.check(CheckRouteRequest.builder()
97116
.domain(domainName)
@@ -125,7 +144,7 @@ public void delete() {
125144
String hostName = getHostName();
126145
String path = getPath();
127146

128-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
147+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
129148
.then(this.cloudFoundryOperations.routes()
130149
.delete(DeleteRouteRequest.builder()
131150
.domain(domainName)
@@ -164,7 +183,7 @@ public void deleteOrphanedRoutes() {
164183
String hostName = getHostName();
165184
String path = getPath();
166185

167-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
186+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
168187
.then(this.cloudFoundryOperations.routes()
169188
.deleteOrphanedRoutes())
170189
.then(this.cloudFoundryOperations.routes()
@@ -183,7 +202,7 @@ public void listWithOrganizationLevel() {
183202
String hostName = getHostName();
184203
String path = getPath();
185204

186-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
205+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
187206
.thenMany(this.cloudFoundryOperations.routes()
188207
.list(ListRoutesRequest.builder()
189208
.level(ORGANIZATION)
@@ -199,7 +218,7 @@ public void listWithSpaceLevel() {
199218
String hostName = getHostName();
200219
String path = getPath();
201220

202-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
221+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path)
203222
.thenMany(this.cloudFoundryOperations.routes()
204223
.list(ListRoutesRequest.builder()
205224
.level(SPACE)
@@ -218,7 +237,7 @@ public void map() {
218237

219238
Mono
220239
.when(
221-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
240+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
222241
createApplication(this.cloudFoundryOperations, getApplicationBits(), applicationName, true)
223242
)
224243
.then(this.cloudFoundryOperations.routes()
@@ -246,7 +265,7 @@ public void mapNoHost() {
246265

247266
Mono
248267
.when(
249-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
268+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
250269
createApplication(this.cloudFoundryOperations, getApplicationBits(), applicationName, true)
251270
)
252271
.then(this.cloudFoundryOperations.routes()
@@ -274,7 +293,7 @@ public void mapNoPath() {
274293

275294
Mono
276295
.when(
277-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
296+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
278297
createApplication(this.cloudFoundryOperations, getApplicationBits(), applicationName, true)
279298
)
280299
.then(this.cloudFoundryOperations.routes()
@@ -302,7 +321,7 @@ public void unmap() {
302321

303322
Mono
304323
.when(
305-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
324+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
306325
createApplication(this.cloudFoundryOperations, getApplicationBits(), applicationName, true)
307326
)
308327
.then(this.cloudFoundryOperations.routes()
@@ -336,7 +355,7 @@ public void unmapNoPath() {
336355

337356
Mono
338357
.when(
339-
createRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
358+
createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path),
340359
createApplication(this.cloudFoundryOperations, getApplicationBits(), applicationName, true)
341360
)
342361
.then(this.cloudFoundryOperations.routes()
@@ -374,19 +393,39 @@ private static Mono<Void> createApplication(CloudFoundryOperations cloudFoundryO
374393
.build());
375394
}
376395

377-
private static Mono<Void> createRoute(CloudFoundryOperations cloudFoundryOperations, String organizationName, String spaceName, String domainName, String hostName, String path) {
396+
private static Mono<Void> createDomain(CloudFoundryOperations cloudFoundryOperations, String organizationName, String domainName) {
378397
return cloudFoundryOperations.domains()
379398
.create(CreateDomainRequest.builder()
380399
.domain(domainName)
381400
.organization(organizationName)
382-
.build())
383-
.then(cloudFoundryOperations.routes()
384-
.create(CreateRouteRequest.builder()
385-
.domain(domainName)
386-
.host(hostName)
387-
.path(path)
388-
.space(spaceName)
389-
.build()));
401+
.build());
402+
}
403+
404+
private static Mono<Void> createSharedDomain(CloudFoundryOperations cloudFoundryOperations, String domainName) {
405+
return cloudFoundryOperations.domains()
406+
.createShared(CreateSharedDomainRequest.builder()
407+
.domain(domainName)
408+
.build());
409+
}
410+
411+
private static Mono<Void> createDomainAndRoute(CloudFoundryOperations cloudFoundryOperations, String organizationName, String spaceName, String domainName, String hostName, String path) {
412+
return createDomain(cloudFoundryOperations, organizationName, domainName)
413+
.then(createRoute(cloudFoundryOperations, spaceName, domainName, hostName, path));
414+
}
415+
416+
private static Mono<Void> createSharedDomainAndRoute(CloudFoundryOperations cloudFoundryOperations, String spaceName, String domainName, String hostName, String path) {
417+
return createSharedDomain(cloudFoundryOperations, domainName)
418+
.then(createRoute(cloudFoundryOperations, spaceName, domainName, hostName, path));
419+
}
420+
421+
private static Mono<Void> createRoute(CloudFoundryOperations cloudFoundryOperations, String spaceName, String domainName, String hostName, String path) {
422+
return cloudFoundryOperations.routes()
423+
.create(CreateRouteRequest.builder()
424+
.domain(domainName)
425+
.host(hostName)
426+
.path(path)
427+
.space(spaceName)
428+
.build());
390429
}
391430

392431
private static Predicate<Route> filterRoutes(String domainName, String host, String path, String applicationName) {

0 commit comments

Comments
 (0)