Search in sources :

Example 31 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class MySqlConnectorIT method shouldFailToValidateInvalidConfiguration.

@Test
public void shouldFailToValidateInvalidConfiguration() {
    Configuration config = Configuration.create().with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class).with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH).build();
    MySqlConnector connector = new MySqlConnector();
    Config result = connector.validate(config.asMap());
    assertConfigurationErrors(result, MySqlConnectorConfig.HOSTNAME, 1);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.PORT);
    assertConfigurationErrors(result, MySqlConnectorConfig.USER, 1);
    assertConfigurationErrors(result, MySqlConnectorConfig.PASSWORD, 1);
    assertConfigurationErrors(result, MySqlConnectorConfig.SERVER_NAME, 2);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SERVER_ID);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TABLES_IGNORE_BUILTIN);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DATABASE_WHITELIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DATABASE_BLACKLIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TABLE_WHITELIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TABLE_BLACKLIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.COLUMN_BLACKLIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.CONNECTION_TIMEOUT_MS);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.KEEP_ALIVE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.KEEP_ALIVE_INTERVAL_MS);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.MAX_QUEUE_SIZE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.MAX_BATCH_SIZE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.POLL_INTERVAL_MS);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DATABASE_HISTORY);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SNAPSHOT_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SNAPSHOT_LOCKING_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_KEYSTORE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_KEYSTORE_PASSWORD);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_TRUSTSTORE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_TRUSTSTORE_PASSWORD);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DECIMAL_HANDLING_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TIME_PRECISION_MODE);
    assertConfigurationErrors(result, KafkaDatabaseHistory.BOOTSTRAP_SERVERS);
    assertConfigurationErrors(result, KafkaDatabaseHistory.TOPIC);
    assertNoConfigurationErrors(result, KafkaDatabaseHistory.RECOVERY_POLL_ATTEMPTS);
    assertNoConfigurationErrors(result, KafkaDatabaseHistory.RECOVERY_POLL_INTERVAL_MS);
}
Also used : Configuration(io.debezium.config.Configuration) Config(org.apache.kafka.common.config.Config) CommonConnectorConfig(io.debezium.config.CommonConnectorConfig) Test(org.junit.Test) AbstractConnectorTest(io.debezium.embedded.AbstractConnectorTest)

Example 32 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class MySqlConnectorIT method shouldValidateLockingModeWithOutMinimalLocksEnabledConfiguration.

/**
 * Validates that if you use the deprecated snapshot.minimal.locking configuration value is set to false
 * and its replacement snapshot.locking.mode is not explicitly defined, configuration validates as acceptable.
 */
@Test
@FixFor("DBZ-602")
public void shouldValidateLockingModeWithOutMinimalLocksEnabledConfiguration() {
    Configuration config = DATABASE.defaultJdbcConfigBuilder().with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.DISABLED).with(MySqlConnectorConfig.SERVER_ID, 18765).with(MySqlConnectorConfig.SERVER_NAME, "myServer").with(KafkaDatabaseHistory.BOOTSTRAP_SERVERS, "some.host.com").with(KafkaDatabaseHistory.TOPIC, "my.db.history.topic").with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true).with(MySqlConnectorConfig.SNAPSHOT_MINIMAL_LOCKING, false).build();
    MySqlConnector connector = new MySqlConnector();
    Config result = connector.validate(config.asMap());
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SNAPSHOT_LOCKING_MODE);
    assertThat(new MySqlConnectorConfig(config).getSnapshotLockingMode()).isEqualTo(SnapshotLockingMode.EXTENDED);
}
Also used : Configuration(io.debezium.config.Configuration) Config(org.apache.kafka.common.config.Config) CommonConnectorConfig(io.debezium.config.CommonConnectorConfig) Test(org.junit.Test) AbstractConnectorTest(io.debezium.embedded.AbstractConnectorTest) FixFor(io.debezium.doc.FixFor)

Example 33 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class MySqlConnectorIT method shouldValidateValidConfigurationWithSSL.

@Test
public void shouldValidateValidConfigurationWithSSL() {
    Configuration config = DATABASE.defaultJdbcConfigBuilder().with(MySqlConnectorConfig.SSL_MODE, SecureConnectionMode.REQUIRED).with(MySqlConnectorConfig.SSL_KEYSTORE, "/some/path/to/keystore").with(MySqlConnectorConfig.SSL_KEYSTORE_PASSWORD, "keystore1234").with(MySqlConnectorConfig.SSL_TRUSTSTORE, "/some/path/to/truststore").with(MySqlConnectorConfig.SSL_TRUSTSTORE_PASSWORD, "truststore1234").with(MySqlConnectorConfig.SERVER_ID, 18765).with(MySqlConnectorConfig.SERVER_NAME, "myServer").with(KafkaDatabaseHistory.BOOTSTRAP_SERVERS, "some.host.com").with(KafkaDatabaseHistory.TOPIC, "my.db.history.topic").with(MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES, true).build();
    MySqlConnector connector = new MySqlConnector();
    Config result = connector.validate(config.asMap());
    // Can't connect to MySQL using SSL on a container using the 'mysql/mysql-server' image maintained by MySQL team,
    // but can actually connect to MySQL using SSL on a container using the 'mysql' image maintained by Docker, Inc.
    assertConfigurationErrors(result, MySqlConnectorConfig.HOSTNAME, 0, 1);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.PORT);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.USER);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.PASSWORD);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SERVER_NAME);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SERVER_ID);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TABLES_IGNORE_BUILTIN);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DATABASE_WHITELIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DATABASE_BLACKLIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TABLE_WHITELIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TABLE_BLACKLIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.COLUMN_BLACKLIST);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.CONNECTION_TIMEOUT_MS);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.KEEP_ALIVE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.KEEP_ALIVE_INTERVAL_MS);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.MAX_QUEUE_SIZE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.MAX_BATCH_SIZE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.POLL_INTERVAL_MS);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DATABASE_HISTORY);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.INCLUDE_SCHEMA_CHANGES);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SNAPSHOT_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SNAPSHOT_LOCKING_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_KEYSTORE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_KEYSTORE_PASSWORD);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_TRUSTSTORE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.SSL_TRUSTSTORE_PASSWORD);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.DECIMAL_HANDLING_MODE);
    assertNoConfigurationErrors(result, MySqlConnectorConfig.TIME_PRECISION_MODE);
    assertNoConfigurationErrors(result, KafkaDatabaseHistory.BOOTSTRAP_SERVERS);
    assertNoConfigurationErrors(result, KafkaDatabaseHistory.TOPIC);
    assertNoConfigurationErrors(result, KafkaDatabaseHistory.RECOVERY_POLL_ATTEMPTS);
    assertNoConfigurationErrors(result, KafkaDatabaseHistory.RECOVERY_POLL_INTERVAL_MS);
}
Also used : Configuration(io.debezium.config.Configuration) Config(org.apache.kafka.common.config.Config) CommonConnectorConfig(io.debezium.config.CommonConnectorConfig) Test(org.junit.Test) AbstractConnectorTest(io.debezium.embedded.AbstractConnectorTest)

Example 34 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class MongoDbConnector method start.

@Override
public void start(Map<String, String> props) {
    // Validate the configuration ...
    final Configuration config = Configuration.from(props);
    if (!config.validateAndRecord(MongoDbConnectorConfig.ALL_FIELDS, logger::error)) {
        throw new ConnectException("Error configuring an instance of " + getClass().getSimpleName() + "; check the logs for details");
    }
    this.config = config;
    // Set up the replication context ...
    taskContext = new MongoDbTaskContext(config);
    this.connectionContext = taskContext.getConnectionContext();
    PreviousContext previousLogContext = taskContext.configureLoggingContext("conn");
    try {
        logger.info("Starting MongoDB connector and discovering replica set(s) at {}", connectionContext.hosts());
        // Set up and start the thread that monitors the members of all of the replica sets ...
        replicaSetMonitorExecutor = Threads.newSingleThreadExecutor(MongoDbConnector.class, taskContext.serverName(), "replica-set-monitor");
        ReplicaSetDiscovery monitor = new ReplicaSetDiscovery(taskContext);
        monitorThread = new ReplicaSetMonitorThread(monitor::getReplicaSets, connectionContext.pollPeriodInSeconds(), TimeUnit.SECONDS, Clock.SYSTEM, () -> taskContext.configureLoggingContext("disc"), this::replicaSetsChanged);
        replicaSetMonitorExecutor.execute(monitorThread);
        logger.info("Successfully started MongoDB connector, and continuing to discover changes in replica sets", connectionContext.hosts());
    } finally {
        previousLogContext.restore();
    }
}
Also used : PreviousContext(io.debezium.util.LoggingContext.PreviousContext) Configuration(io.debezium.config.Configuration) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 35 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class MongoDbConnector method validate.

@Override
public Config validate(Map<String, String> connectorConfigs) {
    Configuration config = Configuration.from(connectorConfigs);
    // First, validate all of the individual fields, which is easy since don't make any of the fields invisible ...
    Map<String, ConfigValue> results = config.validate(MongoDbConnectorConfig.EXPOSED_FIELDS);
    // Get the config values for each of the connection-related fields ...
    ConfigValue hostsValue = results.get(MongoDbConnectorConfig.HOSTS.name());
    ConfigValue userValue = results.get(MongoDbConnectorConfig.USER.name());
    ConfigValue passwordValue = results.get(MongoDbConnectorConfig.PASSWORD.name());
    // If there are no errors on any of these ...
    if (hostsValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty()) {
        // Try to connect to the database ...
        try (ConnectionContext connContext = new ConnectionContext(config)) {
            try (MongoClient client = connContext.clientFor(connContext.hosts())) {
                client.listDatabaseNames();
            }
        } catch (MongoException e) {
            hostsValue.addErrorMessage("Unable to connect: " + e.getMessage());
        }
    }
    return new Config(new ArrayList<>(results.values()));
}
Also used : MongoClient(com.mongodb.MongoClient) ConfigValue(org.apache.kafka.common.config.ConfigValue) MongoException(com.mongodb.MongoException) Configuration(io.debezium.config.Configuration) Config(org.apache.kafka.common.config.Config)

Aggregations

Configuration (io.debezium.config.Configuration)38 Test (org.junit.Test)21 AbstractConnectorTest (io.debezium.embedded.AbstractConnectorTest)16 Config (org.apache.kafka.common.config.Config)15 CommonConnectorConfig (io.debezium.config.CommonConnectorConfig)10 FixFor (io.debezium.doc.FixFor)6 ConnectException (org.apache.kafka.connect.errors.ConnectException)6 ConfigValue (org.apache.kafka.common.config.ConfigValue)5 HashMap (java.util.HashMap)4 JsonConverter (org.apache.kafka.connect.json.JsonConverter)4 SQLException (java.sql.SQLException)3 Map (java.util.Map)3 Field (io.debezium.config.Field)2 SchemaUtil (io.debezium.data.SchemaUtil)2 VerifyRecord (io.debezium.data.VerifyRecord)2 CompletionCallback (io.debezium.embedded.EmbeddedEngine.CompletionCallback)2 EmbeddedConfig (io.debezium.embedded.EmbeddedEngine.EmbeddedConfig)2 JdbcConnection (io.debezium.jdbc.JdbcConnection)2 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2