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 npe on AWS Storage Tier and treat the STANDARD tier status first #855

Merged
merged 1 commit into from
Oct 20, 2020
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ dependencies {
[group: 'org.netbeans.external', name: 'AbsoluteLayout', version: 'RELEASE110'],

// Amazon deps
[group: 'software.amazon.awssdk', name: 'http-client-spi', version: '2.8.5'],
[group: 'software.amazon.awssdk', name: 'cognitoidentity', version: '2.8.5'],
[group: 'software.amazon.awssdk', name: 'sts', version: '2.8.5'],
[group: 'software.amazon.awssdk', name: 's3', version: '2.8.5'],
[group: 'software.amazon.awssdk', name: 'http-client-spi', version: '2.15.9'],
[group: 'software.amazon.awssdk', name: 'cognitoidentity', version: '2.15.9'],
[group: 'software.amazon.awssdk', name: 'sts', version: '2.15.9'],
[group: 'software.amazon.awssdk', name: 's3', version: '2.15.9'],
)

testImplementation(
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/org/broad/igv/util/AmazonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,15 @@ public static s3ObjectAccessResult isObjectAccessible(String bucket, String key)
String s3ObjectStorageStatus = null;
String s3ObjectStorageClass;

// Simple "null" case. The object is directly accessible in
// STANDARD, INFREQUENT_ACCESS, INTELLIGENT_TIERING
// or any other "immediately available" tier.
s3Meta = AmazonUtils.getObjectMetadata(bucket, key);
s3ObjectStorageClass = s3Meta.storageClass().toString();
if (s3Meta.storageClass() == null) {
res.setErrorReason("Object is in an accessible tier, no errors are expected");
res.setObjAvailable(true);
return res; // nothing else to check, return early
}

// Determine in which state this object really is:
// 1. Archived.
Expand All @@ -260,6 +267,8 @@ public static s3ObjectAccessResult isObjectAccessible(String bucket, String key)
//
// Possible error reason messages for the users are:

s3ObjectStorageClass = s3Meta.storageClass().toString();

String archived = "Amazon S3 object is in " + s3ObjectStorageClass + " storage tier, not accessible at this moment. " +
"Please contact your local system administrator about object: s3://" + bucket + "/" + key;
String restoreInProgress = "Amazon S3 object is in " + s3ObjectStorageClass + " and being restored right now, please be patient, this can take up to 48h. " +
Expand All @@ -269,30 +278,24 @@ public static s3ObjectAccessResult isObjectAccessible(String bucket, String key)
s3ObjectStorageClass.contains("GLACIER")) {
try {
s3ObjectStorageStatus = s3Meta.sdkHttpResponse().headers().get("x-amz-restore").toString();
//S3ObjectStorageStatus = S3Meta.restore();
} catch(NullPointerException npe) {
} catch (NullPointerException npe) {
res.setObjAvailable(false);
res.setErrorReason(archived);
return res;
}

if(s3ObjectStorageStatus.contains("ongoing-request=\"true\"")) {
if (s3ObjectStorageStatus.contains("ongoing-request=\"true\"")) {
res.setObjAvailable(false);
res.setErrorReason(restoreInProgress);

// "If an archive copy is already restored, the header value indicates when Amazon S3 is scheduled to delete the object copy"
} else if(s3ObjectStorageStatus.contains("ongoing-request=\"false\"") && s3ObjectStorageStatus.contains("expiry-date=")) {
// "If an archive copy is already restored, the header value indicates when Amazon S3 is scheduled to delete the object copy"
} else if (s3ObjectStorageStatus.contains("ongoing-request=\"false\"") && s3ObjectStorageStatus.contains("expiry-date=")) {
res.setObjAvailable(true);
} else {
// The object has never been restored?
// The object has never been restored?
res.setObjAvailable(false);
res.setErrorReason(archived);
}
} else {
// The object must be either in STANDARD, INFREQUENT_ACCESS, INTELLIGENT_TIERING or
// any other "immediately available" tier...
res.setErrorReason("Object is in an accessible tier, no errors are expected");
res.setObjAvailable(true);
}

return res;
Expand Down