From 79bacb7de7f10d6327779d057e9d1976fd130b49 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 | 6 +++++- .../sns/SNSMessageFactorySpec.groovy | 1 + .../sns/SNSNotificationServiceImpl.java | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 5 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..b7b882943 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 @@ -35,6 +35,7 @@ @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) public class RenameTableMessage extends UpdateOrRenameTableMessageBase { + private final String newName; /** * Create a new RenameTableMessage. @@ -42,7 +43,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 +53,10 @@ public RenameTableMessage( @JsonProperty("timestamp") final long timestamp, @JsonProperty("requestId") final String requestId, @JsonProperty("name") final String name, + @JsonProperty("newName") final String newName, @JsonProperty("payload") final UpdatePayload payload ) { super(id, timestamp, requestId, name, payload, SNSMessageType.TABLE_RENAME); + this.newName = newName; } } 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..226175af7 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 renameTableMessage = (RenameTableMessage) message; + final RenameTableMessage voidRenameMessage = new RenameTableMessage(message.getId(), + message.getTimestamp(), message.getRequestId(), message.getName(), + renameTableMessage.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());