Skip to content

Commit e6e9138

Browse files
committed
Merge branch '929-update-instance-async' into 2.x
2 parents 501cc13 + c88c780 commit e6e9138

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public Mono<Void> createInstance(CreateServiceInstanceRequest request) {
177177
Mono.just(request.getCompletionTimeout()),
178178
createServiceInstance(cloudFoundryClient, spaceId, planId, request)
179179
)))
180-
.then(function(DefaultServices::waitForCreateInstance))
180+
.then(function(DefaultServices::waitForInstanceAction))
181181
.transform(OperationsLogging.log("Create Service Instance"))
182182
.checkpoint();
183183
}
@@ -408,7 +408,13 @@ public Mono<Void> updateInstance(UpdateServiceInstanceRequest request) {
408408
Mono.just(ResourceUtils.getId(serviceInstance)),
409409
getOptionalValidatedServicePlanId(cloudFoundryClient, request.getPlanName(), serviceInstance, organizationId)
410410
)))
411-
.then(function((cloudFoundryClient, serviceInstanceId, servicePlanId) -> updateServiceInstance(cloudFoundryClient, request, serviceInstanceId, servicePlanId.orElse(null))))
411+
.then(function((cloudFoundryClient, serviceInstanceId, servicePlanId) -> Mono
412+
.when(
413+
Mono.just(cloudFoundryClient),
414+
Mono.just(request.getCompletionTimeout()),
415+
requestUpdateServiceInstance(cloudFoundryClient, request, serviceInstanceId, servicePlanId.orElse(null))))
416+
)
417+
.then(function(DefaultServices::waitForInstanceAction))
412418
.then()
413419
.transform(OperationsLogging.log("Update Service Instance"))
414420
.checkpoint();
@@ -474,7 +480,7 @@ private static Mono<Void> deleteServiceInstance(CloudFoundryClient cloudFoundryC
474480
return JobUtils.waitForCompletion(cloudFoundryClient, completionTimeout, (JobEntity) response.getEntity());
475481
} else {
476482
return LastOperationUtils.waitForCompletion(completionTimeout, () -> requestGetServiceInstance(cloudFoundryClient, ResourceUtils.getId(serviceInstance))
477-
.map(r -> ResourceUtils.getEntity(r).getLastOperation()));
483+
.map(r -> ResourceUtils.getEntity(r).getLastOperation()));
478484
}
479485
});
480486
}
@@ -941,6 +947,19 @@ private static Flux<SharedDomainResource> requestSharedDomain(CloudFoundryClient
941947
.build()));
942948
}
943949

950+
private static Mono<UpdateServiceInstanceResponse> requestUpdateServiceInstance(CloudFoundryClient cloudFoundryClient, UpdateServiceInstanceRequest request, String serviceInstanceId,
951+
String servicePlanId) {
952+
return cloudFoundryClient.serviceInstances()
953+
.update(org.cloudfoundry.client.v2.serviceinstances
954+
.UpdateServiceInstanceRequest.builder()
955+
.acceptsIncomplete(true)
956+
.parameters(request.getParameters())
957+
.serviceInstanceId(serviceInstanceId)
958+
.servicePlanId(servicePlanId)
959+
.tags(request.getTags())
960+
.build());
961+
}
962+
944963
private static Mono<UpdateUserProvidedServiceInstanceResponse> requestUserProvidedServiceInstanceUpdate(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String newName) {
945964
return cloudFoundryClient.userProvidedServiceInstances()
946965
.update(org.cloudfoundry.client.v2.userprovidedserviceinstances.UpdateUserProvidedServiceInstanceRequest.builder()
@@ -1041,19 +1060,6 @@ private static List<ServicePlan> toServicePlans(List<ServicePlanResource> servic
10411060
.collect(Collectors.toList());
10421061
}
10431062

1044-
private static Mono<UpdateServiceInstanceResponse> updateServiceInstance(CloudFoundryClient cloudFoundryClient, UpdateServiceInstanceRequest request, String serviceInstanceId,
1045-
String servicePlanId) {
1046-
return cloudFoundryClient.serviceInstances()
1047-
.update(org.cloudfoundry.client.v2.serviceinstances
1048-
.UpdateServiceInstanceRequest.builder()
1049-
.acceptsIncomplete(true)
1050-
.parameters(request.getParameters())
1051-
.serviceInstanceId(serviceInstanceId)
1052-
.servicePlanId(servicePlanId)
1053-
.tags(request.getTags())
1054-
.build());
1055-
}
1056-
10571063
private static Mono<UpdateUserProvidedServiceInstanceResponse> updateUserProvidedServiceInstance(CloudFoundryClient cloudFoundryClient,
10581064
UpdateUserProvidedServiceInstanceRequest request,
10591065
String userProvidedServiceInstanceId) {
@@ -1066,7 +1072,7 @@ private static Mono<UpdateUserProvidedServiceInstanceResponse> updateUserProvide
10661072
.build());
10671073
}
10681074

1069-
private static Mono<Void> waitForCreateInstance(CloudFoundryClient cloudFoundryClient, Duration completionTimeout, AbstractServiceInstanceResource serviceInstance) {
1075+
private static Mono<Void> waitForInstanceAction(CloudFoundryClient cloudFoundryClient, Duration completionTimeout, AbstractServiceInstanceResource serviceInstance) {
10701076
return LastOperationUtils
10711077
.waitForCompletion(completionTimeout, () -> requestGetServiceInstance(cloudFoundryClient, ResourceUtils.getId(serviceInstance))
10721078
.map(response -> ResourceUtils.getEntity(response).getLastOperation()));

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.cloudfoundry.Nullable;
2121
import org.immutables.value.Value;
2222

23+
import java.time.Duration;
2324
import java.util.List;
2425
import java.util.Map;
2526

@@ -29,6 +30,14 @@
2930
@Value.Immutable
3031
abstract class _UpdateServiceInstanceRequest {
3132

33+
/**
34+
* How long to wait for update
35+
*/
36+
@Value.Default
37+
Duration getCompletionTimeout() {
38+
return Duration.ofMinutes(5);
39+
}
40+
3241
/**
3342
* The parameters of the service instance
3443
*/

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/services/DefaultServicesTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ public void updateService() {
860860
requestListSpaceServicePlans(this.cloudFoundryClient, "test-service-id", "test-plan", "test-plan-id");
861861
requestUpdateServiceInstance(this.cloudFoundryClient, Collections.singletonMap("test-parameter-key", "test-parameter-value"), "test-service-instance-id", "test-plan-id",
862862
Collections.singletonList("test-tag"));
863+
requestGetServiceInstance(this.cloudFoundryClient, "test-id", "successful");
863864

864865
this.services
865866
.updateInstance(UpdateServiceInstanceRequest.builder()
@@ -899,6 +900,7 @@ public void updateServiceNoParameters() {
899900
requestGetService(this.cloudFoundryClient, "test-service-id", "test-service");
900901
requestListSpaceServicePlans(this.cloudFoundryClient, "test-service-id", "test-plan", "test-service-plan-id");
901902
requestUpdateServiceInstance(this.cloudFoundryClient, null, "test-service-instance-id", "test-service-plan-id", Collections.singletonList("test-tag"));
903+
requestGetServiceInstance(this.cloudFoundryClient, "test-id", "successful");
902904

903905
this.services
904906
.updateInstance(UpdateServiceInstanceRequest.builder()
@@ -916,6 +918,7 @@ public void updateServiceNoPlan() {
916918
requestListSpaceServiceInstances(this.cloudFoundryClient, "test-service", TEST_SPACE_ID);
917919
requestUpdateServiceInstance(this.cloudFoundryClient, Collections.singletonMap("test-parameter-key", "test-parameter-value"), "test-service-instance-id", null,
918920
Collections.singletonList("test-tag"));
921+
requestGetServiceInstance(this.cloudFoundryClient, "test-id", "successful");
919922

920923
this.services
921924
.updateInstance(UpdateServiceInstanceRequest.builder()
@@ -951,6 +954,7 @@ public void updateServiceNoTags() {
951954
requestGetService(this.cloudFoundryClient, "test-service-id", "test-service");
952955
requestListSpaceServicePlans(this.cloudFoundryClient, "test-service-id", "test-plan", "test-plan-id");
953956
requestUpdateServiceInstance(this.cloudFoundryClient, Collections.singletonMap("test-parameter-key", "test-parameter-value"), "test-service-instance-id", "test-plan-id", null);
957+
requestGetServiceInstance(this.cloudFoundryClient, "test-id", "successful");
954958

955959
this.services
956960
.updateInstance(UpdateServiceInstanceRequest.builder()
@@ -972,6 +976,7 @@ public void updateServiceNotPublic() {
972976
requestListSpaceServicePlanVisibilities(this.cloudFoundryClient, "test-organization-id", "test-plan-id");
973977
requestUpdateServiceInstance(this.cloudFoundryClient, Collections.singletonMap("test-parameter-key", "test-parameter-value"), "test-service-instance-id", "test-plan-id",
974978
Collections.singletonList("test-tag"));
979+
requestGetServiceInstance(this.cloudFoundryClient, "test-id", "successful");
975980

976981
this.services
977982
.updateInstance(UpdateServiceInstanceRequest.builder()
@@ -1027,7 +1032,7 @@ public void updateServicePlanNotUpdateable() {
10271032
public void updateUserProvidedService() {
10281033
requestListSpaceServiceInstancesUserProvided(this.cloudFoundryClient, "test-service", TEST_SPACE_ID);
10291034
requestUpdateUserProvidedServiceInstance(this.cloudFoundryClient, Collections.singletonMap("test-credential-key", "test-credential-value"),
1030-
"syslog-url", Collections.singletonList("tag1"),"test-service-instance-id");
1035+
"syslog-url", Collections.singletonList("tag1"), "test-service-instance-id");
10311036

10321037
this.services
10331038
.updateUserProvidedInstance(UpdateUserProvidedServiceInstanceRequest.builder()
@@ -1959,7 +1964,8 @@ private static void requestUpdateServiceInstance(CloudFoundryClient cloudFoundry
19591964
.build()));
19601965
}
19611966

1962-
private static void requestUpdateUserProvidedServiceInstance(CloudFoundryClient cloudFoundryClient, Map<String, Object> credentials, String syslogDrainUrl, List<String> tags, String userProvidedServiceInstanceId) {
1967+
private static void requestUpdateUserProvidedServiceInstance(CloudFoundryClient cloudFoundryClient, Map<String, Object> credentials, String syslogDrainUrl, List<String> tags,
1968+
String userProvidedServiceInstanceId) {
19631969
when(cloudFoundryClient.userProvidedServiceInstances()
19641970
.update(org.cloudfoundry.client.v2.userprovidedserviceinstances.UpdateUserProvidedServiceInstanceRequest.builder()
19651971
.credentials(credentials)

0 commit comments

Comments
 (0)