-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add object retention feature #2277
Merged
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dcc0ca4
feat: add object retention feature
JesseLovelace 7b4a2a7
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 876c293
Merge branch 'main' into objlock
JesseLovelace b620c67
address review comments
JesseLovelace 862a564
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] dc6d226
Add a workaround to avoid a testbench failure
JesseLovelace 7ca2178
Merge branch 'objlock' of github.com:googleapis/java-storage into obj…
JesseLovelace 40ae1f8
chore: some fixes from pairing with jesse
BenWhitehead 5fd0937
chore: put a `!` :don't program while sleepy:
BenWhitehead 9159db3
chore: mvn-fmt
BenWhitehead 70c9c5e
add a way to avoid using the objectRetentionField in bucket tests
JesseLovelace 52eecf7
add retention to blobfield tests
JesseLovelace e16abae
clirr and fmt
JesseLovelace 3bc56f6
add todos
JesseLovelace abd314c
fmt
JesseLovelace 2f9f38b
Merge branch 'main' into objlock
JesseLovelace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,10 @@ | |
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.google.api.client.util.Data; | ||
import com.google.api.core.ApiFunction; | ||
import com.google.api.core.BetaApi; | ||
import com.google.cloud.StringEnumType; | ||
import com.google.cloud.StringEnumValue; | ||
import com.google.cloud.storage.Storage.BlobField; | ||
import com.google.cloud.storage.TransportCompatibility.Transport; | ||
import com.google.cloud.storage.UnifiedOpts.NamedField; | ||
|
@@ -104,6 +107,7 @@ public class BlobInfo implements Serializable { | |
private final Boolean eventBasedHold; | ||
private final Boolean temporaryHold; | ||
private final OffsetDateTime retentionExpirationTime; | ||
private final Retention retention; | ||
private final transient ImmutableSet<NamedField> modifiedFields; | ||
|
||
/** This class is meant for internal use only. Users are discouraged from using this class. */ | ||
|
@@ -168,6 +172,116 @@ public final boolean equals(Object o) { | |
} | ||
} | ||
|
||
/** | ||
* Defines a blob's Retention policy. Can only be used on objects in a retention-enabled bucket. | ||
*/ | ||
public static class Retention implements Serializable { | ||
BenWhitehead marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static final class Mode extends StringEnumValue { | ||
BenWhitehead marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static final long serialVersionUID = 1973143582659557184L; | ||
|
||
private Mode(String constant) { | ||
super(constant); | ||
} | ||
|
||
private static final ApiFunction<String, Mode> CONSTRUCTOR = Mode::new; | ||
|
||
private static final StringEnumType<Mode> type = | ||
new StringEnumType<>(Mode.class, CONSTRUCTOR); | ||
|
||
public static final Mode UNLOCKED = type.createAndRegister("Unlocked"); | ||
|
||
public static final Mode LOCKED = type.createAndRegister("Locked"); | ||
|
||
public static Mode valueOfStrict(String constant) { | ||
return type.valueOfStrict(constant); | ||
} | ||
|
||
public static Mode valueOf(String constant) { | ||
return type.valueOf(constant); | ||
} | ||
|
||
public static Mode[] values() { | ||
return type.values(); | ||
} | ||
} | ||
|
||
private static final long serialVersionUID = 5046718464542688444L; | ||
|
||
private Mode mode; | ||
|
||
private OffsetDateTime retainUntilTime; | ||
|
||
/** Returns the retention policy's Mode. Can be Locked or Unlocked. */ | ||
public Mode getMode() { | ||
return mode; | ||
} | ||
|
||
/** Returns what time this object will be retained until, if the mode is Locked. */ | ||
public OffsetDateTime getRetainUntilTime() { | ||
return retainUntilTime; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof Retention)) { | ||
return false; | ||
} | ||
Retention that = (Retention) o; | ||
return Objects.equals(mode, that.mode) | ||
&& Objects.equals(retainUntilTime, that.retainUntilTime); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(mode, retainUntilTime); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("mode", mode) | ||
.add("retainUntilTime", retainUntilTime) | ||
.toString(); | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remember, do we usually do |
||
|
||
private Retention() {} | ||
|
||
public Retention(Builder builder) { | ||
this.mode = builder.mode; | ||
this.retainUntilTime = builder.retainUntilTime; | ||
} | ||
|
||
public static final class Builder { | ||
|
||
private Mode mode; | ||
private OffsetDateTime retainUntilTime; | ||
|
||
/** Sets the retention policy's Mode. Can be Locked or Unlocked. */ | ||
public Builder setMode(Mode mode) { | ||
this.mode = mode; | ||
return this; | ||
} | ||
|
||
/** Sets what time this object will be retained until, if the mode is Locked. */ | ||
public Builder setRetainUntilTime(OffsetDateTime retainUntilTime) { | ||
this.retainUntilTime = retainUntilTime; | ||
return this; | ||
} | ||
|
||
public Retention build() { | ||
return new Retention(this); | ||
} | ||
} | ||
} | ||
|
||
/** Builder for {@code BlobInfo}. */ | ||
public abstract static class Builder { | ||
|
||
|
@@ -408,6 +522,8 @@ Builder setRetentionExpirationTimeOffsetDateTime(OffsetDateTime retentionExpirat | |
return setRetentionExpirationTime(millisOffsetDateTimeCodec.decode(retentionExpirationTime)); | ||
} | ||
|
||
public abstract Builder setRetention(Retention retention); | ||
|
||
/** Creates a {@code BlobInfo} object. */ | ||
public abstract BlobInfo build(); | ||
|
||
|
@@ -506,6 +622,7 @@ static final class BuilderImpl extends Builder { | |
private Boolean eventBasedHold; | ||
private Boolean temporaryHold; | ||
private OffsetDateTime retentionExpirationTime; | ||
private Retention retention; | ||
private final ImmutableSet.Builder<NamedField> modifiedFields = ImmutableSet.builder(); | ||
|
||
BuilderImpl(BlobId blobId) { | ||
|
@@ -543,6 +660,7 @@ static final class BuilderImpl extends Builder { | |
eventBasedHold = blobInfo.eventBasedHold; | ||
temporaryHold = blobInfo.temporaryHold; | ||
retentionExpirationTime = blobInfo.retentionExpirationTime; | ||
this.retention = blobInfo.retention; | ||
} | ||
|
||
@Override | ||
|
@@ -916,6 +1034,15 @@ Builder setRetentionExpirationTimeOffsetDateTime(OffsetDateTime retentionExpirat | |
return this; | ||
} | ||
|
||
@Override | ||
public Builder setRetention(Retention retention) { | ||
if (!Objects.equals(this.retention, retention)) { | ||
modifiedFields.add(BlobField.RETENTION); | ||
} | ||
this.retention = retention; | ||
return this; | ||
} | ||
|
||
@Override | ||
public BlobInfo build() { | ||
checkNotNull(blobId); | ||
|
@@ -1139,6 +1266,7 @@ Builder clearRetentionExpirationTime() { | |
eventBasedHold = builder.eventBasedHold; | ||
temporaryHold = builder.temporaryHold; | ||
retentionExpirationTime = builder.retentionExpirationTime; | ||
retention = builder.retention; | ||
modifiedFields = builder.modifiedFields.build(); | ||
} | ||
|
||
|
@@ -1532,6 +1660,11 @@ public OffsetDateTime getRetentionExpirationTimeOffsetDateTime() { | |
return retentionExpirationTime; | ||
} | ||
|
||
/** Returns the object's Retention policy. */ | ||
public Retention getRetention() { | ||
return retention; | ||
} | ||
|
||
/** Returns a builder for the current blob. */ | ||
public Builder toBuilder() { | ||
return new BuilderImpl(this); | ||
|
@@ -1581,6 +1714,7 @@ public int hashCode() { | |
kmsKeyName, | ||
eventBasedHold, | ||
temporaryHold, | ||
retention, | ||
retentionExpirationTime); | ||
} | ||
|
||
|
@@ -1622,7 +1756,8 @@ public boolean equals(Object o) { | |
&& Objects.equals(kmsKeyName, blobInfo.kmsKeyName) | ||
&& Objects.equals(eventBasedHold, blobInfo.eventBasedHold) | ||
&& Objects.equals(temporaryHold, blobInfo.temporaryHold) | ||
&& Objects.equals(retentionExpirationTime, blobInfo.retentionExpirationTime); | ||
&& Objects.equals(retentionExpirationTime, blobInfo.retentionExpirationTime) | ||
&& Objects.equals(retention, blobInfo.retention); | ||
} | ||
|
||
ImmutableSet<NamedField> getModifiedFields() { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the conclusion on detecting if a user set retention to null vs. it not being modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't work, due to the modified fields not being passed along to the final patch call. I talked to ben and we agreed to just do it this way, there's precedent for it in the logging encoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying, is this value mutable once set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only certain cases work (i.e. going from Unlocked to Locked, reducing the retainUntilTime on an unlocked policy, and setting to null), and you have to pass in
overrideUnlockedRetention
for any of those cases to work, but yes