Search in sources :

Example 1 with CloudException

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;
}
Also used : ServiceInfo(org.springframework.cloud.service.ServiceInfo) MongoServiceInfo(org.springframework.cloud.service.common.MongoServiceInfo) CloudException(org.springframework.cloud.CloudException) Mongobee(com.github.mongobee.Mongobee) MongoServiceInfo(org.springframework.cloud.service.common.MongoServiceInfo) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)

Example 2 with CloudException

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) CloudException(org.springframework.cloud.CloudException) Map(java.util.Map) CloudException(org.springframework.cloud.CloudException)

Example 3 with CloudException

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);
}
Also used : CloudException(org.springframework.cloud.CloudException)

Example 4 with CloudException

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();
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) CloudException(org.springframework.cloud.CloudException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Aggregations

CloudException (org.springframework.cloud.CloudException)4 Mongobee (com.github.mongobee.Mongobee)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 CloudFactory (org.springframework.cloud.CloudFactory)1 ServiceInfo (org.springframework.cloud.service.ServiceInfo)1 MongoServiceInfo (org.springframework.cloud.service.common.MongoServiceInfo)1 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)1