Skip to content

Commit 89a8275

Browse files
committed
Merge branch '730-unbind-route-service-instances'
2 parents bcbc1ec + 18fdcb8 commit 89a8275

File tree

5 files changed

+186
-7
lines changed

5 files changed

+186
-7
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/services/DefaultServices.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.cloudfoundry.client.v2.userprovidedserviceinstances.AssociateUserProvidedServiceInstanceRouteResponse;
7171
import org.cloudfoundry.client.v2.userprovidedserviceinstances.CreateUserProvidedServiceInstanceResponse;
7272
import org.cloudfoundry.client.v2.userprovidedserviceinstances.DeleteUserProvidedServiceInstanceRequest;
73+
import org.cloudfoundry.client.v2.userprovidedserviceinstances.RemoveUserProvidedServiceInstanceRouteRequest;
7374
import org.cloudfoundry.client.v2.userprovidedserviceinstances.UpdateUserProvidedServiceInstanceResponse;
7475
import org.cloudfoundry.operations.util.OperationsLogging;
7576
import org.cloudfoundry.util.ExceptionUtils;
@@ -369,6 +370,28 @@ public Mono<Void> unbind(UnbindServiceInstanceRequest request) {
369370
.checkpoint();
370371
}
371372

373+
@Override
374+
public Mono<Void> unbindRoute(UnbindRouteServiceInstanceRequest request) {
375+
return Mono
376+
.when(this.cloudFoundryClient, this.organizationId, this.spaceId)
377+
.then(function((cloudFoundryClient, organizationId, spaceId) -> Mono
378+
.when(
379+
Mono.just(cloudFoundryClient),
380+
getDomainId(cloudFoundryClient, request.getDomainName(), organizationId),
381+
Mono.just(spaceId)
382+
)))
383+
.then(function((cloudFoundryClient, domainId, spaceId) -> Mono
384+
.when(
385+
Mono.just(cloudFoundryClient),
386+
getRouteId(cloudFoundryClient, request.getDomainName(), domainId, request.getHostname(), request.getPath()),
387+
getSpaceServiceInstanceId(cloudFoundryClient, request.getServiceInstanceName(), spaceId)
388+
)))
389+
.then(function(DefaultServices::requestRemoveRoute))
390+
.then()
391+
.transform(OperationsLogging.log("Unbind Route from Service Instance"))
392+
.checkpoint();
393+
}
394+
372395
@Override
373396
public Mono<Void> updateInstance(UpdateServiceInstanceRequest request) {
374397
return Mono
@@ -526,7 +549,7 @@ private static Mono<String> getPrivateDomainId(CloudFoundryClient cloudFoundryCl
526549
.singleOrEmpty();
527550
}
528551

529-
private static Mono<RouteResource> getRoute(CloudFoundryClient cloudFoundryClient, String domainId, String domain, String host, String path) {
552+
private static Mono<RouteResource> getRoute(CloudFoundryClient cloudFoundryClient, String domain, String domainId, String host, String path) {
530553
return getRoute(cloudFoundryClient, domainId, host, path)
531554
.otherwiseIfEmpty(ExceptionUtils.illegalArgument("Route %s.%s does not exist", host, domain));
532555
}
@@ -539,7 +562,7 @@ private static Mono<RouteResource> getRoute(CloudFoundryClient cloudFoundryClien
539562
}
540563

541564
private static Mono<String> getRouteId(CloudFoundryClient cloudFoundryClient, String domain, String domainId, String host, String path) {
542-
return getRoute(cloudFoundryClient, domainId, domain, host, path)
565+
return getRoute(cloudFoundryClient, domain, domainId, host, path)
543566
.map(ResourceUtils::getId);
544567
}
545568

@@ -590,6 +613,11 @@ private static Mono<String> getServicePlanIdByName(CloudFoundryClient cloudFound
590613
.otherwise(NoSuchElementException.class, t -> ExceptionUtils.illegalArgument("Service plan %s does not exist", plan));
591614
}
592615

616+
private static Mono<List<ServicePlanResource>> getServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) {
617+
return requestListServicePlans(cloudFoundryClient, serviceId)
618+
.collectList();
619+
}
620+
593621
private static Mono<String> getSharedDomainId(CloudFoundryClient cloudFoundryClient, String domain) {
594622
return requestSharedDomain(cloudFoundryClient, domain)
595623
.map(ResourceUtils::getId)
@@ -869,6 +897,14 @@ private static Flux<PrivateDomainResource> requestPrivateDomain(CloudFoundryClie
869897
.build()));
870898
}
871899

900+
private static Mono<Void> requestRemoveRoute(CloudFoundryClient cloudFoundryClient, String routeId, String userProvidedServiceInstanceId) {
901+
return cloudFoundryClient.userProvidedServiceInstances()
902+
.removeRoute(RemoveUserProvidedServiceInstanceRouteRequest.builder()
903+
.routeId(routeId)
904+
.userProvidedServiceInstanceId(userProvidedServiceInstanceId)
905+
.build());
906+
}
907+
872908
private static Flux<RouteResource> requestRoutes(CloudFoundryClient cloudFoundryClient, UnaryOperator<ListRoutesRequest.Builder> modifier) {
873909

874910
ListRoutesRequest.Builder listBuilder = modifier.apply(ListRoutesRequest.builder());
@@ -1035,9 +1071,4 @@ private static Mono<Void> waitForCreateInstance(CloudFoundryClient cloudFoundryC
10351071
.map(response -> ResourceUtils.getEntity(response).getLastOperation()));
10361072
}
10371073

1038-
private Mono<List<ServicePlanResource>> getServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) {
1039-
return requestListServicePlans(cloudFoundryClient, serviceId)
1040-
.collectList();
1041-
}
1042-
10431074
}

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/services/Services.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ public interface Services {
135135
*/
136136
Mono<Void> unbind(UnbindServiceInstanceRequest request);
137137

138+
/**
139+
* Unbind a service instance from a route
140+
*
141+
* @param request the unbind service instance from a route request
142+
* @return a completion indicator
143+
*/
144+
Mono<Void> unbindRoute(UnbindRouteServiceInstanceRequest request);
145+
138146
/**
139147
* Update a service instance
140148
*
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2013-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.operations.services;
18+
19+
import org.cloudfoundry.Nullable;
20+
import org.immutables.value.Value;
21+
22+
/**
23+
* The request options for the unbind service instance operation
24+
*/
25+
@Value.Immutable
26+
abstract class _UnbindRouteServiceInstanceRequest {
27+
28+
/**
29+
* The domain for the bound route
30+
*/
31+
abstract String getDomainName();
32+
33+
/**
34+
* The hostname for the bound route
35+
*/
36+
@Nullable
37+
abstract String getHostname();
38+
39+
/**
40+
* The path for the bound route
41+
*/
42+
@Nullable
43+
abstract String getPath();
44+
45+
/**
46+
* The name of the service instance to bind
47+
*/
48+
abstract String getServiceInstanceName();
49+
50+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2013-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.operations.services;
18+
19+
import org.junit.Test;
20+
21+
public final class BindRouteServiceInstanceRequestTest {
22+
23+
@Test(expected = IllegalStateException.class)
24+
public void noDomainName() {
25+
BindRouteServiceInstanceRequest.builder()
26+
.serviceInstanceName("test-service-instance-name")
27+
.build();
28+
}
29+
30+
@Test(expected = IllegalStateException.class)
31+
public void noServiceInstanceName() {
32+
BindRouteServiceInstanceRequest.builder()
33+
.domainName("test-domain-name")
34+
.build();
35+
}
36+
37+
@Test
38+
public void valid() {
39+
BindRouteServiceInstanceRequest.builder()
40+
.domainName("test-domain-name")
41+
.serviceInstanceName("test-service-instance-name")
42+
.build();
43+
}
44+
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2013-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.operations.services;
18+
19+
import org.junit.Test;
20+
21+
public final class UnbindRouteServiceInstanceRequestTest {
22+
23+
@Test(expected = IllegalStateException.class)
24+
public void noDomainName() {
25+
UnbindRouteServiceInstanceRequest.builder()
26+
.serviceInstanceName("test-service-instance-name")
27+
.build();
28+
}
29+
30+
@Test(expected = IllegalStateException.class)
31+
public void noServiceInstanceName() {
32+
UnbindRouteServiceInstanceRequest.builder()
33+
.domainName("test-domain-name")
34+
.build();
35+
}
36+
37+
@Test
38+
public void valid() {
39+
UnbindRouteServiceInstanceRequest.builder()
40+
.domainName("test-domain-name")
41+
.serviceInstanceName("test-service-instance-name")
42+
.build();
43+
}
44+
45+
}

0 commit comments

Comments
 (0)