Search in sources :

Example 1 with ServiceDefinition

use of org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition 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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ServiceInstanceDoesNotExistException(org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException) DeleteServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest) ServiceDefinition(org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition) DeleteServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 2 with ServiceDefinition

use of org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition in project spring-cloud-open-service-broker by spring-cloud.

the class ExampleCatalogConfiguration method catalog.

@Bean
public Catalog catalog() {
    Plan plan = Plan.builder().id("simple-plan").name("standard").description("A simple plan").free(true).build();
    ServiceDefinition serviceDefinition = ServiceDefinition.builder().id("example-service").name("example").description("A simple example").bindable(true).tags("example", "tags").plans(plan).build();
    return Catalog.builder().serviceDefinitions(serviceDefinition).build();
}
Also used : Plan(org.springframework.cloud.servicebroker.model.catalog.Plan) ServiceDefinition(org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition) Bean(org.springframework.context.annotation.Bean)

Example 3 with ServiceDefinition

use of org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceController method updateServiceInstance.

@PatchMapping(value = { "/{platformInstanceId}/v2/service_instances/{instanceId}", "/v2/service_instances/{instanceId}" })
public ResponseEntity<UpdateServiceInstanceResponse> updateServiceInstance(@PathVariable Map<String, String> pathVariables, @PathVariable(INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId, @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, @Valid @RequestBody UpdateServiceInstanceRequest request) {
    ServiceDefinition serviceDefinition = getRequiredServiceDefinition(request.getServiceDefinitionId());
    request.setServiceInstanceId(serviceInstanceId);
    request.setServiceDefinition(serviceDefinition);
    setCommonRequestFields(request, pathVariables.get(PLATFORM_INSTANCE_ID_VARIABLE), apiInfoLocation, originatingIdentityString, acceptsIncomplete);
    LOGGER.debug("Updating a service instance: request={}", request);
    UpdateServiceInstanceResponse response = service.updateServiceInstance(request);
    LOGGER.debug("Updating a service instance succeeded: serviceInstanceId={}, response={}", serviceInstanceId, response);
    return new ResponseEntity<>(response, getAsyncResponseCode(response));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) UpdateServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.UpdateServiceInstanceResponse) ServiceDefinition(org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 4 with ServiceDefinition

use of org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceController method createServiceInstance.

@PutMapping(value = { "/{platformInstanceId}/v2/service_instances/{instanceId}", "/v2/service_instances/{instanceId}" })
public ResponseEntity<CreateServiceInstanceResponse> createServiceInstance(@PathVariable Map<String, String> pathVariables, @PathVariable(INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId, @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, @Valid @RequestBody CreateServiceInstanceRequest request) {
    ServiceDefinition serviceDefinition = getRequiredServiceDefinition(request.getServiceDefinitionId());
    request.setServiceInstanceId(serviceInstanceId);
    request.setServiceDefinition(serviceDefinition);
    setCommonRequestFields(request, pathVariables.get(PLATFORM_INSTANCE_ID_VARIABLE), apiInfoLocation, originatingIdentityString, acceptsIncomplete);
    LOGGER.debug("Creating a service instance: request={}", request);
    CreateServiceInstanceResponse response = service.createServiceInstance(request);
    LOGGER.debug("Creating a service instance succeeded: serviceInstanceId={}, response={}", serviceInstanceId, response);
    return new ResponseEntity<>(response, getCreateResponseCode(response));
}
Also used : CreateServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse) ResponseEntity(org.springframework.http.ResponseEntity) ServiceDefinition(org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 5 with ServiceDefinition

use of org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceBindingControllerResponseCodeTest method setUp.

@BeforeEach
void setUp() {
    controller = new ServiceInstanceBindingController(catalogService, bindingService);
    ServiceDefinition serviceDefinition = mock(ServiceDefinition.class);
    List<Plan> plans = new ArrayList<>();
    plans.add(Plan.builder().id("service-definition-plan-id").build());
    given(serviceDefinition.getPlans()).willReturn(plans);
    given(serviceDefinition.getId()).willReturn("service-definition-id");
    given(catalogService.getServiceDefinition(any())).willReturn(Mono.just(serviceDefinition));
}
Also used : ArrayList(java.util.ArrayList) Plan(org.springframework.cloud.servicebroker.model.catalog.Plan) ServiceDefinition(org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ServiceDefinition (org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition)6 Plan (org.springframework.cloud.servicebroker.model.catalog.Plan)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ArrayList (java.util.ArrayList)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ServiceInstanceDoesNotExistException (org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException)1 CreateServiceInstanceResponse (org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse)1 DeleteServiceInstanceRequest (org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest)1 DeleteServiceInstanceResponse (org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse)1 UpdateServiceInstanceResponse (org.springframework.cloud.servicebroker.model.instance.UpdateServiceInstanceResponse)1 Bean (org.springframework.context.annotation.Bean)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1