org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingResponse Java Examples

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingResponse. 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: ExampleServiceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	String serviceInstanceId = request.getServiceInstanceId();
	String bindingId = request.getBindingId();

	//
	// retrieve the details of the specified service binding
	//

	String url = new String(/* retrieved URL */);
	String bindingUsername = new String(/* retrieved user */);
	String bindingPassword = new String(/* retrieved password */);

	GetServiceInstanceBindingResponse response = GetServiceInstanceAppBindingResponse.builder()
			.credentials("username", bindingUsername)
			.credentials("password", bindingPassword)
			.credentials("url", url)
			.build();

	return Mono.just(response);
}
 
Example #2
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
private void validateGetServiceBindingResponseStatus(GetServiceInstanceBindingResponse response,
		HttpStatus httpStatus) {
	Mono<GetServiceInstanceBindingResponse> responseMono;
	if (response == null) {
		responseMono = Mono.empty();
	}
	else {
		responseMono = Mono.just(response);
	}
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willReturn(responseMono);

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, null, null, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(httpStatus);
	assertThat(responseEntity.getBody()).isEqualTo(response);
}
 
Example #3
Source File: BookStoreServiceInstanceBindingService.java    From bookstore-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	return Mono.just(request.getBindingId())
			.flatMap(bindingId -> bindingRepository.findById(bindingId)
					.flatMap(Mono::justOrEmpty)
					.switchIfEmpty(Mono.error(new ServiceInstanceBindingDoesNotExistException(bindingId)))
					.flatMap(serviceBinding -> Mono.just(GetServiceInstanceAppBindingResponse.builder()
							.parameters(serviceBinding.getParameters())
							.credentials(serviceBinding.getCredentials())
							.build())));
}
 
Example #4
Source File: TestServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerOperationInProgressException("task_10"));
	}
	return Mono.just(GetServiceInstanceAppBindingResponse.builder()
			.build());
}
 
Example #5
Source File: ServiceInstanceBindingController.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 binding
 *
 * @param pathVariables the path variables
 * @param serviceInstanceId the service instance ID
 * @param bindingId the service binding 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<GetServiceInstanceBindingResponse>> getServiceInstanceBinding(
		@PathVariable Map<String, String> pathVariables,
		@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
		@PathVariable(ServiceBrokerRequest.BINDING_ID_PATH_VARIABLE) String bindingId,
		@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(GetServiceInstanceBindingRequest.builder()
			.serviceInstanceId(serviceInstanceId)
			.bindingId(bindingId)
			.platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE))
			.apiInfoLocation(apiInfoLocation)
			.originatingIdentity(parseOriginatingIdentity(originatingIdentityString))
			.requestIdentity(requestIdentity)
			.build())
			.flatMap(req -> service.getServiceInstanceBinding(req)
					.doOnRequest(v -> {
						LOG.info("Getting a service instance binding");
						LOG.debug(DEBUG_REQUEST, req);
					})
					.doOnSuccess(response -> {
						LOG.info("Getting a service instance binding succeeded");
						LOG.debug("bindingId={}", bindingId);
					})
					.doOnError(e -> LOG.error("Error getting service instance binding. error=" +
							e.getMessage(), e)))
			.map(response -> new ResponseEntity<>(response, HttpStatus.OK))
			.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK)))
			.onErrorResume(e -> {
				if (e instanceof ServiceInstanceBindingDoesNotExistException ||
						e instanceof ServiceInstanceDoesNotExistException) {
					return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
				}
				else {
					return Mono.error(e);
				}
			});
}
 
Example #6
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceBindingWithMissingBindingGivesExpectedStatus() {
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingDoesNotExistException("binding-id"));

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, null, null, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
Example #7
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceBindingWithMissingServiceInstanceGivesExpectedStatus() {
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceDoesNotExistException("nonexistent-service-id"));

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, "nonexistent-service-id", "nonexistent-binding-id", null,
					null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
Example #8
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	if (request.getBindingId() == null) {
		return Mono.error(new ServiceInstanceDoesNotExistException("service-instance-id"));
	}
	return Mono.just(GetServiceInstanceAppBindingResponse.builder().build());
}
 
Example #9
Source File: MailServiceInstanceBindingService.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
    return mailService.getServiceBinding(request.getServiceInstanceId(), request.getBindingId())
        .switchIfEmpty(Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId())))
        .flatMap(mailServiceBinding -> Mono.just(GetServiceInstanceAppBindingResponse.builder()
            .credentials(mailServiceBinding.getCredentials())
            .build()));
}
 
Example #10
Source File: AbstractServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
protected void setupServiceInstanceBindingService(GetServiceInstanceBindingResponse getResponse) {
	given(serviceInstanceBindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willReturn(Mono.just(getResponse));
}
 
Example #11
Source File: ServiceInstanceBindingEventService.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	return service.getServiceInstanceBinding(request);
}
 
Example #12
Source File: ServiceInstanceBindingControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example #13
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Test
void getServiceBindingWithResponseGivesExpectedStatus2() {
	GetServiceInstanceBindingResponse response = GetServiceInstanceAppBindingResponse.builder()
			.build();
	validateGetServiceBindingResponseStatus(response, HttpStatus.OK);
}
 
Example #14
Source File: ServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 3 votes vote down vote up
/**
 * Get the details of a binding to a service instance.
 *
 * @param request containing the details of the request
 * @return a {@link GetServiceInstanceBindingResponse} on successful processing of the request
 * @throws ServiceInstanceDoesNotExistException if a service instance with the given ID is not known to the
 * 		broker
 * @throws ServiceInstanceBindingDoesNotExistException if a binding with the given ID is not known to the broker
 * @throws ServiceBrokerOperationInProgressException if a an operation is in progress for the service binding
 */
default Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	return Mono.error(new UnsupportedOperationException(
			"This service broker does not support retrieving service bindings. " +
					"The service broker should set 'bindings_retrievable:false' in the service catalog, " +
					"or provide an implementation of the fetch binding API."));
}