Search in sources :

Example 1 with CloudConfigFactory

use of com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory in project dsbulk by datastax.

the class DefaultSNIProxyServer method start.

@Override
public void start() {
    CommandLine run = CommandLine.parse(proxyPath.resolve("run.sh").toString());
    execute(run);
    running = true;
    try {
        config = new CloudConfigFactory().createCloudConfig(Files.newInputStream(getSecureBundlePath()));
    } catch (IOException | GeneralSecurityException e) {
        // should never happen, the bundle is always present and readable once the proxy is started
        throw new RuntimeException(e);
    }
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) GeneralSecurityException(java.security.GeneralSecurityException) CloudConfigFactory(com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory) IOException(java.io.IOException)

Example 2 with CloudConfigFactory

use of com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory in project java-driver by datastax.

the class SessionBuilder method buildDefaultSessionAsync.

@NonNull
protected final CompletionStage<CqlSession> buildDefaultSessionAsync() {
    try {
        ProgrammaticArguments programmaticArguments = programmaticArgumentsBuilder.build();
        DriverConfigLoader configLoader = this.configLoader != null ? this.configLoader : defaultConfigLoader(programmaticArguments.getClassLoader());
        DriverExecutionProfile defaultConfig = configLoader.getInitialConfig().getDefaultProfile();
        if (cloudConfigInputStream == null) {
            String configUrlString = defaultConfig.getString(DefaultDriverOption.CLOUD_SECURE_CONNECT_BUNDLE, null);
            if (configUrlString != null) {
                cloudConfigInputStream = () -> getURL(configUrlString).openStream();
            }
        }
        List<String> configContactPoints = defaultConfig.getStringList(DefaultDriverOption.CONTACT_POINTS, Collections.emptyList());
        if (cloudConfigInputStream != null) {
            if (!programmaticContactPoints.isEmpty() || !configContactPoints.isEmpty()) {
                LOG.info("Both a secure connect bundle and contact points were provided. These are mutually exclusive. The contact points from the secure bundle will have priority.");
                // clear the contact points provided in the setting file and via addContactPoints
                configContactPoints = Collections.emptyList();
                programmaticContactPoints = new HashSet<>();
            }
            if (programmaticSslFactory || defaultConfig.isDefined(DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS)) {
                LOG.info("Both a secure connect bundle and SSL options were provided. They are mutually exclusive. The SSL options from the secure bundle will have priority.");
            }
            CloudConfig cloudConfig = new CloudConfigFactory().createCloudConfig(cloudConfigInputStream.call());
            addContactEndPoints(cloudConfig.getEndPoints());
            boolean localDataCenterDefined = anyProfileHasDatacenterDefined(configLoader.getInitialConfig());
            if (programmaticLocalDatacenter || localDataCenterDefined) {
                LOG.info("Both a secure connect bundle and a local datacenter were provided. They are mutually exclusive. The local datacenter from the secure bundle will have priority.");
                programmaticArgumentsBuilder.clearDatacenters();
            }
            withLocalDatacenter(cloudConfig.getLocalDatacenter());
            withSslEngineFactory(cloudConfig.getSslEngineFactory());
            withCloudProxyAddress(cloudConfig.getProxyAddress());
            programmaticArguments = programmaticArgumentsBuilder.build();
        }
        boolean resolveAddresses = defaultConfig.getBoolean(DefaultDriverOption.RESOLVE_CONTACT_POINTS, true);
        Set<EndPoint> contactPoints = ContactPoints.merge(programmaticContactPoints, configContactPoints, resolveAddresses);
        if (keyspace == null && defaultConfig.isDefined(DefaultDriverOption.SESSION_KEYSPACE)) {
            keyspace = CqlIdentifier.fromCql(defaultConfig.getString(DefaultDriverOption.SESSION_KEYSPACE));
        }
        return DefaultSession.init((InternalDriverContext) buildContext(configLoader, programmaticArguments), contactPoints, keyspace);
    } catch (Throwable t) {
        // failed future if anything goes wrong. So wrap any error from that synchronous part.
        return CompletableFutures.failedFuture(t);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) CloudConfig(com.datastax.oss.driver.internal.core.config.cloud.CloudConfig) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) DefaultDriverConfigLoader(com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader) CloudConfigFactory(com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) DefaultEndPoint(com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

CloudConfigFactory (com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory)2 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)1 CloudConfig (com.datastax.oss.driver.internal.core.config.cloud.CloudConfig)1 DefaultDriverConfigLoader (com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader)1 DefaultEndPoint (com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 CommandLine (org.apache.commons.exec.CommandLine)1