World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#2966] feat(core): supports generate topic event (#2968)
FANNGb04efd01fcab
diff --git a/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java b/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.javaindex 02498d2d07..57c3ea18bc 100644--- a/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java+++ b/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java@@ -18,6 +18,8 @@ import com.datastrato.gravitino.catalog.SchemaOperationDispatcher;import com.datastrato.gravitino.catalog.TableDispatcher;import com.datastrato.gravitino.catalog.TableEventDispatcher;import com.datastrato.gravitino.catalog.TableOperationDispatcher;+import com.datastrato.gravitino.catalog.TopicDispatcher;+import com.datastrato.gravitino.catalog.TopicEventDispatcher;import com.datastrato.gravitino.catalog.TopicOperationDispatcher;import com.datastrato.gravitino.listener.EventBus;import com.datastrato.gravitino.listener.EventListenerManager;@@ -55,7 +57,7 @@ public class GravitinoEnv {private FilesetDispatcher filesetDispatcher;- private TopicOperationDispatcher topicOperationDispatcher;+ private TopicDispatcher topicDispatcher;private MetalakeDispatcher metalakeDispatcher;@@ -149,8 +151,9 @@ public class GravitinoEnv {FilesetOperationDispatcher filesetOperationDispatcher =new FilesetOperationDispatcher(catalogManager, entityStore, idGenerator);this.filesetDispatcher = new FilesetEventDispatcher(eventBus, filesetOperationDispatcher);- this.topicOperationDispatcher =+ TopicOperationDispatcher topicOperationDispatcher =new TopicOperationDispatcher(catalogManager, entityStore, idGenerator);+ this.topicDispatcher = new TopicEventDispatcher(eventBus, topicOperationDispatcher);// Create and initialize access control related modulesboolean enableAuthorization = config.get(Configs.ENABLE_AUTHORIZATION);@@ -225,12 +228,12 @@ public class GravitinoEnv {}/**- * Get the TopicOperationDispatcher associated with the Gravitino environment.+ * Get the TopicDispatcher associated with the Gravitino environment.*- * @return The TopicOperationDispatcher instance.+ * @return The TopicDispatcher instance.*/- public TopicOperationDispatcher topicOperationDispatcher() {- return topicOperationDispatcher;+ public TopicDispatcher topicDispatcher() {+ return topicDispatcher;}/**diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/TopicDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/TopicDispatcher.javanew file mode 100644index 0000000000..131a600c62--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/catalog/TopicDispatcher.java@@ -0,0 +1,16 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.catalog;++import com.datastrato.gravitino.messaging.TopicCatalog;++/**+ * {@code TopicDispatcher} interface acts as a specialization of the {@link TopicCatalog} interface.+ * This interface is designed to potentially add custom behaviors or operations related to+ * dispatching or handling topic-related events or actions that are not covered by the standard+ * {@code TopicCatalog} operations.+ */+public interface TopicDispatcher extends TopicCatalog {}diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/TopicEventDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/TopicEventDispatcher.javanew file mode 100644index 0000000000..9375cae604--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/catalog/TopicEventDispatcher.java@@ -0,0 +1,131 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.catalog;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.exceptions.NoSuchTopicException;+import com.datastrato.gravitino.exceptions.TopicAlreadyExistsException;+import com.datastrato.gravitino.listener.EventBus;+import com.datastrato.gravitino.listener.api.event.AlterTopicEvent;+import com.datastrato.gravitino.listener.api.event.AlterTopicFailureEvent;+import com.datastrato.gravitino.listener.api.event.CreateTopicEvent;+import com.datastrato.gravitino.listener.api.event.CreateTopicFailureEvent;+import com.datastrato.gravitino.listener.api.event.DropTopicEvent;+import com.datastrato.gravitino.listener.api.event.DropTopicFailureEvent;+import com.datastrato.gravitino.listener.api.event.ListTopicEvent;+import com.datastrato.gravitino.listener.api.event.ListTopicFailureEvent;+import com.datastrato.gravitino.listener.api.event.LoadTopicEvent;+import com.datastrato.gravitino.listener.api.event.LoadTopicFailureEvent;+import com.datastrato.gravitino.listener.api.info.TopicInfo;+import com.datastrato.gravitino.messaging.DataLayout;+import com.datastrato.gravitino.messaging.Topic;+import com.datastrato.gravitino.messaging.TopicChange;+import com.datastrato.gravitino.utils.PrincipalUtils;+import java.util.Map;++/**+ * {@code TopicEventDispatcher} is a decorator for {@link TopicDispatcher} that not only delegates+ * topic operations to the underlying catalog dispatcher but also dispatches corresponding events to+ * an {@link EventBus} after each operation is completed. This allows for event-driven workflows or+ * monitoring of topic operations.+ */+public class TopicEventDispatcher implements TopicDispatcher {+ private final EventBus eventBus;+ private final TopicDispatcher dispatcher;++ /**+ * Constructs a TopicEventDispatcher with a specified EventBus and TopicCatalog.+ *+ * @param eventBus The EventBus to which events will be dispatched.+ * @param dispatcher The underlying {@link TopicDispatcher} that will perform the actual topic+ * operations.+ */+ public TopicEventDispatcher(EventBus eventBus, TopicDispatcher dispatcher) {+ this.eventBus = eventBus;+ this.dispatcher = dispatcher;+ }++ @Override+ public Topic alterTopic(NameIdentifier ident, TopicChange... changes)+ throws NoSuchTopicException, IllegalArgumentException {+ try {+ Topic topic = dispatcher.alterTopic(ident, changes);+ eventBus.dispatchEvent(+ new AlterTopicEvent(+ PrincipalUtils.getCurrentUserName(), ident, changes, new TopicInfo(topic)));+ return topic;+ } catch (Exception e) {+ eventBus.dispatchEvent(+ new AlterTopicFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e, changes));+ throw e;+ }+ }++ @Override+ public boolean dropTopic(NameIdentifier ident) {+ try {+ boolean isExists = dispatcher.dropTopic(ident);+ eventBus.dispatchEvent(+ new DropTopicEvent(PrincipalUtils.getCurrentUserName(), ident, isExists));+ return isExists;+ } catch (Exception e) {+ eventBus.dispatchEvent(+ new DropTopicFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e));+ throw e;+ }+ }++ @Override+ public NameIdentifier[] listTopics(Namespace namespace) throws NoSuchTopicException {+ try {+ NameIdentifier[] nameIdentifiers = dispatcher.listTopics(namespace);+ eventBus.dispatchEvent(new ListTopicEvent(PrincipalUtils.getCurrentUserName(), namespace));+ return nameIdentifiers;+ } catch (Exception e) {+ eventBus.dispatchEvent(+ new ListTopicFailureEvent(PrincipalUtils.getCurrentUserName(), namespace, e));+ throw e;+ }+ }++ @Override+ public Topic loadTopic(NameIdentifier ident) throws NoSuchTopicException {+ try {+ Topic topic = dispatcher.loadTopic(ident);+ eventBus.dispatchEvent(+ new LoadTopicEvent(PrincipalUtils.getCurrentUserName(), ident, new TopicInfo(topic)));+ return topic;+ } catch (Exception e) {+ eventBus.dispatchEvent(+ new LoadTopicFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e));+ throw e;+ }+ }++ @Override+ public boolean topicExists(NameIdentifier ident) {+ return dispatcher.topicExists(ident);+ }++ @Override+ public Topic createTopic(+ NameIdentifier ident, String comment, DataLayout dataLayout, Map<String, String> properties)+ throws NoSuchTopicException, TopicAlreadyExistsException {+ try {+ Topic topic = dispatcher.createTopic(ident, comment, dataLayout, properties);+ eventBus.dispatchEvent(+ new CreateTopicEvent(PrincipalUtils.getCurrentUserName(), ident, new TopicInfo(topic)));+ return topic;+ } catch (Exception e) {+ TopicInfo createTopicRequest = new TopicInfo(ident.name(), comment, properties, null);+ eventBus.dispatchEvent(+ new CreateTopicFailureEvent(+ PrincipalUtils.getCurrentUserName(), ident, e, createTopicRequest));+ throw e;+ }+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.javaindex 26c5962719..8935f4f651 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/TopicOperationDispatcher.java@@ -19,7 +19,6 @@ import com.datastrato.gravitino.exceptions.NoSuchTopicException;import com.datastrato.gravitino.exceptions.TopicAlreadyExistsException;import com.datastrato.gravitino.messaging.DataLayout;import com.datastrato.gravitino.messaging.Topic;-import com.datastrato.gravitino.messaging.TopicCatalog;import com.datastrato.gravitino.messaging.TopicChange;import com.datastrato.gravitino.meta.AuditInfo;import com.datastrato.gravitino.meta.TopicEntity;@@ -31,7 +30,7 @@ import org.apache.commons.lang3.StringUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-public class TopicOperationDispatcher extends OperationDispatcher implements TopicCatalog {+public class TopicOperationDispatcher extends OperationDispatcher implements TopicDispatcher {private static final Logger LOG = LoggerFactory.getLogger(TopicOperationDispatcher.class);/**diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterTopicEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterTopicEvent.javanew file mode 100644index 0000000000..c6a0b6961b--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterTopicEvent.java@@ -0,0 +1,58 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;+import com.datastrato.gravitino.listener.api.info.TopicInfo;+import com.datastrato.gravitino.messaging.TopicChange;++/** Represents an event fired when a topic is successfully altered. */+@DeveloperApi+public final class AlterTopicEvent extends TopicEvent {+ private final TopicInfo updatedTopicInfo;+ private final TopicChange[] topicChanges;++ /**+ * Constructs an instance of {@code AlterTopicEvent}, encapsulating the key details about the+ * successful alteration of a topic.+ *+ * @param user The username of the individual responsible for initiating the topic alteration.+ * @param identifier The unique identifier of the altered topic, serving as a clear reference+ * point for the topic in question.+ * @param topicChanges An array of {@link TopicChange} objects representing the specific changes+ * applied to the topic during the alteration process.+ * @param updatedTopicInfo The post-alteration state of the topic.+ */+ public AlterTopicEvent(+ String user,+ NameIdentifier identifier,+ TopicChange[] topicChanges,+ TopicInfo updatedTopicInfo) {+ super(user, identifier);+ this.topicChanges = topicChanges.clone();+ this.updatedTopicInfo = updatedTopicInfo;+ }++ /**+ * Retrieves the updated state of the topic after the successful alteration.+ *+ * @return A {@link TopicInfo} instance encapsulating the details of the altered topic.+ */+ public TopicInfo updatedTopicInfo() {+ return updatedTopicInfo;+ }++ /**+ * Retrieves the specific changes that were made to the topic during the alteration process.+ *+ * @return An array of {@link TopicChange} objects detailing each modification applied to the+ * topic.+ */+ public TopicChange[] topicChanges() {+ return topicChanges;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterTopicFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterTopicFailureEvent.javanew file mode 100644index 0000000000..dc20745026--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterTopicFailureEvent.java@@ -0,0 +1,43 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;+import com.datastrato.gravitino.messaging.TopicChange;++/**+ * Represents an event that is triggered when an attempt to alter a topic fails due to an exception.+ */+@DeveloperApi+public final class AlterTopicFailureEvent extends TopicFailureEvent {+ private final TopicChange[] topicChanges;++ /**+ * Constructs an {@code AlterTopicFailureEvent} instance, capturing detailed information about the+ * failed topic alteration attempt.+ *+ * @param user The user who initiated the topic alteration operation.+ * @param identifier The identifier of the topic that was attempted to be altered.+ * @param exception The exception that was thrown during the topic alteration operation.+ * @param topicChanges The changes that were attempted on the topic.+ */+ public AlterTopicFailureEvent(+ String user, NameIdentifier identifier, Exception exception, TopicChange[] topicChanges) {+ super(user, identifier, exception);+ this.topicChanges = topicChanges.clone();+ }++ /**+ * Retrieves the changes that were attempted on the topic.+ *+ * @return An array of {@link TopicChange} objects representing the attempted modifications to the+ * topic.+ */+ public TopicChange[] topicChanges() {+ return topicChanges;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateTopicEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateTopicEvent.javanew file mode 100644index 0000000000..f3418faf0f--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateTopicEvent.java@@ -0,0 +1,40 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;+import com.datastrato.gravitino.listener.api.info.TopicInfo;++/** Represents an event triggered upon the successful creation of a topic. */+@DeveloperApi+public final class CreateTopicEvent extends TopicEvent {+ private final TopicInfo createdTopicInfo;++ /**+ * Constructs an instance of {@code CreateTopicEvent}, capturing essential details about the+ * successful creation of a topic.+ *+ * @param user The username of the individual who initiated the topic creation.+ * @param identifier The unique identifier of the topic that was created.+ * @param createdTopicInfo The final state of the topic post-creation.+ */+ public CreateTopicEvent(String user, NameIdentifier identifier, TopicInfo createdTopicInfo) {+ super(user, identifier);+ this.createdTopicInfo = createdTopicInfo;+ }++ /**+ * Retrieves the final state of the topic as it was returned to the user after successful+ * creation.+ *+ * @return A {@link TopicInfo} instance encapsulating the comprehensive details of the newly+ * created topic.+ */+ public TopicInfo createdTopicInfo() {+ return createdTopicInfo;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateTopicFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateTopicFailureEvent.javanew file mode 100644index 0000000000..3ec9425a94--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateTopicFailureEvent.java@@ -0,0 +1,47 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;+import com.datastrato.gravitino.listener.api.info.TopicInfo;++/**+ * Represents an event that is generated when an attempt to create a topic fails due to an+ * exception.+ */+@DeveloperApi+public final class CreateTopicFailureEvent extends TopicFailureEvent {+ private final TopicInfo createTopicRequest;++ /**+ * Constructs a {@code CreateTopicFailureEvent} instance, capturing detailed information about the+ * failed topic creation attempt.+ *+ * @param user The user who initiated the topic creation operation.+ * @param identifier The identifier of the topic that was attempted to be created.+ * @param exception The exception that was thrown during the topic creation operation, providing+ * insight into what went wrong.+ * @param createTopicRequest The original request information used to attempt to create the topic.+ * This includes details such as the intended topic schema, properties, and other+ * configuration options that were specified.+ */+ public CreateTopicFailureEvent(+ String user, NameIdentifier identifier, Exception exception, TopicInfo createTopicRequest) {+ super(user, identifier, exception);+ this.createTopicRequest = createTopicRequest;+ }++ /**+ * Retrieves the original request information for the attempted topic creation.+ *+ * @return The {@link TopicInfo} instance representing the request information for the failed+ * topic creation attempt.+ */+ public TopicInfo createTopicRequest() {+ return createTopicRequest;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropTopicEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropTopicEvent.javanew file mode 100644index 0000000000..70051e6ae2--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropTopicEvent.java@@ -0,0 +1,41 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;++/**+ * Represents an event that is generated after a topic is successfully dropped from the database.+ */+@DeveloperApi+public final class DropTopicEvent extends TopicEvent {+ private final boolean isExists;++ /**+ * Constructs a new {@code DropTopicEvent} instance, encapsulating information about the outcome+ * of a topic drop operation.+ *+ * @param user The user who initiated the drop topic operation.+ * @param identifier The identifier of the topic that was attempted to be dropped.+ * @param isExists A boolean flag indicating whether the topic existed at the time of the drop+ * operation.+ */+ public DropTopicEvent(String user, NameIdentifier identifier, boolean isExists) {+ super(user, identifier);+ this.isExists = isExists;+ }++ /**+ * Retrieves the existence status of the topic at the time of the drop operation.+ *+ * @return A boolean value indicating whether the topic existed. {@code true} if the topic+ * existed, otherwise {@code false}.+ */+ public boolean isExists() {+ return isExists;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropTopicFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropTopicFailureEvent.javanew file mode 100644index 0000000000..5668783a66--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropTopicFailureEvent.java@@ -0,0 +1,29 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;++/**+ * Represents an event that is generated when an attempt to drop a topic from the database fails due+ * to an exception.+ */+@DeveloperApi+public final class DropTopicFailureEvent extends TopicFailureEvent {+ /**+ * Constructs a new {@code DropTopicFailureEvent} instance, capturing detailed information about+ * the failed attempt to drop a topic.+ *+ * @param user The user who initiated the drop topic operation.+ * @param identifier The identifier of the topic that the operation attempted to drop.+ * @param exception The exception that was thrown during the drop topic operation, offering+ * insights into what went wrong and why the operation failed.+ */+ public DropTopicFailureEvent(String user, NameIdentifier identifier, Exception exception) {+ super(user, identifier, exception);+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListTopicEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListTopicEvent.javanew file mode 100644index 0000000000..4eacc1fbf1--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListTopicEvent.java@@ -0,0 +1,36 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.annotation.DeveloperApi;++/** Represents an event that is triggered upon the successful list of topics within a namespace. */+@DeveloperApi+public final class ListTopicEvent extends TopicEvent {+ private final Namespace namespace;++ /**+ * Constructs an instance of {@code ListTopicEvent}.+ *+ * @param user The username of the individual who initiated the topic listing.+ * @param namespace The namespace from which topics were listed.+ */+ public ListTopicEvent(String user, Namespace namespace) {+ super(user, NameIdentifier.parse(namespace.toString()));+ this.namespace = namespace;+ }++ /**+ * Provides the namespace associated with this event.+ *+ * @return A {@link Namespace} instance from which topics were listed.+ */+ public Namespace namespace() {+ return namespace;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListTopicFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListTopicFailureEvent.javanew file mode 100644index 0000000000..e98212fb74--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListTopicFailureEvent.java@@ -0,0 +1,40 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.annotation.DeveloperApi;++/**+ * Represents an event that is triggered when an attempt to list topics within a namespace fails due+ * to an exception.+ */+@DeveloperApi+public final class ListTopicFailureEvent extends TopicFailureEvent {+ private final Namespace namespace;++ /**+ * Constructs a {@code ListTopicFailureEvent} instance.+ *+ * @param user The username of the individual who initiated the operation to list topics.+ * @param namespace The namespace for which the topic listing was attempted.+ * @param exception The exception encountered during the attempt to list topics.+ */+ public ListTopicFailureEvent(String user, Namespace namespace, Exception exception) {+ super(user, NameIdentifier.of(namespace.toString()), exception);+ this.namespace = namespace;+ }++ /**+ * Retrieves the namespace associated with this failure event.+ *+ * @return A {@link Namespace} instance for which the topic listing was attempted+ */+ public Namespace namespace() {+ return namespace;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadTopicEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadTopicEvent.javanew file mode 100644index 0000000000..ce516ffa9c--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadTopicEvent.java@@ -0,0 +1,37 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;+import com.datastrato.gravitino.listener.api.info.TopicInfo;++/** Represents an event triggered upon the successful loading of a topic. */+@DeveloperApi+public final class LoadTopicEvent extends TopicEvent {+ private final TopicInfo loadedTopicInfo;++ /**+ * Constructs an instance of {@code LoadTopicEvent}.+ *+ * @param user The username of the individual who initiated the topic loading.+ * @param identifier The unique identifier of the topic that was loaded.+ * @param topicInfo The state of the topic post-loading.+ */+ public LoadTopicEvent(String user, NameIdentifier identifier, TopicInfo topicInfo) {+ super(user, identifier);+ this.loadedTopicInfo = topicInfo;+ }++ /**+ * Retrieves the state of the topic as it was made available to the user after successful loading.+ *+ * @return A {@link TopicInfo} instance encapsulating the details of the topic as loaded.+ */+ public TopicInfo loadedTopicInfo() {+ return loadedTopicInfo;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadTopicFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadTopicFailureEvent.javanew file mode 100644index 0000000000..ee3f5b6401--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadTopicFailureEvent.java@@ -0,0 +1,25 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;++/** Represents an event that occurs when an attempt to load a topic fails due to an exception. */+@DeveloperApi+public final class LoadTopicFailureEvent extends TopicFailureEvent {+ /**+ * Constructs a {@code LoadTopicFailureEvent} instance.+ *+ * @param user The user who initiated the topic loading operation.+ * @param identifier The identifier of the topic that the loading attempt was made for.+ * @param exception The exception that was thrown during the topic loading operation, offering+ * insight into the issues encountered.+ */+ public LoadTopicFailureEvent(String user, NameIdentifier identifier, Exception exception) {+ super(user, identifier, exception);+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/TopicEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/TopicEvent.javanew file mode 100644index 0000000000..f6fadae14a--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/TopicEvent.java@@ -0,0 +1,32 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;++/**+ * Represents an abstract base class for events related to topic operations. This class extends+ * {@link Event} to provide a more specific context involving operations on topics, such as+ * creation, deletion, or modification. It captures essential information including the user+ * performing the operation and the identifier of the topic being operated on.+ *+ * <p>Concrete implementations of this class should provide additional details pertinent to the+ * specific type of topic operation being represented.+ */+@DeveloperApi+public abstract class TopicEvent extends Event {+ /**+ * Constructs a new {@code TopicEvent} with the specified user and topic identifier.+ *+ * @param user The user responsible for triggering the topic operation.+ * @param identifier The identifier of the topic involved in the operation. This encapsulates+ * details such as the metalake, catalog, schema, and topic name.+ */+ protected TopicEvent(String user, NameIdentifier identifier) {+ super(user, identifier);+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/TopicFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/TopicFailureEvent.javanew file mode 100644index 0000000000..a05b45862d--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/TopicFailureEvent.java@@ -0,0 +1,35 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.event;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.annotation.DeveloperApi;++/**+ * An abstract class representing events that are triggered when a topic operation fails due to an+ * exception. This class extends {@link FailureEvent} to provide a more specific context related to+ * topic operations, encapsulating details about the user who initiated the operation, the+ * identifier of the topic involved, and the exception that led to the failure.+ *+ * <p>Implementations of this class can be used to convey detailed information about failures in+ * operations such as creating, updating, deleting, or querying topics, making it easier to diagnose+ * and respond to issues.+ */+@DeveloperApi+public abstract class TopicFailureEvent extends FailureEvent {+ /**+ * Constructs a new {@code TopicFailureEvent} instance, capturing information about the failed+ * topic operation.+ *+ * @param user The user associated with the failed topic operation.+ * @param identifier The identifier of the topic that was involved in the failed operation.+ * @param exception The exception that was thrown during the topic operation, indicating the cause+ * of the failure.+ */+ protected TopicFailureEvent(String user, NameIdentifier identifier, Exception exception) {+ super(user, identifier, exception);+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/info/TopicInfo.java b/core/src/main/java/com/datastrato/gravitino/listener/api/info/TopicInfo.javanew file mode 100644index 0000000000..2c5f8bd05d--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/info/TopicInfo.java@@ -0,0 +1,84 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.gravitino.listener.api.info;++import com.datastrato.gravitino.Audit;+import com.datastrato.gravitino.annotation.DeveloperApi;+import com.datastrato.gravitino.messaging.Topic;+import com.google.common.collect.ImmutableMap;+import java.util.Map;+import javax.annotation.Nullable;++/** Provides read-only access to topic information for event listeners. */+@DeveloperApi+public final class TopicInfo {+ private final String name;+ @Nullable private final String comment;+ private final Map<String, String> properties;+ @Nullable private final Audit audit;++ /**+ * Constructs topic information based on a given topic.+ *+ * @param topic The topic to extract information from.+ */+ public TopicInfo(Topic topic) {+ this(topic.name(), topic.comment(), topic.properties(), topic.auditInfo());+ }++ /**+ * Constructs topic information with detailed parameters.+ *+ * @param name The name of the topic.+ * @param comment An optional description of the topic.+ * @param properties A map of topic properties.+ * @param audit Optional audit information.+ */+ public TopicInfo(String name, String comment, Map<String, String> properties, Audit audit) {+ this.name = name;+ this.comment = comment;+ this.properties = properties == null ? ImmutableMap.of() : ImmutableMap.copyOf(properties);+ this.audit = audit;+ }++ /**+ * Gets the topic name.+ *+ * @return The topic name.+ */+ public String name() {+ return name;+ }++ /**+ * Gets the optional topic comment.+ *+ * @return The topic comment, or null if not provided.+ */+ @Nullable+ public String comment() {+ return comment;+ }++ /**+ * Gets the topic properties.+ *+ * @return An immutable map of topic properties.+ */+ public Map<String, String> properties() {+ return properties;+ }++ /**+ * Gets the optional audit information.+ *+ * @return The audit information, or null if not provided.+ */+ @Nullable+ public Audit audit() {+ return audit;+ }+}diff --git a/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java b/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.javaindex 88ca4a815a..d54f3c8fdf 100644--- a/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java+++ b/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java@@ -10,6 +10,7 @@ import com.datastrato.gravitino.catalog.CatalogDispatcher;import com.datastrato.gravitino.catalog.FilesetDispatcher;import com.datastrato.gravitino.catalog.SchemaDispatcher;import com.datastrato.gravitino.catalog.TableDispatcher;+import com.datastrato.gravitino.catalog.TopicDispatcher;import com.datastrato.gravitino.metalake.MetalakeDispatcher;import com.datastrato.gravitino.metrics.MetricsSystem;import com.datastrato.gravitino.metrics.source.MetricsSource;@@ -82,9 +83,7 @@ public class GravitinoServer extends ResourceConfig {bind(gravitinoEnv.schemaDispatcher()).to(SchemaDispatcher.class).ranked(1);bind(gravitinoEnv.tableDispatcher()).to(TableDispatcher.class).ranked(1);bind(gravitinoEnv.filesetDispatcher()).to(FilesetDispatcher.class).ranked(1);- bind(gravitinoEnv.topicOperationDispatcher())- .to(com.datastrato.gravitino.catalog.TopicOperationDispatcher.class)- .ranked(1);+ bind(gravitinoEnv.topicDispatcher()).to(TopicDispatcher.class).ranked(1);}});register(ObjectMapperProvider.class).register(JacksonFeature.class);diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.javaindex c0b52751bb..bff22a9151 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java@@ -8,7 +8,7 @@ import com.codahale.metrics.annotation.ResponseMetered;import com.codahale.metrics.annotation.Timed;import com.datastrato.gravitino.NameIdentifier;import com.datastrato.gravitino.Namespace;-import com.datastrato.gravitino.catalog.TopicOperationDispatcher;+import com.datastrato.gravitino.catalog.TopicDispatcher;import com.datastrato.gravitino.dto.requests.TopicCreateRequest;import com.datastrato.gravitino.dto.requests.TopicUpdateRequest;import com.datastrato.gravitino.dto.requests.TopicUpdatesRequest;@@ -40,12 +40,12 @@ import org.slf4j.LoggerFactory;public class TopicOperations {private static final Logger LOG = LoggerFactory.getLogger(TopicOperations.class);- private final TopicOperationDispatcher dispatcher;+ private final TopicDispatcher dispatcher;@Context private HttpServletRequest httpRequest;@Inject- public TopicOperations(TopicOperationDispatcher dispatcher) {+ public TopicOperations(TopicDispatcher dispatcher) {this.dispatcher = dispatcher;}diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestTopicOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestTopicOperations.javaindex 35acfedf27..a65b75fdf4 100644--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestTopicOperations.java+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestTopicOperations.java@@ -16,6 +16,7 @@ import com.datastrato.gravitino.Audit;import com.datastrato.gravitino.Config;import com.datastrato.gravitino.GravitinoEnv;import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.catalog.TopicDispatcher;import com.datastrato.gravitino.catalog.TopicOperationDispatcher;import com.datastrato.gravitino.dto.messaging.TopicDTO;import com.datastrato.gravitino.dto.requests.TopicCreateRequest;@@ -91,7 +92,7 @@ public class TestTopicOperations extends JerseyTest {new AbstractBinder() {@Overrideprotected void configure() {- bind(dispatcher).to(TopicOperationDispatcher.class).ranked(2);+ bind(dispatcher).to(TopicDispatcher.class).ranked(2);bindFactory(TestTopicOperations.MockServletRequestFactory.class).to(HttpServletRequest.class);}