Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public interface ElasticsearchWriteOptions extends PipelineOptions {

void setBatchSizeBytes(Long batchSizeBytes);

@Description("Elastic search socket timeout. Default: 30 minutes")
@Default.Integer(1800000)
Integer getMaxSocketTimeout();

void setMaxSocketTimeout(Integer maxSocketTimeout);

@Description("Optional: Max retry attempts, must be > 0, ex: 3. Default: no retries")
Integer getMaxRetryAttempts();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public PDone expand(PCollection<String> jsonStrings) {
options().getIndex(),
DOCUMENT_TYPE);

config = config.withSocketTimeout(options().getMaxSocketTimeout());
// If username and password are not blank, use them instead of ApiKey
if (StringUtils.isNotBlank(options().getElasticsearchUsername())
&& StringUtils.isNotBlank(options().getElasticsearchPassword())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.cloud.ServiceOptions;
import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse;
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
import com.google.cloud.secretmanager.v1.SecretVersionName;


/**
* Transforms for reading and writing data from/to Elasticsearch.
*
Expand Down Expand Up @@ -469,8 +475,20 @@ RestClient createClient() throws IOException {
httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
}
if (getApiKey() != null) {
SecretManagerServiceClient client = SecretManagerServiceClient.create();
String projectId = ServiceOptions.getDefaultProjectId();
String secretId = getApiKey();
String versionId = "latest";
SecretVersionName secretVersionName = SecretVersionName.of(projectId, secretId, versionId);

AccessSecretVersionResponse response = client.accessSecretVersion(secretVersionName);
String plainTextSecret = response.getPayload().getData().toStringUtf8();
URL url = new URL(plainTextSecret);
String userInfo = url.getUserInfo();

String[] userInfoArray = userInfo.split(":");
restClientBuilder.setDefaultHeaders(
new Header[] {new BasicHeader("Authorization", "ApiKey " + getApiKey())});
new Header[] {new BasicHeader("Authorization", "ApiKey " + userInfoArray[1])});
}
if (getBearerToken() != null) {
restClientBuilder.setDefaultHeaders(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mainClass": "com.google.cloud.teleport.v2.elasticsearch.templates.BigQueryToElasticsearch",
"classPath": "/template/googlecloud-to-elasticsearch/*:/template/googlecloud-to-elasticsearch/libs/*:/template/googlecloud-to-elasticsearch/classes",
"defaultParameterValues": {
"labels": "{\"goog-dataflow-provided-template-type\":\"flex\", \"goog-dataflow-provided-template-name\":\"bigquery_to_elasticsearch\"}"
}
}
4 changes: 2 additions & 2 deletions v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- <dependency>
<groupId>com.google.cloud.teleport</groupId>
<artifactId>integration-testing-lib</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependency> -->


<!-- Misc -->
Expand Down