-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix
- Loading branch information
Showing
12 changed files
with
274 additions
and
343 deletions.
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
39 changes: 0 additions & 39 deletions
39
...singwave-sink-es-7/src/main/java/com/risingwave/connector/BulkRequestConsumerFactory.java
This file was deleted.
Oops, something went wrong.
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
73 changes: 73 additions & 0 deletions
73
...e-sink-es-7/src/main/java/com/risingwave/connector/ElasticRestHighLevelClientAdapter.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,73 @@ | ||
package com.risingwave.connector; | ||
|
||
import java.io.IOException; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.auth.AuthScope; | ||
import org.apache.http.auth.UsernamePasswordCredentials; | ||
import org.apache.http.client.CredentialsProvider; | ||
import org.apache.http.impl.client.BasicCredentialsProvider; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.bulk.BulkRequest; | ||
import org.elasticsearch.action.bulk.BulkResponse; | ||
import org.elasticsearch.action.search.SearchRequest; | ||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.client.Cancellable; | ||
import org.elasticsearch.client.RequestOptions; | ||
import org.elasticsearch.client.RestClient; | ||
import org.elasticsearch.client.RestClientBuilder; | ||
import org.elasticsearch.client.RestHighLevelClient; | ||
import org.elasticsearch.client.RestHighLevelClientBuilder; | ||
|
||
public class ElasticRestHighLevelClientAdapter implements RestHighLevelClientAdapter { | ||
RestHighLevelClient esClient; | ||
|
||
private static RestClientBuilder configureRestClientBuilder( | ||
RestClientBuilder builder, EsSinkConfig config) { | ||
// Possible config: | ||
// 1. Connection path prefix | ||
// 2. Username and password | ||
if (config.getPassword() != null && config.getUsername() != null) { | ||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); | ||
credentialsProvider.setCredentials( | ||
AuthScope.ANY, | ||
new UsernamePasswordCredentials(config.getUsername(), config.getPassword())); | ||
builder.setHttpClientConfigCallback( | ||
httpClientBuilder -> | ||
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); | ||
} | ||
// 3. Timeout | ||
return builder; | ||
} | ||
|
||
public ElasticRestHighLevelClientAdapter(HttpHost host, EsSinkConfig config) { | ||
this.esClient = | ||
new RestHighLevelClientBuilder( | ||
configureRestClientBuilder(RestClient.builder(host), config) | ||
.build()) | ||
.setApiCompatibilityMode(true) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
esClient.close(); | ||
} | ||
|
||
public boolean ping(RequestOptions options) throws IOException { | ||
boolean flag = esClient.ping(options); | ||
return flag; | ||
} | ||
|
||
public Cancellable bulkAsync( | ||
BulkRequest bulkRequest, | ||
RequestOptions options, | ||
ActionListener<BulkResponse> listener) { | ||
Cancellable cancellable = esClient.bulkAsync(bulkRequest, options, listener); | ||
return cancellable; | ||
} | ||
|
||
public SearchResponse search(SearchRequest searchRequest, RequestOptions options) | ||
throws IOException { | ||
return this.esClient.search(searchRequest, options); | ||
} | ||
} |
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
Oops, something went wrong.