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

fix: Errors handling and objects fetching from s3. #959

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -136,7 +137,10 @@ private String resolveSingularPath(
String rootFolder = daoRoot(credentials, objectType.getGroup()) + "/" + objectKey;
ObjectListing bucketListing =
amazonS3.listObjects(new ListObjectsRequest(bucket, rootFolder, null, null, 10000));
List<S3ObjectSummary> summaries = bucketListing.getObjectSummaries();
List<S3ObjectSummary> summaries =
bucketListing.getObjectSummaries().stream()
.filter(summary -> !summary.getKey().endsWith("/"))
.collect(Collectors.toList());

if (summaries != null && summaries.size() == 1) {
return summaries.get(0).getKey();
Expand Down Expand Up @@ -387,6 +391,10 @@ public List<Map<String, Object>> listObjectKeys(

if (summaries != null) {
for (S3ObjectSummary summary : summaries) {
if (summary.getKey().endsWith("/")) {
continue;
}

String itemName = summary.getKey();
int indexOfLastSlash = itemName.lastIndexOf("/");
Map<String, Object> objectMetadataMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.netflix.kayenta.storage.ObjectType;
import com.netflix.kayenta.storage.StorageService;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,17 +82,31 @@ private void migrate(ObjectType objectType) {

var errors = new ConcurrentLinkedQueue<String>();

for (var objectKey : objectKeysToMigrate) {
executorService.submit(
() -> {
try {
var object =
sourceStorageService.loadObject(sourceAccountName, objectType, objectKey);
targetStorageService.storeObject(targetAccountName, objectType, objectKey, object);
} catch (Exception e) {
errors.add(String.format("[objectType: %s, objectKey: %s]", objectType, objectKey));
}
});
var tasks =
objectKeysToMigrate.stream()
.map(
objectKey ->
(Callable<Void>)
() -> {
try {
var object =
sourceStorageService.loadObject(
sourceAccountName, objectType, objectKey);
targetStorageService.storeObject(
targetAccountName, objectType, objectKey, object);
} catch (Exception e) {
errors.add(
String.format(
"[objectType: %s, objectKey: %s]", objectType, objectKey));
}
return null;
})
.collect(Collectors.toList());

try {
executorService.invokeAll(tasks);
} catch (InterruptedException e) {
log.error("Unable to migrate objects", e);
}

if (!errors.isEmpty()) {
Expand Down