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

Bump and adapt AWS dependency to version 2.0 #222

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
26 changes: 16 additions & 10 deletions adapters/klab.ogc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@
</exclusions>
</dependency>
<!--- AWS dependencies-->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<version>${aws.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>protocol-core</artifactId>
<version>${aws.version}</version>
</dependency>

<!-- <dependency> <groupId>org.geotools.xsd</groupId> <artifactId>gt-xsd-core</artifactId>
<version>${geotools.version}</version> </dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
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.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;

public class STACEncoder implements IResourceEncoder {

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

private AmazonS3 buildS3Client(String bucketRegion) throws IOException {
private S3AsyncClient buildS3Client(String bucketRegion) throws IOException {
ExternalAuthenticationCredentials awsCredentials = Authentication.INSTANCE.getCredentials(S3URLUtils.AWS_ENDPOINT);
BasicAWSCredentials awsCreds = null;
AwsCredentials credentials = null;
try {
awsCreds = new BasicAWSCredentials(awsCredentials.getCredentials().get(0), awsCredentials.getCredentials().get(1));
credentials = AwsBasicCredentials.create(awsCredentials.getCredentials().get(0), awsCredentials.getCredentials().get(1));
} catch (Exception e) {
throw new KlabIOException("Error defining AWS credenetials. " + e.getMessage());
}
AmazonS3 s3Client = null;
try {
s3Client = AmazonS3Client.builder()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(bucketRegion)
.build();
} catch (Exception e) {
throw new KlabIOException("Error building S3 client. " + e.getMessage());
}
return s3Client;
return S3AsyncClient.builder()
.httpClient(NettyNioAsyncHttpClient.builder().build())
.region(Region.of(bucketRegion))
.credentialsProvider(StaticCredentialsProvider.create(credentials))
.build();
}

@Override
Expand Down Expand Up @@ -239,7 +236,8 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters
.findFirst().orElseThrow();
Time resourceTime = (Time) Scale.create(resource.getGeometry()).getDimension(Type.TIME);

if (resourceTime.getStart() != null && resourceTime.getEnd() != null && resourceTime.getCoveredExtent() > 0) {
if (resourceTime != null &&
resourceTime.getStart() != null && resourceTime.getEnd() != null && resourceTime.getCoveredExtent() > 0) {
time = validateTemporalDimension(time, resourceTime);
}
ITimeInstant start = time.getStart();
Expand Down Expand Up @@ -277,9 +275,9 @@ public void getEncodedData(IResource resource, Map<String, String> urnParameters

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

// Allow transform ensures the process to finish, but I would not bet on the resulting
Expand Down
3 changes: 3 additions & 0 deletions adapters/klab.ogc/src/main/resources/ogc/prototypes/stac.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
optional text 'asset'
"The asset that is going to be retrieved from the items."

optional text 's3BucketRegion'
"The Region for S3 elements."

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<!-- Careful here: geotools must be right for hortonmachine to work; JTS
should be the same one that geotools and HM needs. -->
<geotools.version>28.0</geotools.version>
<hortonmachine.version>0.10.9-SNAPSHOT</hortonmachine.version>
<hortonmachine.version>0.10.9-S3-SDK-2.0-SNAPSHOT</hortonmachine.version>
<jts.version>1.20.0</jts.version>
<h2gis.version>1.5.0</h2gis.version>
<maven.compiler.source>11</maven.compiler.source>
Expand Down Expand Up @@ -131,7 +131,7 @@
<mockito.version>5.6.0</mockito.version>
<hamcrest.version>2.2</hamcrest.version>
<powermock.version>2.0.9</powermock.version>
<aws.version>1.12.767</aws.version>
<aws.version>2.29.14</aws.version>
</properties>

<build>
Expand Down