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

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingResponse. 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> delete(DeleteServiceInstanceBindingRequest request,
	DeleteServiceInstanceBindingResponse response) {
	return stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
		OperationState.IN_PROGRESS, "delete service instance binding started")
		.thenMany(invokeDeleteWorkflows(request, response)
			.doOnRequest(l -> {
				LOG.info("Deleting service instance binding");
				LOG.debug("request={}", request);
			})
			.doOnComplete(() -> {
				LOG.info("Finish deleting service instance binding");
				LOG.debug("request={}, response={}", request, response);
			})
			.doOnError(e -> LOG.error(String.format("Error deleting service instance binding. error=%s",
				e.getMessage()), e)))
		.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
			OperationState.SUCCEEDED, "delete service instance binding completed")
			.then())
		.onErrorResume(
			exception -> stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
				OperationState.FAILED, exception.getMessage())
				.then());
}
 
Example #2
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void deleteBindingWithoutAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.build());

	client.delete().uri(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.exchange()
			.expectStatus().isOk()
			.expectBody()
			.json("{}");


	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertHeaderValuesSet(actualRequest);
}
 
Example #3
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void deleteServiceInstanceBindingSucceeds() {
	prepareBindingFlows();

	StepVerifier
			.create(serviceInstanceBindingEventService.deleteServiceInstanceBinding(
					DeleteServiceInstanceBindingRequest.builder()
							.serviceInstanceId("service-instance-id")
							.bindingId("service-binding-id")
							.build()))
			.expectNext(DeleteServiceInstanceBindingResponse.builder().build())
			.verifyComplete();

	assertThat(this.results.getBeforeCreate()).isNullOrEmpty();
	assertThat(this.results.getAfterCreate()).isNullOrEmpty();
	assertThat(this.results.getErrorCreate()).isNullOrEmpty();
	assertThat(this.results.getBeforeDelete()).isEqualTo("before delete service-instance-id");
	assertThat(this.results.getAfterDelete()).isEqualTo("after delete service-instance-id");
	assertThat(this.results.getErrorDelete()).isNullOrEmpty();
}
 
Example #4
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void deleteBindingFiltersPlansSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.build());

	client.delete().uri(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.exchange()
			.expectStatus().isOk()
			.expectBody()
			.json("{}");

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId());
	assertHeaderValuesSet(actualRequest);
}
 
Example #5
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void deleteBindingWithAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.async(true)
			.operation("working")
			.build());

	client.delete().uri(buildDeleteUrl(PLATFORM_INSTANCE_ID, true))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.exchange()
			.expectStatus().isAccepted()
			.expectBody()
			.jsonPath("$.operation").isEqualTo("working");

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true);
	assertHeaderValuesSet(actualRequest);
}
 
Example #6
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
private void validateDeleteServiceBindingWithResponseStatus(DeleteServiceInstanceBindingResponse response,
		HttpStatus expectedStatus) {
	Mono<DeleteServiceInstanceBindingResponse> responseMono;
	if (response == null) {
		responseMono = Mono.empty();
	}
	else {
		responseMono = Mono.just(response);
	}
	given(bindingService.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)))
			.willReturn(responseMono);

	ResponseEntity<DeleteServiceInstanceBindingResponse> responseEntity = controller
			.deleteServiceInstanceBinding(pathVariables, null, null, "service-definition-id",
					"service-definition-plan-id", false, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(expectedStatus);
	assertThat(responseEntity.getBody()).isEqualTo(response);

	then(bindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));
}
 
Example #7
Source File: TestServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerDeleteOperationInProgressException("task_10"));
	}
	if (UNKNOWN_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceInstanceDoesNotExistException(request.getServiceInstanceId()));
	}
	if (UNKNOWN_BINDING_ID.equals(request.getBindingId())) {
		return Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId()));
	}
	if (request.isAsyncAccepted()) {
		return Mono.just(DeleteServiceInstanceBindingResponse.builder()
				.async(true)
				.operation("working")
				.build());
	}
	else {
		return Mono.just(DeleteServiceInstanceBindingResponse.builder()
				.build());
	}
}
 
Example #8
Source File: BookStoreServiceInstanceBindingService.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	return Mono.just(request.getBindingId())
			.flatMap(bindingId -> bindingRepository.existsById(bindingId)
					.flatMap(exists -> {
						if (exists) {
							return bindingRepository.deleteById(bindingId)
									.then(userService.deleteUser(bindingId))
									.thenReturn(DeleteServiceInstanceBindingResponse.builder().build());
						}
						else {
							return Mono.error(new ServiceInstanceBindingDoesNotExistException(bindingId));
						}
					}));
}
 
Example #9
Source File: CredHubPersistingDeleteServiceInstanceBindingWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
@Test
void deleteCredentialsFromCredHubWhenNotFound() {
	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest
		.builder()
		.bindingId("foo-binding-id")
		.serviceInstanceId("foo-instance-id")
		.serviceDefinitionId("foo-definition-id")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder =
		DeleteServiceInstanceBindingResponse.builder();

	given(this.credHubOperations.credentials())
		.willReturn(credHubCredentialOperations);

	given(this.credHubCredentialOperations.findByName(any()))
		.willReturn(Flux.fromIterable(Collections.emptyList()));

	StepVerifier
		.create(this.workflow.buildResponse(request, responseBuilder))
		.expectNext(responseBuilder)
		.verifyComplete();

	verifyNoMoreInteractions(this.credHubCredentialOperations);
	verifyNoMoreInteractions(this.credHubPermissionOperations);
}
 
Example #10
Source File: ExampleServiceBindingEventFlowsConfiguration2.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Bean
public DeleteServiceInstanceBindingCompletionFlow deleteServiceInstanceBindingCompletionFlow() {
	return new DeleteServiceInstanceBindingCompletionFlow() {
		@Override
		public Mono<Void> complete(DeleteServiceInstanceBindingRequest request,
				DeleteServiceInstanceBindingResponse response) {
			//
			// do something after the service instance binding is deleted
			//
			return Mono.empty();
		}
	};
}
 
Example #11
Source File: EventFlowsAutoConfigurationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Bean
public DeleteServiceInstanceBindingCompletionFlow createCompleteFlow() {
	return new DeleteServiceInstanceBindingCompletionFlow() {
		@Override
		public Mono<Void> complete(DeleteServiceInstanceBindingRequest request,
				DeleteServiceInstanceBindingResponse response) {
			return Mono.empty();
		}
	};
}
 
Example #12
Source File: ExampleServiceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request) {
	String serviceInstanceId = request.getServiceInstanceId();
	String bindingId = request.getBindingId();

	//
	// delete any binding-specific credentials
	//

	return Mono.just(DeleteServiceInstanceBindingResponse.builder()
			.async(true)
			.build());
}
 
Example #13
Source File: MailServiceInstanceBindingService.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
    DeleteServiceInstanceBindingRequest request) {
    return mailService.serviceBindingExists(request.getServiceInstanceId(), request.getBindingId())
        .flatMap(exists -> {
            if (exists) {
                return mailService.deleteServiceBinding(request.getServiceInstanceId())
                    .thenReturn(DeleteServiceInstanceBindingResponse.builder().build());
            } else {
                return Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId()));
            }
        });
}
 
Example #14
Source File: ServiceInstanceBindingEventService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	return flows.getDeleteInstanceBindingRegistry().getInitializationFlows(request)
			.then(service.deleteServiceInstanceBinding(request))
			.onErrorResume(e -> flows.getDeleteInstanceBindingRegistry().getErrorFlows(request, e)
					.then(Mono.error(e)))
			.flatMap(response -> flows.getDeleteInstanceBindingRegistry().getCompletionFlows(request, response)
					.then(Mono.just(response)));
}
 
Example #15
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deleteServiceBindingWithMissingBindingGivesExpectedStatus() {
	given(bindingService.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingDoesNotExistException("binding-id"));

	ResponseEntity<DeleteServiceInstanceBindingResponse> responseEntity = controller
			.deleteServiceInstanceBinding(pathVariables, null, null, "service-definition-id",
					"service-definition-plan-id", false, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.GONE);
}
 
Example #16
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 #17
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	if (request.getBindingId() == null) {
		return Mono.error(new ServiceInstanceBindingDoesNotExistException("service-binding-id"));
	}
	return Mono.just(DeleteServiceInstanceBindingResponse.builder().build());
}
 
Example #18
Source File: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
	DeleteServiceInstanceBindingRequest request) {
	return invokeDeleteResponseBuilders(request)
		.flatMap(response -> {
			if (response.isAsync()) {
				return Mono.just(response).publishOn(Schedulers.parallel())
					.doOnNext(r -> delete(request, r)
						.subscribe());
			}
			else {
				return delete(request, response).thenReturn(response);
			}
		});
}
 
Example #19
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deleteBindingWithAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.async(true)
			.operation("working")
			.build());

	MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, true))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.accept(MediaType.APPLICATION_JSON)
			.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andExpect(status().isOk())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isAccepted())
			.andExpect(jsonPath("$.operation", equalTo("working")));

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true);
	assertHeaderValuesSet(actualRequest);
}
 
Example #20
Source File: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private Mono<DeleteServiceInstanceBindingResponse> invokeDeleteResponseBuilders(
	DeleteServiceInstanceBindingRequest request) {
	AtomicReference<DeleteServiceInstanceBindingResponseBuilder> responseBuilder =
		new AtomicReference<>(DeleteServiceInstanceBindingResponse.builder());

	return Flux.fromIterable(deleteServiceInstanceBindingWorkflows)
		.filterWhen(workflow -> workflow.accept(request))
		.flatMap(workflow -> workflow.buildResponse(request, responseBuilder.get())
			.doOnNext(responseBuilder::set))
		.last(responseBuilder.get())
		.map(DeleteServiceInstanceBindingResponseBuilder::build);
}
 
Example #21
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deleteServiceInstanceBindingsWithNoWorkflows() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(
			Mono.just(new ServiceInstanceState(OperationState.IN_PROGRESS, "delete service instance started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(
			Mono.just(new ServiceInstanceState(OperationState.SUCCEEDED, "delete service instance completed",
				new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	this.workflowServiceInstanceBindingService = new WorkflowServiceInstanceBindingService(
		this.stateRepository, null, null, null);

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.build();

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.assertNext(response -> {
			InOrder repoOrder = inOrder(stateRepository);
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.IN_PROGRESS),
					eq("delete service instance binding started"));
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.SUCCEEDED),
					eq("delete service instance binding completed"));
			repoOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
			assertThat(response).isInstanceOf(DeleteServiceInstanceBindingResponse.class);
		})
		.verifyComplete();
}
 
Example #22
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deleteServiceInstanceBindingWithResponseError() {
	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo")
		.bindingId("bar")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder = DeleteServiceInstanceBindingResponse.builder();

	given(deleteServiceInstanceBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow1
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.error(new ServiceBrokerException("delete foo binding error")));

	given(deleteServiceInstanceBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow2
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.expectErrorSatisfies(e -> assertThat(e)
			.isInstanceOf(ServiceBrokerException.class)
			.hasMessage("delete foo binding error"))
		.verify();
}
 
Example #23
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deleteBindingFiltersPlansSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse
			.builder()
			.build());

	MvcResult mvcResult = mockMvc
			.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
					.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
					.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
					.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andExpect(status().isOk())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isOk())
			.andExpect(content().string("{}"));

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId());
	assertHeaderValuesSet(actualRequest);
}
 
Example #24
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void deleteBindingWithoutAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.build());

	MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andExpect(status().isOk())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isOk())
			.andExpect(content().string("{}"));

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertHeaderValuesSet(actualRequest);
}
 
Example #25
Source File: EcsServiceInstanceBindingService.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request)
        throws ServiceBrokerException {

    String bindingId = request.getBindingId();
    try {
        BindingWorkflow workflow = getWorkflow(request)
                .withDeleteRequest(request);

        LOG.info("looking up binding: " + bindingId);
        ServiceInstanceBinding binding = repository.find(bindingId);
        if (binding == null)
            throw new ServiceInstanceBindingDoesNotExistException(bindingId);
        LOG.info("binding found: " + bindingId);

        workflow.removeBinding(binding);

        LOG.info("deleting from repository" + bindingId);
        repository.delete(bindingId);
        return Mono.just(DeleteServiceInstanceBindingResponse.builder()
                .async(false)
                .build());
    } catch (Exception e) {
        LOG.error("Error deleting binding: " + e);
        throw new ServiceBrokerException(e);
    }
}
 
Example #26
Source File: ServiceInstanceBindingControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example #27
Source File: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
private Flux<Void> invokeDeleteWorkflows(DeleteServiceInstanceBindingRequest request,
	DeleteServiceInstanceBindingResponse response) {
	return Flux.fromIterable(deleteServiceInstanceBindingWorkflows)
		.filterWhen(workflow -> workflow.accept(request))
		.concatMap(workflow -> workflow.delete(request, response));
}
 
Example #28
Source File: DeleteServiceInstanceBindingWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
default Mono<Void> delete(DeleteServiceInstanceBindingRequest request,
	DeleteServiceInstanceBindingResponse response) {
	return Mono.empty();
}
 
Example #29
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deleteServiceInstanceBinding() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.IN_PROGRESS, "delete service instance binding started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.SUCCEEDED, "delete service instance binding completed",
				new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder = DeleteServiceInstanceBindingResponse.builder();
	DeleteServiceInstanceBindingResponse builtResponse = DeleteServiceInstanceBindingResponse.builder()
		.async(true)
		.operation("working2")
		.build();

	TestPublisher<Void> lowerOrderFlow = TestPublisher.create();
	TestPublisher<Void> higherOrderFlow = TestPublisher.create();

	given(deleteServiceInstanceBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow1.delete(eq(request), eq(builtResponse)))
		.willReturn(lowerOrderFlow.mono());
	given(deleteServiceInstanceBindingWorkflow1
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder
			.async(true)
			.operation("working1")));

	given(deleteServiceInstanceBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow2.delete(eq(request), eq(builtResponse)))
		.willReturn(higherOrderFlow.mono());
	given(deleteServiceInstanceBindingWorkflow2
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder
			.operation("working2")));

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.assertNext(response -> {
			InOrder repoOrder = inOrder(stateRepository);
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.IN_PROGRESS),
					eq("delete service instance binding started"));
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.SUCCEEDED),
					eq("delete service instance binding completed"));
			repoOrder.verifyNoMoreInteractions();

			lowerOrderFlow.complete();
			lowerOrderFlow.assertWasNotRequested();

			higherOrderFlow.complete();
			lowerOrderFlow.assertWasRequested();

			InOrder deleteOrder = inOrder(deleteServiceInstanceBindingWorkflow1,
				deleteServiceInstanceBindingWorkflow2);
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).delete(request, responseBuilder.build());
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).delete(request, responseBuilder.build());
			deleteOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
			assertThat(response.isAsync()).isTrue();
			assertThat(response.getOperation()).isEqualTo("working2");
		})
		.verifyComplete();
}
 
Example #30
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deleteServiceInstanceBindingWithAsyncError() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(
			Mono.just(new ServiceInstanceState(OperationState.IN_PROGRESS, "delete service instance started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(Mono.just(new ServiceInstanceState(OperationState.FAILED, "delete service instance failed",
			new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder = DeleteServiceInstanceBindingResponse.builder();

	given(deleteServiceInstanceBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow1.delete(request, responseBuilder.build()))
		.willReturn(Mono.error(new RuntimeException("delete foo binding error")));
	given(deleteServiceInstanceBindingWorkflow1
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	given(deleteServiceInstanceBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow2.delete(request, responseBuilder.build()))
		.willReturn(Mono.empty());
	given(deleteServiceInstanceBindingWorkflow2
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.assertNext(response -> {
			InOrder repoOrder = inOrder(stateRepository);
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.IN_PROGRESS),
					eq("delete service instance binding started"));
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.FAILED),
					eq("delete foo binding error"));
			repoOrder.verifyNoMoreInteractions();

			InOrder deleteOrder = inOrder(deleteServiceInstanceBindingWorkflow1,
				deleteServiceInstanceBindingWorkflow2);
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).delete(request, responseBuilder.build());
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).delete(request, responseBuilder.build());
			deleteOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
		})
		.verifyComplete();
}