use of org.springframework.cloud.CloudException in project jhipster-sample-app-mongodb by jhipster.
the class CloudDatabaseConfiguration method mongobee.
@Bean
public Mongobee mongobee(MongoDbFactory mongoDbFactory, MongoTemplate mongoTemplate, Cloud cloud) {
log.debug("Configuring Cloud Mongobee");
List<ServiceInfo> matchingServiceInfos = cloud.getServiceInfos(MongoDbFactory.class);
if (matchingServiceInfos.size() != 1) {
throw new CloudException("No unique service matching MongoDbFactory found. Expected 1, found " + matchingServiceInfos.size());
}
MongoServiceInfo info = (MongoServiceInfo) matchingServiceInfos.get(0);
Mongobee mongobee = new Mongobee(info.getUri());
mongobee.setDbName(mongoDbFactory.getDb().getName());
mongobee.setMongoTemplate(mongoTemplate);
// package to scan for migrations
mongobee.setChangeLogsScanPackage("io.github.jhipster.sample.config.dbmigrations");
mongobee.setEnabled(true);
return mongobee;
}
use of org.springframework.cloud.CloudException in project spring-cloud-connectors by spring-cloud.
the class CloudFoundryFallbackServiceInfoCreator method getServicesData.
/**
* 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;
}
use of org.springframework.cloud.CloudException in project spring-cloud-connectors by spring-cloud.
the class GenericCloudServiceFactoryParser method doParse.
@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);
}
use of org.springframework.cloud.CloudException in project spring-cloud-connectors by spring-cloud.
the class AbstractCloudServiceConnectorFactory method afterPropertiesSet.
@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();
}
Aggregations