From 07c66be88ace37ce42f350c40802b26e410a9b03 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Wed, 1 Dec 2021 13:58:02 -0800 Subject: [PATCH 1/6] fix: Remove all client side validation for OLM, allow nonspecific lifecycle actions --- .../com/google/cloud/storage/BucketInfo.java | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index 83a836f78..9d9ef127d 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -548,8 +548,12 @@ static LifecycleRule fromPb(Rule rule) { StorageClass.valueOf(action.getStorageClass())); break; default: - throw new UnsupportedOperationException( - "The specified lifecycle action " + action.getType() + " is not currently supported"); + log.warning( + "Creating a lifecycle rule with no supported actions: " + + rule + + ". Attempting to update with this rule may cause errors. Please " + + "update to the latest version of google-cloud-storage."); + lifecycleAction = LifecycleAction.newLifecycleAction(action.getType()); } Rule.Condition condition = rule.getCondition(); @@ -799,13 +803,25 @@ public LifecycleCondition build() { } /** - * Base class for the Action to take when a Lifecycle Condition is met. Specific Actions are + * Base class for the Action to take when a Lifecycle Condition is met. Supported Actions are * expressed as subclasses of this class, accessed by static factory methods. */ - public abstract static class LifecycleAction implements Serializable { + public static class LifecycleAction implements Serializable { private static final long serialVersionUID = 5801228724709173284L; - public abstract String getActionType(); + private final String actionType; + + public String getActionType() { + return actionType; + } + + private LifecycleAction(String actionType) { + this.actionType = actionType; + } + + public static LifecycleAction newLifecycleAction(String actionType) { + return new LifecycleAction(actionType); + } @Override public String toString() { @@ -836,11 +852,8 @@ public static class DeleteLifecycleAction extends LifecycleAction { public static final String TYPE = "Delete"; private static final long serialVersionUID = -2050986302222644873L; - private DeleteLifecycleAction() {} - - @Override - public String getActionType() { - return TYPE; + private DeleteLifecycleAction() { + super(TYPE); } } @@ -851,14 +864,10 @@ public static class SetStorageClassLifecycleAction extends LifecycleAction { private final StorageClass storageClass; private SetStorageClassLifecycleAction(StorageClass storageClass) { + super(TYPE); this.storageClass = storageClass; } - @Override - public String getActionType() { - return TYPE; - } - @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -1007,7 +1016,11 @@ static class RawDeleteRule extends DeleteRule { @Override void populateCondition(Rule.Condition condition) { - throw new UnsupportedOperationException(); + log.warning( + "The lifecycle condition " + + condition + + " is not currently supported. Please update to the latest version of google-cloud-java." + + " Also, use LifecycleRule rather than the deprecated DeleteRule."); } private void writeObject(ObjectOutputStream out) throws IOException { From e9baf280159fdab349065a91400ae065915d6c05 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Mon, 6 Dec 2021 11:23:04 -0800 Subject: [PATCH 2/6] Test unsupported actions --- .../java/com/google/cloud/storage/BucketInfo.java | 9 +++++---- .../java/com/google/cloud/storage/BucketInfoTest.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index 9d9ef127d..ab906f093 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -549,11 +549,12 @@ static LifecycleRule fromPb(Rule rule) { break; default: log.warning( - "Creating a lifecycle rule with no supported actions: " - + rule - + ". Attempting to update with this rule may cause errors. Please " + "The lifecycle action " + + action.getType() + + " is not supported by this version of the library. " + + "Attempting to update with this rule may cause errors. Please " + "update to the latest version of google-cloud-storage."); - lifecycleAction = LifecycleAction.newLifecycleAction(action.getType()); + lifecycleAction = LifecycleAction.newLifecycleAction("Unknown action"); } Rule.Condition condition = rule.getCondition(); diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java index c74625a15..c4d5204a6 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java @@ -363,6 +363,17 @@ public void testLifecycleRules() { assertEquals(StorageClass.COLDLINE.toString(), lifecycleRule.getAction().getStorageClass()); assertEquals(30, lifecycleRule.getCondition().getDaysSinceCustomTime().intValue()); assertNotNull(lifecycleRule.getCondition().getCustomTimeBefore()); + + Rule unsupportedRule = + new LifecycleRule( + LifecycleAction.newLifecycleAction("This action type doesn't exist"), + LifecycleCondition.newBuilder().setAge(10).build()) + .toPb(); + unsupportedRule.setAction( + unsupportedRule.getAction().setType("This action type also doesn't exist")); + + LifecycleRule.fromPb( + unsupportedRule); // If this doesn't throw an exception, unsupported rules are working } @Test From a6ed5533a6d2706a76a9b03cac76182e3566f370 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Wed, 8 Dec 2021 10:58:31 -0800 Subject: [PATCH 3/6] address comments --- .../com/google/cloud/storage/BucketInfo.java | 18 ++++++++++++------ .../google/cloud/storage/BucketInfoTest.java | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index ab906f093..973d4be60 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -812,16 +812,12 @@ public static class LifecycleAction implements Serializable { private final String actionType; - public String getActionType() { - return actionType; - } - private LifecycleAction(String actionType) { this.actionType = actionType; } - public static LifecycleAction newLifecycleAction(String actionType) { - return new LifecycleAction(actionType); + public String getActionType() { + return actionType; } @Override @@ -847,6 +843,16 @@ public static SetStorageClassLifecycleAction newSetStorageClassAction( StorageClass storageClass) { return new SetStorageClassLifecycleAction(storageClass); } + + /** + * Creates a new {@code LifecycleAction , with no specific supported action associated with it. This + * is only intended as a "backup" for when the library doesn't recognize the type, and should + * generally not be used, instead use the supported actions, and upgrade the library if necessary + * to get new supported actions. + */ + public static LifecycleAction newLifecycleAction(String actionType) { + return new LifecycleAction(actionType); + } } public static class DeleteLifecycleAction extends LifecycleAction { diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java index c4d5204a6..2041de556 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java @@ -314,6 +314,10 @@ public void testDeleteRules() { for (DeleteRule delRule : rules) { assertEquals(delRule, DeleteRule.fromPb(delRule.toPb())); } + Rule unsupportedRule = + new Rule().setAction(new Rule.Action().setType("This action doesn't exist")); + DeleteRule.fromPb( + unsupportedRule); // if this doesn't throw an exception, unsupported rules work } @Test From 35741bb87f89f9798c15e12844bbf715f3de0107 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Wed, 5 Jan 2022 15:13:20 -0800 Subject: [PATCH 4/6] Fix clirr --- google-cloud-storage/clirr-ignored-differences.xml | 5 +++++ .../src/main/java/com/google/cloud/storage/BucketInfo.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/clirr-ignored-differences.xml b/google-cloud-storage/clirr-ignored-differences.xml index 85c4887d6..2907efa05 100644 --- a/google-cloud-storage/clirr-ignored-differences.xml +++ b/google-cloud-storage/clirr-ignored-differences.xml @@ -16,6 +16,11 @@ com/google/cloud/storage/spi/v1/StorageRpc *.StorageObject writeWithResponse(*.String, byte[], int, long, int, boolean) + + com/google/cloud/storage/BucketInfo$LifecycleRule$LifecycleAction + BucketInfo$LifecycleRule$LifecycleAction() + 7004 + com/google/cloud/storage/BucketInfo$Builder com.google.cloud.storage.BucketInfo$Builder deleteLifecycleRules() diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index 973d4be60..2404a7c1e 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -812,7 +812,7 @@ public static class LifecycleAction implements Serializable { private final String actionType; - private LifecycleAction(String actionType) { + public LifecycleAction(String actionType) { this.actionType = actionType; } From 219c04fcbb75f5dccc565cd4093441740cd67985 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 7 Jan 2022 22:07:53 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d05eed117..42a0678cd 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-storage' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-storage:2.2.2' +implementation 'com.google.cloud:google-cloud-storage:2.2.3' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.2.2" +libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.2.3" ``` ## Authentication From 6e19fe2873fc7348fabb6869ba43c8de9f2627b8 Mon Sep 17 00:00:00 2001 From: JesseLovelace <43148100+JesseLovelace@users.noreply.github.com> Date: Fri, 7 Jan 2022 15:36:18 -0800 Subject: [PATCH 6/6] checkstyle --- .../src/main/java/com/example/storage/ConfigureRetries.java | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/snippets/src/main/java/com/example/storage/ConfigureRetries.java b/samples/snippets/src/main/java/com/example/storage/ConfigureRetries.java index 9d037a821..e1db27ab0 100644 --- a/samples/snippets/src/main/java/com/example/storage/ConfigureRetries.java +++ b/samples/snippets/src/main/java/com/example/storage/ConfigureRetries.java @@ -15,6 +15,7 @@ */ package com.example.storage; + // [START storage_configure_retries] import com.google.api.gax.retrying.RetrySettings;