org.springframework.cloud.servicebroker.exception.ServiceBrokerException Java Examples
The following examples show how to use
org.springframework.cloud.servicebroker.exception.ServiceBrokerException.
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: MongoServiceInstanceService.java From cloudfoundry-service-broker with Apache License 2.0 | 6 votes |
@Override public CreateServiceInstanceResponse createServiceInstance(CreateServiceInstanceRequest request) { // TODO MongoDB dashboard ServiceInstance instance = repository.findOne(request.getServiceInstanceId()); if (instance != null) { throw new ServiceInstanceExistsException(request.getServiceInstanceId(), request.getServiceDefinitionId()); } instance = new ServiceInstance(request); if (mongo.databaseExists(instance.getServiceInstanceId())) { // ensure the instance is empty mongo.deleteDatabase(instance.getServiceInstanceId()); } MongoDatabase db = mongo.createDatabase(instance.getServiceInstanceId()); if (db == null) { throw new ServiceBrokerException("Failed to create new DB instance: " + instance.getServiceInstanceId()); } repository.save(instance); return new CreateServiceInstanceResponse(); }
Example #2
Source File: EcsServiceInstanceBindingService.java From ecs-cf-service-broker with Apache License 2.0 | 6 votes |
@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 #3
Source File: BackingServicesParametersTransformationServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 6 votes |
@Test void transformParametersWithUnknownTransformer() { BackingServicesParametersTransformationService service = new BackingServicesParametersTransformationService(Collections.emptyList()); BackingServices backingServices = BackingServices .builder() .backingService(BackingService.builder() .name("misconfigured-service") .parameterTransformers(ParametersTransformerSpec .builder() .name("unknown-transformer") .build()) .build()) .build(); StepVerifier .create(service.transformParameters(backingServices, new HashMap<>())) .expectErrorSatisfies(e -> assertThat(e) .isInstanceOf(ServiceBrokerException.class) .hasMessageContaining("unknown-transformer")) .verify(); }
Example #4
Source File: BackingApplicationsParametersTransformationServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 6 votes |
@Test void transformParametersWithUnknownTransformer() { BackingApplicationsParametersTransformationService service = new BackingApplicationsParametersTransformationService(Collections.emptyList()); BackingApplications backingApplications = BackingApplications .builder() .backingApplication(BackingApplication .builder() .name("misconfigured-app") .parameterTransformers(ParametersTransformerSpec.builder() .name("unknown-transformer") .build()) .build()) .build(); StepVerifier .create(service.transformParameters(backingApplications, new HashMap<>())) .expectErrorSatisfies(e -> assertThat(e) .isInstanceOf(ServiceBrokerException.class) .hasMessageContaining("unknown-transformer")) .verify(); }
Example #5
Source File: KafkaBrokerTest.java From kafka-service-broker with Apache License 2.0 | 6 votes |
@Test public void testCreateAndDeleteInstance() throws ServiceBrokerException { serviceInstance.getParameters().put(KafkaBroker.TOPIC_NAME_KEY, "myTopic"); Object o = serviceInstance.getParameters().get(KafkaBroker.TOPIC_NAME_KEY); assertNotNull(o); assertEquals("myTopic", o.toString()); String topicName = "topic" + System.currentTimeMillis(); serviceInstance.getParameters().put(KafkaBroker.TOPIC_NAME_KEY, topicName); kafkaBroker.createInstance(serviceInstance); o = serviceInstance.getParameters().get(KafkaBroker.TOPIC_NAME_KEY); assertNotNull(o); assertEquals(topicName, o.toString()); kafkaBroker.deleteInstance(serviceInstance); }
Example #6
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 6 votes |
String getNamespaceURL(String namespace, Map<String, Object> parametersAbstract, Map<String, Object> serviceSettings) { HashMap<String, Object> parameters = (parametersAbstract instanceof HashMap) ? (HashMap) parametersAbstract : new HashMap<>(parametersAbstract); if (serviceSettings != null) { // merge serviceSettings into parameters, overwriting parameter values // with serviceSettings, since serviceSettings are forced by administrator // through the catalog. parameters.putAll(serviceSettings); } try { return getNamespaceURL(namespace, parameters); } catch (EcsManagementClientException e) { throw new ServiceBrokerException(e); } }
Example #7
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 6 votes |
private void lookupObjectEndpoints() throws EcsManagementClientException { if (broker.getObjectEndpoint() != null) { objectEndpoint = broker.getObjectEndpoint(); } else { List<BaseUrl> baseUrlList = BaseUrlAction.list(connection); String urlId; if (baseUrlList.isEmpty()) { throw new ServiceBrokerException( "No object endpoint or base URL available"); } else if (broker.getBaseUrl() != null) { urlId = baseUrlList.stream() .filter(b -> broker.getBaseUrl().equals(b.getName())) .findFirst() .orElseThrow(() -> new ServiceBrokerException("configured ECS Base URL not found")) .getId(); } else { urlId = detectDefaultBaseUrlId(baseUrlList); } objectEndpoint = BaseUrlAction.get(connection, urlId) .getNamespaceUrl(broker.getNamespace(), false); } if (broker.getRepositoryEndpoint() == null) broker.setRepositoryEndpoint(objectEndpoint); }
Example #8
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
private String getNamespaceURL(String namespace, Boolean useSSL, String baseURL) throws EcsManagementClientException { List<BaseUrl> baseUrlList = BaseUrlAction.list(connection); String urlId = baseUrlList.stream() .filter(b -> baseURL.equals(b.getName())) .findFirst() .orElseThrow(() -> new ServiceBrokerException("Configured ECS namespace not found.")) .getId(); return BaseUrlAction.get(connection, urlId).getNamespaceUrl(namespace, useSSL); }
Example #9
Source File: ExtensionLocator.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
private ExtensionFactory<T, ?> getFactoryByName(String name) { if (factoriesByName.containsKey(name)) { return factoriesByName.get(name); } else { throw new ServiceBrokerException("Unknown extension " + name + ". " + "Registered extensions are " + factoriesByName.keySet()); } }
Example #10
Source File: RemoteConnectBindingWorkflow.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
@Override public String createBindingUser() throws ServiceBrokerException, IOException, JAXBException { ServiceInstance instance = instanceRepository.find(instanceId); if (instance == null) throw new ServiceInstanceDoesNotExistException(instanceId); String secretKey = instance.addRemoteConnectionKey(bindingId); instanceRepository.save(instance); return secretKey; }
Example #11
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
CompletableFuture deleteBucket(String id) { try { BucketAction.delete(connection, prefix(id), broker.getNamespace()); return null; } catch (Exception e) { throw new ServiceBrokerException(e); } }
Example #12
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
CompletableFuture wipeAndDeleteBucket(String id) { try { addUserToBucket(id, broker.getRepositoryUser()); logger.info("Started Wiped of bucket {}", prefix(id)); BucketWipeResult result = bucketWipeFactory.newBucketWipeResult(); bucketWipe.deleteAllObjects(prefix(id), "", result); return result.getCompletedFuture().thenRun(() -> bucketWipeCompleted(result, id)); } catch (Exception e) { throw new ServiceBrokerException(e); } }
Example #13
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
Map<String, Object> createBucket(String id, ServiceDefinitionProxy service, PlanProxy plan, Map<String, Object> parameters) { if (parameters == null) parameters = new HashMap<>(); logger.info(String.format("Creating bucket %s", id)); try { if (bucketExists(id)) { throw new ServiceInstanceExistsException(id, service.getId()); } // merge serviceSettings into parameters, overwriting parameter values // with service/plan serviceSettings, since serviceSettings are forced // by administrator through the catalog. parameters.putAll(plan.getServiceSettings()); parameters.putAll(service.getServiceSettings()); // Validate the reclaim-policy if (!ReclaimPolicy.isPolicyAllowed(parameters)) { throw new ServiceBrokerException("Reclaim Policy "+ReclaimPolicy.getReclaimPolicy(parameters)+" is not one of the allowed polices "+ReclaimPolicy.getAllowedReclaimPolicies(parameters)); } BucketAction.create(connection, new ObjectBucketCreate(prefix(id), broker.getNamespace(), replicationGroupID, parameters)); if (parameters.containsKey(QUOTA) && parameters.get(QUOTA) != null) { logger.info("Applying quota"); Map<String, Integer> quota = (Map<String, Integer>) parameters.get(QUOTA); BucketQuotaAction.create(connection, prefix(id), broker.getNamespace(), quota.get(LIMIT), quota.get(WARN)); } if (parameters.containsKey(DEFAULT_RETENTION) && parameters.get(DEFAULT_RETENTION) != null) { logger.info("Applying retention policy"); BucketRetentionAction.update(connection, broker.getNamespace(), prefix(id), (int) parameters.get(DEFAULT_RETENTION)); } } catch (Exception e) { logger.error(String.format("Failed to create bucket %s", id), e); throw new ServiceBrokerException(e); } return parameters; }
Example #14
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
Map<String, Object> changeBucketPlan(String id, ServiceDefinitionProxy service, PlanProxy plan, Map<String, Object> parameters) { if (parameters == null) { parameters = new HashMap<>(); } // merge serviceSettings into parameters, overwriting parameter values // with service/plan serviceSettings, since serviceSettings are forced // by administrator through the catalog. parameters.putAll(plan.getServiceSettings()); parameters.putAll(service.getServiceSettings()); // Validate the reclaim-policy validateReclaimPolicy(parameters); @SuppressWarnings(UNCHECKED) Map<String, Object> quota = (Map<String, Object>) parameters .getOrDefault(QUOTA, new HashMap<>()); int limit = (int) quota.getOrDefault(LIMIT, -1); int warn = (int) quota.getOrDefault(WARN, -1); try { if (limit == -1 && warn == -1) { parameters.remove(QUOTA); BucketQuotaAction.delete(connection, prefix(id), broker.getNamespace()); } else { BucketQuotaAction.create(connection, prefix(id), broker.getNamespace(), limit, warn); } } catch (EcsManagementClientException e) { throw new ServiceBrokerException(e); } return parameters; }
Example #15
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
UserSecretKey createUser(String id) { try { logger.info(String.format("Creating user %s", prefix(id))); ObjectUserAction.create(connection, prefix(id), broker.getNamespace()); logger.info(String.format("Creating secret for user %s", prefix(id))); ObjectUserSecretAction.create(connection, prefix(id)); return ObjectUserSecretAction.list(connection, prefix(id)).get(0); } catch (Exception e) { throw new ServiceBrokerException(e); } }
Example #16
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
Boolean userExists(String id) throws ServiceBrokerException { try { return ObjectUserAction.exists(connection, prefix(id), broker.getNamespace()); } catch (Exception e) { throw new ServiceBrokerException(e); } }
Example #17
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
void addUserToBucket(String id, String username) { logger.info(String.format("Adding user %s to bucket %s", username, id)); try { addUserToBucket(id, username, Collections.singletonList("full_control")); } catch (Exception e) { throw new ServiceBrokerException(e); } }
Example #18
Source File: BucketInstanceWorkflow.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
@Override public CompletableFuture delete(String id) { try { ServiceInstance instance = instanceRepository.find(id); if (instance.getReferences().size() > 1) { removeInstanceFromReferences(instance, id); return null; } else { ReclaimPolicy reclaimPolicy = ReclaimPolicy.getReclaimPolicy(instance.getServiceSettings()); switch(reclaimPolicy) { case Fail: logger.info("Reclaim Policy is {} for bucket {}, attempting to delete bucket", reclaimPolicy, ecs.prefix(instance.getName())); ecs.deleteBucket(id); return null; case Detach: logger.info("Reclaim Policy is {} for bucket {}, Not Deleting Bucket", reclaimPolicy, ecs.prefix(instance.getName())); return null; case Delete: logger.info("Reclaim Policy is {} for bucket {}, Wiping and Deleting bucket", reclaimPolicy, ecs.prefix(instance.getName())); return ecs.wipeAndDeleteBucket(id); default: throw new ServiceBrokerException("ReclaimPolicy "+reclaimPolicy+" not supported"); } } } catch (IOException e) { throw new ServiceBrokerException(e); } }
Example #19
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
private void lookupReplicationGroupID() throws EcsManagementClientException { replicationGroupID = ReplicationGroupAction.list(connection).stream() .filter(r -> broker.getReplicationGroup().equals(r.getName())) .findFirst() .orElseThrow(() -> new ServiceBrokerException("Configured ECS replication group not found.")) .getId(); }
Example #20
Source File: EcsService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
ServiceDefinitionProxy lookupServiceDefinition( String serviceDefinitionId) throws ServiceBrokerException { ServiceDefinitionProxy service = catalog .findServiceDefinition(serviceDefinitionId); if (service == null) throw new ServiceBrokerException(SERVICE_NOT_FOUND + serviceDefinitionId); return service; }
Example #21
Source File: NamespaceInstanceWorkflow.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
@Override public CompletableFuture delete(String id) { try { ServiceInstance instance = instanceRepository.find(id); if (instance.getReferences().size() > 1) { removeInstanceFromReferences(instance, id); } else { ecs.deleteNamespace(id); } return null; } catch (EcsManagementClientException | JAXBException | IOException e) { throw new ServiceBrokerException(e); } }
Example #22
Source File: EcsServiceTest.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
/** * When initializing the ecs-service, if neither the object-endpoint is not * set statically nor the base-url, the service will lookup an endpoint * named default in the base-url list. If none is found, it will throw an * exception. * * @throws EcsManagementClientException when ECS resources do not exist */ @Test(expected = ServiceBrokerException.class) public void initializeBaseUrlDefaultLookupFails() throws EcsManagementClientException { PowerMockito.mockStatic(BaseUrlAction.class); when(BaseUrlAction.list(same(connection))) .thenReturn(Collections.emptyList()); ecs.initialize(); }
Example #23
Source File: ServiceBrokerExceptionHandlerTest.java From spring-cloud-open-service-broker with Apache License 2.0 | 5 votes |
@Test void serviceBrokerException() { ServiceBrokerException exception = new ServiceBrokerException("test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("test message"); }
Example #24
Source File: ServiceBrokerExceptionHandlerTest.java From spring-cloud-open-service-broker with Apache License 2.0 | 5 votes |
@Test void serviceBrokerExceptionWithErrorCode() { ServiceBrokerException exception = new ServiceBrokerException("ErrorCode", "test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isEqualTo("ErrorCode"); assertThat(errorMessage.getMessage()).contains("test message"); }
Example #25
Source File: MongoServiceInstanceBindingServiceTest.java From cloudfoundry-service-broker with Apache License 2.0 | 5 votes |
@Test(expected = ServiceBrokerException.class) public void serviceInstanceBindingCreationFailsWithUserCreationFailure() throws Exception { when(repository.findOne(any(String.class))).thenReturn(null); doThrow(new MongoServiceException("fail")).when(mongo).createUser(any(String.class), any(String.class), any(String.class)); service.createServiceInstanceBinding(buildCreateRequest()); }
Example #26
Source File: MongoServiceInstanceServiceTest.java From cloudfoundry-service-broker with Apache License 2.0 | 5 votes |
@Test(expected=ServiceBrokerException.class) public void serviceInstanceCreationFailsWithDBCreationFailure() throws Exception { when(repository.findOne(any(String.class))).thenReturn(null); when(mongo.databaseExists(any(String.class))).thenReturn(false); when(mongo.createDatabase(any(String.class))).thenReturn(null); service.createServiceInstance(buildCreateRequest()); }
Example #27
Source File: EcsServiceInstanceBindingService.java From ecs-cf-service-broker with Apache License 2.0 | 5 votes |
@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 #28
Source File: WorkflowServiceInstanceBindingServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@Test void createServiceInstanceAppBindingWithResponseError() { CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder() .serviceInstanceId("foo-id") .bindResource(BindResource.builder() .appGuid("foo-guid") .build()) .build(); CreateServiceInstanceAppBindingResponseBuilder responseBuilder = CreateServiceInstanceAppBindingResponse .builder(); given(createServiceInstanceAppBindingWorkflow1.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceAppBindingWorkflow1 .buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class))) .willReturn(Mono.error(new ServiceBrokerException("create foo error"))); given(createServiceInstanceAppBindingWorkflow2.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceAppBindingWorkflow2 .buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class))) .willReturn(Mono.just(responseBuilder)); StepVerifier.create(workflowServiceInstanceBindingService.createServiceInstanceBinding(request)) .expectErrorSatisfies(e -> assertThat(e) .isInstanceOf(ServiceBrokerException.class) .hasMessage("create foo error")) .verify(); }
Example #29
Source File: WorkflowServiceInstanceBindingServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@Test void createServiceInstanceRouteBindingWithResponseError() { CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder() .serviceInstanceId("foo-id") .bindResource(BindResource.builder() .route("foo-route") .build()) .build(); CreateServiceInstanceRouteBindingResponseBuilder responseBuilder = CreateServiceInstanceRouteBindingResponse .builder(); given(createServiceInstanceRouteBindingWorkflow1.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceRouteBindingWorkflow1 .buildResponse(eq(request), any(CreateServiceInstanceRouteBindingResponseBuilder.class))) .willReturn(Mono.error(new ServiceBrokerException("create foo error"))); given(createServiceInstanceRouteBindingWorkflow2.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceRouteBindingWorkflow2 .buildResponse(eq(request), any(CreateServiceInstanceRouteBindingResponseBuilder.class))) .willReturn(Mono.just(responseBuilder)); StepVerifier.create(workflowServiceInstanceBindingService.createServiceInstanceBinding(request)) .expectErrorSatisfies(e -> assertThat(e) .isInstanceOf(ServiceBrokerException.class) .hasMessage("create foo error")) .verify(); }
Example #30
Source File: WorkflowServiceInstanceBindingServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@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(); }