Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#2822] feat(core): support catalog events for event listener (#2891)

FANNG6a8cf806c57d
diff --git a/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java b/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
index e224fa48b2..1286b8c9c9 100644
--- a/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
+++ b/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
@@ -6,6 +6,8 @@ package com.datastrato.gravitino;
import com.datastrato.gravitino.authorization.AccessControlManager;
import com.datastrato.gravitino.auxiliary.AuxiliaryServiceManager;
+import com.datastrato.gravitino.catalog.CatalogDispatcher;
+import com.datastrato.gravitino.catalog.CatalogEventDispatcher;
import com.datastrato.gravitino.catalog.CatalogManager;
import com.datastrato.gravitino.catalog.FilesetDispatcher;
import com.datastrato.gravitino.catalog.FilesetEventDispatcher;
@@ -41,6 +43,8 @@ public class GravitinoEnv {
private EntityStore entityStore;
+ private CatalogDispatcher catalogDispatcher;
+
private CatalogManager catalogManager;
private SchemaDispatcher schemaDispatcher;
@@ -131,6 +135,8 @@ public class GravitinoEnv {
// Create and initialize Catalog related modules
this.catalogManager = new CatalogManager(config, entityStore, idGenerator);
+ this.catalogDispatcher = new CatalogEventDispatcher(eventBus, catalogManager);
+
SchemaOperationDispatcher schemaOperationDispatcher =
new SchemaOperationDispatcher(catalogManager, entityStore, idGenerator);
this.schemaDispatcher = new SchemaEventDispatcher(eventBus, schemaOperationDispatcher);
@@ -180,12 +186,12 @@ public class GravitinoEnv {
}
/**
- * Get the CatalogManager associated with the Gravitino environment.
+ * Get the CatalogDispatcher associated with the Gravitino environment.
*
- * @return The CatalogManager instance.
+ * @return The CatalogDispatcher instance.
*/
- public CatalogManager catalogManager() {
- return catalogManager;
+ public CatalogDispatcher catalogDispatcher() {
+ return catalogDispatcher;
}
/**
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogDispatcher.java
new file mode 100644
index 0000000000..a1d4d4031b
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogDispatcher.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.SupportsCatalogs;
+
+/**
+ * {@code CatalogDispatcher} interface acts as a specialization of the {@link SupportsCatalogs}
+ * interface. This interface is designed to potentially add custom behaviors or operations related
+ * to dispatching or handling catalog-related events or actions that are not covered by the standard
+ * {@code SupportsCatalogs} operations.
+ */
+public interface CatalogDispatcher extends SupportsCatalogs {}
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogEventDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogEventDispatcher.java
new file mode 100644
index 0000000000..dc8e1dbb57
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogEventDispatcher.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.catalog;
+
+import com.datastrato.gravitino.Catalog;
+import com.datastrato.gravitino.CatalogChange;
+import com.datastrato.gravitino.NameIdentifier;
+import com.datastrato.gravitino.Namespace;
+import com.datastrato.gravitino.exceptions.CatalogAlreadyExistsException;
+import com.datastrato.gravitino.exceptions.NoSuchCatalogException;
+import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
+import com.datastrato.gravitino.listener.EventBus;
+import com.datastrato.gravitino.listener.api.event.AlterCatalogEvent;
+import com.datastrato.gravitino.listener.api.event.AlterCatalogFailureEvent;
+import com.datastrato.gravitino.listener.api.event.CreateCatalogEvent;
+import com.datastrato.gravitino.listener.api.event.CreateCatalogFailureEvent;
+import com.datastrato.gravitino.listener.api.event.DropCatalogEvent;
+import com.datastrato.gravitino.listener.api.event.DropCatalogFailureEvent;
+import com.datastrato.gravitino.listener.api.event.ListCatalogEvent;
+import com.datastrato.gravitino.listener.api.event.ListCatalogFailureEvent;
+import com.datastrato.gravitino.listener.api.event.LoadCatalogEvent;
+import com.datastrato.gravitino.listener.api.event.LoadCatalogFailureEvent;
+import com.datastrato.gravitino.listener.api.info.CatalogInfo;
+import com.datastrato.gravitino.utils.PrincipalUtils;
+import java.util.Map;
+
+/**
+ * {@code CatalogEventDispatcher} is a decorator for {@link CatalogDispatcher} that not only
+ * delegates catalog 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 catalog operations.
+ */
+public class CatalogEventDispatcher implements CatalogDispatcher {
+ private final EventBus eventBus;
+ private final CatalogDispatcher dispatcher;
+
+ /**
+ * Constructs a CatalogEventDispatcher with a specified EventBus and CatalogDispatcher.
+ *
+ * @param eventBus The EventBus to which events will be dispatched.
+ * @param dispatcher The underlying {@link CatalogDispatcher} that will perform the actual catalog
+ * operations.
+ */
+ public CatalogEventDispatcher(EventBus eventBus, CatalogDispatcher dispatcher) {
+ this.eventBus = eventBus;
+ this.dispatcher = dispatcher;
+ }
+
+ @Override
+ public NameIdentifier[] listCatalogs(Namespace namespace) throws NoSuchMetalakeException {
+ try {
+ NameIdentifier[] nameIdentifiers = dispatcher.listCatalogs(namespace);
+ eventBus.dispatchEvent(new ListCatalogEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ return nameIdentifiers;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new ListCatalogFailureEvent(PrincipalUtils.getCurrentUserName(), e, namespace));
+ throw e;
+ }
+ }
+
+ @Override
+ public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {
+ try {
+ Catalog[] catalogs = dispatcher.listCatalogsInfo(namespace);
+ eventBus.dispatchEvent(new ListCatalogEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ return catalogs;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new ListCatalogFailureEvent(PrincipalUtils.getCurrentUserName(), e, namespace));
+ throw e;
+ }
+ }
+
+ @Override
+ public Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {
+ try {
+ Catalog catalog = dispatcher.loadCatalog(ident);
+ eventBus.dispatchEvent(
+ new LoadCatalogEvent(
+ PrincipalUtils.getCurrentUserName(), ident, new CatalogInfo(catalog)));
+ return catalog;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new LoadCatalogFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public Catalog createCatalog(
+ NameIdentifier ident,
+ Catalog.Type type,
+ String provider,
+ String comment,
+ Map<String, String> properties)
+ throws NoSuchMetalakeException, CatalogAlreadyExistsException {
+ try {
+ Catalog catalog = dispatcher.createCatalog(ident, type, provider, comment, properties);
+ eventBus.dispatchEvent(
+ new CreateCatalogEvent(
+ PrincipalUtils.getCurrentUserName(), ident, new CatalogInfo(catalog)));
+ return catalog;
+ } catch (Exception e) {
+ CatalogInfo createCatalogRequest =
+ new CatalogInfo(ident.name(), type, provider, comment, properties, null);
+ eventBus.dispatchEvent(
+ new CreateCatalogFailureEvent(
+ PrincipalUtils.getCurrentUserName(), ident, e, createCatalogRequest));
+ throw e;
+ }
+ }
+
+ @Override
+ public Catalog alterCatalog(NameIdentifier ident, CatalogChange... changes)
+ throws NoSuchCatalogException, IllegalArgumentException {
+ try {
+ Catalog catalog = dispatcher.alterCatalog(ident, changes);
+ eventBus.dispatchEvent(
+ new AlterCatalogEvent(
+ PrincipalUtils.getCurrentUserName(), ident, changes, new CatalogInfo(catalog)));
+ return catalog;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new AlterCatalogFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e, changes));
+ throw e;
+ }
+ }
+
+ @Override
+ public boolean dropCatalog(NameIdentifier ident) {
+ try {
+ boolean isExists = dispatcher.dropCatalog(ident);
+ eventBus.dispatchEvent(
+ new DropCatalogEvent(PrincipalUtils.getCurrentUserName(), ident, isExists));
+ return isExists;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new DropCatalogFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e));
+ throw e;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java
index 93857febf1..884a5adfff 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java
@@ -22,7 +22,6 @@ import com.datastrato.gravitino.EntityStore;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.StringIdentifier;
-import com.datastrato.gravitino.SupportsCatalogs;
import com.datastrato.gravitino.connector.BaseCatalog;
import com.datastrato.gravitino.connector.HasPropertyMetadata;
import com.datastrato.gravitino.connector.capability.Capability;
@@ -73,7 +72,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Manages the catalog instances and operations. */
-public class CatalogManager implements SupportsCatalogs, Closeable {
+public class CatalogManager implements CatalogDispatcher, Closeable {
private static final String CATALOG_DOES_NOT_EXIST_MSG = "Catalog %s does not exist";
private static final String METALAKE_DOES_NOT_EXIST_MSG = "Metalake %s does not exist";
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterCatalogEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterCatalogEvent.java
new file mode 100644
index 0000000000..8d712f75cf
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterCatalogEvent.java
@@ -0,0 +1,60 @@
+/*
+ * 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.CatalogChange;
+import com.datastrato.gravitino.NameIdentifier;
+import com.datastrato.gravitino.annotation.DeveloperApi;
+import com.datastrato.gravitino.listener.api.info.CatalogInfo;
+
+/** Represents an event triggered upon the successful creation of a catalog. */
+@DeveloperApi
+public final class AlterCatalogEvent extends CatalogEvent {
+ private final CatalogInfo updatedCatalogInfo;
+ private final CatalogChange[] catalogChanges;
+
+ /**
+ * Constructs an instance of {@code AlterCatalogEvent}, encapsulating the key details about the
+ * successful alteration of a catalog.
+ *
+ * @param user The username of the individual responsible for initiating the catalog alteration.
+ * @param identifier The unique identifier of the altered catalog, serving as a clear reference
+ * point for the catalog in question.
+ * @param catalogChanges An array of {@link CatalogChange} objects representing the specific
+ * changes applied to the catalog during the alteration process.
+ * @param updatedCatalogInfo The post-alteration state of the catalog.
+ */
+ public AlterCatalogEvent(
+ String user,
+ NameIdentifier identifier,
+ CatalogChange[] catalogChanges,
+ CatalogInfo updatedCatalogInfo) {
+ super(user, identifier);
+ this.catalogChanges = catalogChanges.clone();
+ this.updatedCatalogInfo = updatedCatalogInfo;
+ }
+
+ /**
+ * Retrieves the final state of the catalog as it was returned to the user after successful
+ * creation.
+ *
+ * @return A {@link CatalogInfo} instance encapsulating the comprehensive details of the newly
+ * created catalog.
+ */
+ public CatalogInfo updatedCatalogInfo() {
+ return updatedCatalogInfo;
+ }
+
+ /**
+ * Retrieves the specific changes that were made to the catalog during the alteration process.
+ *
+ * @return An array of {@link CatalogChange} objects detailing each modification applied to the
+ * catalog.
+ */
+ public CatalogChange[] catalogChanges() {
+ return catalogChanges;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterCatalogFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterCatalogFailureEvent.java
new file mode 100644
index 0000000000..a47781cdf1
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterCatalogFailureEvent.java
@@ -0,0 +1,44 @@
+/*
+ * 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.CatalogChange;
+import com.datastrato.gravitino.NameIdentifier;
+import com.datastrato.gravitino.annotation.DeveloperApi;
+
+/**
+ * Represents an event that is generated when an attempt to create a catalog fails due to an
+ * exception.
+ */
+@DeveloperApi
+public final class AlterCatalogFailureEvent extends CatalogFailureEvent {
+ private final CatalogChange[] catalogChanges;
+
+ /**
+ * Constructs an {@code AlterCatalogFailureEvent} instance, capturing detailed information about
+ * the failed catalog alteration attempt.
+ *
+ * @param user The user who initiated the catalog alteration operation.
+ * @param identifier The identifier of the catalog that was attempted to be altered.
+ * @param exception The exception that was thrown during the catalog alteration operation.
+ * @param catalogChanges The changes that were attempted on the catalog.
+ */
+ public AlterCatalogFailureEvent(
+ String user, NameIdentifier identifier, Exception exception, CatalogChange[] catalogChanges) {
+ super(user, identifier, exception);
+ this.catalogChanges = catalogChanges.clone();
+ }
+
+ /**
+ * Retrieves the specific changes that were made to the catalog during the alteration process.
+ *
+ * @return An array of {@link CatalogChange} objects detailing each modification applied to the
+ * catalog.
+ */
+ public CatalogChange[] catalogChanges() {
+ return catalogChanges;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CatalogEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CatalogEvent.java
new file mode 100644
index 0000000000..03223c90ff
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CatalogEvent.java
@@ -0,0 +1,27 @@
+/*
+ * 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 catalog operations. This class extends
+ * {@link Event} to provide a more specific context involving operations on catalogs, such as
+ * creation, deletion, or modification.
+ */
+@DeveloperApi
+public abstract class CatalogEvent extends Event {
+ /**
+ * Constructs a new {@code CatalogEvent} with the specified user and catalog identifier.
+ *
+ * @param user The user responsible for triggering the catalog operation.
+ * @param identifier The identifier of the catalog involved in the operation.
+ */
+ protected CatalogEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CatalogFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CatalogFailureEvent.java
new file mode 100644
index 0000000000..80fbbffb16
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CatalogFailureEvent.java
@@ -0,0 +1,31 @@
+/*
+ * 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 catalog operation fails due to an
+ * exception. This class extends {@link FailureEvent} to provide a more specific context related to
+ * catalog operations, encapsulating details about the user who initiated the operation, the
+ * identifier of the catalog involved, and the exception that led to the failure.
+ */
+@DeveloperApi
+public abstract class CatalogFailureEvent extends FailureEvent {
+ /**
+ * Constructs a new {@code CatalogFailureEvent} instance, capturing information about the failed
+ * catalog operation.
+ *
+ * @param user The user associated with the failed catalog operation.
+ * @param identifier The identifier of the catalog that was involved in the failed operation.
+ * @param exception The exception that was thrown during the catalog operation, indicating the
+ * cause of the failure.
+ */
+ protected CatalogFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateCatalogEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateCatalogEvent.java
new file mode 100644
index 0000000000..8bc04f1895
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateCatalogEvent.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;
+import com.datastrato.gravitino.listener.api.info.CatalogInfo;
+
+/** Represents an event that is activated upon the successful creation of a catalog. */
+@DeveloperApi
+public class CreateCatalogEvent extends CatalogEvent {
+ private final CatalogInfo createdCatalogInfo;
+
+ /**
+ * Constructs an instance of {@code CreateCatalogEvent}, capturing essential details about the
+ * successful creation of a catalog.
+ *
+ * @param user The username of the individual who initiated the catalog creation.
+ * @param identifier The unique identifier of the catalog that was created.
+ * @param createdCatalogInfo The final state of the catalog post-creation.
+ */
+ public CreateCatalogEvent(
+ String user, NameIdentifier identifier, CatalogInfo createdCatalogInfo) {
+ super(user, identifier);
+ this.createdCatalogInfo = createdCatalogInfo;
+ }
+
+ /**
+ * Provides the final state of the catalog as it is presented to the user following the successful
+ * creation.
+ *
+ * @return A {@link CatalogInfo} object that encapsulates the detailed characteristics of the
+ * newly created catalog.
+ */
+ public CatalogInfo createdCatalogInfo() {
+ return createdCatalogInfo;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateCatalogFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateCatalogFailureEvent.java
new file mode 100644
index 0000000000..2194ce0b9b
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateCatalogFailureEvent.java
@@ -0,0 +1,50 @@
+/*
+ * 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.CatalogInfo;
+
+/**
+ * Represents an event that is generated when an attempt to create a catalog fails due to an
+ * exception.
+ */
+@DeveloperApi
+public final class CreateCatalogFailureEvent extends CatalogFailureEvent {
+ private final CatalogInfo createCatalogRequest;
+
+ /**
+ * Constructs a {@code CreateCatalogFailureEvent} instance, capturing detailed information about
+ * the failed catalog creation attempt.
+ *
+ * @param user The user who initiated the catalog creation operation.
+ * @param identifier The identifier of the catalog that was attempted to be created.
+ * @param exception The exception that was thrown during the catalog creation operation, providing
+ * insight into what went wrong.
+ * @param createCatalogRequest The original request information used to attempt to create the
+ * catalog. This includes details such as the intended catalog schema, properties, and other
+ * configuration options that were specified.
+ */
+ public CreateCatalogFailureEvent(
+ String user,
+ NameIdentifier identifier,
+ Exception exception,
+ CatalogInfo createCatalogRequest) {
+ super(user, identifier, exception);
+ this.createCatalogRequest = createCatalogRequest;
+ }
+
+ /**
+ * Retrieves the original request information for the attempted catalog creation.
+ *
+ * @return The {@link CatalogInfo} instance representing the request information for the failed
+ * catalog creation attempt.
+ */
+ public CatalogInfo createCatalogRequest() {
+ return createCatalogRequest;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropCatalogEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropCatalogEvent.java
new file mode 100644
index 0000000000..bf2f01effb
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropCatalogEvent.java
@@ -0,0 +1,39 @@
+/*
+ * 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 catalog is successfully dropped. */
+@DeveloperApi
+public final class DropCatalogEvent extends CatalogEvent {
+ private final boolean isExists;
+
+ /**
+ * Constructs a new {@code DropCatalogEvent} instance, encapsulating information about the outcome
+ * of a catalog drop operation.
+ *
+ * @param user The user who initiated the drop catalog operation.
+ * @param identifier The identifier of the catalog that was attempted to be dropped.
+ * @param isExists A boolean flag indicating whether the catalog existed at the time of the drop
+ * operation.
+ */
+ public DropCatalogEvent(String user, NameIdentifier identifier, boolean isExists) {
+ super(user, identifier);
+ this.isExists = isExists;
+ }
+
+ /**
+ * Retrieves the existence status of the catalog at the time of the drop operation.
+ *
+ * @return A boolean value indicating whether the catalog existed. {@code true} if the catalog
+ * existed, otherwise {@code false}.
+ */
+ public boolean isExists() {
+ return isExists;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropCatalogFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropCatalogFailureEvent.java
new file mode 100644
index 0000000000..48319ed8e4
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropCatalogFailureEvent.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 catalog fails due to an
+ * exception.
+ */
+@DeveloperApi
+public final class DropCatalogFailureEvent extends CatalogFailureEvent {
+ /**
+ * Constructs a new {@code DropCatalogFailureEvent} instance, capturing detailed information about
+ * the failed attempt to drop a catalog.
+ *
+ * @param user The user who initiated the drop catalog operation.
+ * @param identifier The identifier of the catalog that the operation attempted to drop.
+ * @param exception The exception that was thrown during the drop catalog operation, offering
+ * insights into what went wrong and why the operation failed.
+ */
+ public DropCatalogFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListCatalogEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListCatalogEvent.java
new file mode 100644
index 0000000000..37b4d666f9
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListCatalogEvent.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 catalogs. */
+@DeveloperApi
+public final class ListCatalogEvent extends CatalogEvent {
+ private final Namespace namespace;
+
+ /**
+ * Constructs an instance of {@code ListCatalogEvent}.
+ *
+ * @param user The username of the individual who initiated the catalog listing.
+ * @param namespace The namespace from which catalogs were listed.
+ */
+ public ListCatalogEvent(String user, Namespace namespace) {
+ super(user, NameIdentifier.of(namespace.toString()));
+ this.namespace = namespace;
+ }
+
+ /**
+ * Provides the namespace associated with this event.
+ *
+ * @return A {@link Namespace} instance from which catalogs were listed.
+ */
+ public Namespace namespace() {
+ return namespace;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListCatalogFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListCatalogFailureEvent.java
new file mode 100644
index 0000000000..30e4b24e3e
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListCatalogFailureEvent.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 catalogs within a namespace fails
+ * due to an exception.
+ */
+@DeveloperApi
+public final class ListCatalogFailureEvent extends CatalogFailureEvent {
+ private final Namespace namespace;
+
+ /**
+ * Constructs a {@code ListCatalogFailureEvent} instance.
+ *
+ * @param user The username of the individual who initiated the operation to list catalogs.
+ * @param namespace The namespace for which the catalog listing was attempted.
+ * @param exception The exception encountered during the attempt to list catalogs.
+ */
+ public ListCatalogFailureEvent(String user, Exception exception, Namespace namespace) {
+ super(user, NameIdentifier.of(namespace.toString()), exception);
+ this.namespace = namespace;
+ }
+
+ /**
+ * Provides the namespace associated with this event.
+ *
+ * @return A {@link Namespace} instance from which catalogs were listed.
+ */
+ public Namespace namespace() {
+ return namespace;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadCatalogEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadCatalogEvent.java
new file mode 100644
index 0000000000..f07d2cda6d
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadCatalogEvent.java
@@ -0,0 +1,38 @@
+/*
+ * 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.CatalogInfo;
+
+/** Represents an event triggered upon the successful loading of a catalog. */
+@DeveloperApi
+public final class LoadCatalogEvent extends CatalogEvent {
+ private final CatalogInfo loadedCatalogInfo;
+
+ /**
+ * Constructs an instance of {@code LoadCatalogEvent}.
+ *
+ * @param user The username of the individual who initiated the catalog loading.
+ * @param identifier The unique identifier of the catalog that was loaded.
+ * @param loadedCatalogInfo The state of the catalog post-loading.
+ */
+ public LoadCatalogEvent(String user, NameIdentifier identifier, CatalogInfo loadedCatalogInfo) {
+ super(user, identifier);
+ this.loadedCatalogInfo = loadedCatalogInfo;
+ }
+
+ /**
+ * Retrieves the state of the catalog as it was made available to the user after successful
+ * loading.
+ *
+ * @return A {@link CatalogInfo} instance encapsulating the details of the catalog as loaded.
+ */
+ public CatalogInfo loadedCatalogInfo() {
+ return loadedCatalogInfo;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadCatalogFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadCatalogFailureEvent.java
new file mode 100644
index 0000000000..3972fb0526
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadCatalogFailureEvent.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 catalog fails due to an exception. */
+@DeveloperApi
+public final class LoadCatalogFailureEvent extends CatalogFailureEvent {
+ /**
+ * Constructs a {@code LoadCatalogFailureEvent} instance.
+ *
+ * @param user The user who initiated the catalog loading operation.
+ * @param identifier The identifier of the catalog that the loading attempt was made for.
+ * @param exception The exception that was thrown during the catalog loading operation, offering
+ * insight into the issues encountered.
+ */
+ public LoadCatalogFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/info/CatalogInfo.java b/core/src/main/java/com/datastrato/gravitino/listener/api/info/CatalogInfo.java
new file mode 100644
index 0000000000..0e1f64f927
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/info/CatalogInfo.java
@@ -0,0 +1,119 @@
+/*
+ * 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.Catalog;
+import com.datastrato.gravitino.annotation.DeveloperApi;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/** Encapsulates read-only information about a catalog, intended for use in event listeners. */
+@DeveloperApi
+public final class CatalogInfo {
+ private final String name;
+ private final Catalog.Type type;
+ private final String provider;
+ @Nullable private final String comment;
+ private final Map<String, String> properties;
+ @Nullable private final Audit auditInfo;
+
+ /**
+ * Constructs catalog information from a given catalog instance.
+ *
+ * @param catalog The source catalog.
+ */
+ public CatalogInfo(Catalog catalog) {
+ this(
+ catalog.name(),
+ catalog.type(),
+ catalog.provider(),
+ catalog.comment(),
+ catalog.properties(),
+ catalog.auditInfo());
+ }
+
+ /**
+ * Constructs catalog information with specified details.
+ *
+ * @param name The catalog name.
+ * @param type The catalog type.
+ * @param provider The catalog provider.
+ * @param comment An optional comment about the catalog.
+ * @param properties Catalog properties.
+ * @param auditInfo Optional audit information.
+ */
+ public CatalogInfo(
+ String name,
+ Catalog.Type type,
+ String provider,
+ String comment,
+ Map<String, String> properties,
+ Audit auditInfo) {
+ this.name = name;
+ this.type = type;
+ this.provider = provider;
+ this.comment = comment;
+ this.properties = properties == null ? ImmutableMap.of() : ImmutableMap.copyOf(properties);
+ this.auditInfo = auditInfo;
+ }
+
+ /**
+ * Returns the catalog name.
+ *
+ * @return Catalog name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Returns the catalog type.
+ *
+ * @return Catalog type.
+ */
+ public Catalog.Type type() {
+ return type;
+ }
+
+ /**
+ * Returns the catalog provider.
+ *
+ * @return Catalog provider.
+ */
+ public String provider() {
+ return provider;
+ }
+
+ /**
+ * Returns an optional comment about the catalog.
+ *
+ * @return Catalog comment, or null if not provided.
+ */
+ @Nullable
+ public String comment() {
+ return comment;
+ }
+
+ /**
+ * Returns the catalog properties.
+ *
+ * @return An immutable map of catalog properties.
+ */
+ public Map<String, String> properties() {
+ return properties;
+ }
+
+ /**
+ * Returns optional audit information for the catalog.
+ *
+ * @return Audit information, or null if not provided.
+ */
+ @Nullable
+ public Audit auditInfo() {
+ return auditInfo;
+ }
+}
diff --git a/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java b/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
index 9dc90458ba..bc1182865b 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
@@ -6,7 +6,7 @@ package com.datastrato.gravitino.server;
import com.datastrato.gravitino.Configs;
import com.datastrato.gravitino.GravitinoEnv;
-import com.datastrato.gravitino.catalog.CatalogManager;
+import com.datastrato.gravitino.catalog.CatalogDispatcher;
import com.datastrato.gravitino.catalog.FilesetDispatcher;
import com.datastrato.gravitino.catalog.SchemaDispatcher;
import com.datastrato.gravitino.catalog.TableDispatcher;
@@ -77,7 +77,7 @@ public class GravitinoServer extends ResourceConfig {
@Override
protected void configure() {
bind(gravitinoEnv.metalakesManager()).to(MetalakeManager.class).ranked(1);
- bind(gravitinoEnv.catalogManager()).to(CatalogManager.class).ranked(1);
+ bind(gravitinoEnv.catalogDispatcher()).to(CatalogDispatcher.class).ranked(1);
bind(gravitinoEnv.schemaDispatcher()).to(SchemaDispatcher.class).ranked(1);
bind(gravitinoEnv.tableDispatcher()).to(TableDispatcher.class).ranked(1);
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java
index cefbca7b60..3abbeb20c5 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java
@@ -8,7 +8,7 @@ import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.CatalogChange;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
-import com.datastrato.gravitino.catalog.CatalogManager;
+import com.datastrato.gravitino.catalog.CatalogDispatcher;
import com.datastrato.gravitino.dto.requests.CatalogCreateRequest;
import com.datastrato.gravitino.dto.requests.CatalogUpdateRequest;
import com.datastrato.gravitino.dto.requests.CatalogUpdatesRequest;
@@ -45,13 +45,13 @@ public class CatalogOperations {
private static final Logger LOG = LoggerFactory.getLogger(CatalogOperations.class);
- private final CatalogManager manager;
+ private final CatalogDispatcher catalogDispatcher;
@Context private HttpServletRequest httpRequest;
@Inject
- public CatalogOperations(CatalogManager manager) {
- this.manager = manager;
+ public CatalogOperations(CatalogDispatcher catalogDispatcher) {
+ this.catalogDispatcher = catalogDispatcher;
}
@GET
@@ -70,10 +70,10 @@ public class CatalogOperations {
LockType.READ,
() -> {
if (verbose) {
- Catalog[] catalogs = manager.listCatalogsInfo(catalogNS);
+ Catalog[] catalogs = catalogDispatcher.listCatalogsInfo(catalogNS);
return Utils.ok(new CatalogListResponse(DTOConverters.toDTOs(catalogs)));
} else {
- NameIdentifier[] idents = manager.listCatalogs(catalogNS);
+ NameIdentifier[] idents = catalogDispatcher.listCatalogs(catalogNS);
return Utils.ok(new EntityListResponse(idents));
}
});
@@ -98,7 +98,7 @@ public class CatalogOperations {
NameIdentifier.ofMetalake(metalake),
LockType.WRITE,
() ->
- manager.createCatalog(
+ catalogDispatcher.createCatalog(
ident,
request.getType(),
request.getProvider(),
@@ -121,7 +121,8 @@ public class CatalogOperations {
try {
NameIdentifier ident = NameIdentifier.ofCatalog(metalakeName, catalogName);
Catalog catalog =
- TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> manager.loadCatalog(ident));
+ TreeLockUtils.doWithTreeLock(
+ ident, LockType.READ, () -> catalogDispatcher.loadCatalog(ident));
return Utils.ok(new CatalogResponse(DTOConverters.toDTO(catalog)));
} catch (Exception e) {
@@ -151,7 +152,7 @@ public class CatalogOperations {
TreeLockUtils.doWithTreeLock(
NameIdentifier.ofMetalake(metalakeName),
LockType.WRITE,
- () -> manager.alterCatalog(ident, changes));
+ () -> catalogDispatcher.alterCatalog(ident, changes));
return Utils.ok(new CatalogResponse(DTOConverters.toDTO(catalog)));
});
@@ -175,7 +176,7 @@ public class CatalogOperations {
TreeLockUtils.doWithTreeLock(
NameIdentifier.ofMetalake(metalakeName),
LockType.WRITE,
- () -> manager.dropCatalog(ident));
+ () -> catalogDispatcher.dropCatalog(ident));
if (!dropped) {
LOG.warn("Failed to drop catalog {} under metalake {}", catalogName, metalakeName);
}
diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.java
index 009b824e8a..2ffb138a45 100644
--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.java
+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.java
@@ -17,6 +17,7 @@ import com.datastrato.gravitino.Config;
import com.datastrato.gravitino.GravitinoEnv;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
+import com.datastrato.gravitino.catalog.CatalogDispatcher;
import com.datastrato.gravitino.catalog.CatalogManager;
import com.datastrato.gravitino.dto.CatalogDTO;
import com.datastrato.gravitino.dto.requests.CatalogCreateRequest;
@@ -91,7 +92,7 @@ public class TestCatalogOperations extends JerseyTest {
new AbstractBinder() {
@Override
protected void configure() {
- bind(manager).to(CatalogManager.class).ranked(2);
+ bind(manager).to(CatalogDispatcher.class).ranked(2);
bindFactory(MockServletRequestFactory.class).to(HttpServletRequest.class);
}
});