-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add new source tidb * formate java code style and add item in SUMMARY.md * update doc * Update airbyte-integrations/connectors/source-tidb/src/main/resources/spec.json uptdate doc Co-authored-by: Xiang Zhang <angwerzx@126.com> * Update airbyte-integrations/connectors/source-tidb/README.md * Update docs/integrations/sources/tidb.md Co-authored-by: Xiang Zhang <angwerzx@126.com> * Update docs/integrations/sources/tidb.md Co-authored-by: Xiang Zhang <angwerzx@126.com> * add seed and doc changelog * run format * regenerate seed file Co-authored-by: Xiang Zhang <angwerzx@126.com> Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
- Loading branch information
1 parent
d415485
commit 5164e12
Showing
13 changed files
with
947 additions
and
1 deletion.
There are no files selected for viewing
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
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,21 @@ | ||
FROM airbyte/integration-base-java:dev AS build | ||
|
||
WORKDIR /airbyte | ||
|
||
ENV APPLICATION source-tidb | ||
|
||
COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar | ||
|
||
RUN tar xf ${APPLICATION}.tar --strip-components=1 && rm -rf ${APPLICATION}.tar | ||
|
||
FROM airbyte/integration-base-java:dev | ||
|
||
WORKDIR /airbyte | ||
|
||
ENV APPLICATION source-tidb | ||
|
||
COPY --from=build /airbyte /airbyte | ||
|
||
# Airbyte's build system uses these labels to know what to name and tag the docker images produced by this Dockerfile. | ||
LABEL io.airbyte.version=0.1.0 | ||
LABEL io.airbyte.name=airbyte/source-tidb |
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,69 @@ | ||
# Source Tidb | ||
|
||
This is the repository for the Tidb source connector in Java. | ||
For information about how to use this connector within Airbyte, see [the User Documentation](https://docs.airbyte.io/integrations/sources/tidb). | ||
|
||
## Local development | ||
|
||
#### Building via Gradle | ||
From the Airbyte repository root, run: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:source-tidb:build | ||
``` | ||
|
||
#### Create credentials | ||
**If you are a community contributor**, generate the necessary credentials and place them in `secrets/config.json` conforming to the spec file in `src/main/resources/spec.json`. | ||
Note that the `secrets` directory is git-ignored by default, so there is no danger of accidentally checking in sensitive information. | ||
|
||
**If you are an Airbyte core member**, follow the [instructions](https://docs.airbyte.io/connector-development#using-credentials-in-ci) to set up the credentials. | ||
|
||
### Locally running the connector docker image | ||
|
||
#### Build | ||
Build the connector image via Gradle: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:source-tidb:airbyteDocker | ||
``` | ||
When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in | ||
the Dockerfile. | ||
|
||
#### Run | ||
Then run any of the connector commands as follows: | ||
``` | ||
docker run --rm airbyte/source-tidb:dev spec | ||
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-tidb:dev check --config /secrets/config.json | ||
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-tidb:dev discover --config /secrets/config.json | ||
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-tidb:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json | ||
``` | ||
|
||
## Testing | ||
We use `JUnit` for Java tests. | ||
|
||
### Unit and Integration Tests | ||
Place unit tests under `src/test/...` | ||
Place integration tests in `src/test-integration/...` | ||
|
||
#### Acceptance Tests | ||
Airbyte has a standard test suite that all source connectors must pass. Implement the `TODO`s in | ||
`src/test-integration/java/io/airbyte/integrations/sources/TiDBSourceAcceptanceTest.java`. | ||
|
||
### Using gradle to run tests | ||
All commands should be run from airbyte project root. | ||
To run unit tests: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:source-tidb:unitTest | ||
``` | ||
To run acceptance and custom integration tests: | ||
``` | ||
./gradlew :airbyte-integrations:connectors:source-tidb:integrationTest | ||
``` | ||
|
||
## Dependency Management | ||
|
||
### Publishing a new version of the connector | ||
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what? | ||
1. Make sure your changes are passing unit and integration tests. | ||
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)). | ||
1. Create a Pull Request. | ||
1. Pat yourself on the back for being an awesome contributor. | ||
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master. |
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,36 @@ | ||
plugins { | ||
id 'application' | ||
id 'airbyte-docker' | ||
id 'airbyte-integration-test-java' | ||
} | ||
|
||
application { | ||
mainClass = 'io.airbyte.integrations.source.tidb.TiDBSource' | ||
applicationDefaultJvmArgs = ['-XX:+ExitOnOutOfMemoryError', '-XX:MaxRAMPercentage=75.0'] | ||
} | ||
|
||
dependencies { | ||
implementation project(':airbyte-db:lib') | ||
implementation project(':airbyte-integrations:bases:base-java') | ||
implementation project(':airbyte-protocol:models') | ||
implementation project(':airbyte-integrations:connectors:source-jdbc') | ||
implementation project(':airbyte-integrations:connectors:source-relational-db') | ||
|
||
//TODO Add jdbc driver import here. Ex: implementation 'com.microsoft.sqlserver:mssql-jdbc:8.4.1.jre14' | ||
implementation 'mysql:mysql-connector-java:8.0.22' | ||
|
||
// Add testcontainers and use GenericContainer for TiDB | ||
implementation "org.testcontainers:testcontainers:1.16.3" | ||
|
||
testImplementation testFixtures(project(':airbyte-integrations:connectors:source-jdbc')) | ||
|
||
testImplementation 'org.apache.commons:commons-lang3:3.11' | ||
|
||
integrationTestJavaImplementation project(':airbyte-integrations:connectors:source-tidb') | ||
integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-source-test') | ||
|
||
integrationTestJavaImplementation "org.testcontainers:testcontainers:1.16.3" | ||
|
||
implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs) | ||
integrationTestJavaImplementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs) | ||
} |
83 changes: 83 additions & 0 deletions
83
.../connectors/source-tidb/src/main/java/io/airbyte/integrations/source/tidb/TiDBSource.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,83 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.tidb; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.mysql.cj.MysqlType; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.db.jdbc.NoOpJdbcStreamingQueryConfiguration; | ||
import io.airbyte.integrations.base.IntegrationRunner; | ||
import io.airbyte.integrations.base.Source; | ||
import io.airbyte.integrations.base.ssh.SshWrappedSource; | ||
import io.airbyte.integrations.source.jdbc.AbstractJdbcSource; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TiDBSource extends AbstractJdbcSource<MysqlType> implements Source { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TiDBSource.class); | ||
|
||
static final String DRIVER_CLASS = "com.mysql.cj.jdbc.Driver"; | ||
public static final List<String> SSL_PARAMETERS = List.of( | ||
"useSSL=true", | ||
"requireSSL=true", | ||
"verifyServerCertificate=false"); | ||
|
||
public static Source sshWrappedSource() { | ||
return new SshWrappedSource(new TiDBSource(), List.of("host"), List.of("port")); | ||
} | ||
|
||
public TiDBSource() { | ||
super(DRIVER_CLASS, new NoOpJdbcStreamingQueryConfiguration(), new TiDBSourceOperations()); | ||
} | ||
|
||
@Override | ||
public JsonNode toDatabaseConfig(final JsonNode config) { | ||
final StringBuilder jdbcUrl = new StringBuilder(String.format("jdbc:mysql://%s:%s/%s", | ||
config.get("host").asText(), | ||
config.get("port").asText(), | ||
config.get("database").asText())); | ||
|
||
if (config.get("jdbc_url_params") != null | ||
&& !config.get("jdbc_url_params").asText().isEmpty()) { | ||
jdbcUrl.append("&").append(config.get("jdbc_url_params").asText()); | ||
} | ||
|
||
// only if config ssl and ssl == true, use ssl to connect db | ||
if (config.has("ssl") && config.get("ssl").asBoolean()) { | ||
jdbcUrl.append("&").append(String.join("&", SSL_PARAMETERS)); | ||
} | ||
|
||
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> getExcludedInternalNameSpaces() { | ||
return Set.of( | ||
"information_schema", | ||
"metrics_schema", | ||
"performance_schema", | ||
"mysql"); | ||
} | ||
|
||
public static void main(final String[] args) throws Exception { | ||
final Source source = TiDBSource.sshWrappedSource(); | ||
LOGGER.info("starting source: {}", TiDBSource.class); | ||
new IntegrationRunner(source).run(args); | ||
LOGGER.info("completed source: {}", TiDBSource.class); | ||
} | ||
|
||
} |
Oops, something went wrong.