Search in sources :

Example 1 with LoggerConfig

use of com.couchbase.client.core.env.LoggerConfig in project couchbase-jdbc-driver by couchbaselabs.

the class ConnectionManager method clusterForCoordinate.

private Cluster clusterForCoordinate(final ConnectionCoordinate coordinate) {
    synchronized (this) {
        if (environment == null) {
            // This logger config makes sure the SDK also uses java.util.Logging.
            LoggerConfig.Builder loggerConfig = LoggerConfig.builder().disableSlf4J(true).fallbackToConsole(false);
            SecurityConfig.Builder securityConfig = SecurityConfig.builder();
            if (Boolean.parseBoolean(CouchbaseDriverProperty.SSL.get(coordinate.properties()))) {
                securityConfig = securityConfig.enableTls(true);
                if ("no-verify".equals(CouchbaseDriverProperty.SSL_MODE.get(coordinate.properties()))) {
                    securityConfig = securityConfig.trustManagerFactory(InsecureTrustManagerFactory.INSTANCE);
                } else {
                    if ("verify-ca".equals(CouchbaseDriverProperty.SSL_MODE.get(coordinate.properties()))) {
                        securityConfig = securityConfig.enableHostnameVerification(false);
                    }
                    String certPath = CouchbaseDriverProperty.SSL_CERT_PATH.get(coordinate.properties());
                    if (!isNullOrEmpty(certPath)) {
                        securityConfig.trustCertificate(Paths.get(certPath));
                    }
                    String keyStorePath = CouchbaseDriverProperty.SSL_KEYSTORE_PATH.get(coordinate.properties());
                    if (!isNullOrEmpty(keyStorePath)) {
                        String keyStorePassword = CouchbaseDriverProperty.SSL_KEYSTORE_PASSWORD.get(coordinate.properties());
                        if (isNull(keyStorePassword)) {
                            throw new IllegalArgumentException("If a keystore is provided, the password also needs to be provided");
                        }
                        securityConfig.trustStore(Paths.get(keyStorePath), keyStorePassword, Optional.empty());
                    }
                }
            }
            environment = ClusterEnvironment.builder().load((PropertyLoader<CoreEnvironment.Builder>) builder -> new SystemPropertyPropertyLoader(coordinate.properties()).load(builder)).loggerConfig(loggerConfig).securityConfig(securityConfig).retryStrategy(new InterceptingRetryStrategy()).build();
        }
        long newHandleCount = openHandles.compute(coordinate, (k, v) -> {
            if (v == null) {
                return 1L;
            } else {
                return v + 1;
            }
        });
        LOGGER.fine("Incrementing Handle Count to " + newHandleCount + " for Coordinate " + coordinate);
        return clusterCache.computeIfAbsent(coordinate, s -> {
            Cluster c = Cluster.connect(coordinate.connectionString(), clusterOptions(coordinate.authenticator()).environment(environment));
            maybeWaitUntilReady(coordinate, c);
            return c;
        });
    }
}
Also used : SystemPropertyPropertyLoader(com.couchbase.client.core.env.SystemPropertyPropertyLoader) SecurityConfig(com.couchbase.client.core.env.SecurityConfig) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) Cluster(com.couchbase.client.java.Cluster) SystemPropertyPropertyLoader(com.couchbase.client.core.env.SystemPropertyPropertyLoader) PropertyLoader(com.couchbase.client.core.env.PropertyLoader) LoggerConfig(com.couchbase.client.core.env.LoggerConfig)

Aggregations

CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)1 LoggerConfig (com.couchbase.client.core.env.LoggerConfig)1 PropertyLoader (com.couchbase.client.core.env.PropertyLoader)1 SecurityConfig (com.couchbase.client.core.env.SecurityConfig)1 SystemPropertyPropertyLoader (com.couchbase.client.core.env.SystemPropertyPropertyLoader)1 Cluster (com.couchbase.client.java.Cluster)1