@Test public void new_binding_raise_exception_if_unknow_routing_type() { createRouteBindingTemplate = new CreateServiceInstanceBindingRequest(SERVICE_DEFINITION_ID, PLAN_ID, null, Collections.singletonMap("NorRouteNeitherApp", "à!"), null); verifyThrown(() -> bindingService.createServiceInstanceBinding(createRouteBindingTemplate .withServiceInstanceId("Sid") .withBindingId("Bidroute")), ServiceBrokerException.class); verify(bindingRepository, never()).save(any(Binding.class)); }
@Override public CreateServiceInstanceBindingResponse createServiceInstanceBinding( CreateServiceInstanceBindingRequest request) throws ServiceInstanceBindingExistsException, ServiceBrokerException { final String bindingId = request.getBindingId(); final String configId = request.getServiceInstanceId(); log.debug("createServiceInstanceBinding - {}", bindingId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(configId); String targetAppId = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_APP.toString()); String route = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_ROUTE.toString()); Binding.BindingBuilder bindingBuilder = Binding.builder() .serviceInstanceId(configId) .serviceBindingId(bindingId); if (targetAppId != null) { log.info("Creating binding {} for app {}", bindingId, targetAppId); bindingBuilder.resourceId(targetAppId) .resourceType(Application); applicationLocker.executeThreadSafe(targetAppId, () -> { ApplicationInfo appInfo = appRepository.findOne(targetAppId); if (appInfo == null) { appInfo = ApplicationInfo.builder() .uuid(targetAppId) .build(); } appInfo.getEnrollmentState().addEnrollmentState(configId); bindingRepository.save(bindingBuilder.build()); appRepository.save(appInfo); workerManager.registerApplicationStopper(spaceEnrollerConfig, targetAppId, bindingId); }); return new CreateServiceInstanceAppBindingResponse().withCredentials(Collections.singletonMap( Config.ServiceInstanceParameters.IDLE_DURATION, spaceEnrollerConfig.getIdleDuration().toString())); } else if (route != null) { log.error("AutoWakeup based on route services not implemented yet. "); return null; } else { throw new ServiceBrokerException("Unknown bind resource type"); } }
AutosleepBindingService implements ServiceInstanceBindingService { @Override public CreateServiceInstanceBindingResponse createServiceInstanceBinding( CreateServiceInstanceBindingRequest request) throws ServiceInstanceBindingExistsException, ServiceBrokerException { final String bindingId = request.getBindingId(); final String configId = request.getServiceInstanceId(); log.debug("createServiceInstanceBinding - {}", bindingId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(configId); String targetAppId = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_APP.toString()); String route = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_ROUTE.toString()); Binding.BindingBuilder bindingBuilder = Binding.builder() .serviceInstanceId(configId) .serviceBindingId(bindingId); if (targetAppId != null) { log.info("Creating binding {} for app {}", bindingId, targetAppId); bindingBuilder.resourceId(targetAppId) .resourceType(Application); applicationLocker.executeThreadSafe(targetAppId, () -> { ApplicationInfo appInfo = appRepository.findOne(targetAppId); if (appInfo == null) { appInfo = ApplicationInfo.builder() .uuid(targetAppId) .build(); } appInfo.getEnrollmentState().addEnrollmentState(configId); bindingRepository.save(bindingBuilder.build()); appRepository.save(appInfo); workerManager.registerApplicationStopper(spaceEnrollerConfig, targetAppId, bindingId); }); return new CreateServiceInstanceAppBindingResponse().withCredentials(Collections.singletonMap( Config.ServiceInstanceParameters.IDLE_DURATION, spaceEnrollerConfig.getIdleDuration().toString())); } else if (route != null) { log.error("AutoWakeup based on route services not implemented yet. "); return null; } else { throw new ServiceBrokerException("Unknown bind resource type"); } } }
AutosleepBindingService implements ServiceInstanceBindingService { @Override public CreateServiceInstanceBindingResponse createServiceInstanceBinding( CreateServiceInstanceBindingRequest request) throws ServiceInstanceBindingExistsException, ServiceBrokerException { final String bindingId = request.getBindingId(); final String configId = request.getServiceInstanceId(); log.debug("createServiceInstanceBinding - {}", bindingId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(configId); String targetAppId = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_APP.toString()); String route = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_ROUTE.toString()); Binding.BindingBuilder bindingBuilder = Binding.builder() .serviceInstanceId(configId) .serviceBindingId(bindingId); if (targetAppId != null) { log.info("Creating binding {} for app {}", bindingId, targetAppId); bindingBuilder.resourceId(targetAppId) .resourceType(Application); applicationLocker.executeThreadSafe(targetAppId, () -> { ApplicationInfo appInfo = appRepository.findOne(targetAppId); if (appInfo == null) { appInfo = ApplicationInfo.builder() .uuid(targetAppId) .build(); } appInfo.getEnrollmentState().addEnrollmentState(configId); bindingRepository.save(bindingBuilder.build()); appRepository.save(appInfo); workerManager.registerApplicationStopper(spaceEnrollerConfig, targetAppId, bindingId); }); return new CreateServiceInstanceAppBindingResponse().withCredentials(Collections.singletonMap( Config.ServiceInstanceParameters.IDLE_DURATION, spaceEnrollerConfig.getIdleDuration().toString())); } else if (route != null) { log.error("AutoWakeup based on route services not implemented yet. "); return null; } else { throw new ServiceBrokerException("Unknown bind resource type"); } }  }
AutosleepBindingService implements ServiceInstanceBindingService { @Override public CreateServiceInstanceBindingResponse createServiceInstanceBinding( CreateServiceInstanceBindingRequest request) throws ServiceInstanceBindingExistsException, ServiceBrokerException { final String bindingId = request.getBindingId(); final String configId = request.getServiceInstanceId(); log.debug("createServiceInstanceBinding - {}", bindingId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(configId); String targetAppId = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_APP.toString()); String route = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_ROUTE.toString()); Binding.BindingBuilder bindingBuilder = Binding.builder() .serviceInstanceId(configId) .serviceBindingId(bindingId); if (targetAppId != null) { log.info("Creating binding {} for app {}", bindingId, targetAppId); bindingBuilder.resourceId(targetAppId) .resourceType(Application); applicationLocker.executeThreadSafe(targetAppId, () -> { ApplicationInfo appInfo = appRepository.findOne(targetAppId); if (appInfo == null) { appInfo = ApplicationInfo.builder() .uuid(targetAppId) .build(); } appInfo.getEnrollmentState().addEnrollmentState(configId); bindingRepository.save(bindingBuilder.build()); appRepository.save(appInfo); workerManager.registerApplicationStopper(spaceEnrollerConfig, targetAppId, bindingId); }); return new CreateServiceInstanceAppBindingResponse().withCredentials(Collections.singletonMap( Config.ServiceInstanceParameters.IDLE_DURATION, spaceEnrollerConfig.getIdleDuration().toString())); } else if (route != null) { log.error("AutoWakeup based on route services not implemented yet. "); return null; } else { throw new ServiceBrokerException("Unknown bind resource type"); } }  @Override CreateServiceInstanceBindingResponse createServiceInstanceBinding(
            CreateServiceInstanceBindingRequest request); @Override void deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request); }
AutosleepBindingService implements ServiceInstanceBindingService { @Override public CreateServiceInstanceBindingResponse createServiceInstanceBinding( CreateServiceInstanceBindingRequest request) throws ServiceInstanceBindingExistsException, ServiceBrokerException { final String bindingId = request.getBindingId(); final String configId = request.getServiceInstanceId(); log.debug("createServiceInstanceBinding - {}", bindingId); SpaceEnrollerConfig spaceEnrollerConfig = spaceEnrollerConfigRepository.findOne(configId); String targetAppId = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_APP.toString()); String route = (String) request.getBindResource() .get(ServiceBindingResource.BIND_RESOURCE_KEY_ROUTE.toString()); Binding.BindingBuilder bindingBuilder = Binding.builder() .serviceInstanceId(configId) .serviceBindingId(bindingId); if (targetAppId != null) { log.info("Creating binding {} for app {}", bindingId, targetAppId); bindingBuilder.resourceId(targetAppId) .resourceType(Application); applicationLocker.executeThreadSafe(targetAppId, () -> { ApplicationInfo appInfo = appRepository.findOne(targetAppId); if (appInfo == null) { appInfo = ApplicationInfo.builder() .uuid(targetAppId) .build(); } appInfo.getEnrollmentState().addEnrollmentState(configId); bindingRepository.save(bindingBuilder.build()); appRepository.save(appInfo); workerManager.registerApplicationStopper(spaceEnrollerConfig, targetAppId, bindingId); }); return new CreateServiceInstanceAppBindingResponse().withCredentials(Collections.singletonMap( Config.ServiceInstanceParameters.IDLE_DURATION, spaceEnrollerConfig.getIdleDuration().toString())); } else if (route != null) { log.error("AutoWakeup based on route services not implemented yet. "); return null; } else { throw new ServiceBrokerException("Unknown bind resource type"); } }  @Override CreateServiceInstanceBindingResponse createServiceInstanceBinding(
            CreateServiceInstanceBindingRequest request); @Override void deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request);  }