Skip to content

Commit

Permalink
Publish new name on table rename event
Browse files Browse the repository at this point in the history
  • Loading branch information
insyncoss committed May 8, 2024
1 parent 5d0a3a0 commit 73a37fe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import lombok.Getter;
import lombok.ToString;

import javax.annotation.Nullable;

/**
* A message sent when a table is renamed.
*
Expand All @@ -35,14 +37,16 @@
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class RenameTableMessage extends UpdateOrRenameTableMessageBase {
private final String newName;

/**
* Create a new RenameTableMessage.
*
* @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
Expand All @@ -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<TableDto> payload
@JsonProperty("newName") final String newName,
@Nullable @JsonProperty("payload") final UpdatePayload<TableDto> payload
) {
super(id, timestamp, requestId, name, payload, SNSMessageType.TABLE_RENAME);
this.newName = newName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import lombok.Getter;
import lombok.ToString;

import javax.annotation.Nullable;

/**
* Base message type for Update and Rename messages.
*
Expand All @@ -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<TableDto> payload,
@Nullable @JsonProperty("payload") final UpdatePayload<TableDto> payload,
final SNSMessageType messageType
) {
super(id, timestamp, requestId, messageType, name, payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class SNSMessageFactorySpec extends Specification {
Instant.now().toEpochMilli(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
new UpdatePayload<TableDto>(
new TableDto(),
JsonDiff.asJsonPatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down Expand Up @@ -413,10 +415,18 @@ private void publishNotification(
log.error("SNS Publish message failed.", exception);
notificationMetric.counterIncrement(
Metrics.CounterSNSNotificationPublishMessageSizeExceeded.getMetricName());
final SNSMessage<Void> 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<Void> 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());
Expand Down

0 comments on commit 73a37fe

Please sign in to comment.