-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
ec41936
commit c3e382a
Showing
17 changed files
with
1,831 additions
and
86 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ns/repository-s3/src/main/java/org/opensearch/repositories/s3/AmazonAsyncS3Reference.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,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); | ||
} | ||
} | ||
}); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ository-s3/src/main/java/org/opensearch/repositories/s3/AmazonAsyncS3WithCredentials.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,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); | ||
} | ||
} |
Oops, something went wrong.