Search in sources :

Example 1 with ServiceConnectorCreationException

use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.

the class MongoDbFactoryCreator method create.

@Override
public MongoDbFactory create(MongoServiceInfo serviceInfo, ServiceConnectorConfig config) {
    try {
        MongoClientOptions.Builder mongoOptionsToUse = getMongoOptions((MongoDbFactoryConfig) config);
        SimpleMongoDbFactory mongoDbFactory = createMongoDbFactory(serviceInfo, mongoOptionsToUse);
        return configure(mongoDbFactory, (MongoDbFactoryConfig) config);
    } catch (UnknownHostException e) {
        throw new ServiceConnectorCreationException(e);
    } catch (MongoException e) {
        throw new ServiceConnectorCreationException(e);
    }
}
Also used : MongoException(com.mongodb.MongoException) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) UnknownHostException(java.net.UnknownHostException) MongoClientOptions(com.mongodb.MongoClientOptions) ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException)

Example 2 with ServiceConnectorCreationException

use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.

the class DataSourceCreator method create.

@Override
public DataSource create(SI serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
    try {
        DataSource ds = createPooledDataSource(serviceInfo, serviceConnectorConfig);
        if (ds != null) {
            return ds;
        }
        // Only for testing outside Tomcat/CloudFoundry
        logger.warning("No connection pooling DataSource implementation found on the classpath - no pooling is in effect.");
        return new UrlDecodingDataSource(serviceInfo.getJdbcUrl());
    } catch (Exception e) {
        throw new ServiceConnectorCreationException("Failed to created cloud datasource for " + serviceInfo.getId() + " service", e);
    }
}
Also used : ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException) ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException) CloudException(org.springframework.cloud.CloudException) DataSource(javax.sql.DataSource)

Example 3 with ServiceConnectorCreationException

use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.

the class RedisConnectionFactoryCreator method create.

@Override
public RedisConnectionFactory create(RedisServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(serviceInfo.getHost());
    configuration.setPort(serviceInfo.getPort());
    configuration.setPassword(RedisPassword.of(serviceInfo.getPassword()));
    if (hasClass(JEDIS_CLASS_NAME)) {
        JedisClientConfigurationBuilder builder = JedisClientConfiguration.builder();
        RedisJedisClientConfigurer clientConfigurer = new RedisJedisClientConfigurer();
        if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
            clientConfigurer.configure(builder, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        } else {
            clientConfigurer.configure(builder, (PooledServiceConnectorConfig) serviceConnectorConfig);
        }
        if (connectionIsSecure(serviceInfo)) {
            builder.useSsl();
        }
        JedisConnectionFactory connectionFactory = new JedisConnectionFactory(configuration, builder.build());
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else if (hasClass(LETTUCE_CLASS_NAME)) {
        LettuceClientConfigurationBuilder builder;
        if (serviceConnectorConfig != null && ((PooledServiceConnectorConfig) serviceConnectorConfig).getPoolConfig() != null) {
            if (!hasClass(APACHE_COMMONS_POOL_CLASS_NAME)) {
                throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis " + "connection factory for %s service. Apache Commons Pool must be available on " + "the classpath if pooling parameters are provided.", serviceInfo.getId()));
            }
            builder = LettucePoolingClientConfiguration.builder();
        } else {
            builder = LettuceClientConfiguration.builder();
        }
        if (connectionIsSecure(serviceInfo)) {
            builder.useSsl();
        }
        RedisLettuceClientConfigurer clientConfigurer = new RedisLettuceClientConfigurer();
        if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
            clientConfigurer.configure(builder, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        } else {
            clientConfigurer.configure(builder, (PooledServiceConnectorConfig) serviceConnectorConfig);
        }
        LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(configuration, builder.build());
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else {
        throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis " + "connection factory for %s service. No client implementation classes " + " of Jedis or Lettuce clients implementation (%s, %s) not found", serviceInfo.getId(), JEDIS_CLASS_NAME, LETTUCE_CLASS_NAME));
    }
}
Also used : JedisClientConfigurationBuilder(org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder) ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) PooledServiceConnectorConfig(org.springframework.cloud.service.PooledServiceConnectorConfig) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) RedisStandaloneConfiguration(org.springframework.data.redis.connection.RedisStandaloneConfiguration) LettuceClientConfigurationBuilder(org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)

Example 4 with ServiceConnectorCreationException

use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.

the class SpringData1RedisConnectionFactoryCreator method create.

@Override
public RedisConnectionFactory create(RedisServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
    if (hasClass(JEDIS_CLASS_NAME)) {
        SpringData1RedisConnectionFactoryConfigurer configurer = new SpringData1RedisConnectionFactoryConfigurer();
        JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
        connectionFactory.setHostName(serviceInfo.getHost());
        connectionFactory.setPort(serviceInfo.getPort());
        connectionFactory.setPassword(serviceInfo.getPassword());
        if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
            configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        } else {
            configurer.configure(connectionFactory, (PooledServiceConnectorConfig) serviceConnectorConfig);
        }
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else if (hasClass(LETTUCE_CLASS_NAME)) {
        SpringData1RedisLettuceConnectionFactoryConfigurer configurer = new SpringData1RedisLettuceConnectionFactoryConfigurer();
        LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
        connectionFactory.setHostName(serviceInfo.getHost());
        connectionFactory.setPort(serviceInfo.getPort());
        connectionFactory.setPassword(serviceInfo.getPassword());
        configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
        connectionFactory.afterPropertiesSet();
        return connectionFactory;
    } else {
        throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis connection factory " + "for %s service. No client implementation classes " + " of jedis or lettuce clients implementation (%s, %s) not found", serviceInfo.getId(), JEDIS_CLASS_NAME, LETTUCE_CLASS_NAME));
    }
}
Also used : ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)

Example 5 with ServiceConnectorCreationException

use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.

the class TomcatDbcpPooledDataSourceCreator method createDataSource.

private DataSource createDataSource(String className, RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) {
    try {
        DataSource dataSource = (DataSource) Class.forName(className).newInstance();
        setBasicDataSourceProperties(dataSource, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery);
        return new UrlDecodingDataSource(dataSource, "url");
    } catch (Throwable e) {
        throw new ServiceConnectorCreationException("Error instantiating Tomcat DBCP connection pool", e);
    }
}
Also used : ServiceConnectorCreationException(org.springframework.cloud.service.ServiceConnectorCreationException) DataSource(javax.sql.DataSource)

Aggregations

ServiceConnectorCreationException (org.springframework.cloud.service.ServiceConnectorCreationException)5 DataSource (javax.sql.DataSource)2 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)2 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)2 MongoClientOptions (com.mongodb.MongoClientOptions)1 MongoException (com.mongodb.MongoException)1 UnknownHostException (java.net.UnknownHostException)1 CloudException (org.springframework.cloud.CloudException)1 PooledServiceConnectorConfig (org.springframework.cloud.service.PooledServiceConnectorConfig)1 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)1 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)1 JedisClientConfigurationBuilder (org.springframework.data.redis.connection.jedis.JedisClientConfiguration.JedisClientConfigurationBuilder)1 LettuceClientConfigurationBuilder (org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder)1