Skip to content

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

[#2769] feat(core): supports schema event for event listener (#2880)

FANNGd1d99954c0ab
diff --git a/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java b/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
index 61144fe3e4..e224fa48b2 100644
--- a/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
+++ b/core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
@@ -10,6 +10,8 @@ import com.datastrato.gravitino.catalog.CatalogManager;
import com.datastrato.gravitino.catalog.FilesetDispatcher;
import com.datastrato.gravitino.catalog.FilesetEventDispatcher;
import com.datastrato.gravitino.catalog.FilesetOperationDispatcher;
+import com.datastrato.gravitino.catalog.SchemaDispatcher;
+import com.datastrato.gravitino.catalog.SchemaEventDispatcher;
import com.datastrato.gravitino.catalog.SchemaOperationDispatcher;
import com.datastrato.gravitino.catalog.TableDispatcher;
import com.datastrato.gravitino.catalog.TableEventDispatcher;
@@ -41,7 +43,7 @@ public class GravitinoEnv {
private CatalogManager catalogManager;
- private SchemaOperationDispatcher schemaOperationDispatcher;
+ private SchemaDispatcher schemaDispatcher;
private TableDispatcher tableDispatcher;
@@ -129,8 +131,9 @@ public class GravitinoEnv {
// Create and initialize Catalog related modules
this.catalogManager = new CatalogManager(config, entityStore, idGenerator);
- this.schemaOperationDispatcher =
+ SchemaOperationDispatcher schemaOperationDispatcher =
new SchemaOperationDispatcher(catalogManager, entityStore, idGenerator);
+ this.schemaDispatcher = new SchemaEventDispatcher(eventBus, schemaOperationDispatcher);
TableOperationDispatcher tableOperationDispatcher =
new TableOperationDispatcher(catalogManager, entityStore, idGenerator);
this.tableDispatcher = new TableEventDispatcher(eventBus, tableOperationDispatcher);
@@ -186,12 +189,12 @@ public class GravitinoEnv {
}
/**
- * Get the SchemaOperationDispatcher associated with the Gravitino environment.
+ * Get the SchemaDispatcher associated with the Gravitino environment.
*
- * @return The SchemaOperationDispatcher instance.
+ * @return The SchemaDispatcher instance.
*/
- public SchemaOperationDispatcher schemaOperationDispatcher() {
- return schemaOperationDispatcher;
+ public SchemaDispatcher schemaDispatcher() {
+ return schemaDispatcher;
}
/**
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaDispatcher.java
new file mode 100644
index 0000000000..0667da3df9
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaDispatcher.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.rel.SupportsSchemas;
+
+/**
+ * {@code SchemaDispatcher} interface acts as a specialization of the {@link SupportsSchemas}
+ * interface. This interface is designed to potentially add custom behaviors or operations related
+ * to dispatching or handling schema-related events or actions that are not covered by the standard
+ * {@code SupportsSchemas} operations.
+ */
+public interface SchemaDispatcher extends SupportsSchemas {}
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaEventDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaEventDispatcher.java
new file mode 100644
index 0000000000..7ca3409394
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaEventDispatcher.java
@@ -0,0 +1,132 @@
+/*
+ * 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.NoSuchCatalogException;
+import com.datastrato.gravitino.exceptions.NoSuchSchemaException;
+import com.datastrato.gravitino.exceptions.NonEmptySchemaException;
+import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;
+import com.datastrato.gravitino.listener.EventBus;
+import com.datastrato.gravitino.listener.api.event.AlterSchemaEvent;
+import com.datastrato.gravitino.listener.api.event.AlterSchemaFailureEvent;
+import com.datastrato.gravitino.listener.api.event.CreateSchemaEvent;
+import com.datastrato.gravitino.listener.api.event.CreateSchemaFailureEvent;
+import com.datastrato.gravitino.listener.api.event.DropSchemaEvent;
+import com.datastrato.gravitino.listener.api.event.DropSchemaFailureEvent;
+import com.datastrato.gravitino.listener.api.event.ListSchemaEvent;
+import com.datastrato.gravitino.listener.api.event.ListSchemaFailureEvent;
+import com.datastrato.gravitino.listener.api.event.LoadSchemaEvent;
+import com.datastrato.gravitino.listener.api.event.LoadSchemaFailureEvent;
+import com.datastrato.gravitino.listener.api.info.SchemaInfo;
+import com.datastrato.gravitino.rel.Schema;
+import com.datastrato.gravitino.rel.SchemaChange;
+import com.datastrato.gravitino.utils.PrincipalUtils;
+import java.util.Map;
+
+/**
+ * {@code SchemaEventDispatcher} is a decorator for {@link SchemaDispatcher} that not only delegates
+ * schema operations to the underlying schema dispatcher but also dispatches corresponding events to
+ * an {@link EventBus} after each operation is completed. This allows for event-driven workflows or
+ * monitoring of schema operations.
+ */
+public class SchemaEventDispatcher implements SchemaDispatcher {
+ private final EventBus eventBus;
+ private final SchemaDispatcher dispatcher;
+
+ /**
+ * Constructs a SchemaEventDispatcher with a specified EventBus and SchemaDispatcher.
+ *
+ * @param eventBus The EventBus to which events will be dispatched.
+ * @param dispatcher The underlying {@link SchemaOperationDispatcher} that will perform the actual
+ * schema operations.
+ */
+ public SchemaEventDispatcher(EventBus eventBus, SchemaDispatcher dispatcher) {
+ this.eventBus = eventBus;
+ this.dispatcher = dispatcher;
+ }
+
+ @Override
+ public NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {
+ try {
+ NameIdentifier[] nameIdentifiers = dispatcher.listSchemas(namespace);
+ eventBus.dispatchEvent(new ListSchemaEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ return nameIdentifiers;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new ListSchemaFailureEvent(PrincipalUtils.getCurrentUserName(), namespace, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public boolean schemaExists(NameIdentifier ident) {
+ return dispatcher.schemaExists(ident);
+ }
+
+ @Override
+ public Schema createSchema(NameIdentifier ident, String comment, Map<String, String> properties)
+ throws NoSuchCatalogException, SchemaAlreadyExistsException {
+ try {
+ Schema schema = dispatcher.createSchema(ident, comment, properties);
+ eventBus.dispatchEvent(
+ new CreateSchemaEvent(
+ PrincipalUtils.getCurrentUserName(), ident, new SchemaInfo(schema)));
+ return schema;
+ } catch (Exception e) {
+ SchemaInfo createSchemaRequest = new SchemaInfo(ident.name(), comment, properties, null);
+ eventBus.dispatchEvent(
+ new CreateSchemaFailureEvent(
+ PrincipalUtils.getCurrentUserName(), ident, e, createSchemaRequest));
+ throw e;
+ }
+ }
+
+ @Override
+ public Schema loadSchema(NameIdentifier ident) throws NoSuchSchemaException {
+ try {
+ Schema schema = dispatcher.loadSchema(ident);
+ eventBus.dispatchEvent(
+ new LoadSchemaEvent(PrincipalUtils.getCurrentUserName(), ident, new SchemaInfo(schema)));
+ return schema;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new LoadSchemaFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)
+ throws NoSuchSchemaException {
+ try {
+ Schema schema = dispatcher.alterSchema(ident, changes);
+ eventBus.dispatchEvent(
+ new AlterSchemaEvent(
+ PrincipalUtils.getCurrentUserName(), ident, changes, new SchemaInfo(schema)));
+ return schema;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new AlterSchemaFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e, changes));
+ throw e;
+ }
+ }
+
+ @Override
+ public boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {
+ try {
+ boolean isExists = dispatcher.dropSchema(ident, cascade);
+ eventBus.dispatchEvent(
+ new DropSchemaEvent(PrincipalUtils.getCurrentUserName(), ident, isExists, cascade));
+ return isExists;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new DropSchemaFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e, cascade));
+ throw e;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java
index 20a952f0ae..b13124c3af 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaOperationDispatcher.java
@@ -21,7 +21,6 @@ import com.datastrato.gravitino.meta.AuditInfo;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.rel.Schema;
import com.datastrato.gravitino.rel.SchemaChange;
-import com.datastrato.gravitino.rel.SupportsSchemas;
import com.datastrato.gravitino.storage.IdGenerator;
import com.datastrato.gravitino.utils.PrincipalUtils;
import java.time.Instant;
@@ -29,7 +28,7 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SchemaOperationDispatcher extends OperationDispatcher implements SupportsSchemas {
+public class SchemaOperationDispatcher extends OperationDispatcher implements SchemaDispatcher {
private static final Logger LOG = LoggerFactory.getLogger(SchemaOperationDispatcher.class);
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterSchemaEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterSchemaEvent.java
new file mode 100644
index 0000000000..de32ec8206
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterSchemaEvent.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.SchemaInfo;
+import com.datastrato.gravitino.rel.SchemaChange;
+
+/** Represents an event fired when a schema is successfully altered. */
+@DeveloperApi
+public final class AlterSchemaEvent extends SchemaEvent {
+ private final SchemaChange[] schemaChanges;
+ private final SchemaInfo updatedSchemaInfo;
+
+ public AlterSchemaEvent(
+ String user,
+ NameIdentifier identifier,
+ SchemaChange[] schemaChanges,
+ SchemaInfo updatedSchemaInfo) {
+ super(user, identifier);
+ this.schemaChanges = schemaChanges.clone();
+ this.updatedSchemaInfo = updatedSchemaInfo;
+ }
+
+ /**
+ * Retrieves the updated state of the schema after the successful alteration.
+ *
+ * @return A {@link SchemaInfo} instance encapsulating the details of the altered schema.
+ */
+ public SchemaInfo updatedSchemaInfo() {
+ return updatedSchemaInfo;
+ }
+
+ /**
+ * Retrieves the specific changes that were made to the schema during the alteration process.
+ *
+ * @return An array of {@link SchemaChange} objects detailing each modification applied to the
+ * schema.
+ */
+ public SchemaChange[] schemaChanges() {
+ return schemaChanges;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterSchemaFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterSchemaFailureEvent.java
new file mode 100644
index 0000000000..a5b0643e9e
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/AlterSchemaFailureEvent.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;
+import com.datastrato.gravitino.rel.SchemaChange;
+
+/**
+ * Represents an event that is triggered when an attempt to alter a schema fails due to an
+ * exception.
+ */
+@DeveloperApi
+public final class AlterSchemaFailureEvent extends SchemaFailureEvent {
+ private final SchemaChange[] schemaChanges;
+
+ public AlterSchemaFailureEvent(
+ String user, NameIdentifier identifier, Exception exception, SchemaChange[] schemaChanges) {
+ super(user, identifier, exception);
+ this.schemaChanges = schemaChanges.clone();
+ }
+
+ /**
+ * Retrieves the specific changes that were made to the schema during the alteration process.
+ *
+ * @return An array of {@link SchemaChange} objects detailing each modification applied to the
+ * schema.
+ */
+ public SchemaChange[] schemaChanges() {
+ return schemaChanges;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateSchemaEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateSchemaEvent.java
new file mode 100644
index 0000000000..4c5f08e475
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateSchemaEvent.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;
+import com.datastrato.gravitino.listener.api.info.SchemaInfo;
+
+/** Represents an event triggered upon the successful creation of a schema. */
+@DeveloperApi
+public final class CreateSchemaEvent extends SchemaEvent {
+ private final SchemaInfo createdSchemaInfo;
+
+ public CreateSchemaEvent(String user, NameIdentifier identifier, SchemaInfo schemaInfo) {
+ super(user, identifier);
+ this.createdSchemaInfo = schemaInfo;
+ }
+
+ /**
+ * Retrieves the final state of the schema as it was returned to the user after successful
+ * creation.
+ *
+ * @return A {@link SchemaInfo} instance encapsulating the comprehensive details of the newly
+ * created schema.
+ */
+ public SchemaInfo createdSchemaInfo() {
+ return createdSchemaInfo;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateSchemaFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateSchemaFailureEvent.java
new file mode 100644
index 0000000000..5215d1b623
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/CreateSchemaFailureEvent.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;
+import com.datastrato.gravitino.listener.api.info.SchemaInfo;
+
+/**
+ * Represents an event that is generated when an attempt to create a schema fails due to an
+ * exception.
+ */
+@DeveloperApi
+public final class CreateSchemaFailureEvent extends SchemaFailureEvent {
+ private final SchemaInfo createSchemaRequest;
+
+ public CreateSchemaFailureEvent(
+ String user, NameIdentifier identifier, Exception exception, SchemaInfo createSchemaRequest) {
+ super(user, identifier, exception);
+ this.createSchemaRequest = createSchemaRequest;
+ }
+
+ /**
+ * Retrieves the original request information for the attempted schema creation.
+ *
+ * @return The {@link SchemaInfo} instance representing the request information for the failed
+ * schema creation attempt.
+ */
+ public SchemaInfo createSchemaRequest() {
+ return createSchemaRequest;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropSchemaEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropSchemaEvent.java
new file mode 100644
index 0000000000..6c1dbbda91
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropSchemaEvent.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.NameIdentifier;
+import com.datastrato.gravitino.annotation.DeveloperApi;
+
+/** Represents an event that is generated after a schema is successfully dropped. */
+@DeveloperApi
+public final class DropSchemaEvent extends SchemaEvent {
+ private final boolean isExists;
+ private final boolean cascade;
+
+ public DropSchemaEvent(
+ String user, NameIdentifier identifier, boolean isExists, boolean cascade) {
+ super(user, identifier);
+ this.isExists = isExists;
+ this.cascade = cascade;
+ }
+
+ /**
+ * Retrieves the existence status of the schema at the time of the drop operation.
+ *
+ * @return A boolean value indicating whether the schema existed. {@code true} if the schema
+ * existed, otherwise {@code false}.
+ */
+ public boolean isExists() {
+ return isExists;
+ }
+
+ /**
+ * Indicates whether the drop operation was performed with a cascade option.
+ *
+ * @return A boolean value indicating whether the drop operation was set to cascade. If {@code
+ * true}, dependent objects such as tables and views within the schema were also dropped.
+ * Otherwise, the operation would fail if the schema contained any dependent objects.
+ */
+ public boolean cascade() {
+ return cascade;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropSchemaFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropSchemaFailureEvent.java
new file mode 100644
index 0000000000..5fa43362e8
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/DropSchemaFailureEvent.java
@@ -0,0 +1,34 @@
+/*
+ * 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 schema fails due to an exception.
+ */
+@DeveloperApi
+public final class DropSchemaFailureEvent extends SchemaFailureEvent {
+ private final boolean cascade;
+
+ public DropSchemaFailureEvent(
+ String user, NameIdentifier identifier, Exception exception, boolean cascade) {
+ super(user, identifier, exception);
+ this.cascade = cascade;
+ }
+
+ /**
+ * Indicates whether the drop operation was performed with a cascade option.
+ *
+ * @return A boolean value indicating whether the drop operation was set to cascade. If {@code
+ * true}, dependent objects such as tables and views within the schema were also dropped.
+ * Otherwise, the operation would fail if the schema contained any dependent objects.
+ */
+ public boolean cascade() {
+ return cascade;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListSchemaEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListSchemaEvent.java
new file mode 100644
index 0000000000..dd13768aab
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListSchemaEvent.java
@@ -0,0 +1,30 @@
+/*
+ * 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 schemas. */
+@DeveloperApi
+public final class ListSchemaEvent extends SchemaEvent {
+ private final Namespace namespace;
+
+ public ListSchemaEvent(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 schema were listed.
+ */
+ public Namespace namespace() {
+ return namespace;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListSchemaFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListSchemaFailureEvent.java
new file mode 100644
index 0000000000..cb233503db
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/ListSchemaFailureEvent.java
@@ -0,0 +1,33 @@
+/*
+ * 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 schemas within a namespace fails
+ * due to an exception.
+ */
+@DeveloperApi
+public final class ListSchemaFailureEvent extends SchemaFailureEvent {
+ private final Namespace namespace;
+
+ public ListSchemaFailureEvent(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 schema listing was attempted
+ */
+ public Namespace namespace() {
+ return namespace;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadSchemaEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadSchemaEvent.java
new file mode 100644
index 0000000000..c941892302
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadSchemaEvent.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;
+import com.datastrato.gravitino.listener.api.info.SchemaInfo;
+
+/** Represents an event triggered upon the successful loading of a schema. */
+@DeveloperApi
+public final class LoadSchemaEvent extends SchemaEvent {
+ private final SchemaInfo loadedSchemaInfo;
+
+ public LoadSchemaEvent(String user, NameIdentifier identifier, SchemaInfo loadedSchemaInfo) {
+ super(user, identifier);
+ this.loadedSchemaInfo = loadedSchemaInfo;
+ }
+
+ /**
+ * Retrieves the state of the schema as it was made available to the user after successful
+ * loading.
+ *
+ * @return A {@link SchemaInfo} instance encapsulating the details of the schema as loaded.
+ */
+ public SchemaInfo loadedSchemaInfo() {
+ return loadedSchemaInfo;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadSchemaFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadSchemaFailureEvent.java
new file mode 100644
index 0000000000..c552568233
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/LoadSchemaFailureEvent.java
@@ -0,0 +1,17 @@
+/*
+ * 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 schema fails due to an exception. */
+@DeveloperApi
+public final class LoadSchemaFailureEvent extends SchemaFailureEvent {
+ public LoadSchemaFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/SchemaEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/SchemaEvent.java
new file mode 100644
index 0000000000..60b667afb3
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/SchemaEvent.java
@@ -0,0 +1,17 @@
+/*
+ * 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 schema operations. */
+@DeveloperApi
+public abstract class SchemaEvent extends Event {
+ protected SchemaEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/event/SchemaFailureEvent.java b/core/src/main/java/com/datastrato/gravitino/listener/api/event/SchemaFailureEvent.java
new file mode 100644
index 0000000000..3c0cd1e4af
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/event/SchemaFailureEvent.java
@@ -0,0 +1,20 @@
+/*
+ * 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 schema operation fails due to an
+ * exception.
+ */
+@DeveloperApi
+public abstract class SchemaFailureEvent extends FailureEvent {
+ protected SchemaFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/listener/api/info/SchemaInfo.java b/core/src/main/java/com/datastrato/gravitino/listener/api/info/SchemaInfo.java
new file mode 100644
index 0000000000..b16192f22c
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/listener/api/info/SchemaInfo.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.rel.Schema;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/** Provides read-only access to schema information for event listeners. */
+@DeveloperApi
+public final class SchemaInfo {
+ private final String name;
+ @Nullable private final String comment;
+ private final Map<String, String> properties;
+ @Nullable private final Audit audit;
+
+ /**
+ * Constructs schema information based on a given schema.
+ *
+ * @param schema The schema to extract information from.
+ */
+ public SchemaInfo(Schema schema) {
+ this(schema.name(), schema.comment(), schema.properties(), schema.auditInfo());
+ }
+
+ /**
+ * Constructs schema information with detailed parameters.
+ *
+ * @param name The name of the schema.
+ * @param comment An optional description of the schema.
+ * @param properties A map of schema properties.
+ * @param audit Optional audit information.
+ */
+ public SchemaInfo(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 schema name.
+ *
+ * @return The schema name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Gets the optional schema comment.
+ *
+ * @return The schema comment, or null if not provided.
+ */
+ @Nullable
+ public String comment() {
+ return comment;
+ }
+
+ /**
+ * Gets the schema properties.
+ *
+ * @return An immutable map of schema 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.java
index 9c7ba40a3a..9dc90458ba 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/GravitinoServer.java
@@ -8,7 +8,7 @@ import com.datastrato.gravitino.Configs;
import com.datastrato.gravitino.GravitinoEnv;
import com.datastrato.gravitino.catalog.CatalogManager;
import com.datastrato.gravitino.catalog.FilesetDispatcher;
-import com.datastrato.gravitino.catalog.SchemaOperationDispatcher;
+import com.datastrato.gravitino.catalog.SchemaDispatcher;
import com.datastrato.gravitino.catalog.TableDispatcher;
import com.datastrato.gravitino.metalake.MetalakeManager;
import com.datastrato.gravitino.metrics.MetricsSystem;
@@ -79,9 +79,7 @@ public class GravitinoServer extends ResourceConfig {
bind(gravitinoEnv.metalakesManager()).to(MetalakeManager.class).ranked(1);
bind(gravitinoEnv.catalogManager()).to(CatalogManager.class).ranked(1);
- bind(gravitinoEnv.schemaOperationDispatcher())
- .to(SchemaOperationDispatcher.class)
- .ranked(1);
+ 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())
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java
index 00b4ff6b13..78e2fa6acf 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.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.SchemaOperationDispatcher;
+import com.datastrato.gravitino.catalog.SchemaDispatcher;
import com.datastrato.gravitino.dto.requests.SchemaCreateRequest;
import com.datastrato.gravitino.dto.requests.SchemaUpdateRequest;
import com.datastrato.gravitino.dto.requests.SchemaUpdatesRequest;
@@ -47,12 +47,12 @@ public class SchemaOperations {
private static final Logger LOG = LoggerFactory.getLogger(SchemaOperations.class);
- private final SchemaOperationDispatcher dispatcher;
+ private final SchemaDispatcher dispatcher;
@Context private HttpServletRequest httpRequest;
@Inject
- public SchemaOperations(SchemaOperationDispatcher dispatcher) {
+ public SchemaOperations(SchemaDispatcher dispatcher) {
this.dispatcher = dispatcher;
}
diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestSchemaOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestSchemaOperations.java
index 90dec8989f..7b36cac138 100644
--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestSchemaOperations.java
+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestSchemaOperations.java
@@ -17,6 +17,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.SchemaDispatcher;
import com.datastrato.gravitino.catalog.SchemaOperationDispatcher;
import com.datastrato.gravitino.dto.rel.SchemaDTO;
import com.datastrato.gravitino.dto.requests.SchemaCreateRequest;
@@ -93,7 +94,7 @@ public class TestSchemaOperations extends JerseyTest {
new AbstractBinder() {
@Override
protected void configure() {
- bind(dispatcher).to(SchemaOperationDispatcher.class).ranked(2);
+ bind(dispatcher).to(SchemaDispatcher.class).ranked(2);
bindFactory(MockServletRequestFactory.class).to(HttpServletRequest.class);
}
});