Search in sources :

Example 11 with PostgresConnection

use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.

the class PostgresSchemaIT method shouldLoadSchemaForExtensionPostgresTypes.

@Test
public void shouldLoadSchemaForExtensionPostgresTypes() throws Exception {
    TestHelper.executeDDL("postgres_create_tables.ddl");
    PostgresConnectorConfig config = new PostgresConnectorConfig(TestHelper.defaultConfig().with(PostgresConnectorConfig.INCLUDE_UNKNOWN_DATATYPES, true).build());
    schema = new PostgresSchema(config, TestHelper.getTypeRegistry(), TopicSelector.create(config));
    try (PostgresConnection connection = TestHelper.create()) {
        schema.refresh(connection, false);
        assertTablesIncluded(TEST_TABLES);
        assertTableSchema("public.custom_table", "lt, i", Schema.OPTIONAL_BYTES_SCHEMA, Schema.OPTIONAL_BYTES_SCHEMA);
    }
}
Also used : PostgresConnection(io.debezium.connector.postgresql.connection.PostgresConnection) Test(org.junit.Test)

Example 12 with PostgresConnection

use of io.debezium.connector.postgresql.connection.PostgresConnection in project debezium by debezium.

the class PostgresConnector method validate.

@Override
public Config validate(Map<String, String> connectorConfigs) {
    PostgresConnectorConfig config = new PostgresConnectorConfig(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();
    // Get the config values for each of the connection-related fields ...
    ConfigValue hostnameValue = results.get(PostgresConnectorConfig.HOSTNAME.name());
    ConfigValue portValue = results.get(PostgresConnectorConfig.PORT.name());
    ConfigValue databaseValue = results.get(PostgresConnectorConfig.DATABASE_NAME.name());
    ConfigValue userValue = results.get(PostgresConnectorConfig.USER.name());
    ConfigValue passwordValue = results.get(PostgresConnectorConfig.PASSWORD.name());
    // If there are no errors on any of these ...
    if (hostnameValue.errorMessages().isEmpty() && portValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty() && databaseValue.errorMessages().isEmpty()) {
        // Try to connect to the database ...
        try (PostgresConnection connection = new PostgresConnection(config.jdbcConfig())) {
            try {
                connection.execute("SELECT version()");
                logger.info("Successfully tested connection for {} with user '{}'", connection.connectionString(), connection.username());
            } catch (SQLException e) {
                logger.info("Failed testing connection for {} with user '{}'", connection.connectionString(), connection.username());
                hostnameValue.addErrorMessage("Unable to connect: " + e.getMessage());
            }
        }
    }
    return new Config(new ArrayList<>(results.values()));
}
Also used : ConfigValue(org.apache.kafka.common.config.ConfigValue) SQLException(java.sql.SQLException) Config(org.apache.kafka.common.config.Config) PostgresConnection(io.debezium.connector.postgresql.connection.PostgresConnection)

Aggregations

PostgresConnection (io.debezium.connector.postgresql.connection.PostgresConnection)12 Test (org.junit.Test)5 SQLException (java.sql.SQLException)4 ReplicationConnection (io.debezium.connector.postgresql.connection.ReplicationConnection)2 TableSchema (io.debezium.relational.TableSchema)2 Connection (java.sql.Connection)2 ConnectException (org.apache.kafka.connect.errors.ConnectException)2 Table (io.debezium.relational.Table)1 TableId (io.debezium.relational.TableId)1 LoggingContext (io.debezium.util.LoggingContext)1 URL (java.net.URL)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Config (org.apache.kafka.common.config.Config)1 ConfigValue (org.apache.kafka.common.config.ConfigValue)1 SourceRecord (org.apache.kafka.connect.source.SourceRecord)1