Search in sources :

Example 1 with ConnectionPoolConfigurationImpl

use of com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl in project titan by thinkaurelius.

the class AstyanaxStoreManager method getContextBuilder.

private AstyanaxContext.Builder getContextBuilder(Configuration config, int maxConnsPerHost, String usedFor) {
    final ConnectionPoolType poolType = ConnectionPoolType.valueOf(config.get(CONNECTION_POOL_TYPE));
    final NodeDiscoveryType discType = NodeDiscoveryType.valueOf(config.get(NODE_DISCOVERY_TYPE));
    final int maxConnections = config.get(MAX_CONNECTIONS);
    final int maxOperationsPerConnection = config.get(MAX_OPERATIONS_PER_CONNECTION);
    final int connectionTimeout = (int) connectionTimeoutMS.toMillis();
    ConnectionPoolConfigurationImpl cpool = new ConnectionPoolConfigurationImpl(usedFor + "TitanConnectionPool").setPort(port).setMaxOperationsPerConnection(maxOperationsPerConnection).setMaxConnsPerHost(maxConnsPerHost).setRetryDelaySlice(retryDelaySlice).setRetryMaxDelaySlice(retryMaxDelaySlice).setRetrySuspendWindow(retrySuspendWindow).setSocketTimeout(connectionTimeout).setConnectTimeout(connectionTimeout).setSeeds(StringUtils.join(hostnames, ","));
    if (null != retryBackoffStrategy) {
        cpool.setRetryBackoffStrategy(retryBackoffStrategy);
        log.debug("Custom RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
    } else {
        log.debug("Default RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
    }
    if (StringUtils.isNotBlank(localDatacenter)) {
        cpool.setLocalDatacenter(localDatacenter);
        log.debug("Set local datacenter: {}", cpool.getLocalDatacenter());
    }
    AstyanaxConfigurationImpl aconf = new AstyanaxConfigurationImpl().setConnectionPoolType(poolType).setDiscoveryType(discType).setTargetCassandraVersion("1.2").setMaxThriftSize(thriftFrameSizeBytes);
    if (0 < maxConnections) {
        cpool.setMaxConns(maxConnections);
    }
    if (hasAuthentication()) {
        cpool.setAuthenticationCredentials(new SimpleAuthenticationCredentials(username, password));
    }
    if (config.get(SSL_ENABLED)) {
        cpool.setSSLConnectionContext(new SSLConnectionContext(config.get(SSL_TRUSTSTORE_LOCATION), config.get(SSL_TRUSTSTORE_PASSWORD)));
    }
    AstyanaxContext.Builder ctxBuilder = new AstyanaxContext.Builder();
    // Standard context builder options
    ctxBuilder.forCluster(clusterName).forKeyspace(keySpaceName).withAstyanaxConfiguration(aconf).withConnectionPoolConfiguration(cpool).withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
    // Conditional context builder option: host supplier
    if (config.has(HOST_SUPPLIER)) {
        String hostSupplier = config.get(HOST_SUPPLIER);
        Supplier<List<Host>> supplier = null;
        if (hostSupplier != null) {
            try {
                supplier = (Supplier<List<Host>>) Class.forName(hostSupplier).newInstance();
                ctxBuilder.withHostSupplier(supplier);
            } catch (Exception e) {
                log.warn("Problem with host supplier class " + hostSupplier + ", going to use default.", e);
            }
        }
    }
    return ctxBuilder;
}
Also used : NodeDiscoveryType(com.netflix.astyanax.connectionpool.NodeDiscoveryType) ConnectionPoolType(com.netflix.astyanax.connectionpool.impl.ConnectionPoolType) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) SSLConnectionContext(com.netflix.astyanax.connectionpool.SSLConnectionContext) ConnectionPoolConfigurationImpl(com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl) AstyanaxContext(com.netflix.astyanax.AstyanaxContext) List(java.util.List) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl) SimpleAuthenticationCredentials(com.netflix.astyanax.connectionpool.impl.SimpleAuthenticationCredentials) CountingConnectionPoolMonitor(com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor)

Example 2 with ConnectionPoolConfigurationImpl

use of com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl in project zuul by Netflix.

the class CassandraHelper method getZuulCassKeyspace.

/**
     * @return the Keyspace for the Zuul Cassandra cluster which stores filters
     * @throws Exception
     */
public Keyspace getZuulCassKeyspace() throws Exception {
    if (zuulCassKeyspace != null)
        return zuulCassKeyspace;
    try {
        setAstynaxConfiguration(ConfigurationManager.getConfigInstance());
        AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder().forKeyspace(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_KEYSPACE, "zuul_scripts").get()).withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)).withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("cass_connection_pool").setPort(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get()).setMaxConnsPerHost(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_MAXCONNECTIONSPERHOST, 1).get()).setSeeds(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_HOST, "").get() + ":" + DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()).buildKeyspace(ThriftFamilyFactory.getInstance());
        context.start();
        zuulCassKeyspace = context.getClient();
        return zuulCassKeyspace;
    } catch (Exception e) {
        LOG.error("Exception occurred when initializing Cassandra keyspace: " + e);
        throw e;
    }
}
Also used : Keyspace(com.netflix.astyanax.Keyspace) ConnectionPoolConfigurationImpl(com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl) AstyanaxContext(com.netflix.astyanax.AstyanaxContext) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl) CountingConnectionPoolMonitor(com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor)

Example 3 with ConnectionPoolConfigurationImpl

use of com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method getContextBuilder.

private AstyanaxContext.Builder getContextBuilder(Configuration config, int maxConnsPerHost, String usedFor) {
    final ConnectionPoolType poolType = ConnectionPoolType.valueOf(config.get(CONNECTION_POOL_TYPE));
    final NodeDiscoveryType discType = NodeDiscoveryType.valueOf(config.get(NODE_DISCOVERY_TYPE));
    final int maxConnections = config.get(MAX_CONNECTIONS);
    final int maxOperationsPerConnection = config.get(MAX_OPERATIONS_PER_CONNECTION);
    final int connectionTimeout = (int) connectionTimeoutMS.toMillis();
    ConnectionPoolConfigurationImpl cpool = new ConnectionPoolConfigurationImpl(usedFor + "JanusGraphConnectionPool").setPort(port).setMaxOperationsPerConnection(maxOperationsPerConnection).setMaxConnsPerHost(maxConnsPerHost).setRetryDelaySlice(retryDelaySlice).setRetryMaxDelaySlice(retryMaxDelaySlice).setRetrySuspendWindow(retrySuspendWindow).setSocketTimeout(connectionTimeout).setConnectTimeout(connectionTimeout).setSeeds(StringUtils.join(hostnames, ","));
    if (null != retryBackoffStrategy) {
        cpool.setRetryBackoffStrategy(retryBackoffStrategy);
        log.debug("Custom RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
    } else {
        log.debug("Default RetryBackoffStrategy {}", cpool.getRetryBackoffStrategy());
    }
    if (StringUtils.isNotBlank(localDatacenter)) {
        cpool.setLocalDatacenter(localDatacenter);
        log.debug("Set local datacenter: {}", cpool.getLocalDatacenter());
    }
    AstyanaxConfigurationImpl astyanaxConfiguration = new AstyanaxConfigurationImpl().setConnectionPoolType(poolType).setDiscoveryType(discType).setTargetCassandraVersion("1.2").setMaxThriftSize(thriftFrameSizeBytes);
    if (0 < maxConnections) {
        cpool.setMaxConns(maxConnections);
    }
    if (hasAuthentication()) {
        cpool.setAuthenticationCredentials(new SimpleAuthenticationCredentials(username, password));
    }
    if (config.get(SSL_ENABLED)) {
        cpool.setSSLConnectionContext(new SSLConnectionContext(config.get(SSL_TRUSTSTORE_LOCATION), config.get(SSL_TRUSTSTORE_PASSWORD)));
    }
    AstyanaxContext.Builder ctxBuilder = new AstyanaxContext.Builder();
    // Standard context builder options
    ctxBuilder.forCluster(clusterName).forKeyspace(keySpaceName).withAstyanaxConfiguration(astyanaxConfiguration).withConnectionPoolConfiguration(cpool).withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
    // Conditional context builder option: host supplier
    if (config.has(HOST_SUPPLIER)) {
        String hostSupplier = config.get(HOST_SUPPLIER);
        final Supplier<List<Host>> supplier;
        if (hostSupplier != null) {
            try {
                supplier = (Supplier<List<Host>>) Class.forName(hostSupplier).newInstance();
                ctxBuilder.withHostSupplier(supplier);
            } catch (Exception e) {
                log.warn("Problem with host supplier class " + hostSupplier + ", going to use default.", e);
            }
        }
    }
    return ctxBuilder;
}
Also used : NodeDiscoveryType(com.netflix.astyanax.connectionpool.NodeDiscoveryType) ConnectionPoolType(com.netflix.astyanax.connectionpool.impl.ConnectionPoolType) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) SSLConnectionContext(com.netflix.astyanax.connectionpool.SSLConnectionContext) ConnectionPoolConfigurationImpl(com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl) AstyanaxContext(com.netflix.astyanax.AstyanaxContext) List(java.util.List) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl) SimpleAuthenticationCredentials(com.netflix.astyanax.connectionpool.impl.SimpleAuthenticationCredentials) CountingConnectionPoolMonitor(com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor)

Aggregations

AstyanaxContext (com.netflix.astyanax.AstyanaxContext)3 ConnectionPoolConfigurationImpl (com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl)3 CountingConnectionPoolMonitor (com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor)3 AstyanaxConfigurationImpl (com.netflix.astyanax.impl.AstyanaxConfigurationImpl)3 NodeDiscoveryType (com.netflix.astyanax.connectionpool.NodeDiscoveryType)2 SSLConnectionContext (com.netflix.astyanax.connectionpool.SSLConnectionContext)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 ConnectionPoolType (com.netflix.astyanax.connectionpool.impl.ConnectionPoolType)2 SimpleAuthenticationCredentials (com.netflix.astyanax.connectionpool.impl.SimpleAuthenticationCredentials)2 List (java.util.List)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 Keyspace (com.netflix.astyanax.Keyspace)1 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)1 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)1 TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)1 BackendException (org.janusgraph.diskstorage.BackendException)1 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)1 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)1