Skip to content

Commit

Permalink
chore: attempting to get some buckets cleanup info
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWhitehead committed Sep 25, 2024
1 parent 2e50b5a commit 8a19eb9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 47 deletions.
30 changes: 15 additions & 15 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ set +e
case ${JOB_TYPE} in
test)
echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}"
mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT}
RETURN_CODE=$?
# mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT}
RETURN_CODE=1
;;
lint)
mvn com.coveo:fmt-maven-plugin:check -B -ntp
Expand All @@ -60,25 +60,25 @@ javadoc)
RETURN_CODE=$?
;;
integration)
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
-Penable-integration-tests \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-fae \
verify
RETURN_CODE=$?
# mvn -B ${INTEGRATION_TEST_ARGS} \
# -ntp \
# -Penable-integration-tests \
# -DtrimStackTrace=false \
# -Dclirr.skip=true \
# -Denforcer.skip=true \
# -fae \
# verify
RETURN_CODE=1
;;
graalvm)
# Run Unit and Integration Tests with Native Image
mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative test
RETURN_CODE=$?
# mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative test
RETURN_CODE=1
;;
graalvm17)
# Run Unit and Integration Tests with Native Image
mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative test
RETURN_CODE=$?
# mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative test
RETURN_CODE=1
;;
samples)
SAMPLES_DIR=samples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.storage.it;

import com.google.api.gax.grpc.GrpcCallContext;
import com.google.api.gax.paging.Page;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.FailedPreconditionException;
Expand All @@ -26,8 +27,12 @@
import com.google.cloud.storage.Storage.BlobSourceOption;
import com.google.cloud.storage.Storage.BucketSourceOption;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.storage.control.v2.BucketName;
import com.google.storage.control.v2.Folder;
import com.google.storage.control.v2.GetStorageLayoutRequest;
import com.google.storage.control.v2.ListFoldersRequest;
import com.google.storage.control.v2.ListManagedFoldersRequest;
import com.google.storage.control.v2.StorageControlClient;
import com.google.storage.control.v2.StorageLayout;
import com.google.storage.control.v2.StorageLayoutName;
Expand Down Expand Up @@ -97,15 +102,34 @@ public static void doCleanup(String bucketName, Storage s, StorageControlClient
boolean anyFailedFolderDelete = false;
boolean anyFailedManagedFolderDelete = false;

GrpcCallContext grpcCallContext =
GrpcCallContext.createDefault()
.withExtraHeaders(
ImmutableMap.of("x-goog-user-project", ImmutableList.of(projectId)));
if (!anyFailedObjectDelete) {
BucketName parent = BucketName.of("_", bucketName);
StorageLayout storageLayout =
ctrl.getStorageLayout(StorageLayoutName.of(parent.getProject(), parent.getBucket()));
ctrl.getStorageLayoutCallable()
.call(
GetStorageLayoutRequest.newBuilder()
.setName(
StorageLayoutName.of(parent.getProject(), parent.getBucket())
.toString())
.build(),
grpcCallContext);

List<DeleteResult> folderDeletes;
if (storageLayout.hasHierarchicalNamespace()
&& storageLayout.getHierarchicalNamespace().getEnabled()) {
folderDeletes =
StreamSupport.stream(ctrl.listFolders(parent).iterateAll().spliterator(), false)
StreamSupport.stream(
ctrl.listFoldersPagedCallable()
.call(
ListFoldersRequest.newBuilder().setParent(parent.toString()).build(),
grpcCallContext)
.iterateAll()
.spliterator(),
false)
.collect(Collectors.toList())
.stream()
.sorted(Collections.reverseOrder(Comparator.comparing(Folder::getName)))
Expand All @@ -129,7 +153,15 @@ public static void doCleanup(String bucketName, Storage s, StorageControlClient
try {
managedFolderDeletes =
StreamSupport.stream(
ctrl.listManagedFolders(parent).iterateAll().spliterator(), false)
ctrl.listManagedFoldersPagedCallable()
.call(
ListManagedFoldersRequest.newBuilder()
.setParent(parent.toString())
.build(),
grpcCallContext)
.iterateAll()
.spliterator(),
false)
.map(
managedFolder -> {
LOGGER.warning(
Expand Down
17 changes: 0 additions & 17 deletions samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,9 @@
</properties>

<modules>
<!-- <module>install-without-bom</module>-->
<module>snapshot</module>
<!-- <module>snippets</module>-->
</modules>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.16</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
<scope>runtime</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
Expand Down
21 changes: 9 additions & 12 deletions samples/snapshot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,25 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.14</version>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.132.2</version>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- compile and run all snippet tests -->
<build>
<plugins>
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down Expand Up @@ -103,6 +99,7 @@
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
</project>

0 comments on commit 8a19eb9

Please sign in to comment.