7070import org .cloudfoundry .client .v2 .userprovidedserviceinstances .AssociateUserProvidedServiceInstanceRouteResponse ;
7171import org .cloudfoundry .client .v2 .userprovidedserviceinstances .CreateUserProvidedServiceInstanceResponse ;
7272import org .cloudfoundry .client .v2 .userprovidedserviceinstances .DeleteUserProvidedServiceInstanceRequest ;
73+ import org .cloudfoundry .client .v2 .userprovidedserviceinstances .RemoveUserProvidedServiceInstanceRouteRequest ;
7374import org .cloudfoundry .client .v2 .userprovidedserviceinstances .UpdateUserProvidedServiceInstanceResponse ;
7475import org .cloudfoundry .operations .util .OperationsLogging ;
7576import 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}
0 commit comments