Search in sources :

Example 1 with SSLConnectionContext

use of com.netflix.astyanax.connectionpool.SSLConnectionContext in project coprhd-controller by CoprHD.

the class DbClientContext method init.

public void init(final HostSupplierImpl hostSupplier) {
    String svcName = hostSupplier.getDbSvcName();
    log.info("Initializing hosts for {}", svcName);
    List<Host> hosts = hostSupplier.get();
    if ((hosts != null) && (hosts.isEmpty())) {
        throw new IllegalStateException(String.format("DbClientContext.init() : host list in hostsupplier for %s is empty", svcName));
    } else {
        int hostCount = hosts == null ? 0 : hosts.size();
        log.info(String.format("number of hosts in the hostsupplier for %s is %d", svcName, hostCount));
    }
    Partitioner murmur3partitioner = Murmur3Partitioner.get();
    Map<String, Partitioner> partitioners = new HashMap<>();
    partitioners.put("org.apache.cassandra.dht.Murmur3Partitioner.class.getCanonicalName()", murmur3partitioner);
    ConsistencyLevel readCL = ConsistencyLevel.CL_LOCAL_QUORUM;
    ConsistencyLevel writeCL = ConsistencyLevel.CL_EACH_QUORUM;
    ConnectionPoolConfigurationImpl cfg = new ConnectionPoolConfigurationImpl(DEFAULT_CN_POOL_NANE).setMaxConns(maxConnections).setMaxConnsPerHost(maxConnectionsPerHost).setConnectTimeout(DEFAULT_CONN_TIMEOUT).setMaxBlockedThreadsPerHost(DEFAULT_MAX_BLOCKED_THREADS).setPartitioner(murmur3partitioner);
    log.info("The client to node is encrypted={}", isClientToNodeEncrypted);
    if (isClientToNodeEncrypted) {
        SSLConnectionContext sslContext = getSSLConnectionContext();
        cfg.setSSLConnectionContext(sslContext);
    }
    // TODO revisit it to see if we need set different retry policy, timeout, discovery delay etc for geodb
    keyspaceContext = new AstyanaxContext.Builder().withHostSupplier(hostSupplier).forCluster(clusterName).forKeyspace(keyspaceName).withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN).setDiscoveryDelayInSeconds(svcListPoolIntervalSec).setDefaultReadConsistencyLevel(readCL).setDefaultWriteConsistencyLevel(writeCL).setTargetCassandraVersion("2.0").setPartitioners(partitioners).setRetryPolicy(retryPolicy)).withConnectionPoolConfiguration(cfg).withTracerFactory(new KeyspaceTracerFactoryImpl()).withConnectionPoolMonitor(new CustomConnectionPoolMonitor(monitorIntervalSecs)).buildKeyspace(ThriftFamilyFactory.getInstance());
    keyspaceContext.start();
    keyspace = keyspaceContext.getClient();
    // Check and reset default write consistency level
    final DrUtil drUtil = new DrUtil(hostSupplier.getCoordinatorClient());
    if (drUtil.isMultivdc()) {
        // geodb in mutlivdc should be EACH_QUORUM always. Never retry for write failures
        setRetryFailedWriteWithLocalQuorum(false);
        log.info("Retry for failed write with LOCAL_QUORUM: {}", retryFailedWriteWithLocalQuorum);
    } else {
        setRetryFailedWriteWithLocalQuorum(true);
    }
    if (drUtil.isActiveSite() && !drUtil.isMultivdc()) {
        log.info("Schedule db consistency level monitor on DR active site");
        exe.scheduleWithFixedDelay(new Runnable() {

            @Override
            public void run() {
                try {
                    checkAndResetConsistencyLevel(drUtil, hostSupplier.getDbSvcName());
                } catch (Exception ex) {
                    log.warn("Encounter Unexpected exception during check consistency level. Retry in next run", ex);
                }
            }
        }, 60, DEFAULT_CONSISTENCY_LEVEL_CHECK_SEC, TimeUnit.SECONDS);
    }
    initDone = true;
}
Also used : HashMap(java.util.HashMap) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) Host(com.netflix.astyanax.connectionpool.Host) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) ConsistencyLevel(com.netflix.astyanax.model.ConsistencyLevel) SSLConnectionContext(com.netflix.astyanax.connectionpool.SSLConnectionContext) ConnectionPoolConfigurationImpl(com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl) AstyanaxContext(com.netflix.astyanax.AstyanaxContext) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl) Murmur3Partitioner(com.netflix.astyanax.partitioner.Murmur3Partitioner) Partitioner(com.netflix.astyanax.partitioner.Partitioner)

Example 2 with SSLConnectionContext

use of com.netflix.astyanax.connectionpool.SSLConnectionContext in project coprhd-controller by CoprHD.

the class DbClientContext method initClusterContext.

/**
 * Initialize the cluster context and cluster instances.
 * This has to be separated from init() because dbsvc need this to start
 * while init() depends on dbclient which in turn depends on dbsvc.
 */
private void initClusterContext() {
    int port = getThriftPort();
    ConnectionPoolConfigurationImpl cfg = new ConnectionPoolConfigurationImpl(clusterName).setMaxConnsPerHost(1).setSeeds(String.format("%1$s:%2$d", LOCAL_HOST, port));
    if (isClientToNodeEncrypted()) {
        SSLConnectionContext sslContext = getSSLConnectionContext();
        cfg.setSSLConnectionContext(sslContext);
    }
    clusterContext = new AstyanaxContext.Builder().forCluster(clusterName).forKeyspace(getKeyspaceName()).withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setRetryPolicy(new QueryRetryPolicy(10, 1000))).withConnectionPoolConfiguration(cfg).buildCluster(ThriftFamilyFactory.getInstance());
    clusterContext.start();
    cluster = clusterContext.getClient();
}
Also used : SSLConnectionContext(com.netflix.astyanax.connectionpool.SSLConnectionContext) ConnectionPoolConfigurationImpl(com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl)

Example 3 with SSLConnectionContext

use of com.netflix.astyanax.connectionpool.SSLConnectionContext 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

SSLConnectionContext (com.netflix.astyanax.connectionpool.SSLConnectionContext)3 ConnectionPoolConfigurationImpl (com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl)3 AstyanaxConfigurationImpl (com.netflix.astyanax.impl.AstyanaxConfigurationImpl)3 AstyanaxContext (com.netflix.astyanax.AstyanaxContext)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 Host (com.netflix.astyanax.connectionpool.Host)1 NodeDiscoveryType (com.netflix.astyanax.connectionpool.NodeDiscoveryType)1 ConnectionPoolType (com.netflix.astyanax.connectionpool.impl.ConnectionPoolType)1 CountingConnectionPoolMonitor (com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor)1 SimpleAuthenticationCredentials (com.netflix.astyanax.connectionpool.impl.SimpleAuthenticationCredentials)1 ConsistencyLevel (com.netflix.astyanax.model.ConsistencyLevel)1 Murmur3Partitioner (com.netflix.astyanax.partitioner.Murmur3Partitioner)1 Partitioner (com.netflix.astyanax.partitioner.Partitioner)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 BackendException (org.janusgraph.diskstorage.BackendException)1 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)1