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

Switch from Async to Synchronous S3 client #223

Merged
Merged
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
8 changes: 4 additions & 4 deletions adapters/klab.ogc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
</dependency>
<!--- AWS dependencies-->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<version>${aws.version}</version>
<exclusions>
<artifactId>apache-client</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>${aws.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import kong.unirest.apache.ApacheClient;
import kong.unirest.json.JSONObject;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.S3Client;

public class STACEncoder implements IResourceEncoder {

Expand Down Expand Up @@ -162,16 +163,16 @@ private void sortByDate(List<HMStacItem> items, IMonitor monitor) {
"Ordered STAC items. First: [" + items.get(0).getTimestamp() + "]; Last [" + items.get(items.size() - 1).getTimestamp() + "]");
}

private S3AsyncClient buildS3Client(String bucketRegion) throws IOException {
private S3Client buildS3Client(String bucketRegion) throws IOException {
ExternalAuthenticationCredentials awsCredentials = Authentication.INSTANCE.getCredentials(S3URLUtils.AWS_ENDPOINT);
AwsCredentials credentials = null;
try {
credentials = AwsBasicCredentials.create(awsCredentials.getCredentials().get(0), awsCredentials.getCredentials().get(1));
} catch (Exception e) {
throw new KlabIOException("Error defining AWS credenetials. " + e.getMessage());
}
return S3AsyncClient.builder()
.httpClient(NettyNioAsyncHttpClient.builder().build())
return S3Client.builder()
.httpClientBuilder(ApacheHttpClient.builder())
.region(Region.of(bucketRegion))
.credentialsProvider(StaticCredentialsProvider.create(credentials))
.build();
Expand Down Expand Up @@ -275,8 +276,7 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters

if (resource.getParameters().contains("s3BucketRegion")) {
String bucketRegion = resource.getParameters().get("s3BucketRegion", String.class);
S3AsyncClient s3Client = buildS3Client(bucketRegion);
// TODO waiting until the library version is updated
S3Client s3Client = buildS3Client(bucketRegion);
collection.setS3Client(s3Client);
}

Expand Down