Search in sources :

Example 21 with Configuration

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

the class MySqlConnector 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(MySqlConnectorConfig.EXPOSED_FIELDS);
    // Get the config values for each of the connection-related fields ...
    ConfigValue hostnameValue = results.get(MySqlConnectorConfig.HOSTNAME.name());
    ConfigValue portValue = results.get(MySqlConnectorConfig.PORT.name());
    ConfigValue userValue = results.get(MySqlConnectorConfig.USER.name());
    ConfigValue passwordValue = results.get(MySqlConnectorConfig.PASSWORD.name());
    // If there are no errors on any of these ...
    if (hostnameValue.errorMessages().isEmpty() && portValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty()) {
        // Try to connect to the database ...
        try (MySqlJdbcContext jdbcContext = new MySqlJdbcContext(config)) {
            jdbcContext.start();
            JdbcConnection mysql = jdbcContext.jdbc();
            try {
                mysql.execute("SELECT version()");
                logger.info("Successfully tested connection for {} with user '{}'", jdbcContext.connectionString(), mysql.username());
            } catch (SQLException e) {
                logger.info("Failed testing connection for {} with user '{}'", jdbcContext.connectionString(), mysql.username());
                hostnameValue.addErrorMessage("Unable to connect: " + e.getMessage());
            } finally {
                jdbcContext.shutdown();
            }
        }
    }
    return new Config(new ArrayList<>(results.values()));
}
Also used : ConfigValue(org.apache.kafka.common.config.ConfigValue) Configuration(io.debezium.config.Configuration) SQLException(java.sql.SQLException) Config(org.apache.kafka.common.config.Config) JdbcConnection(io.debezium.jdbc.JdbcConnection)

Example 22 with Configuration

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

the class DebeziumIOTest method testSourceMySqlConnectorValidConfiguration.

@Test
public void testSourceMySqlConnectorValidConfiguration() {
    Map<String, String> configurationMap = MYSQL_CONNECTOR_CONFIGURATION.getConfigurationMap();
    Configuration debeziumConf = Configuration.from(configurationMap);
    Map<String, ConfigValue> validConfig = debeziumConf.validate(MySqlConnectorConfig.ALL_FIELDS);
    for (ConfigValue configValue : validConfig.values()) {
        assertTrue(configValue.errorMessages().isEmpty());
    }
}
Also used : ConfigValue(org.apache.kafka.common.config.ConfigValue) ConnectorConfiguration(org.apache.beam.io.debezium.DebeziumIO.ConnectorConfiguration) Configuration(io.debezium.config.Configuration) Test(org.junit.Test)

Example 23 with Configuration

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

the class DebeziumIOTest method testSourceConnectorUsernamePassword.

@Test
public void testSourceConnectorUsernamePassword() {
    String username = "debezium";
    String password = "dbz";
    ConnectorConfiguration configuration = MYSQL_CONNECTOR_CONFIGURATION.withUsername(username).withPassword(password);
    Map<String, String> configurationMap = configuration.getConfigurationMap();
    Configuration debeziumConf = Configuration.from(configurationMap);
    Map<String, ConfigValue> validConfig = debeziumConf.validate(MySqlConnectorConfig.ALL_FIELDS);
    for (ConfigValue configValue : validConfig.values()) {
        assertTrue(configValue.errorMessages().isEmpty());
    }
}
Also used : ConfigValue(org.apache.kafka.common.config.ConfigValue) ConnectorConfiguration(org.apache.beam.io.debezium.DebeziumIO.ConnectorConfiguration) Configuration(io.debezium.config.Configuration) ConnectorConfiguration(org.apache.beam.io.debezium.DebeziumIO.ConnectorConfiguration) Test(org.junit.Test)

Example 24 with Configuration

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

the class PostgresConnectorIT method shouldSupportSSLParameters.

@Test
public void shouldSupportSSLParameters() throws Exception {
    // the default docker image we're testing against doesn't use SSL, so check that the connector fails to start when
    // SSL is enabled
    Configuration config = TestHelper.defaultConfig().with(PostgresConnectorConfig.SSL_MODE, PostgresConnectorConfig.SecureConnectionMode.REQUIRED).build();
    start(PostgresConnector.class, config, (success, msg, error) -> {
        if (TestHelper.shouldSSLConnectionFail()) {
            // we expect the task to fail at startup when we're printing the server info
            assertThat(success).isFalse();
            assertThat(error).isInstanceOf(ConnectException.class);
            Throwable cause = error.getCause();
            assertThat(cause).isInstanceOf(SQLException.class);
            assertThat(PSQLState.CONNECTION_REJECTED).isEqualTo(new PSQLState(((SQLException) cause).getSQLState()));
        }
    });
    if (TestHelper.shouldSSLConnectionFail()) {
        assertConnectorNotRunning();
    } else {
        assertConnectorIsRunning();
        Thread.sleep(10000);
        stopConnector();
    }
}
Also used : Configuration(io.debezium.config.Configuration) SQLException(java.sql.SQLException) PSQLState(org.postgresql.util.PSQLState) Test(org.junit.Test) AbstractConnectorTest(io.debezium.embedded.AbstractConnectorTest)

Example 25 with Configuration

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

the class PostgresConnectorIT method shouldValidateMinimalConfiguration.

@Test
public void shouldValidateMinimalConfiguration() throws Exception {
    Configuration config = TestHelper.defaultConfig().build();
    Config validateConfig = new PostgresConnector().validate(config.asMap());
    validateConfig.configValues().forEach(configValue -> assertTrue("Unexpected error for: " + configValue.name(), configValue.errorMessages().isEmpty()));
}
Also used : Configuration(io.debezium.config.Configuration) Config(org.apache.kafka.common.config.Config) Test(org.junit.Test) AbstractConnectorTest(io.debezium.embedded.AbstractConnectorTest)

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