Skip to content

Commit

Permalink
Merge pull request #1902 from t-rana/issues/OAK-11306
Browse files Browse the repository at this point in the history
OAK-11306: fix GCP bucket cleanup post running tests
  • Loading branch information
rishabhdaim authored Dec 13, 2024
2 parents 78451c4 + 24f511e commit 5a0dbb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ public KeyRenameThread(String oldKey) {
/**
* Enum to indicate remote storage mode
*/
private enum RemoteStorageMode {
enum RemoteStorageMode {
S3,
GCP
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@
import org.apache.jackrabbit.core.data.DataStore;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Backend.RemoteStorageMode;

/**
* Extension to {@link DataStoreUtils} to enable S3 extensions for cleaning and initialization.
*/
Expand Down Expand Up @@ -155,13 +158,20 @@ public static void deleteBucket(String bucket, Date date) throws Exception {
ObjectListing prevObjectListing = s3service.listObjects(bucket);
while (prevObjectListing != null) {
List<DeleteObjectsRequest.KeyVersion> deleteList = new ArrayList<DeleteObjectsRequest.KeyVersion>();
List<String> keysToDelete = new ArrayList<>();
for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
deleteList.add(new DeleteObjectsRequest.KeyVersion(s3ObjSumm.getKey()));
keysToDelete.add(s3ObjSumm.getKey());
}
if (deleteList.size() > 0) {
DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket);
delObjsReq.setKeys(deleteList);
s3service.deleteObjects(delObjsReq);
if (!deleteList.isEmpty()) {
RemoteStorageMode mode = getMode(props);
if (mode == RemoteStorageMode.S3) {
DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket);
delObjsReq.setKeys(deleteList);
s3service.deleteObjects(delObjsReq);
} else {
keysToDelete.forEach(key -> s3service.deleteObject(bucket, key));
}
}
if (!prevObjectListing.isTruncated())
break;
Expand All @@ -177,6 +187,12 @@ public static void deleteBucket(String bucket, Date date) throws Exception {
s3service.shutdown();
}

@NotNull
private static RemoteStorageMode getMode(@NotNull Properties props) {
return props.getProperty(S3Constants.S3_END_POINT, "").contains("googleapis") ?
RemoteStorageMode.GCP : RemoteStorageMode.S3;
}

protected static HttpsURLConnection getHttpsConnection(long length, URI uri) throws IOException {
HttpsURLConnection conn = (HttpsURLConnection) uri.toURL().openConnection();
conn.setDoOutput(true);
Expand Down

0 comments on commit 5a0dbb9

Please sign in to comment.