org.springframework.cloud.servicebroker.model.instance.GetServiceInstanceResponse Java Examples

The following examples show how to use org.springframework.cloud.servicebroker.model.instance.GetServiceInstanceResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceInstanceControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void getServiceInstanceSucceeds() throws Exception {
	setupServiceInstanceService(GetServiceInstanceResponse.builder()
			.build());

	MvcResult mvcResult = mockMvc.perform(get(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.contentType(MediaType.APPLICATION_JSON)
			.accept(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isOk());

	GetServiceInstanceRequest actualRequest = verifyGetServiceInstance();
	assertHeaderValuesSet(actualRequest);
}
 
Example #2
Source File: ServiceInstanceControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
private void validateGetServiceInstanceWithResponseStatus(GetServiceInstanceResponse response,
		HttpStatus expectedStatus) {
	Mono<GetServiceInstanceResponse> responseMono;
	if (response == null) {
		responseMono = Mono.empty();
	}
	else {
		responseMono = Mono.just(response);
	}
	given(serviceInstanceService.getServiceInstance(any(GetServiceInstanceRequest.class)))
			.willReturn(responseMono);

	ResponseEntity<GetServiceInstanceResponse> responseEntity = controller
			.getServiceInstance(pathVariables, null, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(expectedStatus);
	assertThat(responseEntity.getBody()).isEqualTo(response);
}
 
Example #3
Source File: ServiceInstanceController.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * REST controller for getting a service instance
 *
 * @param pathVariables the path variables
 * @param serviceInstanceId the service instance ID
 * @param apiInfoLocation location of the API info endpoint of the platform instance
 * @param originatingIdentityString identity of the user that initiated the request from the platform
 * @param requestIdentity identity of the request sent from the platform
 * @return the response
 */
@GetMapping({PLATFORM_PATH_MAPPING, PATH_MAPPING})
public Mono<ResponseEntity<GetServiceInstanceResponse>> getServiceInstance(
		@PathVariable Map<String, String> pathVariables,
		@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
		@RequestHeader(value = ServiceBrokerRequest.API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation,
		@RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString,
		@RequestHeader(value = ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, required = false) String requestIdentity) {
	return Mono.just(GetServiceInstanceRequest.builder()
			.serviceInstanceId(serviceInstanceId)
			.platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE))
			.apiInfoLocation(apiInfoLocation)
			.originatingIdentity(parseOriginatingIdentity(originatingIdentityString))
			.requestIdentity(requestIdentity)
			.build())
			.flatMap(request -> service.getServiceInstance(request)
					.doOnRequest(v -> {
						LOG.info("Getting service instance");
						LOG.debug(DEBUG_REQUEST, request);
					})
					.doOnSuccess(response -> {
						LOG.info("Getting service instance succeeded");
						LOG.debug(DEBUG_RESPONSE, serviceInstanceId, response);
					})
					.doOnError(e -> LOG.error("Error getting service instance. error=" + e.getMessage(), e)))
			.map(response -> new ResponseEntity<>(response, HttpStatus.OK))
			.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK)))
			.onErrorResume(e -> {
				if (e instanceof ServiceInstanceDoesNotExistException) {
					return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
				}
				else {
					return Mono.error(e);
				}
			});
}
 
Example #4
Source File: MailServiceInstanceService.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
    return Mono.just(request.getServiceInstanceId())
        .flatMap(instanceId -> mailService.getServiceInstance(instanceId)
            .switchIfEmpty(Mono.error(new ServiceInstanceDoesNotExistException(instanceId)))
            .flatMap(serviceInstance -> Mono.just(GetServiceInstanceResponse.builder()
                .serviceDefinitionId(serviceInstance.getServiceDefinitionId())
                .planId(serviceInstance.getPlanId())
                .dashboardUrl(serviceInstance.getDashboardUrl())
                .build())));
}
 
Example #5
Source File: ServiceInstanceControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceInstanceWithMissingInstanceGivesExpectedStatus() {
	given(serviceInstanceService.getServiceInstance(any(GetServiceInstanceRequest.class)))
			.willReturn(Mono.error(new ServiceInstanceDoesNotExistException("instance does not exist")));

	ResponseEntity<GetServiceInstanceResponse> responseEntity = controller
			.getServiceInstance(pathVariables, null, "service-definition-id", null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
Example #6
Source File: ServiceInstanceControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceInstanceWithResponseGivesExpectedStatus() {
	validateGetServiceInstanceWithResponseStatus(GetServiceInstanceResponse.builder()
			.serviceDefinitionId("service-definition-id")
			.planId("plan-id")
			.build(), HttpStatus.OK);
}
 
Example #7
Source File: ExampleServiceInstanceService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	String serviceInstanceId = request.getServiceInstanceId();

	//
	// retrieve the details of the specified service instance
	//

	String dashboardUrl = ""; /* retrieve dashboard URL */

	return Mono.just(GetServiceInstanceResponse.builder()
			.dashboardUrl(dashboardUrl)
			.build());
}
 
Example #8
Source File: TestServiceInstanceService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerOperationInProgressException("task_10"));
	}
	return Mono.just(GetServiceInstanceResponse.builder()
			.build());
}
 
Example #9
Source File: ServiceInstanceControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceInstanceSucceeds() throws Exception {
	setupServiceInstanceService(GetServiceInstanceResponse.builder()
			.build());

	client.get().uri(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.accept(MediaType.APPLICATION_JSON)
			.exchange()
			.expectStatus().isOk();

	GetServiceInstanceRequest actualRequest = verifyGetServiceInstance();
	assertHeaderValuesSet(actualRequest);
}
 
Example #10
Source File: BookStoreServiceInstanceService.java    From bookstore-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	return Mono.just(request.getServiceInstanceId())
			.flatMap(instanceId -> instanceRepository.findById(instanceId)
					.switchIfEmpty(Mono.error(new ServiceInstanceDoesNotExistException(instanceId)))
					.flatMap(serviceInstance -> Mono.just(GetServiceInstanceResponse.builder()
							.serviceDefinitionId(serviceInstance.getServiceDefinitionId())
							.planId(serviceInstance.getPlanId())
							.parameters(serviceInstance.getParameters())
							.build())));
}
 
Example #11
Source File: NoOpServiceInstanceService.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	return Mono.empty();
}
 
Example #12
Source File: WorkflowServiceInstanceService.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	//TODO add functionality
	return Mono.empty();
}
 
Example #13
Source File: ServiceInstanceEventService.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	return service.getServiceInstance(request);
}
 
Example #14
Source File: ServiceInstanceControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example #15
Source File: AbstractServiceInstanceControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
protected void setupServiceInstanceService(GetServiceInstanceResponse response) {
	given(serviceInstanceService.getServiceInstance(any(GetServiceInstanceRequest.class)))
			.willReturn(Mono.just(response));
}
 
Example #16
Source File: NoOpServiceInstanceService.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	return Mono.empty();
}
 
Example #17
Source File: ServiceInstanceService.java    From spring-cloud-open-service-broker with Apache License 2.0 3 votes vote down vote up
/**
 * Get the details of a service instance.
 *
 * @param request containing the details of the request
 * @return a {@link GetServiceInstanceResponse} on successful processing of the request
 * @throws ServiceInstanceDoesNotExistException if a service instance with the given ID is not known to the
 * 		broker
 * @throws ServiceBrokerOperationInProgressException if a service instance provisioning is still in progress
 * @throws ServiceBrokerConcurrencyException if a service instance is being updated and therefore cannot be
 * 		fetched
 */
default Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request) {
	return Mono.error(new UnsupportedOperationException(
			"This service broker does not support retrieving service instances. " +
					"The service broker should set 'instances_retrievable:false' in the service catalog, " +
					"or provide an implementation of the fetch instance API."));
}