Skip to content

Commit

Permalink
馃帀 Source Cockroachdb: Added new source for Cockroachdb (#4382)
Browse files Browse the repository at this point in the history
* [1705] Added cockroachdb source connector
  • Loading branch information
etsybaev committed Jul 1, 2021
1 parent 53b02e0 commit 4399656
Show file tree
Hide file tree
Showing 20 changed files with 1,870 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sourceDefinitionId": "9fa5862c-da7c-11eb-8d19-0242ac130003",
"name": "Cockroachdb",
"dockerRepository": "airbyte/source-postgres",
"dockerImageTag": "0.1.1",
"documentationUrl": "https://hub.docker.com/r/airbyte/source-cockroachdb"
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
dockerImageTag: 0.3.4
documentationUrl: https://hub.docker.com/r/airbyte/source-postgres
icon: postgresql.svg
- sourceDefinitionId: 9fa5862c-da7c-11eb-8d19-0242ac130003
name: Cockroachdb
dockerRepository: airbyte/source-postgres
dockerImageTag: 0.1.1
documentationUrl: https://hub.docker.com/r/airbyte/source-cockroachdb
- sourceDefinitionId: af6d50ee-dddf-4126-a8ee-7faee990774f
name: PostHog
dockerRepository: airbyte/source-posthog
Expand Down
2 changes: 2 additions & 0 deletions airbyte-integrations/builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
Plaid [![source-plaid](https://img.shields.io/endpoint?url=https%3A%2F%2Fstatus-api.airbyte.io%2Ftests%2Fsummary%2Fsource-plaid%2Fbadge.json)](https://status-api.airbyte.io/tests/summary/source-plaid)

Postgres [![source-postgres](https://img.shields.io/endpoint?url=https%3A%2F%2Fstatus-api.airbyte.io%2Ftests%2Fsummary%2Fsource-postgres%2Fbadge.json)](https://status-api.airbyte.io/tests/summary/source-postgres)

CockroachDb [![source-cockroachdb](https://img.shields.io/endpoint?url=https%3A%2F%2Fstatus-api.airbyte.io%2Ftests%2Fsummary%2Fsource-cockroachdb%2Fbadge.json)](https://status-api.airbyte.io/tests/summary/source-cockroachdb)

Quickbooks [![source-quickbooks-singer](https://img.shields.io/endpoint?url=https%3A%2F%2Fstatus-api.airbyte.io%2Ftests%2Fsummary%2Fsource-quickbooks-singer%2Fbadge.json)](https://status-api.airbyte.io/tests/summary/source-quickbooks-singer)

Expand Down
12 changes: 12 additions & 0 deletions airbyte-integrations/connectors/source-cockroachdb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM airbyte/integration-base-java:dev

WORKDIR /airbyte

ENV APPLICATION source-cockroachdb

COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar

RUN tar xf ${APPLICATION}.tar --strip-components=1

LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.name=airbyte/source-cockroachdb
34 changes: 34 additions & 0 deletions airbyte-integrations/connectors/source-cockroachdb/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'application'
id 'airbyte-docker'
id 'airbyte-integration-test-java'
}

application {
mainClass = 'io.airbyte.integrations.source.cockroachdb.CockroachDbSource'
}

dependencies {
implementation project(':airbyte-db')
implementation project(':airbyte-integrations:bases:base-java')
implementation project(':airbyte-protocol:models')
implementation project(':airbyte-integrations:connectors:source-jdbc')

implementation 'org.apache.commons:commons-lang3:3.11'
implementation "org.postgresql:postgresql:42.2.18"

testImplementation testFixtures(project(':airbyte-integrations:connectors:source-jdbc'))

testImplementation "org.testcontainers:cockroachdb:1.15.3"
testImplementation 'org.apache.commons:commons-lang3:3.11'

integrationTestJavaImplementation project(':airbyte-integrations:connectors:source-cockroachdb')
integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-source-test')

implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)
integrationTestJavaImplementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)

testImplementation testFixtures(project(':airbyte-integrations:connectors:source-jdbc'))
testImplementation project(":airbyte-json-validation")
testImplementation project(':airbyte-test-utils')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* MIT License
*
* Copyright (c) 2020 Airbyte
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.airbyte.integrations.source.cockroachdb;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableMap;
import io.airbyte.commons.json.Jsons;
import io.airbyte.commons.util.AutoCloseableIterator;
import io.airbyte.db.jdbc.PostgresJdbcStreamingQueryConfiguration;
import io.airbyte.integrations.base.IntegrationRunner;
import io.airbyte.integrations.base.Source;
import io.airbyte.integrations.source.jdbc.AbstractJdbcSource;
import io.airbyte.protocol.models.AirbyteConnectionStatus;
import io.airbyte.protocol.models.AirbyteMessage;
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CockroachDbSource extends AbstractJdbcSource implements Source {

private static final Logger LOGGER = LoggerFactory.getLogger(CockroachDbSource.class);

static final String DRIVER_CLASS = "org.postgresql.Driver";

public CockroachDbSource() {
super(DRIVER_CLASS, new PostgresJdbcStreamingQueryConfiguration());
}

@Override
public JsonNode toJdbcConfig(JsonNode config) {

List<String> additionalParameters = new ArrayList<>();

final StringBuilder jdbcUrl = new StringBuilder(String.format("jdbc:postgresql://%s:%s/%s?",
config.get("host").asText(),
config.get("port").asText(),
config.get("database").asText()));

if (config.has("ssl") && config.get("ssl").asBoolean()) {
additionalParameters.add("ssl=true");
additionalParameters.add("sslmode=require");
}

additionalParameters.forEach(x -> jdbcUrl.append(x).append("&"));

final ImmutableMap.Builder<Object, Object> configBuilder = ImmutableMap.builder()
.put("username", config.get("username").asText())
.put("jdbc_url", jdbcUrl.toString());

if (config.has("password")) {
configBuilder.put("password", config.get("password").asText());
}

return Jsons.jsonNode(configBuilder.build());
}

@Override
public Set<String> getExcludedInternalSchemas() {
return Set
.of("information_schema", "pg_catalog", "pg_internal", "catalog_history", "pg_extension",
"crdb_internal");
}

@Override
public AutoCloseableIterator<AirbyteMessage> read(JsonNode config,
ConfiguredAirbyteCatalog catalog,
JsonNode state)
throws Exception {
final AirbyteConnectionStatus check = check(config);

if (check.getStatus().equals(AirbyteConnectionStatus.Status.FAILED)) {
throw new RuntimeException("Unable establish a connection: " + check.getMessage());
}

return super.read(config, catalog, state);
}

public static void main(String[] args) throws Exception {
final Source source = new CockroachDbSource();
LOGGER.info("starting source: {}", CockroachDbSource.class);
new IntegrationRunner(source).run(args);
LOGGER.info("completed source: {}", CockroachDbSource.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"documentationUrl": "https://docs.airbyte.io/integrations/sources/postgres",
"connectionSpecification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Cockroach Source Spec",
"type": "object",
"required": ["host", "port", "database", "username"],
"additionalProperties": false,
"properties": {
"host": {
"title": "Host",
"description": "Hostname of the database.",
"type": "string",
"order": 0
},
"port": {
"title": "Port",
"description": "Port of the database.",
"type": "integer",
"minimum": 0,
"maximum": 65536,
"default": 5432,
"examples": ["5432"],
"order": 1
},
"database": {
"title": "DB Name",
"description": "Name of the database.",
"type": "string",
"order": 2
},
"username": {
"title": "User",
"description": "Username to use to access the database.",
"type": "string",
"order": 3
},
"password": {
"title": "Password",
"description": "Password associated with the username.",
"type": "string",
"airbyte_secret": true,
"order": 4
},
"ssl": {
"title": "Connect using SSL",
"description": "Encrypt client/server communications for increased security.",
"type": "boolean",
"default": false,
"order": 5
}
}
}
}

0 comments on commit 4399656

Please sign in to comment.