Skip to content

Commit fe64db3

Browse files
JesseLovelacegcf-owl-bot[bot]
authored andcommitted
fix: Remove all client side validation for OLM, allow nonspecific lif… (#1160)
* fix: Remove all client side validation for OLM, allow nonspecific lifecycle actions * Test unsupported actions * address comments * Fix clirr * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * checkstyle Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 2084a23 commit fe64db3

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

google-cloud-storage/clirr-ignored-differences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@
3636
<method>com.google.api.services.storage.model.StorageObject queryCompletedResumableUpload(java.lang.String, long)</method>
3737
<differenceType>7012</differenceType>
3838
</difference>
39+
<difference>
40+
<className>com/google/cloud/storage/BucketInfo$LifecycleRule$LifecycleAction</className>
41+
<method>BucketInfo$LifecycleRule$LifecycleAction()</method>
42+
<differenceType>7004</differenceType>
43+
</difference>
3944
</differences>

google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,13 @@ static LifecycleRule fromPb(Rule rule) {
462462
StorageClass.valueOf(action.getStorageClass()));
463463
break;
464464
default:
465-
throw new UnsupportedOperationException(
466-
"The specified lifecycle action " + action.getType() + " is not currently supported");
465+
log.warning(
466+
"The lifecycle action "
467+
+ action.getType()
468+
+ " is not supported by this version of the library. "
469+
+ "Attempting to update with this rule may cause errors. Please "
470+
+ "update to the latest version of google-cloud-storage.");
471+
lifecycleAction = LifecycleAction.newLifecycleAction("Unknown action");
467472
}
468473

469474
Rule.Condition condition = rule.getCondition();
@@ -713,13 +718,21 @@ public LifecycleCondition build() {
713718
}
714719

715720
/**
716-
* Base class for the Action to take when a Lifecycle Condition is met. Specific Actions are
721+
* Base class for the Action to take when a Lifecycle Condition is met. Supported Actions are
717722
* expressed as subclasses of this class, accessed by static factory methods.
718723
*/
719-
public abstract static class LifecycleAction implements Serializable {
724+
public static class LifecycleAction implements Serializable {
720725
private static final long serialVersionUID = 5801228724709173284L;
721726

722-
public abstract String getActionType();
727+
private final String actionType;
728+
729+
public LifecycleAction(String actionType) {
730+
this.actionType = actionType;
731+
}
732+
733+
public String getActionType() {
734+
return actionType;
735+
}
723736

724737
@Override
725738
public String toString() {
@@ -744,17 +757,24 @@ public static SetStorageClassLifecycleAction newSetStorageClassAction(
744757
StorageClass storageClass) {
745758
return new SetStorageClassLifecycleAction(storageClass);
746759
}
760+
761+
/**
762+
* Creates a new {@code LifecycleAction , with no specific supported action associated with it. This
763+
* is only intended as a "backup" for when the library doesn't recognize the type, and should
764+
* generally not be used, instead use the supported actions, and upgrade the library if necessary
765+
* to get new supported actions.
766+
*/
767+
public static LifecycleAction newLifecycleAction(String actionType) {
768+
return new LifecycleAction(actionType);
769+
}
747770
}
748771

749772
public static class DeleteLifecycleAction extends LifecycleAction {
750773
public static final String TYPE = "Delete";
751774
private static final long serialVersionUID = -2050986302222644873L;
752775

753-
private DeleteLifecycleAction() {}
754-
755-
@Override
756-
public String getActionType() {
757-
return TYPE;
776+
private DeleteLifecycleAction() {
777+
super(TYPE);
758778
}
759779
}
760780

@@ -765,14 +785,10 @@ public static class SetStorageClassLifecycleAction extends LifecycleAction {
765785
private final StorageClass storageClass;
766786

767787
private SetStorageClassLifecycleAction(StorageClass storageClass) {
788+
super(TYPE);
768789
this.storageClass = storageClass;
769790
}
770791

771-
@Override
772-
public String getActionType() {
773-
return TYPE;
774-
}
775-
776792
@Override
777793
public String toString() {
778794
return MoreObjects.toStringHelper(this)
@@ -921,7 +937,11 @@ static class RawDeleteRule extends DeleteRule {
921937

922938
@Override
923939
void populateCondition(Rule.Condition condition) {
924-
throw new UnsupportedOperationException();
940+
log.warning(
941+
"The lifecycle condition "
942+
+ condition
943+
+ " is not currently supported. Please update to the latest version of google-cloud-java."
944+
+ " Also, use LifecycleRule rather than the deprecated DeleteRule.");
925945
}
926946

927947
private void writeObject(ObjectOutputStream out) throws IOException {

google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ public void testDeleteRules() {
306306
for (DeleteRule delRule : rules) {
307307
assertEquals(delRule, DeleteRule.fromPb(delRule.toPb()));
308308
}
309+
Rule unsupportedRule =
310+
new Rule().setAction(new Rule.Action().setType("This action doesn't exist"));
311+
DeleteRule.fromPb(
312+
unsupportedRule); // if this doesn't throw an exception, unsupported rules work
309313
}
310314

311315
@Test
@@ -355,6 +359,17 @@ public void testLifecycleRules() {
355359
assertEquals(StorageClass.COLDLINE.toString(), lifecycleRule.getAction().getStorageClass());
356360
assertEquals(30, lifecycleRule.getCondition().getDaysSinceCustomTime().intValue());
357361
assertNotNull(lifecycleRule.getCondition().getCustomTimeBefore());
362+
363+
Rule unsupportedRule =
364+
new LifecycleRule(
365+
LifecycleAction.newLifecycleAction("This action type doesn't exist"),
366+
LifecycleCondition.newBuilder().setAge(10).build())
367+
.toPb();
368+
unsupportedRule.setAction(
369+
unsupportedRule.getAction().setType("This action type also doesn't exist"));
370+
371+
LifecycleRule.fromPb(
372+
unsupportedRule); // If this doesn't throw an exception, unsupported rules are working
358373
}
359374

360375
@Test

0 commit comments

Comments
 (0)