use of org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse in project spring-cloud-open-service-broker by spring-cloud.
the class ServiceInstanceController method deleteServiceInstance.
@DeleteMapping(value = { "/{platformInstanceId}/v2/service_instances/{instanceId}", "/v2/service_instances/{instanceId}" })
public ResponseEntity<DeleteServiceInstanceResponse> deleteServiceInstance(@PathVariable Map<String, String> pathVariables, @PathVariable(INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId, @RequestParam(SERVICE_ID_PARAMETER) String serviceDefinitionId, @RequestParam(PLAN_ID_PARAMETER) String planId, @RequestParam(value = ASYNC_REQUEST_PARAMETER, required = false) boolean acceptsIncomplete, @RequestHeader(value = API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation, @RequestHeader(value = ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString) {
ServiceDefinition serviceDefinition = getRequiredServiceDefinition(serviceDefinitionId);
DeleteServiceInstanceRequest request = DeleteServiceInstanceRequest.builder().serviceInstanceId(serviceInstanceId).serviceDefinitionId(serviceDefinitionId).planId(planId).serviceDefinition(serviceDefinition).asyncAccepted(acceptsIncomplete).platformInstanceId(pathVariables.get(PLATFORM_INSTANCE_ID_VARIABLE)).apiInfoLocation(apiInfoLocation).originatingIdentity(parseOriginatingIdentity(originatingIdentityString)).build();
LOGGER.debug("Deleting a service instance: request={}", request);
try {
DeleteServiceInstanceResponse response = service.deleteServiceInstance(request);
LOGGER.debug("Deleting a service instance succeeded: serviceInstanceId={}, response={}", serviceInstanceId, response);
return new ResponseEntity<>(response, getAsyncResponseCode(response));
} catch (ServiceInstanceDoesNotExistException e) {
LOGGER.debug("Service instance does not exist: ", e);
return new ResponseEntity<>(DeleteServiceInstanceResponse.builder().build(), HttpStatus.GONE);
}
}
use of org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse in project spring-cloud-open-service-broker by spring-cloud.
the class ServiceInstanceControllerResponseCodeTest method deleteServiceInstanceWithMissingInstanceGivesExpectedStatus.
@Test
public void deleteServiceInstanceWithMissingInstanceGivesExpectedStatus() {
when(serviceInstanceService.deleteServiceInstance(any(DeleteServiceInstanceRequest.class))).thenThrow(new ServiceInstanceDoesNotExistException("instance does not exist"));
ResponseEntity<DeleteServiceInstanceResponse> responseEntity = controller.deleteServiceInstance(pathVariables, null, "service-definition-id", null, false, null, null);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.GONE);
assertThat(responseEntity.getBody()).isEqualTo(DeleteServiceInstanceResponse.builder().build());
}
Aggregations