Skip to content

Commit 00b26df

Browse files
s-bortolussiscottfrederick
authored andcommitted
Added getServiceInstanceLastOperation() to enable the broker to be polled for last service operation status. Former getServiceInstance() has been removed since it was not compliant with broker async api. see http://docs.cloudfoundry.org/services/asynchronous-operations.html for details
1 parent dc1f046 commit 00b26df

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/main/java/org/cloudfoundry/community/servicebroker/controller/ServiceInstanceController.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,23 @@ public ResponseEntity<ServiceInstance> createServiceInstance(
5757

5858
}
5959

60-
@RequestMapping(value = BASE_PATH + "/{instanceId}", method = RequestMethod.GET)
61-
public ResponseEntity<?> getServiceInstance(
60+
@RequestMapping(value = BASE_PATH + "/{instanceId}/last_operation", method = RequestMethod.GET)
61+
public ResponseEntity<?> getServiceInstanceLastOperation(
6262
@PathVariable("instanceId") String instanceId) {
63-
64-
logger.debug("GET: " + BASE_PATH + "/{instanceId}"
63+
64+
logger.debug("GET: " + BASE_PATH + "/{instanceId}/last_operation"
6565
+ ", getServiceInstance(), serviceInstanceId = " + instanceId);
66-
66+
6767
ServiceInstance instance = service.getServiceInstance(instanceId);
68-
68+
6969
HttpHeaders headers = new HttpHeaders();
7070
headers.setContentType(MediaType.APPLICATION_JSON);
71-
if (null == instance) {
71+
if (null == instance) {
7272
return new ResponseEntity<String>("{}", headers, HttpStatus.GONE);
73-
}
74-
logger.debug("ServiceInstance: " + instance.getServiceInstanceId());
75-
return new ResponseEntity<ServiceInstance>(instance, headers, HttpStatus.OK);
73+
}
74+
ServiceInstanceLastOperation lastOperation = instance.getServiceInstanceLastOperation();
75+
logger.debug("ServiceInstance: " + instance.getServiceInstanceId() + "is in " +lastOperation.getState() + " state. Details : " +lastOperation.getDescription());
76+
return new ResponseEntity<ServiceInstanceLastOperation>(lastOperation, headers, HttpStatus.OK);
7677
}
7778

7879
@RequestMapping(value = BASE_PATH + "/{instanceId}", method = RequestMethod.DELETE)

src/test/java/org/cloudfoundry/community/servicebroker/model/fixture/ServiceInstanceControllerIntegrationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public void itShouldNotBeAsyncWhenAcceptsIncompleteParamIsNotPresent() throws Ex
348348
@Test
349349
public void itShouldReturnAnInProgressServiceInstance() throws Exception {
350350
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();
351-
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId();
351+
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId() + "/last_operation";
352352

353353
when(serviceInstanceService.getServiceInstance(any(String.class))).thenReturn(
354354
ServiceInstanceFixture.getAsyncServiceInstance().withLastOperation(
@@ -357,13 +357,13 @@ public void itShouldReturnAnInProgressServiceInstance() throws Exception {
357357
get(url))
358358
.andExpect(status().isOk())
359359
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
360-
.andExpect(jsonPath("$.last_operation.state", is("in progress")));
360+
.andExpect(jsonPath("$.state", is("in progress")));
361361
}
362362

363363
@Test
364364
public void itShouldReturnAFailedServiceInstance() throws Exception {
365365
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();
366-
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId();
366+
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId() + "/last_operation";
367367

368368
when(serviceInstanceService.getServiceInstance(any(String.class))).thenReturn(
369369
ServiceInstanceFixture.getAsyncServiceInstance().withLastOperation(
@@ -372,13 +372,13 @@ public void itShouldReturnAFailedServiceInstance() throws Exception {
372372
get(url))
373373
.andExpect(status().isOk())
374374
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
375-
.andExpect(jsonPath("$.last_operation.state", is("failed")));
375+
.andExpect(jsonPath("$.state", is("failed")));
376376
}
377377

378378
@Test
379379
public void itShouldReturnASucceededServiceInstance() throws Exception {
380380
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();
381-
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId();
381+
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId() + "/last_operation";
382382

383383
when(serviceInstanceService.getServiceInstance(any(String.class))).thenReturn(
384384
ServiceInstanceFixture.getAsyncServiceInstance().withLastOperation(
@@ -387,14 +387,14 @@ public void itShouldReturnASucceededServiceInstance() throws Exception {
387387
get(url))
388388
.andExpect(status().isOk())
389389
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
390-
.andExpect(jsonPath("$.last_operation.state", is("succeeded")));
390+
.andExpect(jsonPath("$.state", is("succeeded")));
391391
}
392392

393393

394394
@Test
395395
public void itShouldReturnGoneIfTheServiceInstanceDoesNotExist() throws Exception {
396396
ServiceInstance instance = ServiceInstanceFixture.getServiceInstance();
397-
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId();
397+
String url = ServiceInstanceController.BASE_PATH + "/" + instance.getServiceInstanceId() + "/last_operation";
398398

399399
when(serviceInstanceService.getServiceInstance(any(String.class))).thenReturn(null);
400400
mockMvc.perform(

0 commit comments

Comments
 (0)