From 73a37fe77b94c66189383da9489ef7fe49c674b4 Mon Sep 17 00:00:00 2001 From: jtian <86805957+insyncoss@users.noreply.github.com> Date: Mon, 6 May 2024 16:37:13 -0700 Subject: [PATCH] Publish new name on table rename event --- .../sns/messages/RenameTableMessage.java | 10 ++++++++-- .../UpdateOrRenameTableMessageBase.java | 4 +++- .../sns/SNSMessageFactorySpec.groovy | 1 + .../sns/SNSNotificationServiceImpl.java | 18 ++++++++++++++---- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/RenameTableMessage.java b/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/RenameTableMessage.java index e87458693..4e55a81f4 100644 --- a/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/RenameTableMessage.java +++ b/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/RenameTableMessage.java @@ -26,6 +26,8 @@ import lombok.Getter; import lombok.ToString; +import javax.annotation.Nullable; + /** * A message sent when a table is renamed. * @@ -35,6 +37,7 @@ @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) public class RenameTableMessage extends UpdateOrRenameTableMessageBase { + private final String newName; /** * Create a new RenameTableMessage. @@ -42,7 +45,8 @@ public class RenameTableMessage extends UpdateOrRenameTableMessageBase { * @param id The unique id of the message * @param timestamp The number of milliseconds since epoch that this message occurred * @param requestId The id of the API request that generated this and possibly other messages. Used for grouping - * @param name The qualified name of the resource that this notification is being generated for + * @param name The previous qualified name of the resource that this notification is being generated for + * @param newName The new qualified name of the resource that this notification is being generated for * @param payload The payload of the notification */ @JsonCreator @@ -51,8 +55,10 @@ public RenameTableMessage( @JsonProperty("timestamp") final long timestamp, @JsonProperty("requestId") final String requestId, @JsonProperty("name") final String name, - @JsonProperty("payload") final UpdatePayload payload + @JsonProperty("newName") final String newName, + @Nullable @JsonProperty("payload") final UpdatePayload payload ) { super(id, timestamp, requestId, name, payload, SNSMessageType.TABLE_RENAME); + this.newName = newName; } } diff --git a/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/UpdateOrRenameTableMessageBase.java b/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/UpdateOrRenameTableMessageBase.java index b81f5fef3..6639d0d54 100644 --- a/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/UpdateOrRenameTableMessageBase.java +++ b/metacat-common/src/main/java/com/netflix/metacat/common/dto/notifications/sns/messages/UpdateOrRenameTableMessageBase.java @@ -27,6 +27,8 @@ import lombok.Getter; import lombok.ToString; +import javax.annotation.Nullable; + /** * Base message type for Update and Rename messages. * @@ -53,7 +55,7 @@ public UpdateOrRenameTableMessageBase( @JsonProperty("timestamp") final long timestamp, @JsonProperty("requestId") final String requestId, @JsonProperty("name") final String name, - @JsonProperty("payload") final UpdatePayload payload, + @Nullable @JsonProperty("payload") final UpdatePayload payload, final SNSMessageType messageType ) { super(id, timestamp, requestId, messageType, name, payload); diff --git a/metacat-common/src/test/groovy/com/netflix/metacat/common/dto/notifications/sns/SNSMessageFactorySpec.groovy b/metacat-common/src/test/groovy/com/netflix/metacat/common/dto/notifications/sns/SNSMessageFactorySpec.groovy index d0c4a312b..ec477552a 100644 --- a/metacat-common/src/test/groovy/com/netflix/metacat/common/dto/notifications/sns/SNSMessageFactorySpec.groovy +++ b/metacat-common/src/test/groovy/com/netflix/metacat/common/dto/notifications/sns/SNSMessageFactorySpec.groovy @@ -92,6 +92,7 @@ class SNSMessageFactorySpec extends Specification { Instant.now().toEpochMilli(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), + UUID.randomUUID().toString(), new UpdatePayload( new TableDto(), JsonDiff.asJsonPatch( diff --git a/metacat-main/src/main/java/com/netflix/metacat/main/services/notifications/sns/SNSNotificationServiceImpl.java b/metacat-main/src/main/java/com/netflix/metacat/main/services/notifications/sns/SNSNotificationServiceImpl.java index 3142ae0f0..db1dc5b90 100644 --- a/metacat-main/src/main/java/com/netflix/metacat/main/services/notifications/sns/SNSNotificationServiceImpl.java +++ b/metacat-main/src/main/java/com/netflix/metacat/main/services/notifications/sns/SNSNotificationServiceImpl.java @@ -349,11 +349,13 @@ private UpdateOrRenameTableMessageBase createUpdateorRenameTableMessage( new UpdatePayload<>(oldTable, patch) ); } else { + final QualifiedName newName = currentTable == null ? null : currentTable.getName(); return new RenameTableMessage( id, timestamp, requestId, name.toString(), + newName == null ? "" : newName.toString(), new UpdatePayload<>(oldTable, patch) ); } @@ -413,10 +415,18 @@ private void publishNotification( log.error("SNS Publish message failed.", exception); notificationMetric.counterIncrement( Metrics.CounterSNSNotificationPublishMessageSizeExceeded.getMetricName()); - final SNSMessage voidMessage = new SNSMessage<>(message.getId(), - message.getTimestamp(), message.getRequestId(), message.getType(), message.getName(), - null); - result = publishNotification(arn, this.mapper.writeValueAsString(voidMessage)); + if (message instanceof RenameTableMessage) { + final RenameTableMessage renameMessage = (RenameTableMessage) message; + final RenameTableMessage voidRenameMessage = new RenameTableMessage(renameMessage.getId(), + renameMessage.getTimestamp(), renameMessage.getRequestId(), renameMessage.getName(), + renameMessage.getNewName(), null); + result = publishNotification(arn, this.mapper.writeValueAsString(voidRenameMessage)); + } else { + final SNSMessage voidMessage = new SNSMessage<>(message.getId(), + message.getTimestamp(), message.getRequestId(), message.getType(), message.getName(), + null); + result = publishNotification(arn, this.mapper.writeValueAsString(voidMessage)); + } } log.info("Successfully published message to topic {} with id {}", arn, result.getMessageId()); log.debug("Successfully published message {} to topic {} with id {}", message, arn, result.getMessageId());