-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
馃帀 Source Cockroachdb: Added new source for Cockroachdb (#4382)
* [1705] Added cockroachdb source connector
- Loading branch information
Showing
20 changed files
with
1,870 additions
and
10 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...ain/resources/config/STANDARD_SOURCE_DEFINITION/9fa5862c-da7c-11eb-8d19-0242ac130003.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
airbyte-integrations/connectors/source-cockroachdb/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
airbyte-integrations/connectors/source-cockroachdb/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} |
110 changes: 110 additions & 0 deletions
110
...ckroachdb/src/main/java/io/airbyte/integrations/source/cockroachdb/CockroachDbSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
airbyte-integrations/connectors/source-cockroachdb/src/main/resources/spec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.