Skip to content

Commit

Permalink
Merge pull request #855 from umccr/2.8.10_fix_storage_tier_null
Browse files Browse the repository at this point in the history
Fix npe on AWS Storage Tier and treat the STANDARD tier status first
# Conflicts:
#	build.gradle
#	src/main/java/org/broad/igv/util/AmazonUtils.java
  • Loading branch information
jrobinso committed Oct 20, 2020
1 parent daf6be3 commit 39658c6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 49 deletions.
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.13.30'],
[group: 'software.amazon.awssdk', name: 'cognitoidentity', version: '2.13.30'],
[group: 'software.amazon.awssdk', name: 'sts', version: '2.13.30'],
[group: 'software.amazon.awssdk', name: 's3', version: '2.13.30']
[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
86 changes: 41 additions & 45 deletions src/main/java/org/broad/igv/util/AmazonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,61 +246,57 @@ 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);
try {
s3ObjectStorageClass = s3Meta.storageClass().toString();
} catch(NullPointerException npe) {
log.error("S3Meta StorageClass: Must be STANDARD since there is no Storage Class metadata");
if (s3Meta.storageClass() == null) {
res.setErrorReason("Object is in an accessible tier, no errors are expected");
res.setObjAvailable(true);
return res;
return res; // nothing else to check, return early
}

// Determine in which state this object really is:
// 1. Archived.
// 2. In the process of being restored.
// 3. Restored
//
// This is important because after restoration the object maintains the Tier (DEEP_ARCHIVE) instead of
// transitioning that attribute to STANDARD, we must look at head_object response for the "Restore"
// attribute.
//
// Possible error reason messages for the users are:

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. " +
"For further enquiries about this dataset, please use the following path when communicating with your system administrator: s3://" + bucket + "/" + key;

if (s3ObjectStorageClass.contains("DEEP_ARCHIVE") ||
s3ObjectStorageClass.contains("GLACIER")) {
try {
s3ObjectStorageStatus = s3Meta.sdkHttpResponse().headers().get("x-amz-restore").toString();
//S3ObjectStorageStatus = S3Meta.restore();
} catch(NullPointerException npe) {
res.setObjAvailable(false);
res.setErrorReason(archived);
return res;
}
// Determine in which state this object really is:
// 1. Archived.
// 2. In the process of being restored.
// 3. Restored
//
// This is important because after restoration the object mantains the Tier (DEEP_ARCHIVE) instead of
// transitioning that attribute to STANDARD, we must look at head_object response for the "Restore"
// attribute.
//
// 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. " +
"For further enquiries about this dataset, please use the following path when communicating with your system administrator: s3://" + bucket + "/" + key;

if (s3ObjectStorageClass.contains("DEEP_ARCHIVE") ||
s3ObjectStorageClass.contains("GLACIER")) {
try {
s3ObjectStorageStatus = s3Meta.sdkHttpResponse().headers().get("x-amz-restore").toString();
} catch (NullPointerException npe) {
res.setObjAvailable(false);
res.setErrorReason(archived);
return res;
}

if(s3ObjectStorageStatus.contains("ongoing-request=\"true\"")) {
res.setObjAvailable(false);
res.setErrorReason(restoreInProgress);
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=")) {
res.setObjAvailable(true);
} else {
// The object has never been restored?
res.setObjAvailable(false);
res.setErrorReason(archived);
}
} else {
// The object must be either in INFREQUENT_ACCESS, INTELLIGENT_TIERING or
// any other "immediately available" tier...
res.setErrorReason("Object is in an accessible tier, no errors are expected");
} else if (s3ObjectStorageStatus.contains("ongoing-request=\"false\"") && s3ObjectStorageStatus.contains("expiry-date=")) {
res.setObjAvailable(true);
} else {
// The object has never been restored?
res.setObjAvailable(false);
res.setErrorReason(archived);
}
}

return res;
}
Expand Down

0 comments on commit 39658c6

Please sign in to comment.