-
Notifications
You must be signed in to change notification settings - Fork 87
fix: fix object metadata and bucket label change tracking to be fine-grained #1830
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
Closed
Closed
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -44,7 +44,9 @@ | |
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.TimeUnit; | ||
| import javax.annotation.Nonnull; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| /** | ||
| * An object in Google Cloud Storage. A {@code Blob} object includes the {@code BlobId} instance, | ||
|
|
@@ -360,7 +362,14 @@ Builder setMediaLink(String mediaLink) { | |
| } | ||
|
|
||
| @Override | ||
| public Builder setMetadata(Map<String, String> metadata) { | ||
| @BetaApi | ||
| public Builder addAllMetadata(@Nonnull Map<@NonNull String, @Nullable String> newMetadata) { | ||
|
Collaborator
Author
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'm not tied to this name, would |
||
| infoBuilder.addAllMetadata(newMetadata); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public Builder setMetadata(@Nullable Map<@NonNull String, @Nullable String> metadata) { | ||
| infoBuilder.setMetadata(metadata); | ||
| return this; | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,22 +19,25 @@ | |
| import static com.google.cloud.storage.BackwardCompatibilityUtils.millisOffsetDateTimeCodec; | ||
| import static com.google.cloud.storage.BackwardCompatibilityUtils.millisUtcCodec; | ||
| import static com.google.cloud.storage.BackwardCompatibilityUtils.nullableDurationSecondsCodec; | ||
| import static com.google.cloud.storage.Utils.diffMaps; | ||
| import static com.google.common.base.MoreObjects.firstNonNull; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
| import static com.google.common.collect.Lists.newArrayList; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import com.google.api.client.json.jackson2.JacksonFactory; | ||
| import com.google.api.client.util.Data; | ||
| import com.google.api.client.util.DateTime; | ||
| import com.google.api.core.BetaApi; | ||
| import com.google.api.services.storage.model.Bucket.Lifecycle.Rule; | ||
| import com.google.cloud.storage.Acl.Entity; | ||
| import com.google.cloud.storage.BlobInfo.ImmutableEmptyMap; | ||
| import com.google.cloud.storage.Storage.BucketField; | ||
| import com.google.cloud.storage.TransportCompatibility.Transport; | ||
| import com.google.cloud.storage.UnifiedOpts.NamedField; | ||
| import com.google.common.base.MoreObjects; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import com.google.common.collect.Maps; | ||
| import com.google.common.collect.Streams; | ||
| import java.io.IOException; | ||
| import java.io.ObjectInputStream; | ||
|
|
@@ -43,6 +46,7 @@ | |
| import java.time.Duration; | ||
| import java.time.OffsetDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
@@ -100,7 +104,7 @@ public class BucketInfo implements Serializable { | |
| private final String location; | ||
| private final Rpo rpo; | ||
| private final StorageClass storageClass; | ||
| private final Map<String, String> labels; | ||
| @Nullable private final Map<String, String> labels; | ||
| private final String defaultKmsKeyName; | ||
| private final Boolean defaultEventBasedHold; | ||
| private final OffsetDateTime retentionEffectiveTime; | ||
|
|
@@ -111,7 +115,7 @@ public class BucketInfo implements Serializable { | |
| private final String locationType; | ||
| private final Logging logging; | ||
| private final CustomPlacementConfig customPlacementConfig; | ||
| private final transient ImmutableSet<Storage.BucketField> modifiedFields; | ||
| private final transient ImmutableSet<NamedField> modifiedFields; | ||
|
|
||
| /** | ||
| * non-private for backward compatibility on message class. log messages are now emitted from | ||
|
|
@@ -1476,8 +1480,27 @@ Builder setUpdateTimeOffsetDateTime(OffsetDateTime updateTime) { | |
| */ | ||
| public abstract Builder setDefaultAcl(Iterable<Acl> acl); | ||
|
|
||
| /** Sets the label of this bucket. */ | ||
| public abstract Builder setLabels(Map<String, String> labels); | ||
| /** | ||
| * Convenience method to add new labels values to any existing present labels. | ||
| * | ||
| * <p>If a key from {@code newLabels} overlaps with any existing key in {@link #getLabels()}, | ||
| * the new value will overwrite the old value. | ||
| * | ||
| * @see #setLabels(Map) | ||
| */ | ||
| @BetaApi | ||
| public abstract Builder addAllLabels(@NonNull Map<@NonNull String, @Nullable String> newLabels); | ||
|
Collaborator
Author
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'm not tied to this name, would |
||
|
|
||
| /** | ||
| * Sets the bucket's user provided labels. | ||
| * | ||
| * <p>This method will set the labels to exactly what is provided by {@code labels}. | ||
| * | ||
| * <p>If you instead want to add or modify existing values use {@link #addAllLabels(Map)}. | ||
| * | ||
| * @see #addAllLabels(Map) | ||
| */ | ||
| public abstract Builder setLabels(@Nullable Map<@NonNull String, @Nullable String> labels); | ||
|
|
||
| /** Sets the default Cloud KMS key name for this bucket. */ | ||
| public abstract Builder setDefaultKmsKeyName(String defaultKmsKeyName); | ||
|
|
@@ -1630,7 +1653,7 @@ static final class BuilderImpl extends Builder { | |
| private String locationType; | ||
| private Logging logging; | ||
| private CustomPlacementConfig customPlacementConfig; | ||
| private final ImmutableSet.Builder<Storage.BucketField> modifiedFields = ImmutableSet.builder(); | ||
| private final ImmutableSet.Builder<NamedField> modifiedFields = ImmutableSet.builder(); | ||
|
|
||
| BuilderImpl(String name) { | ||
| this.name = name; | ||
|
|
@@ -1910,19 +1933,25 @@ public Builder setDefaultAcl(Iterable<Acl> acl) { | |
| } | ||
|
|
||
| @Override | ||
| public Builder setLabels(Map<String, String> labels) { | ||
| if (labels != null) { | ||
| Map<String, String> tmp = | ||
| Maps.transformValues( | ||
| labels, | ||
| input -> { | ||
| // replace null values with empty strings | ||
| return input == null ? Data.nullOf(String.class) : input; | ||
| }); | ||
| if (!Objects.equals(this.labels, tmp)) { | ||
| modifiedFields.add(BucketField.LABELS); | ||
| public Builder addAllLabels(@NonNull Map<@NonNull String, @Nullable String> newLabels) { | ||
| requireNonNull(newLabels, "newLabels must be non null"); | ||
| HashMap<@NonNull String, @Nullable String> map = Utils.newHashMap(this.labels); | ||
| map.putAll(newLabels); | ||
| return setLabels(map); | ||
| } | ||
|
|
||
| @SuppressWarnings("UnnecessaryLocalVariable") | ||
| @Override | ||
| public Builder setLabels(@Nullable Map<@NonNull String, @Nullable String> labels) { | ||
| Map<String, String> left = this.labels; | ||
| Map<String, String> right = labels; | ||
| if (!Objects.equals(left, right)) { | ||
| diffMaps(BucketField.LABELS, left, right, modifiedFields::add); | ||
| if (right != null) { | ||
| this.labels = new HashMap<>(right); | ||
| } else { | ||
| this.labels = (Map<String, String>) Data.nullOf(ImmutableEmptyMap.class); | ||
| } | ||
| this.labels = tmp; | ||
| } | ||
| return this; | ||
| } | ||
|
|
@@ -2483,7 +2512,8 @@ public List<Acl> getDefaultAcl() { | |
| } | ||
|
|
||
| /** Returns the labels for this bucket. */ | ||
| public Map<String, String> getLabels() { | ||
| @Nullable | ||
| public Map<@NonNull String, @Nullable String> getLabels() { | ||
| return labels; | ||
| } | ||
|
|
||
|
|
@@ -2692,7 +2722,7 @@ Bucket asBucket(Storage storage) { | |
| return new Bucket(storage, new BucketInfo.BuilderImpl(this)); | ||
| } | ||
|
|
||
| ImmutableSet<BucketField> getModifiedFields() { | ||
| ImmutableSet<NamedField> getModifiedFields() { | ||
| return modifiedFields; | ||
| } | ||
|
|
||
|
|
||
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.
Intentional use of both
javax.annotation.Nonnullandorg.checkerframework.checker.nullness.qual.NonNull?