Search in sources :

Example 6 with SchemaChangeListener

use of com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener in project cdc-apache-cassandra by datastax.

the class CassandraClient method buildCqlSession.

public static CqlSession buildCqlSession(CassandraSourceConnectorConfig config, String version, String applicationName, SchemaChangeListener schemaChangeListener) {
    log.info("CassandraClient starting with config:\n{}\n", config.toString());
    SslConfig sslConfig = config.getSslConfig();
    // refresh only our keyspace.
    OptionsMap optionsMap = OptionsMap.driverDefaults();
    optionsMap.put(TypedDriverOption.METADATA_SCHEMA_REFRESHED_KEYSPACES, Arrays.asList(config.getKeyspaceName()));
    DriverConfigLoader loader = DriverConfigLoader.fromMap(optionsMap);
    CqlSessionBuilder builder = new SessionBuilder(sslConfig).withConfigLoader(loader).withApplicationVersion(version).withApplicationName(applicationName).withClientId(generateClientId(config.getInstanceName())).withKeyspace(config.getKeyspaceName()).withSchemaChangeListener(schemaChangeListener);
    ContactPointsValidator.validateContactPoints(config.getContactPoints());
    if (sslConfig != null && sslConfig.requireHostnameValidation()) {
        // if requireHostnameValidation then InetSocketAddress must be resolved
        config.getContactPoints().stream().map(hostStr -> new InetSocketAddress(hostStr, config.getPort())).forEach(builder::addContactPoint);
    } else {
        config.getContactPoints().stream().map(hostStr -> InetSocketAddress.createUnresolved(hostStr, config.getPort())).forEach(builder::addContactPoint);
    }
    ProgrammaticDriverConfigLoaderBuilder configLoaderBuilder = dseProgrammaticBuilderWithFallback(ConfigFactory.parseMap(config.getJavaDriverSettings(), "Connector properties"));
    processAuthenticatorConfig(config, configLoaderBuilder);
    if (sslConfig != null) {
        processSslConfig(sslConfig, configLoaderBuilder);
    }
    builder.withConfigLoader(configLoaderBuilder.build());
    CqlSession cqlSession = builder.build();
    cqlSession.setSchemaMetadataEnabled(true);
    return cqlSession;
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) SessionBuilder(com.datastax.oss.common.sink.ssl.SessionBuilder) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ProgrammaticDriverConfigLoaderBuilder(com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder) AUTH_PROVIDER_SERVICE(com.datastax.dse.driver.api.core.config.DseDriverOption.AUTH_PROVIDER_SERVICE) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) NonNull(edu.umd.cs.findbugs.annotations.NonNull) ConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel) AuthenticatorConfig(com.datastax.oss.common.sink.config.AuthenticatorConfig) Path(java.nio.file.Path) Select(com.datastax.oss.driver.api.querybuilder.select.Select) DseDriverOption(com.datastax.dse.driver.api.core.config.DseDriverOption) SslConfig(com.datastax.oss.common.sink.config.SslConfig) TypedDriverOption(com.datastax.oss.driver.api.core.config.TypedDriverOption) QueryBuilder.bindMarker(com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker) CqlSessionBuilder(com.datastax.oss.driver.api.core.CqlSessionBuilder) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) QueryBuilder.selectFrom(com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom) InetSocketAddress(java.net.InetSocketAddress) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Slf4j(lombok.extern.slf4j.Slf4j) CompletionStage(java.util.concurrent.CompletionStage) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) PlainTextAuthProvider(com.datastax.oss.driver.internal.core.auth.PlainTextAuthProvider) Node(com.datastax.oss.driver.api.core.metadata.Node) DseGssApiAuthProvider(com.datastax.dse.driver.internal.core.auth.DseGssApiAuthProvider) java.util(java.util) Getter(lombok.Getter) Function(java.util.function.Function) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) AUTH_PROVIDER_SASL_PROPERTIES(com.datastax.dse.driver.api.core.config.DseDriverOption.AUTH_PROVIDER_SASL_PROPERTIES) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) CqlSession(com.datastax.oss.driver.api.core.CqlSession) ConfigFactory(com.typesafe.config.ConfigFactory) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) Row(com.datastax.oss.driver.api.core.cql.Row) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) NodeState(com.datastax.oss.driver.api.core.metadata.NodeState) Config(com.typesafe.config.Config) UnavailableException(com.datastax.oss.driver.api.core.servererrors.UnavailableException) ContactPointsValidator(com.datastax.oss.common.sink.config.ContactPointsValidator) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) DefaultDriverConfigLoader(com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader) DefaultProgrammaticDriverConfigLoaderBuilder(com.datastax.oss.driver.internal.core.config.typesafe.DefaultProgrammaticDriverConfigLoaderBuilder) ExecutionException(java.util.concurrent.ExecutionException) Tuple2(io.vavr.Tuple2) SchemaChangeListener(com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener) Tuple3(io.vavr.Tuple3) UUIDUtil.generateClientId(com.datastax.oss.common.sink.util.UUIDUtil.generateClientId) SslConfig(com.datastax.oss.common.sink.config.SslConfig) CqlSessionBuilder(com.datastax.oss.driver.api.core.CqlSessionBuilder) InetSocketAddress(java.net.InetSocketAddress) SessionBuilder(com.datastax.oss.common.sink.ssl.SessionBuilder) CqlSessionBuilder(com.datastax.oss.driver.api.core.CqlSessionBuilder) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) DefaultDriverConfigLoader(com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader) ProgrammaticDriverConfigLoaderBuilder(com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder) DefaultProgrammaticDriverConfigLoaderBuilder(com.datastax.oss.driver.internal.core.config.typesafe.DefaultProgrammaticDriverConfigLoaderBuilder) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Aggregations

SchemaChangeListener (com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener)6 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)5 CqlSession (com.datastax.oss.driver.api.core.CqlSession)5 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)5 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)2 DseDriverOption (com.datastax.dse.driver.api.core.config.DseDriverOption)1 AUTH_PROVIDER_SASL_PROPERTIES (com.datastax.dse.driver.api.core.config.DseDriverOption.AUTH_PROVIDER_SASL_PROPERTIES)1 AUTH_PROVIDER_SERVICE (com.datastax.dse.driver.api.core.config.DseDriverOption.AUTH_PROVIDER_SERVICE)1 DseGssApiAuthProvider (com.datastax.dse.driver.internal.core.auth.DseGssApiAuthProvider)1 AuthenticatorConfig (com.datastax.oss.common.sink.config.AuthenticatorConfig)1 ContactPointsValidator (com.datastax.oss.common.sink.config.ContactPointsValidator)1 SslConfig (com.datastax.oss.common.sink.config.SslConfig)1 SessionBuilder (com.datastax.oss.common.sink.ssl.SessionBuilder)1 UUIDUtil.generateClientId (com.datastax.oss.common.sink.util.UUIDUtil.generateClientId)1 ConsistencyLevel (com.datastax.oss.driver.api.core.ConsistencyLevel)1 CqlSessionBuilder (com.datastax.oss.driver.api.core.CqlSessionBuilder)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 OptionsMap (com.datastax.oss.driver.api.core.config.OptionsMap)1 ProgrammaticDriverConfigLoaderBuilder (com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder)1 TypedDriverOption (com.datastax.oss.driver.api.core.config.TypedDriverOption)1