org.springframework.cloud.CloudException Java Examples
The following examples show how to use
org.springframework.cloud.CloudException.
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: CloudFoundryConnector.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
/** * Return object representation of the VCAP_SERVICES environment variable * <p> * Returns a list whose element is a map with service attributes. * </p> * @return parsed service data */ @SuppressWarnings("unchecked") protected List<Map<String,Object>> getServicesData() { String servicesString = environment.getEnvValue("VCAP_SERVICES"); CloudFoundryRawServiceData rawServices = new CloudFoundryRawServiceData(); if (servicesString != null && servicesString.length() > 0) { try { rawServices = objectMapper.readValue(servicesString, CloudFoundryRawServiceData.class); } catch (Exception e) { throw new CloudException(e); } } for (ServiceDataPostProcessor postProcessor : serviceDataPostProcessors) { rawServices = postProcessor.process(rawServices); } List<Map<String, Object>> flatServices = new ArrayList<Map<String, Object>>(); for (Map.Entry<String, List<Map<String,Object>>> entry : rawServices.entrySet()) { flatServices.addAll(entry.getValue()); } return flatServices; }
Example #2
Source File: GenericCloudServiceFactoryParser.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); String connectorTypeName = element.getAttribute(CONNECTOR_TYPE); if (StringUtils.hasText(connectorTypeName)) { try { connectorType = Class.forName(connectorTypeName); builder.addPropertyValue("serviceConnectorType", connectorType); } catch (ClassNotFoundException ex) { throw new CloudException("Failed to load " + connectorTypeName, ex); } } // TBD: Support generic (map-based?) service config builder.addConstructorArgValue(null); }
Example #3
Source File: AbstractCloudServiceConnectorFactory.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() throws Exception { ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) getBeanFactory(); if (cloud == null) { if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) { beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory()); } CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next(); cloud = cloudFactory.getCloud(); } if (!StringUtils.hasText(serviceId)) { List<? extends ServiceInfo> infos = cloud.getServiceInfos(serviceConnectorType); if (infos.size() != 1) { throw new CloudException("Expected 1 service matching " + serviceConnectorType.getName() + " type, but found " + infos.size()); } serviceId = infos.get(0).getId(); } super.afterPropertiesSet(); }
Example #4
Source File: DataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
public String getDriverClassName(SI serviceInfo) { String userSpecifiedDriver = System.getProperty(driverSystemPropKey); if (userSpecifiedDriver != null && !userSpecifiedDriver.isEmpty()) { return userSpecifiedDriver; } else { for (String driver : driverClasses) { try { Class.forName(driver); return driver; } catch (ClassNotFoundException ex) { // continue... } } } throw new CloudException("No suitable database driver found for " + serviceInfo.getId() + " service "); }
Example #5
Source File: ObjectStoreFileStorageFactoryBean.java From multiapps-controller with Apache License 2.0 | 6 votes |
private ObjectStoreServiceInfo getServiceInfo() { if (StringUtils.isEmpty(serviceName)) { LOGGER.warn("service name not specified in config files"); return null; } try { CloudFactory cloudFactory = new CloudFactory(); Cloud cloud = cloudFactory.getCloud(); ServiceInfo serviceInfo = cloud.getServiceInfo(serviceName); if (serviceInfo instanceof ObjectStoreServiceInfo) { return (ObjectStoreServiceInfo) serviceInfo; } LOGGER.warn("Service instance did not match allowed label and plans."); } catch (CloudException e) { LOGGER.warn(MessageFormat.format("Failed to detect service info for service \"{0}\"!", serviceName), e); } return null; }
Example #6
Source File: SsoServiceCredentialsListener.java From spring-cloud-sso-connector with Apache License 2.0 | 5 votes |
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { if (cloud != null) return; try { cloud = new CloudFactory().getCloud(); } catch (CloudException e) { return; // not running on a known cloud environment, so nothing to do } for (ServiceInfo serviceInfo : cloud.getServiceInfos()) { if (serviceInfo instanceof SsoServiceInfo) { Map<String, Object> map = new HashMap<>(); SsoServiceInfo ssoServiceInfo = (SsoServiceInfo) serviceInfo; map.put("security.oauth2.client.clientId", ssoServiceInfo.getClientId()); map.put("security.oauth2.client.clientSecret", ssoServiceInfo.getClientSecret()); map.put("security.oauth2.client.accessTokenUri", ssoServiceInfo.getAuthDomain() + "/oauth/token"); map.put("security.oauth2.client.userAuthorizationUri", ssoServiceInfo.getAuthDomain() + "/oauth/authorize"); map.put("ssoServiceUrl", ssoServiceInfo.getAuthDomain()); map.put("security.oauth2.resource.userInfoUri", ssoServiceInfo.getAuthDomain() + "/userinfo"); map.put("security.oauth2.resource.tokenInfoUri", ssoServiceInfo.getAuthDomain() + "/check_token"); map.put("security.oauth2.resource.jwk.key-set-uri", ssoServiceInfo.getAuthDomain() + "/token_keys"); MapPropertySource mapPropertySource = new MapPropertySource("vcapPivotalSso", map); event.getEnvironment().getPropertySources().addFirst(mapPropertySource); } } }
Example #7
Source File: HerokuConnector.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public ApplicationInstanceInfo getApplicationInstanceInfo() { try { return applicationInstanceInfoCreator.createApplicationInstanceInfo(); } catch (Exception e) { throw new CloudException(e); } }
Example #8
Source File: CloudFoundryConnector.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public ApplicationInstanceInfo getApplicationInstanceInfo() { try { @SuppressWarnings("unchecked") Map<String, Object> rawApplicationInstanceInfo = objectMapper.readValue(environment.getEnvValue("VCAP_APPLICATION"), Map.class); return applicationInstanceInfoCreator.createApplicationInstanceInfo(rawApplicationInstanceInfo); } catch (Exception e) { throw new CloudException(e); } }
Example #9
Source File: EnvironmentAccessor.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
public String getHost() { try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException ex) { throw new CloudException(ex); } }
Example #10
Source File: SpringApplicationContextInitializer.java From spring-music with Apache License 2.0 | 5 votes |
private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { return null; } }
Example #11
Source File: AbstractWebApplicationInitializer.java From bearchoke with Apache License 2.0 | 5 votes |
protected Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { return null; } }
Example #12
Source File: CustomerApplicationContextInitializer.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
/** * Returns cloud object if the application runs on cloud environment * * @return cloud object if the application runs on cloud environment */ private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { logger.error("no suitable cloud found"); return null; } }
Example #13
Source File: TestRestController.java From bluemix-cloud-connectors with Apache License 2.0 | 5 votes |
private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { return null; } }
Example #14
Source File: ContextInitializer.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException e) { return null; } }
Example #15
Source File: ContextInitializer.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException e) { return null; } }
Example #16
Source File: CloudDataSourceFactoryBeanTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Test public void testFallBackToDefault() { when(configurationMock.getDbConnectionThreads()).thenReturn(30); when(springCloudMock.getServiceConnector(any(), any(), any())).thenThrow(new CloudException("unknown service")); testedFactory.setDefaultDataSource(defaultDataSource); testedFactory.setServiceName("any"); testedFactory.setConfiguration(configurationMock); testedFactory.afterPropertiesSet(); verify(springCloudMock, atLeastOnce()).getServiceConnector(any(), any(), any()); assertEquals(testedFactory.getObject(), defaultDataSource); }
Example #17
Source File: FileSystemFileStorageFactoryBean.java From multiapps-controller with Apache License 2.0 | 5 votes |
private String getStoragePath(String serviceName) { if (StringUtils.isEmpty(serviceName)) { LOGGER.warn(Messages.FILE_SYSTEM_SERVICE_NAME_IS_NOT_SPECIFIED); return null; } try { CloudFactory cloudFactory = new CloudFactory(); Cloud cloud = cloudFactory.getCloud(); FileSystemServiceInfo serviceInfo = (FileSystemServiceInfo) cloud.getServiceInfo(serviceName); return serviceInfo.getStoragePath(); } catch (CloudException e) { LOGGER.warn(MessageFormat.format(Messages.FAILED_TO_DETECT_FILE_SERVICE_STORAGE_PATH, serviceName), e); } return null; }
Example #18
Source File: CloudDataSourceFactoryBean.java From multiapps-controller with Apache License 2.0 | 5 votes |
private DataSource getCloudDataSource(String serviceName) { DataSource cloudDataSource = null; try { if (serviceName != null && !serviceName.isEmpty()) { int maxPoolSize = configuration.getDbConnectionThreads(); DataSourceConfig config = new DataSourceConfig(new PoolConfig(maxPoolSize, 30000), null); cloudDataSource = getSpringCloud().getServiceConnector(serviceName, DataSource.class, config); } } catch (CloudException e) { // Do nothing } return cloudDataSource; }
Example #19
Source File: MicrometerConfiguration.java From multiapps-controller with Apache License 2.0 | 5 votes |
private DynatraceServiceInfo getDynatraceServiceInfo() { String serviceName = DynatraceServiceInfoCreator.DEFAULT_DYNATRACE_SERVICE_ID; try { CloudFactory cloudFactory = new CloudFactory(); Cloud cloud = cloudFactory.getCloud(); ServiceInfo serviceInfo = cloud.getServiceInfo(serviceName); if (serviceInfo instanceof DynatraceServiceInfo) { return (DynatraceServiceInfo) serviceInfo; } LOGGER.warn("Service instance did not match allowed name and type."); } catch (CloudException e) { LOGGER.warn(MessageFormat.format("Failed to detect service info for service \"{0}\"!", serviceName), e); } return null; }
Example #20
Source File: WorkerContextInitializer.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { logger.error("no suitable cloud found"); return null; } }
Example #21
Source File: SaleApplicationContextInitializer.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
/** * Returns cloud object if the application runs on cloud environment * * @return cloud object if the application runs on cloud environment */ private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { logger.error("no suitable cloud found"); return null; } }
Example #22
Source File: TaxApplicationContextInitializer.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
/** * Returns cloud object if the application runs on cloud environment * * @return cloud object if the application runs on cloud environment */ private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { logger.error("no suitable cloud found"); return null; } }
Example #23
Source File: ProductApplicationContextInitializer.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
/** * Returns cloud object if the application runs on cloud environment * * @return cloud object if the application runs on cloud environment */ private Cloud getCloud() { try { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); } catch (CloudException ce) { logger.error("no suitable cloud found"); return null; } }
Example #24
Source File: HystrixAmqpServiceInfo.java From spring-cloud-services-connector with Apache License 2.0 | 4 votes |
public HystrixAmqpServiceInfo(String id, String uri) throws CloudException { super(id); delegate = new AmqpServiceInfo(id, uri); }
Example #25
Source File: AmqpServiceInfo.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public AmqpServiceInfo(String id, String uri) throws CloudException { this(id, uri, null); }
Example #26
Source File: AmqpServiceInfo.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public AmqpServiceInfo(String id, String uri, String managementUri) throws CloudException { super(id, uri); this.managementUri = managementUri; this.virtualHost = decode(getUriInfo().getPath()); }
Example #27
Source File: CloudFoundryConnectorApplicationTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
@Test(expected = CloudException.class) public void servicesInfosWithNonJsonServices() { when(mockEnvironment.getEnvValue("VCAP_SERVICES")).thenReturn("some value"); testCloudConnector.getServiceInfos(); }