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

Small upgrade #7

Merged
merged 1 commit into from
Apr 4, 2024
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<gbif-common-ws.version>1.28-SNAPSHOT</gbif-common-ws.version>
<spring-security-core.version>6.2.2</spring-security-core.version>
<lucene.version>9.9.1</lucene.version>
<amazon.awssdk.version>2.25.18</amazon.awssdk.version>
<amazon.awssdk.version>2.25.23</amazon.awssdk.version>
<commons-compress.version>1.26.0</commons-compress.version>
<swagger-annotations.version>2.2.20</swagger-annotations.version>
<springdoc-openapi.version>2.3.0</springdoc-openapi.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.transfer.s3.S3TransferManager;
Expand All @@ -16,7 +16,7 @@ public class S3Configuration {
@Bean
public S3AsyncClient s3Client() {
return S3AsyncClient.crtBuilder()
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.credentialsProvider(DefaultCredentialsProvider.create())
.region(Region.EU_WEST_2)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Repository;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
import software.amazon.awssdk.transfer.s3.S3TransferManager;
Expand Down Expand Up @@ -49,26 +51,33 @@ public void uploadIndex(String indexLocation) throws IndexingFailedException {

public void downloadIndex(String indexLocation) throws IndexingFailedException {
log.info("Checking if index: {} exists in S3", indexingProperties.getColDataset());
var directory = s3Client.listObjects(b -> b.bucket(BUCKET_NAME)
.prefix(String.valueOf(indexingProperties.getColDataset()))).join();
if (!directory.contents().isEmpty()) {
log.info("Downloading index from S3");
var directoryDownload = transferManager.downloadDirectory(
b -> b.destination(Paths.get(indexLocation))
.listObjectsV2RequestTransformer(
t -> t.prefix(String.valueOf(indexingProperties.getColDataset())))
.bucket(BUCKET_NAME)
);
var completedDirectoryDownload = directoryDownload.completionFuture().join();
if (!completedDirectoryDownload.failedTransfers().isEmpty()) {
var firstEx = completedDirectoryDownload.failedTransfers().getFirst();
log.error("Failed to download index to S3 with message: {}", firstEx, firstEx.exception());
throw new IndexingFailedException("Failed to download index from S3");
try {
var directory = s3Client.listObjects(b -> b.bucket(BUCKET_NAME)
.prefix(String.valueOf(indexingProperties.getColDataset()))).join();
if (!directory.contents().isEmpty()) {
log.info("Downloading index from S3");
var directoryDownload = transferManager.downloadDirectory(
b -> b.destination(Paths.get(indexLocation))
.listObjectsV2RequestTransformer(
t -> t.prefix(String.valueOf(indexingProperties.getColDataset())))
.bucket(BUCKET_NAME)
);
var completedDirectoryDownload = directoryDownload.completionFuture().join();
if (!completedDirectoryDownload.failedTransfers().isEmpty()) {
var firstEx = completedDirectoryDownload.failedTransfers().getFirst();
log.error("Failed to download index to S3 with message: {}", firstEx,
firstEx.exception());
throw new IndexingFailedException("Failed to download index from S3");
}
} else {
log.warn("No index for dataset {} found in S3", indexingProperties.getColDataset());
throw new IndexingFailedException(
"Index: " + indexingProperties.getColDataset() + " not available on S3");
}
} else {
log.warn("No index for dataset {} found in S3", indexingProperties.getColDataset());
throw new IndexingFailedException(
"Index: " + indexingProperties.getColDataset() + " not available on S3");
} catch (SdkException ex) {
log.error("Failed to check for a download in S3 with message: {}", ex.getMessage(), ex);
throw new IndexingFailedException("Failed to check for existing indexes in bucket on S3");
}
}

}
Loading