Skip to content

Commit

Permalink
[Remote Store] Add S3 async upload utilities and models (#7217) (#8664)
Browse files Browse the repository at this point in the history
(cherry picked from commit c40323b)

Signed-off-by: Raghuvansh Raj <raghraaj@amazon.com>
Co-authored-by: Vikas Bansal <vikasvb@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and vikasvb90 authored Jul 13, 2023
1 parent ec41936 commit c3e382a
Show file tree
Hide file tree
Showing 17 changed files with 1,831 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.repositories.s3;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.common.concurrent.RefCountedReleasable;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;

import java.io.Closeable;
import java.io.IOException;

/**
* Handles the shutdown of the wrapped {@link software.amazon.awssdk.services.s3.S3AsyncClient} using reference
* counting.
*/
public class AmazonAsyncS3Reference extends RefCountedReleasable<AmazonAsyncS3WithCredentials> {

private static final Logger logger = LogManager.getLogger(AmazonAsyncS3Reference.class);

AmazonAsyncS3Reference(AmazonAsyncS3WithCredentials client) {
super("AWS_S3_CLIENT", client, () -> {
client.client().close();
client.priorityClient().close();
AwsCredentialsProvider credentials = client.credentials();
if (credentials instanceof Closeable) {
try {
((Closeable) credentials).close();
} catch (IOException e) {
logger.error("Exception while closing AwsCredentialsProvider", e);
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.repositories.s3;

import org.opensearch.common.Nullable;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.services.s3.S3AsyncClient;

/**
* The holder of the AmazonS3 and AWSCredentialsProvider
*/
final class AmazonAsyncS3WithCredentials {
private final S3AsyncClient client;
private final S3AsyncClient priorityClient;
private final AwsCredentialsProvider credentials;

private AmazonAsyncS3WithCredentials(
final S3AsyncClient client,
final S3AsyncClient priorityClient,
@Nullable final AwsCredentialsProvider credentials
) {
this.client = client;
this.credentials = credentials;
this.priorityClient = priorityClient;
}

S3AsyncClient client() {
return client;
}

S3AsyncClient priorityClient() {
return priorityClient;
}

AwsCredentialsProvider credentials() {
return credentials;
}

static AmazonAsyncS3WithCredentials create(
final S3AsyncClient client,
final S3AsyncClient priorityClient,
@Nullable final AwsCredentialsProvider credentials
) {
return new AmazonAsyncS3WithCredentials(client, priorityClient, credentials);
}
}
Loading

0 comments on commit c3e382a

Please sign in to comment.