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

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse. 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: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private Mono<Void> create(CreateServiceInstanceBindingRequest request,
	CreateServiceInstanceBindingResponse response) {
	return stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
		OperationState.IN_PROGRESS, "create service instance binding started")
		.thenMany(invokeCreateWorkflows(request, response)
			.doOnRequest(l -> {
				LOG.info("Creating service instance binding");
				LOG.debug("request={}", request);
			})
			.doOnComplete(() -> {
				LOG.debug("Finish creating service instance binding");
				LOG.debug("request={}, response={}", request, response);
			})
			.doOnError(e -> LOG.error(String.format("Error creating service instance binding. error=%s",
				e.getMessage()), e)))
		.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
			OperationState.SUCCEEDED, "create service instance binding completed")
			.then())
		.onErrorResume(
			exception -> stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
				OperationState.FAILED, exception.getMessage())
				.then());
}
 
Example #2
Source File: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private Flux<Void> invokeCreateWorkflows(CreateServiceInstanceBindingRequest request,
	CreateServiceInstanceBindingResponse response) {
	return Flux.defer(() -> {
		if (isAppBindingRequest(request)) {
			return Flux.fromIterable(createServiceInstanceAppBindingWorkflows)
				.filterWhen(workflow -> workflow.accept(request))
				.concatMap(workflow -> workflow.create(request,
					(CreateServiceInstanceAppBindingResponse) response));
		}
		else if (isRouteBindingRequest(request)) {
			return Flux.fromIterable(createServiceInstanceRouteBindingWorkflows)
				.filterWhen(workflow -> workflow.accept(request))
				.concatMap(workflow -> workflow.create(request,
					(CreateServiceInstanceRouteBindingResponse) response));
		}
		return Flux.empty();
	});
}
 
Example #3
Source File: BookStoreServiceInstanceBindingService.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	return Mono.just(CreateServiceInstanceAppBindingResponse.builder())
			.flatMap(responseBuilder -> bindingRepository.existsById(request.getBindingId())
					.flatMap(exists -> {
						if (exists) {
							return bindingRepository.findById(request.getBindingId())
									.flatMap(serviceBinding -> Mono.just(responseBuilder
											.bindingExisted(true)
											.credentials(serviceBinding.getCredentials())
											.build()));
						}
						else {
							return createUser(request)
									.flatMap(user -> buildCredentials(request.getServiceInstanceId(), user))
									.flatMap(credentials -> bindingRepository
											.save(new ServiceBinding(request.getBindingId(),
													request.getParameters(), credentials))
											.thenReturn(responseBuilder
													.bindingExisted(false)
													.credentials(credentials)
													.build()));
						}
					}));
}
 
Example #4
Source File: EcsServiceInstanceBindingService.java    From ecs-cf-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) throws ServiceBrokerException {
    try {
        BindingWorkflow workflow = getWorkflow(request);

        LOG.info("creating binding");
        workflow.checkIfUserExists();
        String secretKey = workflow.createBindingUser();

        LOG.info("building binding response");
        Map<String, Object> credentials = workflow.getCredentials(secretKey,
                request.getParameters());
        ServiceInstanceBinding binding = workflow.getBinding(credentials);

        LOG.info("saving binding...");
        repository.save(binding);
        LOG.info("binding saved.");

        return Mono.just(workflow.getResponse(credentials));
    } catch (IOException | JAXBException | EcsManagementClientException e) {
        throw new ServiceBrokerException(e);
    }
}
 
Example #5
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
private void validateCreateServiceBindingResponseStatus(CreateServiceInstanceBindingResponse response,
		HttpStatus httpStatus) {
	Mono<CreateServiceInstanceBindingResponse> responseMono;
	if (response == null) {
		responseMono = Mono.empty();
	}
	else {
		responseMono = Mono.just(response);
	}
	given(bindingService.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class)))
			.willReturn(responseMono);

	CreateServiceInstanceBindingRequest createRequest = CreateServiceInstanceBindingRequest.builder()
			.serviceDefinitionId("service-definition-id")
			.planId("service-definition-plan-id")
			.build();

	ResponseEntity<CreateServiceInstanceBindingResponse> responseEntity = controller
			.createServiceInstanceBinding(pathVariables, null, null, false, null, null, null,
					createRequest)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(httpStatus);
	assertThat(responseEntity.getBody()).isEqualTo(response);
}
 
Example #6
Source File: ExampleServiceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) {
	String serviceInstanceId = request.getServiceInstanceId();
	String bindingId = request.getBindingId();

	//
	// create credentials and store for later retrieval
	//

	String url = new String(/* build a URL to access the service instance */);
	String bindingUsername = new String(/* create a user */);
	String bindingPassword = new String(/* create a password */);

	CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder()
			.credentials("url", url)
			.credentials("username", bindingUsername)
			.credentials("password", bindingPassword)
			.bindingExisted(false)
			.async(true)
			.build();

	return Mono.just(response);
}
 
Example #7
Source File: MailServiceInstanceBindingService.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
    CreateServiceInstanceBindingRequest request) {
    return Mono.just(CreateServiceInstanceAppBindingResponse.builder())
        .flatMap(responseBuilder -> mailService.serviceBindingExists(
            request.getServiceInstanceId(), request.getBindingId())
            .flatMap(exists -> {
                if (exists) {
                    return mailService.getServiceBinding(
                        request.getServiceInstanceId(), request.getBindingId())
                        .flatMap(serviceBinding -> Mono.just(responseBuilder
                            .bindingExisted(true)
                            .credentials(serviceBinding.getCredentials())
                            .build()));
                } else {
                    return mailService.createServiceBinding(
                        request.getServiceInstanceId(), request.getBindingId())
                        .switchIfEmpty(Mono.error(
                            new ServiceInstanceDoesNotExistException(
                                request.getServiceInstanceId())))
                        .flatMap(mailServiceBinding -> Mono.just(responseBuilder
                            .bindingExisted(false)
                            .credentials(mailServiceBinding.getCredentials())
                            .build()));
                }
            }));
}
 
Example #8
Source File: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
	CreateServiceInstanceBindingRequest request) {
	return invokeCreateResponseBuilders(request)
		.flatMap(response -> {
			if (response.isAsync()) {
				return Mono.just(response).publishOn(Schedulers.parallel())
					.doOnNext(r -> create(request, r)
						.subscribe());
			}
			else {
				return create(request, response).thenReturn(response);
			}
		});
}
 
Example #9
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	if (request.getServiceDefinitionId() == null) {
		return Mono.error(new ServiceInstanceBindingExistsException("service-instance-id", "arrrr"));
	}
	return Mono.just(CreateServiceInstanceAppBindingResponse.builder().build());
}
 
Example #10
Source File: AsyncServiceBrokerResponseTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void equalsAndHashCode() {
	EqualsVerifier
			.forClass(AsyncServiceBrokerResponse.class)
			.withRedefinedSubclass(CreateServiceInstanceResponse.class)
			.withRedefinedSubclass(UpdateServiceInstanceResponse.class)
			.withRedefinedSubclass(CreateServiceInstanceBindingResponse.class)
			.withRedefinedSubclass(DeleteServiceInstanceBindingResponse.class)
			.verify();
}
 
Example #11
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void createServiceBindingWithExistingBindingResponseGivesExpectedStatus() {
	CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder()
			.bindingExisted(true)
			.build();
	validateCreateServiceBindingResponseStatus(response, HttpStatus.OK);
}
 
Example #12
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void createServiceBindingWithNoExistingBindingResponseGivesExpectedStatus() {
	CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder()
			.bindingExisted(false)
			.build();
	validateCreateServiceBindingResponseStatus(response, HttpStatus.CREATED);
}
 
Example #13
Source File: ServiceInstanceBindingEventService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	return flows.getCreateInstanceBindingRegistry().getInitializationFlows(request)
			.then(service.createServiceInstanceBinding(request))
			.onErrorResume(e -> flows.getCreateInstanceBindingRegistry().getErrorFlows(request, e)
					.then(Mono.error(e)))
			.flatMap(response -> flows.getCreateInstanceBindingRegistry().getCompletionFlows(request, response)
					.then(Mono.just(response)));
}
 
Example #14
Source File: ServiceInstanceBindingController.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
private HttpStatus getCreateResponseCode(CreateServiceInstanceBindingResponse response) {
	HttpStatus status = HttpStatus.CREATED;
	if (response != null) {
		if (response.isAsync()) {
			status = HttpStatus.ACCEPTED;
		}
		else if (response.isBindingExisted()) {
			status = HttpStatus.OK;
		}
	}
	return status;
}
 
Example #15
Source File: ExampleServiceBindingEventFlowsConfiguration2.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Bean
public CreateServiceInstanceBindingCompletionFlow createServiceInstanceBindingCompletionFlow() {
	return new CreateServiceInstanceBindingCompletionFlow() {
		@Override
		public Mono<Void> complete(CreateServiceInstanceBindingRequest request,
				CreateServiceInstanceBindingResponse response) {
			//
			// do something after the service instance binding completes
			//
			return Mono.empty();
		}
	};
}
 
Example #16
Source File: TestServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerCreateOperationInProgressException("task_10"));
	}
	if (EXISTING_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.just(CreateServiceInstanceAppBindingResponse.builder()
				.bindingExisted(true)
				.build());
	}
	if (UNKNOWN_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceInstanceDoesNotExistException(request.getServiceInstanceId()));
	}
	if (request.isAsyncAccepted()) {
		return Mono.just(CreateServiceInstanceAppBindingResponse.builder()
				.async(true)
				.operation("working")
				.bindingExisted(false)
				.build());
	}
	else {
		return Mono.just(CreateServiceInstanceAppBindingResponse.builder()
				.bindingExisted(false)
				.build());
	}
}
 
Example #17
Source File: EventFlowsAutoConfigurationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Bean
public CreateServiceInstanceBindingCompletionFlow createCompleteFlow() {
	return new CreateServiceInstanceBindingCompletionFlow() {
		@Override
		public Mono<Void> complete(CreateServiceInstanceBindingRequest request,
				CreateServiceInstanceBindingResponse response) {
			return Mono.empty();
		}
	};
}
 
Example #18
Source File: CreateServiceInstanceBindingEventFlowRegistry.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Flux<Void> getCompletionFlows(CreateServiceInstanceBindingRequest request,
		CreateServiceInstanceBindingResponse response) {
	return getCompletionFlowsInternal()
			.flatMap(flow -> flow.complete(request, response));
}
 
Example #19
Source File: ServiceInstanceBindingControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example #20
Source File: ServiceInstanceBindingController.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
/**
 * REST controller for creating a service instance binding
 *
 * @param pathVariables the path variables
 * @param serviceInstanceId the service instance ID
 * @param bindingId the service binding ID
 * @param acceptsIncomplete indicates an asynchronous request
 * @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
 * @param request the request body
 * @return the response
 */
@PutMapping({PLATFORM_PATH_MAPPING, PATH_MAPPING})
public Mono<ResponseEntity<CreateServiceInstanceBindingResponse>> createServiceInstanceBinding(
		@PathVariable Map<String, String> pathVariables,
		@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
		@PathVariable(ServiceBrokerRequest.BINDING_ID_PATH_VARIABLE) String bindingId,
		@RequestParam(value = AsyncServiceBrokerRequest.ASYNC_REQUEST_PARAMETER, required = false) boolean acceptsIncomplete,
		@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,
		@Valid @RequestBody CreateServiceInstanceBindingRequest request) {
	return getRequiredServiceDefinition(request.getServiceDefinitionId())
			.flatMap(serviceDefinition -> getRequiredServiceDefinitionPlan(serviceDefinition, request.getPlanId())
					.map(plan -> {
						request.setPlan(plan);
						return request;
					})
					.map(req -> {
						request.setServiceInstanceId(serviceInstanceId);
						request.setBindingId(bindingId);
						request.setServiceDefinition(serviceDefinition);
						return request;
					}))
			.cast(AsyncServiceBrokerRequest.class)
			.flatMap(req -> configureCommonRequestFields(req,
					pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE),
					apiInfoLocation, originatingIdentityString, requestIdentity, acceptsIncomplete))
			.cast(CreateServiceInstanceBindingRequest.class)
			.flatMap(req -> service.createServiceInstanceBinding(req)
					.doOnRequest(v -> {
						LOG.info("Creating a service instance binding");
						LOG.debug(DEBUG_REQUEST, req);
					})
					.doOnSuccess(response -> {
						LOG.info("Creating a service instance binding succeeded");
						LOG.debug("serviceInstanceId={}, bindingId={}, response={}", serviceInstanceId, bindingId,
								response);
					})
					.doOnError(e -> LOG.error("Error creating service instance binding. error=" +
							e.getMessage(), e)))
			.map(response -> new ResponseEntity<>(response, getCreateResponseCode(response)))
			.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.CREATED)));
}
 
Example #21
Source File: AbstractServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
protected void setupServiceInstanceBindingService(CreateServiceInstanceBindingResponse createResponse) {
	given(serviceInstanceBindingService
			.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class)))
			.willReturn(Mono.just(createResponse));
}
 
Example #22
Source File: NoOpServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
	CreateServiceInstanceBindingRequest request) {
	return Mono.just(CreateServiceInstanceAppBindingResponse.builder().build());
}
 
Example #23
Source File: NonBindableServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new binding to a service instance.
 *
 * @param request containing the details of the request
 * @return this implementation will always throw a {@literal UnsupportedOperationException}
 */
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	return Mono.error(nonBindableException());
}
 
Example #24
Source File: ServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new binding to a service instance.
 *
 * @param request containing the details of the request
 * @return a {@link CreateServiceInstanceBindingResponse} on successful processing of the request
 * @throws ServiceInstanceBindingExistsException if a binding with the given ID is already known to the broker
 * @throws ServiceInstanceDoesNotExistException if a service instance with the given ID is not known to the
 * 		broker
 * @throws ServiceBrokerBindingRequiresAppException if the broker only supports application binding but an app
 * 		GUID is not provided in the request
 * @throws ServiceBrokerAsyncRequiredException if the broker requires asynchronous processing of the request
 * @throws ServiceBrokerCreateOperationInProgressException if a an operation is in progress for the service
 * 		binding
 */
default Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	return Mono.error(new UnsupportedOperationException(
			"This service broker does not support creating service bindings."));
}
 
Example #25
Source File: CreateServiceInstanceBindingCompletionFlow.java    From spring-cloud-open-service-broker with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the operation on the completion flow
 *
 * @param request the service broker request
 * @param response the service broker response
 * @return an empty Mono
 */
default Mono<Void> complete(CreateServiceInstanceBindingRequest request,
		CreateServiceInstanceBindingResponse response) {
	return Mono.empty();
}