Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marcos/test pr 27182 #28788

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0859611
init opensearch destination
a1tair6 Feb 7, 2023
4d2ab6a
add destination opensearch first commit
a1tair6 Feb 14, 2023
a6bdde7
add opensearch lib
a1tair6 Feb 14, 2023
296cb2a
fix destination opensearch
a1tair6 Feb 16, 2023
0e8db9c
add opensearch testcontainer
a1tair6 Feb 17, 2023
9efaa98
add opensearch
a1tair6 Feb 22, 2023
77879b3
revert
jay-choe Feb 18, 2023
d2c90ac
fix test failure
jay-choe Feb 27, 2023
af6d11d
fix opensearch container version, remove log
jay-choe Feb 28, 2023
1b33c6e
fix readme unittest
jay-choe Feb 28, 2023
f91766b
fix opensearch readme
jay-choe Feb 28, 2023
8c1eb74
revert
p-eye Feb 18, 2023
c6246ca
remove bin directory and source-opensearch connector
a1tair6 Mar 2, 2023
f0966b0
fix error
a1tair6 Mar 2, 2023
ac68b5b
init opensearch source
p-eye Feb 24, 2023
493663e
fix opensearch naming
a1tair6 Apr 6, 2023
f264e09
fix opensearch naming
p-eye Apr 20, 2023
26693dc
fix opensearch field type
p-eye Apr 20, 2023
b2c6d28
add opensearch lib
p-eye Apr 20, 2023
5fea6b6
feat opensearch connector
jay-choe May 2, 2023
2d0d8cc
add testcontainer opensearch lib, fix build.gradle
a1tair6 May 2, 2023
1ae840e
typo
a1tair6 May 2, 2023
7b3cf28
add more type
jay-choe May 2, 2023
6015d24
fix test example json
jay-choe May 2, 2023
53ad6fd
fix source tests
jay-choe May 8, 2023
0f1975e
remove todo comment
jay-choe May 9, 2023
2b11c82
delete destination opensearch
a1tair6 Jun 27, 2023
a306814
add-source-opensearch-readme
a1tair6 Jun 27, 2023
45a8b0a
delete destination opensearch readme
a1tair6 Jun 27, 2023
99002f5
fix-source-readme-integrationtest
a1tair6 Jun 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions airbyte-integrations/connectors/source-opensearch/Dockerfile
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-opensearch

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-opensearch
ENV ENABLE_SENTRY true

COPY --from=build /airbyte /airbyte

LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.name=airbyte/source-opensearch
69 changes: 69 additions & 0 deletions airbyte-integrations/connectors/source-opensearch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Source OpenSearch

This is the repository for the OpenSearch source connector in Java.
For information about how to use this connector within Airbyte, see [the User Documentation](https://docs.airbyte.com/integrations/sources/opensearch).

## Local development

#### Building via Gradle
From the Airbyte repository root, run:
```
./gradlew :airbyte-integrations:connectors:source-opensearch: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.com/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-opensearch: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-opensearch:dev spec
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-opensearch:dev check --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-opensearch:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-opensearch: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/opensearchSourceAcceptanceTest.java`.

### Using gradle to run tests
All commands should be run from airbyte project root.
To run unit tests:
```
./gradlew :airbyte-integrations:connectors:source-opensearch:unitTest
```
To run acceptance and custom integration tests:
```
./gradlew :airbyte-integrations:connectors:source-opensearch:integrationTestJava
```

## 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference)
# for more information about how to configure these tests
connector_image: airbyte/source-opensearch:dev
tests:
spec:
- spec_path: "src/test-integration/resources/expected_spec.json"
config_path: "src/test-integration/resources/dummy_config.json"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# Build latest connector image
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-)

# Pull latest acctest image
docker pull airbyte/connector-acceptance-test:latest

# Run
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp:/tmp \
-v $(pwd):/test_input \
airbyte/connector-acceptance-test \
--acceptance-test-config /test_input

43 changes: 43 additions & 0 deletions airbyte-integrations/connectors/source-opensearch/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
id 'application'
id 'airbyte-docker'
id 'airbyte-integration-test-java'
id 'airbyte-connector-acceptance-test'
}

application {
mainClass = 'io.airbyte.integrations.source.opensearch.OpenSearchSource'
applicationDefaultJvmArgs = ['-XX:+ExitOnOutOfMemoryError', '-XX:MaxRAMPercentage=75.0']
}

dependencies {
implementation project(':airbyte-config:config-models')
implementation libs.airbyte.protocol
implementation project(':airbyte-integrations:bases:base-java')
implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)

implementation 'org.opensearch.client:opensearch-rest-client: 2.5.0'
implementation 'org.opensearch.client:opensearch-java:2.0.0'
implementation 'org.opensearch.client:opensearch-rest-high-level-client:2.5.0'

implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'

// EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// https://eclipse-ee4j.github.io/jsonp/
implementation 'jakarta.json:jakarta.json-api:2.0.1'

// Needed even if using Jackson to have an implementation of the Jsonp object model
// EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// https://github.com/eclipse-ee4j/jsonp
implementation 'org.glassfish:jakarta.json:2.0.1'

// MIT
// https://www.testcontainers.org/
testImplementation libs.connectors.testcontainers
testImplementation libs.connectors.testcontainers.opensearch
integrationTestJavaImplementation libs.connectors.testcontainers.opensearch

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright (c) 2023 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.integrations.source.opensearch;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Objects;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ConnectorConfiguration {

private String endpoint;
private boolean upsert;
private AuthenticationMethod authenticationMethod = new AuthenticationMethod();

public ConnectorConfiguration() {}

public static ConnectorConfiguration fromJsonNode(JsonNode config) {
return new ObjectMapper().convertValue(config, ConnectorConfiguration.class);
}

public String getEndpoint() {
return this.endpoint;
}

public boolean isUpsert() {
return this.upsert;
}

public AuthenticationMethod getAuthenticationMethod() {
return this.authenticationMethod;
}

public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}

public void setUpsert(boolean upsert) {
this.upsert = upsert;
}

public void setAuthenticationMethod(AuthenticationMethod authenticationMethod) {
this.authenticationMethod = authenticationMethod;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ConnectorConfiguration that = (ConnectorConfiguration) o;
return upsert == that.upsert && Objects.equals(endpoint, that.endpoint) && Objects.equals(authenticationMethod, that.authenticationMethod);
}

@Override
public int hashCode() {
return Objects.hash(endpoint, upsert, authenticationMethod);
}

@Override
public String toString() {
return "ConnectorConfiguration{" +
"endpoint='" + endpoint + '\'' +
", upsert=" + upsert +
", authenticationMethod=" + authenticationMethod +
'}';
}

static class AuthenticationMethod {

private OpenSearchAuthenticationMethod method = OpenSearchAuthenticationMethod.none;
private String username;
private String password;
private String apiKeyId;
private String apiKeySecret;

public OpenSearchAuthenticationMethod getMethod() {
return this.method;
}

public String getUsername() {
return this.username;
}

public String getPassword() {
return this.password;
}

public String getApiKeyId() {
return this.apiKeyId;
}

public String getApiKeySecret() {
return this.apiKeySecret;
}

public void setMethod(OpenSearchAuthenticationMethod method) {
this.method = method;
}

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}

public void setApiKeyId(String apiKeyId) {
this.apiKeyId = apiKeyId;
}

public void setApiKeySecret(String apiKeySecret) {
this.apiKeySecret = apiKeySecret;
}

public boolean isValid() {
return switch (this.method) {
case none -> true;
case basic -> Objects.nonNull(this.username) && Objects.nonNull(this.password);
case secret -> Objects.nonNull(this.apiKeyId) && Objects.nonNull(this.apiKeySecret);
};
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
AuthenticationMethod that = (AuthenticationMethod) o;
return method == that.method &&
Objects.equals(username, that.username) &&
Objects.equals(password, that.password) &&
Objects.equals(apiKeyId, that.apiKeyId) &&
Objects.equals(apiKeySecret, that.apiKeySecret);
}

@Override
public int hashCode() {
return Objects.hash(method, username, password, apiKeyId, apiKeySecret);
}

@Override
public String toString() {
return "AuthenticationMethod{" +
"method=" + method +
", username='" + username + '\'' +
", apiKeyId='" + apiKeyId + '\'' +
'}';
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2023 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.integrations.source.opensearch;

public enum OpenSearchAuthenticationMethod {
none,
secret,
basic
}
Loading
Loading