Skip to content

Commit 60e8cd1

Browse files
committed
Merge branch 'update-service-broker' into 2.x
2 parents f182f7d + 671378e commit 60e8cd1

File tree

5 files changed

+199
-0
lines changed

5 files changed

+199
-0
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/serviceadmin/DefaultServiceAdmin.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.cloudfoundry.client.v2.servicebrokers.ListServiceBrokersRequest;
2626
import org.cloudfoundry.client.v2.servicebrokers.ServiceBrokerEntity;
2727
import org.cloudfoundry.client.v2.servicebrokers.ServiceBrokerResource;
28+
import org.cloudfoundry.client.v2.servicebrokers.UpdateServiceBrokerResponse;
2829
import org.cloudfoundry.client.v2.serviceplans.ListServicePlansRequest;
2930
import org.cloudfoundry.client.v2.serviceplans.ServicePlanResource;
3031
import org.cloudfoundry.client.v2.serviceplans.UpdateServicePlanRequest;
@@ -158,6 +159,19 @@ public Flux<ServiceAccess> listServiceAccessSettings(ListServiceAccessSettingsRe
158159
.checkpoint();
159160
}
160161

162+
@Override
163+
public Mono<Void> update(UpdateServiceBrokerRequest request) {
164+
return this.cloudFoundryClient
165+
.then(cloudFoundryClient -> Mono.when(
166+
Mono.just(cloudFoundryClient),
167+
getServiceBrokerId(cloudFoundryClient, request.getName())
168+
))
169+
.then(function((cloudFoundryClient, serviceBrokerId) -> requestUpdateServiceBroker(cloudFoundryClient, request, serviceBrokerId)))
170+
.then()
171+
.transform(OperationsLogging.log("Update Service Broker"))
172+
.checkpoint();
173+
}
174+
161175
private static Flux<ServiceAccess> collectServiceAccessSettings(CloudFoundryClient cloudFoundryClient, List<ServiceBrokerResource> brokers, ListServiceAccessSettingsRequest request,
162176
List<ServicePlanVisibilityResource> visibilities) {
163177
List<String> brokerIds = brokers.stream()
@@ -397,6 +411,17 @@ private static Flux<ServiceResource> requestListServices(CloudFoundryClient clou
397411
.build()));
398412
}
399413

414+
private static Mono<UpdateServiceBrokerResponse> requestUpdateServiceBroker(CloudFoundryClient cloudFoundryClient, UpdateServiceBrokerRequest request, String serviceBrokerId) {
415+
return cloudFoundryClient.serviceBrokers()
416+
.update(org.cloudfoundry.client.v2.servicebrokers.UpdateServiceBrokerRequest.builder()
417+
.serviceBrokerId(serviceBrokerId)
418+
.name(request.getName())
419+
.brokerUrl(request.getUrl())
420+
.authenticationUsername(request.getUsername())
421+
.authenticationPassword(request.getPassword())
422+
.build());
423+
}
424+
400425
private static Mono<UpdateServicePlanResponse> requestUpdateServicePlanPublicStatus(CloudFoundryClient cloudFoundryClient, boolean publiclyVisible, String servicePlanId) {
401426
return cloudFoundryClient.servicePlans()
402427
.update(UpdateServicePlanRequest.builder()

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/serviceadmin/ServiceAdmin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,13 @@ public interface ServiceAdmin {
7171
*/
7272
Flux<ServiceAccess> listServiceAccessSettings(ListServiceAccessSettingsRequest request);
7373

74+
/**
75+
* Update an existing service broker
76+
*
77+
* @param request The Update Service Broker request
78+
* @return a completion indicator
79+
*/
80+
81+
Mono<Void> update(UpdateServiceBrokerRequest request);
82+
7483
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2013-2018 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.serviceadmin;
18+
19+
import org.immutables.value.Value;
20+
21+
/**
22+
* Request options for the update service broker operation
23+
*/
24+
@Value.Immutable
25+
abstract class _UpdateServiceBrokerRequest {
26+
27+
/**
28+
* The name of the service broker
29+
*/
30+
abstract String getName();
31+
32+
/**
33+
* The password to authenticate with the broker
34+
*/
35+
abstract String getPassword();
36+
37+
/**
38+
* The url of the service broker
39+
*/
40+
abstract String getUrl();
41+
42+
/**
43+
* The username to authenticate with the broker
44+
*/
45+
abstract String getUsername();
46+
}

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/serviceadmin/DefaultServiceAdminTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.cloudfoundry.client.v2.servicebrokers.ListServiceBrokersResponse;
2929
import org.cloudfoundry.client.v2.servicebrokers.ServiceBrokerEntity;
3030
import org.cloudfoundry.client.v2.servicebrokers.ServiceBrokerResource;
31+
import org.cloudfoundry.client.v2.servicebrokers.UpdateServiceBrokerResponse;
3132
import org.cloudfoundry.client.v2.serviceplans.ListServicePlansRequest;
3233
import org.cloudfoundry.client.v2.serviceplans.ListServicePlansResponse;
3334
import org.cloudfoundry.client.v2.serviceplans.ServicePlanEntity;
@@ -471,6 +472,42 @@ public void listServiceBrokersNoBrokers() {
471472
.verify(Duration.ofSeconds(5));
472473
}
473474

475+
@Test
476+
public void updateServiceBroker() {
477+
requestListServiceBrokers(this.cloudFoundryClient, "test-service-broker-name");
478+
requestUpdateServiceBroker(this.cloudFoundryClient, "test-service-broker-name", "test-service-broker-url", "test-service-broker-username",
479+
"test-service-broker-password", "test-service-broker-id");
480+
481+
this.serviceAdmin
482+
.update(UpdateServiceBrokerRequest.builder()
483+
.name("test-service-broker-name")
484+
.url("test-service-broker-url")
485+
.username("test-service-broker-username")
486+
.password("test-service-broker-password")
487+
.build())
488+
.as(StepVerifier::create)
489+
.expectComplete()
490+
.verify(Duration.ofSeconds(5));
491+
}
492+
493+
@Test
494+
public void updateServiceBrokerNoServiceBroker() {
495+
requestListServiceBrokersEmpty(this.cloudFoundryClient, "test-service-broker-name");
496+
requestUpdateServiceBroker(this.cloudFoundryClient, "test-service-broker-name", "test-service-broker-url", "test-service-broker-username",
497+
"test-service-broker-password", "test-service-broker-id");
498+
499+
this.serviceAdmin
500+
.update(UpdateServiceBrokerRequest.builder()
501+
.name("test-service-broker-name")
502+
.url("test-service-broker-url")
503+
.username("test-service-broker-username")
504+
.password("test-service-broker-password")
505+
.build())
506+
.as(StepVerifier::create)
507+
.consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Service Broker test-service-broker-name not found"))
508+
.verify(Duration.ofSeconds(5));
509+
}
510+
474511
private static void requestCreateServiceBroker(CloudFoundryClient cloudFoundryClient, String name, String url, String username, String password, String spaceId) {
475512
when(cloudFoundryClient.serviceBrokers()
476513
.create(org.cloudfoundry.client.v2.servicebrokers.CreateServiceBrokerRequest.builder()
@@ -722,6 +759,20 @@ private static void requestListServicesWithNameEmpty(CloudFoundryClient cloudFou
722759
.build()));
723760
}
724761

762+
private static void requestUpdateServiceBroker(CloudFoundryClient cloudFoundryClient, String name, String url, String username, String password, String serviceBrokerId) {
763+
when(cloudFoundryClient.serviceBrokers()
764+
.update(org.cloudfoundry.client.v2.servicebrokers.UpdateServiceBrokerRequest.builder()
765+
.serviceBrokerId(serviceBrokerId)
766+
.name(name)
767+
.brokerUrl(url)
768+
.authenticationUsername(username)
769+
.authenticationPassword(password)
770+
.build()))
771+
.thenReturn(Mono
772+
.just(fill(UpdateServiceBrokerResponse.builder())
773+
.build()));
774+
}
775+
725776
private static void requestUpdateServicePlan(CloudFoundryClient cloudFoundryClient, boolean publiclyVisible, String servicePlanId) {
726777
when(cloudFoundryClient.servicePlans()
727778
.update(UpdateServicePlanRequest.builder()
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2013-2018 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.serviceadmin;
18+
19+
import org.junit.Test;
20+
21+
public class UpdateServiceBrokerRequestTest {
22+
23+
@Test(expected = IllegalStateException.class)
24+
public void noName() {
25+
UpdateServiceBrokerRequest.builder()
26+
.url("test-broker-url")
27+
.username("test-username")
28+
.password("test-password")
29+
.build();
30+
}
31+
32+
@Test(expected = IllegalStateException.class)
33+
public void noPassword() {
34+
UpdateServiceBrokerRequest.builder()
35+
.name("test-broker")
36+
.url("test-broker-url")
37+
.username("test-username")
38+
.build();
39+
}
40+
41+
@Test(expected = IllegalStateException.class)
42+
public void noUrl() {
43+
UpdateServiceBrokerRequest.builder()
44+
.name("test-broker")
45+
.username("test-username")
46+
.password("test-password")
47+
.build();
48+
}
49+
50+
@Test(expected = IllegalStateException.class)
51+
public void noUsername() {
52+
UpdateServiceBrokerRequest.builder()
53+
.name("test-broker")
54+
.url("test-broker-url")
55+
.password("test-password")
56+
.build();
57+
}
58+
59+
@Test
60+
public void valid() {
61+
UpdateServiceBrokerRequest.builder()
62+
.name("test-broker")
63+
.url("test-broker-url")
64+
.username("test-username")
65+
.password("test-password")
66+
.build();
67+
}
68+
}

0 commit comments

Comments
 (0)