Skip to content
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

fix: remove server unimplemented GrpcStorageImpl#{get,list,create,delete}Notification #2710

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.google.cloud.storage.Utils.ifNonNull;
import static com.google.cloud.storage.Utils.lift;
import static com.google.cloud.storage.Utils.projectNameCodec;
import static com.google.cloud.storage.Utils.topicNameCodec;

import com.google.api.pathtemplate.PathTemplate;
import com.google.cloud.Binding;
Expand All @@ -37,8 +36,6 @@
import com.google.cloud.storage.BucketInfo.PublicAccessPrevention;
import com.google.cloud.storage.Conversions.Codec;
import com.google.cloud.storage.HmacKey.HmacKeyState;
import com.google.cloud.storage.NotificationInfo.EventType;
import com.google.cloud.storage.NotificationInfo.PayloadFormat;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand All @@ -52,8 +49,6 @@
import com.google.storage.v2.BucketAccessControl;
import com.google.storage.v2.CryptoKeyName;
import com.google.storage.v2.HmacKeyMetadata;
import com.google.storage.v2.NotificationConfig;
import com.google.storage.v2.NotificationConfigName;
import com.google.storage.v2.Object;
import com.google.storage.v2.ObjectAccessControl;
import com.google.storage.v2.ObjectChecksums;
Expand Down Expand Up @@ -107,8 +102,6 @@ final class GrpcConversions {
Codec.of(this::blobIdEncode, this::blobIdDecode);
private final Codec<BlobInfo, Object> blobInfoCodec =
Codec.of(this::blobInfoEncode, this::blobInfoDecode);
private final Codec<NotificationInfo, com.google.storage.v2.NotificationConfig>
notificationInfoCodec = Codec.of(this::notificationEncode, this::notificationDecode);
private final Codec<Policy, com.google.iam.v1.Policy> policyCodec =
Codec.of(this::policyEncode, this::policyDecode);
private final Codec<Binding, com.google.iam.v1.Binding> bindingCodec =
Expand Down Expand Up @@ -219,10 +212,6 @@ Codec<BlobInfo, Object> blobInfo() {
return blobInfoCodec;
}

Codec<NotificationInfo, com.google.storage.v2.NotificationConfig> notificationInfo() {
return notificationInfoCodec;
}

Codec<Policy, com.google.iam.v1.Policy> policyCodec() {
return policyCodec;
}
Expand Down Expand Up @@ -1003,56 +992,6 @@ private BlobInfo blobInfoDecode(Object from) {
return toBuilder.build();
}

private NotificationConfig notificationEncode(NotificationInfo from) {
NotificationConfig.Builder to = NotificationConfig.newBuilder();
String id = from.getNotificationId();
if (id != null) {
if (NotificationConfigName.isParsableFrom(id)) {
ifNonNull(id, to::setName);
} else {
NotificationConfigName name = NotificationConfigName.of("_", from.getBucket(), id);
to.setName(name.toString());
}
}
ifNonNull(from.getTopic(), topicNameCodec::encode, to::setTopic);
ifNonNull(from.getEtag(), to::setEtag);
ifNonNull(from.getEventTypes(), toImmutableListOf(EventType::name), to::addAllEventTypes);
ifNonNull(from.getCustomAttributes(), to::putAllCustomAttributes);
ifNonNull(from.getObjectNamePrefix(), to::setObjectNamePrefix);
ifNonNull(from.getPayloadFormat(), PayloadFormat::name, to::setPayloadFormat);
return to.build();
}

private NotificationInfo notificationDecode(NotificationConfig from) {
NotificationInfo.Builder to =
NotificationInfo.newBuilder(topicNameCodec.decode(from.getTopic()));
if (!from.getName().isEmpty()) {
NotificationConfigName parse = NotificationConfigName.parse(from.getName());
// the case where parse could return null is already guarded by the preceding isEmpty check
//noinspection DataFlowIssue
to.setNotificationId(parse.getNotificationConfig());
to.setBucket(parse.getBucket());
}
if (!from.getEtag().isEmpty()) {
to.setEtag(from.getEtag());
}
if (!from.getEventTypesList().isEmpty()) {
EventType[] eventTypes =
from.getEventTypesList().stream().map(EventType::valueOf).toArray(EventType[]::new);
to.setEventTypes(eventTypes);
}
if (!from.getCustomAttributesMap().isEmpty()) {
to.setCustomAttributes(from.getCustomAttributesMap());
}
if (!from.getObjectNamePrefix().isEmpty()) {
to.setObjectNamePrefix(from.getObjectNamePrefix());
}
if (!from.getPayloadFormat().isEmpty()) {
to.setPayloadFormat(PayloadFormat.valueOf(from.getPayloadFormat()));
}
return to.build();
}

private com.google.iam.v1.Policy policyEncode(Policy from) {
com.google.iam.v1.Policy.Builder to = com.google.iam.v1.Policy.newBuilder();
ifNonNull(from.getEtag(), byteStringB64StringCodec::decode, to::setEtag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,21 @@
import com.google.storage.v2.ComposeObjectRequest;
import com.google.storage.v2.ComposeObjectRequest.SourceObject;
import com.google.storage.v2.CreateBucketRequest;
import com.google.storage.v2.CreateNotificationConfigRequest;
import com.google.storage.v2.DeleteBucketRequest;
import com.google.storage.v2.DeleteNotificationConfigRequest;
import com.google.storage.v2.DeleteObjectRequest;
import com.google.storage.v2.GetBucketRequest;
import com.google.storage.v2.GetNotificationConfigRequest;
import com.google.storage.v2.GetObjectRequest;
import com.google.storage.v2.ListBucketsRequest;
import com.google.storage.v2.ListNotificationConfigsRequest;
import com.google.storage.v2.ListNotificationConfigsResponse;
import com.google.storage.v2.ListObjectsRequest;
import com.google.storage.v2.ListObjectsResponse;
import com.google.storage.v2.LockBucketRetentionPolicyRequest;
import com.google.storage.v2.NotificationConfig;
import com.google.storage.v2.NotificationConfigName;
import com.google.storage.v2.Object;
import com.google.storage.v2.ObjectAccessControl;
import com.google.storage.v2.ReadObjectRequest;
import com.google.storage.v2.RestoreObjectRequest;
import com.google.storage.v2.RewriteObjectRequest;
import com.google.storage.v2.RewriteResponse;
import com.google.storage.v2.StorageClient;
import com.google.storage.v2.StorageClient.ListNotificationConfigsPage;
import com.google.storage.v2.UpdateBucketRequest;
import com.google.storage.v2.UpdateObjectRequest;
import com.google.storage.v2.WriteObjectRequest;
Expand Down Expand Up @@ -1393,96 +1385,23 @@ public ServiceAccount getServiceAccount(String projectId) {

@Override
public Notification createNotification(String bucket, NotificationInfo notificationInfo) {
NotificationConfig encode = codecs.notificationInfo().encode(notificationInfo);
CreateNotificationConfigRequest req =
CreateNotificationConfigRequest.newBuilder()
.setParent(bucketNameCodec.encode(bucket))
.setNotificationConfig(encode)
.build();
GrpcCallContext retryContext = Retrying.newCallContext();
return Retrying.run(
getOptions(),
retryAlgorithmManager.getFor(req),
() -> storageClient.createNotificationConfigCallable().call(req, retryContext),
syntaxDecoders.notificationConfig);
return throwHttpJsonOnly(
fmtMethodName("createNotification", String.class, NotificationInfo.class));
}

@Override
public Notification getNotification(String bucket, String notificationId) {
String name;
if (NotificationConfigName.isParsableFrom(notificationId)) {
name = notificationId;
} else {
NotificationConfigName configName = NotificationConfigName.of("_", bucket, notificationId);
name = configName.toString();
}
GetNotificationConfigRequest req =
GetNotificationConfigRequest.newBuilder().setName(name).build();
GrpcCallContext retryContext = Retrying.newCallContext();
return Retrying.run(
getOptions(),
retryAlgorithmManager.getFor(req),
() -> {
try {
return storageClient.getNotificationConfigCallable().call(req, retryContext);
} catch (NotFoundException e) {
return null;
}
},
syntaxDecoders.notificationConfig);
return throwHttpJsonOnly(fmtMethodName("getNotification", String.class, String.class));
}

@Override
public List<Notification> listNotifications(String bucket) {
ListNotificationConfigsRequest req =
ListNotificationConfigsRequest.newBuilder()
.setParent(bucketNameCodec.encode(bucket))
.build();
ResultRetryAlgorithm<?> algorithm = retryAlgorithmManager.getFor(req);
GrpcCallContext retryContext = Retrying.newCallContext();
return Retrying.run(
getOptions(),
algorithm,
() -> storageClient.listNotificationConfigsPagedCallable().call(req, retryContext),
resp -> {
TransformingPageDecorator<
ListNotificationConfigsRequest,
ListNotificationConfigsResponse,
NotificationConfig,
ListNotificationConfigsPage,
Notification>
page =
new TransformingPageDecorator<>(
resp.getPage(), syntaxDecoders.notificationConfig, getOptions(), algorithm);
return ImmutableList.copyOf(page.iterateAll());
});
return throwHttpJsonOnly(fmtMethodName("listNotifications", String.class));
}

@Override
public boolean deleteNotification(String bucket, String notificationId) {
String name;
if (NotificationConfigName.isParsableFrom(notificationId)) {
name = notificationId;
} else {
NotificationConfigName configName = NotificationConfigName.of("_", bucket, notificationId);
name = configName.toString();
}
DeleteNotificationConfigRequest req =
DeleteNotificationConfigRequest.newBuilder().setName(name).build();
GrpcCallContext retryContext = Retrying.newCallContext();
return Boolean.TRUE.equals(
Retrying.run(
getOptions(),
retryAlgorithmManager.getFor(req),
() -> {
try {
storageClient.deleteNotificationConfigCallable().call(req, retryContext);
return true;
} catch (NotFoundException e) {
return false;
}
},
Decoder.identity()));
return throwHttpJsonOnly(fmtMethodName("deleteNotification", String.class, String.class));
}

@BetaApi
Expand Down Expand Up @@ -1519,8 +1438,6 @@ private final class SyntaxDecoders {
o -> codecs.blobInfo().decode(o).asBlob(GrpcStorageImpl.this);
final Decoder<com.google.storage.v2.Bucket, Bucket> bucket =
b -> codecs.bucketInfo().decode(b).asBucket(GrpcStorageImpl.this);
final Decoder<NotificationConfig, Notification> notificationConfig =
n -> codecs.notificationInfo().decode(n).asNotification(GrpcStorageImpl.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ final class JsonConversions {
// when converting from gRPC to apiary or vice-versa we want to preserve this property. Until
// such a time as the apiary model has a project field, we manually apply it with this name.
private static final String PROJECT_ID_FIELD_NAME = "x_project";
// gRPC has a NotificationConfig.name property which contains the bucket the config is associated
// with which that apiary doesn't have yet.
// when converting from gRPC to apiary or vice-versa we want to preserve this property. Until
// such a time as the apiary model has a bucket field, we manually apply it with this name.
private static final String NOTIFICATION_BUCKET_FIELD_NAME = "x_bucket";

private final Codec<Entity, String> entityCodec =
Codec.of(this::entityEncode, this::entityDecode);
Expand Down Expand Up @@ -882,7 +877,6 @@ private com.google.api.services.storage.model.Notification notificationEncode(
to.setEtag(from.getEtag());
to.setSelfLink(from.getSelfLink());
to.setTopic(from.getTopic());
ifNonNull(from.getBucket(), b -> to.set(NOTIFICATION_BUCKET_FIELD_NAME, b));
ifNonNull(from.getNotificationId(), to::setId);
ifNonNull(from.getCustomAttributes(), to::setCustomAttributes);
ifNonNull(from.getObjectNamePrefix(), to::setObjectNamePrefix);
Expand Down Expand Up @@ -922,7 +916,6 @@ private BucketInfo.HierarchicalNamespace hierarchicalNamespaceDecode(
private NotificationInfo notificationDecode(
com.google.api.services.storage.model.Notification from) {
NotificationInfo.Builder builder = new NotificationInfo.BuilderImpl(from.getTopic());
ifNonNull(from.get(NOTIFICATION_BUCKET_FIELD_NAME), String.class::cast, builder::setBucket);
ifNonNull(from.getId(), builder::setNotificationId);
ifNonNull(from.getEtag(), builder::setEtag);
ifNonNull(from.getCustomAttributes(), builder::setCustomAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ public Builder setCustomAttributes(Map<String, String> customAttributes) {
return this;
}

@Override
Builder setBucket(String bucket) {
infoBuilder.setBucket(bucket);
return this;
}

@Override
public Notification build() {
return new Notification(storage, infoBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.core.InternalApi;
import com.google.api.pathtemplate.PathTemplate;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
Expand All @@ -35,13 +34,11 @@ public class NotificationInfo implements Serializable {
private static final PathTemplate PATH_TEMPLATE =
PathTemplate.createWithoutUrlEncoding("projects/{project}/topics/{topic}");

// TODO: Change to StringEnum in next major version
public enum PayloadFormat {
JSON_API_V1,
NONE
}

// TODO: Change to StringEnum in next major version
public enum EventType {
OBJECT_FINALIZE,
OBJECT_METADATA_UPDATE,
Expand All @@ -57,7 +54,6 @@ public enum EventType {
private final String objectNamePrefix;
private final String etag;
private final String selfLink;
private final String bucket;

/** Builder for {@code NotificationInfo}. */
public abstract static class Builder {
Expand All @@ -79,8 +75,6 @@ public abstract static class Builder {

public abstract Builder setCustomAttributes(Map<String, String> customAttributes);

abstract Builder setBucket(String bucket);

/** Creates a {@code NotificationInfo} object. */
public abstract NotificationInfo build();
}
Expand All @@ -96,7 +90,6 @@ public static class BuilderImpl extends Builder {
private String objectNamePrefix;
private String etag;
private String selfLink;
private String bucket;

BuilderImpl(String topic) {
this.topic = topic;
Expand All @@ -111,7 +104,6 @@ public static class BuilderImpl extends Builder {
customAttributes = notificationInfo.customAttributes;
payloadFormat = notificationInfo.payloadFormat;
objectNamePrefix = notificationInfo.objectNamePrefix;
bucket = notificationInfo.bucket;
}

@Override
Expand Down Expand Up @@ -164,12 +156,6 @@ public Builder setCustomAttributes(Map<String, String> customAttributes) {
return this;
}

@Override
Builder setBucket(String bucket) {
this.bucket = bucket;
return this;
}

public NotificationInfo build() {
checkNotNull(topic);
checkTopicFormat(topic);
Expand All @@ -186,7 +172,6 @@ public NotificationInfo build() {
customAttributes = builder.customAttributes;
payloadFormat = builder.payloadFormat;
objectNamePrefix = builder.objectNamePrefix;
bucket = builder.bucket;
}

/** Returns the service-generated id for the notification. */
Expand Down Expand Up @@ -240,15 +225,6 @@ public Map<String, String> getCustomAttributes() {
return customAttributes;
}

/**
* gRPC has the bucket name encoded in the notification name, use this internal property to track
* it.
*/
@InternalApi
String getBucket() {
return bucket;
}

@Override
public int hashCode() {
return Objects.hash(
Expand Down
Loading
Loading