Skip to content

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

[#7144] feat(policy): Add event listener support for policy (#9004)

Qiang-Liuc295b9470a3e
diff --git a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java
index 1e01333b15..7e3f003ef2 100644
--- a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java
+++ b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java
@@ -69,6 +69,7 @@ import org.apache.gravitino.listener.JobEventDispatcher;
import org.apache.gravitino.listener.MetalakeEventDispatcher;
import org.apache.gravitino.listener.ModelEventDispatcher;
import org.apache.gravitino.listener.PartitionEventDispatcher;
+import org.apache.gravitino.listener.PolicyEventDispatcher;
import org.apache.gravitino.listener.SchemaEventDispatcher;
import org.apache.gravitino.listener.StatisticEventDispatcher;
import org.apache.gravitino.listener.TableEventDispatcher;
@@ -601,8 +602,9 @@ public class GravitinoEnv {
// Create and initialize Tag related modules
this.tagDispatcher = new TagEventDispatcher(eventBus, new TagManager(idGenerator, entityStore));
- // todo: support policy event dispatcher
- this.policyDispatcher = new PolicyManager(idGenerator, entityStore);
+ // Create and initialize Policy related modules
+ this.policyDispatcher =
+ new PolicyEventDispatcher(eventBus, new PolicyManager(idGenerator, entityStore));
this.jobOperationDispatcher =
new JobEventDispatcher(eventBus, new JobManager(config, entityStore, idGenerator));
diff --git a/core/src/main/java/org/apache/gravitino/listener/PolicyEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/PolicyEventDispatcher.java
new file mode 100644
index 0000000000..f708f06cb2
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/PolicyEventDispatcher.java
@@ -0,0 +1,374 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.listener;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.NoSuchPolicyException;
+import org.apache.gravitino.listener.api.event.policy.AlterPolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.AlterPolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.AlterPolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.AssociatePoliciesForMetadataObjectEvent;
+import org.apache.gravitino.listener.api.event.policy.AssociatePoliciesForMetadataObjectFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.AssociatePoliciesForMetadataObjectPreEvent;
+import org.apache.gravitino.listener.api.event.policy.CreatePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.CreatePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.CreatePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.DeletePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.DeletePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.DeletePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.DisablePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.DisablePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.DisablePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.EnablePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.EnablePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.EnablePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyForMetadataObjectEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyForMetadataObjectFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyForMetadataObjectPreEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListMetadataObjectsForPolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.ListMetadataObjectsForPolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListMetadataObjectsForPolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPoliciesEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPoliciesFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPoliciesPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosForMetadataObjectEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosForMetadataObjectFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosForMetadataObjectPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosPreEvent;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+import org.apache.gravitino.meta.PolicyEntity;
+import org.apache.gravitino.policy.Policy;
+import org.apache.gravitino.policy.PolicyChange;
+import org.apache.gravitino.policy.PolicyContent;
+import org.apache.gravitino.policy.PolicyDispatcher;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.PrincipalUtils;
+
+/**
+ * {@code PolicyEventDispatcher} is a decorator for {@link PolicyDispatcher} that not only delegates
+ * policy operations to the underlying policy dispatcher but also dispatches corresponding events to
+ * an {@link EventBus} after each operation is completed. This allows for event-driven workflows or
+ * monitoring of policy operations.
+ */
+public class PolicyEventDispatcher implements PolicyDispatcher {
+ private final EventBus eventBus;
+ private final PolicyDispatcher dispatcher;
+
+ public PolicyEventDispatcher(EventBus eventBus, PolicyDispatcher dispatcher) {
+ this.eventBus = eventBus;
+ this.dispatcher = dispatcher;
+ }
+
+ @Override
+ public String[] listPolicies(String metalake) {
+ eventBus.dispatchEvent(new ListPoliciesPreEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ try {
+ String[] policyNames = dispatcher.listPolicies(metalake);
+ eventBus.dispatchEvent(new ListPoliciesEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ return policyNames;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new ListPoliciesFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public PolicyEntity[] listPolicyInfos(String metalake) {
+ eventBus.dispatchEvent(
+ new ListPolicyInfosPreEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ try {
+ PolicyEntity[] policies = dispatcher.listPolicyInfos(metalake);
+ eventBus.dispatchEvent(
+ new ListPolicyInfosEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ return policies;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new ListPolicyInfosFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public PolicyEntity getPolicy(String metalake, String policyName) throws NoSuchPolicyException {
+ eventBus.dispatchEvent(
+ new GetPolicyPreEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName)));
+ try {
+ PolicyEntity policy = dispatcher.getPolicy(metalake, policyName);
+ PolicyInfo policyInfo = toPolicyInfo(policy);
+ eventBus.dispatchEvent(
+ new GetPolicyEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ policyInfo));
+ return policy;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new GetPolicyFailureEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ e));
+ throw e;
+ }
+ }
+
+ @Override
+ public PolicyEntity createPolicy(
+ String metalake,
+ String name,
+ Policy.BuiltInType type,
+ String comment,
+ boolean enabled,
+ PolicyContent content) {
+ PolicyInfo policyInfo = new PolicyInfo(name, type.name(), comment, enabled, content, null);
+ eventBus.dispatchEvent(
+ new CreatePolicyPreEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, name),
+ policyInfo));
+ try {
+ PolicyEntity policy =
+ dispatcher.createPolicy(metalake, name, type, comment, enabled, content);
+ eventBus.dispatchEvent(
+ new CreatePolicyEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, name),
+ toPolicyInfo(policy)));
+ return policy;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new CreatePolicyFailureEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, name),
+ e,
+ policyInfo));
+ throw e;
+ }
+ }
+
+ @Override
+ public PolicyEntity alterPolicy(String metalake, String policyName, PolicyChange... changes) {
+ AlterPolicyPreEvent preEvent =
+ new AlterPolicyPreEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ changes);
+
+ eventBus.dispatchEvent(preEvent);
+ try {
+ PolicyEntity policy = dispatcher.alterPolicy(metalake, policyName, changes);
+ eventBus.dispatchEvent(
+ new AlterPolicyEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ changes,
+ toPolicyInfo(policy)));
+ return policy;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new AlterPolicyFailureEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ e,
+ changes));
+ throw e;
+ }
+ }
+
+ @Override
+ public void enablePolicy(String metalake, String policyName) throws NoSuchPolicyException {
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy(metalake, policyName);
+ eventBus.dispatchEvent(
+ new EnablePolicyPreEvent(PrincipalUtils.getCurrentUserName(), identifier));
+ try {
+ dispatcher.enablePolicy(metalake, policyName);
+ eventBus.dispatchEvent(
+ new EnablePolicyEvent(PrincipalUtils.getCurrentUserName(), identifier));
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new EnablePolicyFailureEvent(PrincipalUtils.getCurrentUserName(), identifier, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public void disablePolicy(String metalake, String policyName) throws NoSuchPolicyException {
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy(metalake, policyName);
+ eventBus.dispatchEvent(
+ new DisablePolicyPreEvent(PrincipalUtils.getCurrentUserName(), identifier));
+ try {
+ dispatcher.disablePolicy(metalake, policyName);
+ eventBus.dispatchEvent(
+ new DisablePolicyEvent(PrincipalUtils.getCurrentUserName(), identifier));
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new DisablePolicyFailureEvent(PrincipalUtils.getCurrentUserName(), identifier, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public boolean deletePolicy(String metalake, String policyName) {
+ DeletePolicyPreEvent preEvent =
+ new DeletePolicyPreEvent(
+ PrincipalUtils.getCurrentUserName(), NameIdentifierUtil.ofPolicy(metalake, policyName));
+
+ eventBus.dispatchEvent(preEvent);
+ try {
+ boolean isExists = dispatcher.deletePolicy(metalake, policyName);
+ eventBus.dispatchEvent(
+ new DeletePolicyEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ isExists));
+ return isExists;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new DeletePolicyFailureEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ e));
+ throw e;
+ }
+ }
+
+ @Override
+ public MetadataObject[] listMetadataObjectsForPolicy(String metalake, String policyName) {
+ eventBus.dispatchEvent(
+ new ListMetadataObjectsForPolicyPreEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName)));
+ try {
+ MetadataObject[] metadataObjects =
+ dispatcher.listMetadataObjectsForPolicy(metalake, policyName);
+ eventBus.dispatchEvent(
+ new ListMetadataObjectsForPolicyEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName)));
+ return metadataObjects;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new ListMetadataObjectsForPolicyFailureEvent(
+ PrincipalUtils.getCurrentUserName(),
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ e));
+ throw e;
+ }
+ }
+
+ @Override
+ public PolicyEntity[] listPolicyInfosForMetadataObject(
+ String metalake, MetadataObject metadataObject) {
+ eventBus.dispatchEvent(
+ new ListPolicyInfosForMetadataObjectPreEvent(
+ PrincipalUtils.getCurrentUserName(), metalake, metadataObject));
+ try {
+ PolicyEntity[] policies =
+ dispatcher.listPolicyInfosForMetadataObject(metalake, metadataObject);
+ eventBus.dispatchEvent(
+ new ListPolicyInfosForMetadataObjectEvent(
+ PrincipalUtils.getCurrentUserName(), metalake, metadataObject));
+ return policies;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new ListPolicyInfosForMetadataObjectFailureEvent(
+ PrincipalUtils.getCurrentUserName(), metalake, metadataObject, e));
+ throw e;
+ }
+ }
+
+ @Override
+ public String[] associatePoliciesForMetadataObject(
+ String metalake,
+ MetadataObject metadataObject,
+ String[] policiesToAdd,
+ String[] policiesToRemove) {
+ eventBus.dispatchEvent(
+ new AssociatePoliciesForMetadataObjectPreEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ metadataObject,
+ policiesToAdd,
+ policiesToRemove));
+
+ try {
+ String[] associatedPolicies =
+ dispatcher.associatePoliciesForMetadataObject(
+ metalake, metadataObject, policiesToAdd, policiesToRemove);
+ eventBus.dispatchEvent(
+ new AssociatePoliciesForMetadataObjectEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ metadataObject,
+ policiesToAdd,
+ policiesToRemove));
+ return associatedPolicies;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new AssociatePoliciesForMetadataObjectFailureEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ metadataObject,
+ policiesToAdd,
+ policiesToRemove,
+ e));
+ throw e;
+ }
+ }
+
+ @Override
+ public PolicyEntity getPolicyForMetadataObject(
+ String metalake, MetadataObject metadataObject, String policyName) {
+ eventBus.dispatchEvent(
+ new GetPolicyForMetadataObjectPreEvent(
+ PrincipalUtils.getCurrentUserName(), metalake, metadataObject, policyName));
+ try {
+ PolicyEntity policy =
+ dispatcher.getPolicyForMetadataObject(metalake, metadataObject, policyName);
+ PolicyInfo policyInfo = toPolicyInfo(policy);
+ eventBus.dispatchEvent(
+ new GetPolicyForMetadataObjectEvent(
+ PrincipalUtils.getCurrentUserName(), metalake, metadataObject, policyInfo));
+ return policy;
+ } catch (Exception e) {
+ eventBus.dispatchEvent(
+ new GetPolicyForMetadataObjectFailureEvent(
+ PrincipalUtils.getCurrentUserName(), metalake, metadataObject, policyName, e));
+ throw e;
+ }
+ }
+
+ private PolicyInfo toPolicyInfo(PolicyEntity policy) {
+ return new PolicyInfo(
+ policy.name(),
+ policy.policyType().name(),
+ policy.comment(),
+ policy.enabled(),
+ policy.content(),
+ policy.auditInfo());
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.java b/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.java
index f6247815f0..ea19ccaffc 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/OperationType.java
@@ -168,5 +168,19 @@ public enum OperationType {
UPDATE_STATISTICS,
UPDATE_PARTITION_STATISTICS,
+ // Policy operations
+ CREATE_POLICY,
+ GET_POLICY,
+ ALTER_POLICY,
+ DELETE_POLICY,
+ ENABLE_POLICY,
+ DISABLE_POLICY,
+ LIST_POLICY,
+ LIST_POLICY_INFO,
+ LIST_METADATA_OBJECTS_FOR_POLICY,
+ LIST_POLICY_INFOS_FOR_METADATA_OBJECT,
+ ASSOCIATE_POLICIES_FOR_METADATA_OBJECT,
+ GET_POLICY_FOR_METADATA_OBJECT,
+
UNKNOWN,
}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyEvent.java
new file mode 100644
index 0000000000..da52a74731
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyEvent.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+import org.apache.gravitino.policy.PolicyChange;
+
+/** Represents an event triggered upon the successful alteration of a policy. */
+@DeveloperApi
+public final class AlterPolicyEvent extends PolicyEvent {
+ private final PolicyInfo updatedPolicyInfo;
+ private final PolicyChange[] policyChanges;
+
+ /**
+ * Constructs an instance of {@code AlterPolicyEvent}, encapsulating the key details about the
+ * successful alteration of a policy.
+ *
+ * @param user The username of the individual responsible for initiating the policy alteration.
+ * @param identifier The identifier of the altered policy.
+ * @param policyChanges An array of {@link PolicyChange} objects representing the specific changes
+ * applied to the policy during the alteration process.
+ * @param updatedPolicyInfo The post-alteration state of the policy.
+ */
+ public AlterPolicyEvent(
+ String user,
+ NameIdentifier identifier,
+ PolicyChange[] policyChanges,
+ PolicyInfo updatedPolicyInfo) {
+ super(user, identifier);
+ this.policyChanges = policyChanges != null ? policyChanges.clone() : null;
+ this.updatedPolicyInfo = updatedPolicyInfo;
+ }
+
+ /**
+ * Retrieves the specific changes that were made to the policy during the alteration process.
+ *
+ * @return An array of {@link PolicyChange} objects detailing each modification applied to the
+ * policy.
+ */
+ public PolicyChange[] policyChanges() {
+ return policyChanges;
+ }
+
+ /**
+ * Retrieves the final state of the policy as it was returned to the user after successful
+ * alteration.
+ *
+ * @return A {@link PolicyInfo} instance encapsulating the comprehensive details of the newly
+ * altered policy.
+ */
+ public PolicyInfo updatedPolicyInfo() {
+ return updatedPolicyInfo;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ALTER_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyFailureEvent.java
new file mode 100644
index 0000000000..e642f50031
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyFailureEvent.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.policy.PolicyChange;
+
+/** Represents an event that is triggered when an attempt to alter a policy fails. */
+@DeveloperApi
+public final class AlterPolicyFailureEvent extends PolicyFailureEvent {
+ private final PolicyChange[] policyChanges;
+
+ /**
+ * Constructs an instance of {@code AlterPolicyFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the policy alteration.
+ * @param identifier The identifier of the policy that failed to be altered.
+ * @param exception The exception that was encountered during the policy alteration attempt.
+ * @param policyChanges The changes that were attempted on the policy.
+ */
+ public AlterPolicyFailureEvent(
+ String user, NameIdentifier identifier, Exception exception, PolicyChange[] policyChanges) {
+ super(user, identifier, exception);
+ this.policyChanges = policyChanges != null ? policyChanges.clone() : null;
+ }
+
+ /**
+ * Returns the changes that were attempted on the policy.
+ *
+ * @return the policy changes.
+ */
+ public PolicyChange[] policyChanges() {
+ return policyChanges;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ALTER_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyPreEvent.java
new file mode 100644
index 0000000000..cdc8a784ea
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AlterPolicyPreEvent.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.policy.PolicyChange;
+
+/** Represents an event that is triggered before altering a policy. */
+@DeveloperApi
+public final class AlterPolicyPreEvent extends PolicyPreEvent {
+ private final PolicyChange[] policyChanges;
+
+ /**
+ * Constructs an instance of {@code AlterPolicyPreEvent}.
+ *
+ * @param user The username of the individual who initiated the alter policy operation.
+ * @param identifier The identifier of the policy to be altered.
+ * @param policyChanges The changes to be applied to the policy.
+ */
+ public AlterPolicyPreEvent(String user, NameIdentifier identifier, PolicyChange[] policyChanges) {
+ super(user, identifier);
+ this.policyChanges = policyChanges != null ? policyChanges.clone() : null;
+ }
+
+ /**
+ * Returns the changes to be applied to the policy.
+ *
+ * @return the policy changes.
+ */
+ public PolicyChange[] policyChanges() {
+ return policyChanges;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ALTER_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectEvent.java
new file mode 100644
index 0000000000..932a7e53a4
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectEvent.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/**
+ * Represents an event that is triggered upon successfully associating policies with a metadata
+ * object.
+ */
+@DeveloperApi
+public final class AssociatePoliciesForMetadataObjectEvent extends PolicyEvent {
+ private final MetadataObject metadataObject;
+ private final String[] policiesToAdd;
+ private final String[] policiesToRemove;
+
+ /**
+ * Constructs an instance of {@code AssociatePoliciesForMetadataObjectEvent}.
+ *
+ * @param user The username of the individual who initiated the associate policies operation.
+ * @param metalake The metalake from which the policies were associated.
+ * @param metadataObject The metadata object with which the policies were associated.
+ * @param policiesToAdd The policies that were added.
+ * @param policiesToRemove The policies that were removed.
+ */
+ public AssociatePoliciesForMetadataObjectEvent(
+ String user,
+ String metalake,
+ MetadataObject metadataObject,
+ String[] policiesToAdd,
+ String[] policiesToRemove) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.metadataObject = metadataObject;
+ this.policiesToAdd = policiesToAdd != null ? policiesToAdd : new String[0];
+ this.policiesToRemove = policiesToRemove != null ? policiesToRemove : new String[0];
+ }
+
+ /**
+ * Returns the metadata object with which policies were associated.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the policies that were added.
+ *
+ * @return an array of policy names that were added.
+ */
+ public String[] policiesToAdd() {
+ return policiesToAdd;
+ }
+
+ /**
+ * Returns the policies that were removed.
+ *
+ * @return an array of policy names that were removed.
+ */
+ public String[] policiesToRemove() {
+ return policiesToRemove;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ASSOCIATE_POLICIES_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectFailureEvent.java
new file mode 100644
index 0000000000..38b872d0da
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectFailureEvent.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/**
+ * Represents an event that is triggered when an attempt to associate policies with a metadata
+ * object fails.
+ */
+@DeveloperApi
+public final class AssociatePoliciesForMetadataObjectFailureEvent extends PolicyFailureEvent {
+ private final MetadataObject metadataObject;
+ private final String[] policiesToAdd;
+ private final String[] policiesToRemove;
+
+ /**
+ * Constructs an instance of {@code AssociatePoliciesForMetadataObjectFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the associate policies operation.
+ * @param metalake The metalake from which the policies were to be associated.
+ * @param metadataObject The metadata object with which the policies were to be associated.
+ * @param policiesToAdd The policies to be added.
+ * @param policiesToRemove The policies to be removed.
+ * @param exception The exception that was encountered during the associate policies attempt.
+ */
+ public AssociatePoliciesForMetadataObjectFailureEvent(
+ String user,
+ String metalake,
+ MetadataObject metadataObject,
+ String[] policiesToAdd,
+ String[] policiesToRemove,
+ Exception exception) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject), exception);
+ this.metadataObject = metadataObject;
+ this.policiesToAdd = policiesToAdd != null ? policiesToAdd : new String[0];
+ this.policiesToRemove = policiesToRemove != null ? policiesToRemove : new String[0];
+ }
+
+ /**
+ * Returns the metadata object with which policies were to be associated.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the policies to be added.
+ *
+ * @return an array of policy names to be added.
+ */
+ public String[] policiesToAdd() {
+ return policiesToAdd;
+ }
+
+ /**
+ * Returns the policies to be removed.
+ *
+ * @return an array of policy names to be removed.
+ */
+ public String[] policiesToRemove() {
+ return policiesToRemove;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ASSOCIATE_POLICIES_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectPreEvent.java
new file mode 100644
index 0000000000..06f93105c2
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/AssociatePoliciesForMetadataObjectPreEvent.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/** Represents an event that is triggered before associating policies with a metadata object. */
+@DeveloperApi
+public final class AssociatePoliciesForMetadataObjectPreEvent extends PolicyPreEvent {
+ private final MetadataObject metadataObject;
+ private final String[] policiesToAdd;
+ private final String[] policiesToRemove;
+
+ /**
+ * Constructs an instance of {@code AssociatePoliciesForMetadataObjectPreEvent}.
+ *
+ * @param user The username of the individual who initiated the associate policies operation.
+ * @param metalake The metalake from which the policies will be associated.
+ * @param metadataObject The metadata object with which the policies will be associated.
+ * @param policiesToAdd The policies to be added.
+ * @param policiesToRemove The policies to be removed.
+ */
+ public AssociatePoliciesForMetadataObjectPreEvent(
+ String user,
+ String metalake,
+ MetadataObject metadataObject,
+ String[] policiesToAdd,
+ String[] policiesToRemove) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.metadataObject = metadataObject;
+ this.policiesToAdd = policiesToAdd != null ? policiesToAdd.clone() : new String[0];
+ this.policiesToRemove = policiesToRemove != null ? policiesToRemove.clone() : new String[0];
+ }
+
+ /**
+ * Returns the metadata object with which policies will be associated.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the policies to be added.
+ *
+ * @return an array of policy names to be added.
+ */
+ public String[] policiesToAdd() {
+ return policiesToAdd;
+ }
+
+ /**
+ * Returns the policies to be removed.
+ *
+ * @return an array of policy names to be removed.
+ */
+ public String[] policiesToRemove() {
+ return policiesToRemove;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ASSOCIATE_POLICIES_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyEvent.java
new file mode 100644
index 0000000000..781681fd82
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyEvent.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+
+/** Represents an event that is activated upon the successful creation of a policy. */
+@DeveloperApi
+public final class CreatePolicyEvent extends PolicyEvent {
+ private final PolicyInfo createdPolicyInfo;
+
+ /**
+ * Constructs an instance of {@code CreatePolicyEvent}, capturing essential details about the
+ * successful creation of a policy.
+ *
+ * @param user The username of the individual who initiated the policy creation.
+ * @param identifier The identifier of the created policy.
+ * @param createdPolicyInfo The final state of the policy post-creation.
+ */
+ public CreatePolicyEvent(String user, NameIdentifier identifier, PolicyInfo createdPolicyInfo) {
+ super(user, identifier);
+ this.createdPolicyInfo = createdPolicyInfo;
+ }
+
+ /**
+ * Provides the final state of the policy as it is presented to the user following the successful
+ * creation.
+ *
+ * @return A {@link PolicyInfo} object that encapsulates the detailed characteristics of the newly
+ * created policy.
+ */
+ public PolicyInfo createdPolicyInfo() {
+ return createdPolicyInfo;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.CREATE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyFailureEvent.java
new file mode 100644
index 0000000000..15fdea0bdd
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyFailureEvent.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+
+/** Represents an event that is triggered when an attempt to create a policy fails. */
+@DeveloperApi
+public final class CreatePolicyFailureEvent extends PolicyFailureEvent {
+ private final PolicyInfo createPolicyRequest;
+
+ /**
+ * Constructs an instance of {@code CreatePolicyFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the policy creation.
+ * @param identifier The identifier of the policy that failed to be created.
+ * @param exception The exception that was encountered during the policy creation attempt.
+ * @param createPolicyRequest The policy creation request information.
+ */
+ public CreatePolicyFailureEvent(
+ String user, NameIdentifier identifier, Exception exception, PolicyInfo createPolicyRequest) {
+ super(user, identifier, exception);
+ this.createPolicyRequest = createPolicyRequest;
+ }
+
+ /**
+ * Returns the policy creation request information.
+ *
+ * @return the policy creation request.
+ */
+ public PolicyInfo createPolicyRequest() {
+ return createPolicyRequest;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.CREATE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyPreEvent.java
new file mode 100644
index 0000000000..e5cef999ab
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/CreatePolicyPreEvent.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+
+/** Represents an event triggered before the creation of a policy. */
+@DeveloperApi
+public final class CreatePolicyPreEvent extends PolicyPreEvent {
+ private final PolicyInfo createPolicyRequest;
+
+ /**
+ * Constructs a new {@code CreatePolicyPreEvent} instance.
+ *
+ * @param user The user who initiated the policy creation operation.
+ * @param identifier The identifier of the policy to be created.
+ * @param createPolicyRequest The information about the policy to be created.
+ */
+ public CreatePolicyPreEvent(
+ String user, NameIdentifier identifier, PolicyInfo createPolicyRequest) {
+ super(user, identifier);
+ this.createPolicyRequest = createPolicyRequest;
+ }
+
+ /**
+ * Returns the information about the policy.
+ *
+ * @return the policy information
+ */
+ public PolicyInfo createPolicyRequest() {
+ return createPolicyRequest;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.CREATE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyEvent.java
new file mode 100644
index 0000000000..8716c3ddc5
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyEvent.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered upon successfully deleting a policy. */
+@DeveloperApi
+public final class DeletePolicyEvent extends PolicyEvent {
+ private final boolean isExists;
+
+ /**
+ * Constructs an instance of {@code DeletePolicyEvent}.
+ *
+ * @param user The username of the individual who initiated the policy deletion.
+ * @param identifier The identifier of the deleted policy.
+ * @param isExists Whether the policy existed before deletion.
+ */
+ public DeletePolicyEvent(String user, NameIdentifier identifier, boolean isExists) {
+ super(user, identifier);
+ this.isExists = isExists;
+ }
+
+ /**
+ * Returns whether the policy existed before deletion.
+ *
+ * @return true if the policy existed, false otherwise.
+ */
+ public boolean isExists() {
+ return isExists;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.DELETE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyFailureEvent.java
new file mode 100644
index 0000000000..c97d6a5296
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyFailureEvent.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered when an attempt to delete a policy fails. */
+@DeveloperApi
+public final class DeletePolicyFailureEvent extends PolicyFailureEvent {
+ /**
+ * Constructs an instance of {@code DeletePolicyFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the policy deletion.
+ * @param identifier The identifier of the policy that failed to be deleted.
+ * @param exception The exception that was encountered during the policy deletion attempt.
+ */
+ public DeletePolicyFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.DELETE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyPreEvent.java
new file mode 100644
index 0000000000..0a566a0674
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DeletePolicyPreEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered before deleting a policy. */
+@DeveloperApi
+public final class DeletePolicyPreEvent extends PolicyPreEvent {
+ /**
+ * Constructs an instance of {@code DeletePolicyPreEvent}.
+ *
+ * @param user The username of the individual who initiated the delete policy operation.
+ * @param identifier The identifier of the policy to be deleted.
+ */
+ public DeletePolicyPreEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.DELETE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyEvent.java
new file mode 100644
index 0000000000..d0624db285
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered upon successfully disabling a policy. */
+@DeveloperApi
+public final class DisablePolicyEvent extends PolicyEvent {
+ /**
+ * Constructs an instance of {@code DisablePolicyEvent}.
+ *
+ * @param user The username of the individual who initiated the policy disabling operation.
+ * @param identifier The identifier of the disabled policy.
+ */
+ public DisablePolicyEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.DISABLE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyFailureEvent.java
new file mode 100644
index 0000000000..dfdc7bc3bc
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyFailureEvent.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered when an attempt to disable a policy fails. */
+@DeveloperApi
+public final class DisablePolicyFailureEvent extends PolicyFailureEvent {
+ /**
+ * Constructs an instance of {@code DisablePolicyFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the policy disablement.
+ * @param identifier The identifier of the policy that failed to be disabled.
+ * @param exception The exception that was encountered during the policy disablement attempt.
+ */
+ public DisablePolicyFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.DISABLE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyPreEvent.java
new file mode 100644
index 0000000000..4c6273d609
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/DisablePolicyPreEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered before disabling a policy. */
+@DeveloperApi
+public final class DisablePolicyPreEvent extends PolicyPreEvent {
+ /**
+ * Constructs an instance of {@code DisablePolicyPreEvent}.
+ *
+ * @param user The username of the individual who initiated the disable policy operation.
+ * @param identifier The identifier of the policy to be disabled.
+ */
+ public DisablePolicyPreEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.DISABLE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyEvent.java
new file mode 100644
index 0000000000..d88b9342b3
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered upon successfully enabling a policy. */
+@DeveloperApi
+public final class EnablePolicyEvent extends PolicyEvent {
+ /**
+ * Constructs an instance of {@code EnablePolicyEvent}.
+ *
+ * @param user The username of the individual who initiated the policy enabling operation.
+ * @param identifier The identifier of the enabled policy.
+ */
+ public EnablePolicyEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ENABLE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyFailureEvent.java
new file mode 100644
index 0000000000..0c2cdb6041
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyFailureEvent.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered when an attempt to enable a policy fails. */
+@DeveloperApi
+public final class EnablePolicyFailureEvent extends PolicyFailureEvent {
+ /**
+ * Constructs an instance of {@code EnablePolicyFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the policy enablement.
+ * @param identifier The identifier of the policy that failed to be enabled.
+ * @param exception The exception that was encountered during the policy enablement attempt.
+ */
+ public EnablePolicyFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ENABLE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyPreEvent.java
new file mode 100644
index 0000000000..1d57de1ba3
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/EnablePolicyPreEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered before enabling a policy. */
+@DeveloperApi
+public final class EnablePolicyPreEvent extends PolicyPreEvent {
+ /**
+ * Constructs an instance of {@code EnablePolicyPreEvent}.
+ *
+ * @param user The username of the individual who initiated the enable policy operation.
+ * @param identifier The identifier of the policy to be enabled.
+ */
+ public EnablePolicyPreEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.ENABLE_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyEvent.java
new file mode 100644
index 0000000000..e9878fb27f
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyEvent.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+
+/** Represents an event that is triggered upon successfully retrieving a policy. */
+@DeveloperApi
+public final class GetPolicyEvent extends PolicyEvent {
+ private final PolicyInfo policyInfo;
+
+ /**
+ * Constructs an instance of {@code GetPolicyEvent}.
+ *
+ * @param user The username of the individual who initiated the policy retrieval.
+ * @param identifier The identifier of the retrieved policy.
+ * @param policyInfo The {@link PolicyInfo} object representing the retrieved policy.
+ */
+ public GetPolicyEvent(String user, NameIdentifier identifier, PolicyInfo policyInfo) {
+ super(user, identifier);
+ this.policyInfo = policyInfo;
+ }
+
+ /**
+ * Returns the {@link PolicyInfo} object representing the retrieved policy.
+ *
+ * @return the policy information.
+ */
+ public PolicyInfo policyInfo() {
+ return policyInfo;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.GET_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyFailureEvent.java
new file mode 100644
index 0000000000..83fd1c9eba
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyFailureEvent.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event triggered when retrieving a policy fails. */
+@DeveloperApi
+public final class GetPolicyFailureEvent extends PolicyFailureEvent {
+ /**
+ * Constructs a GetPolicyFailureEvent.
+ *
+ * @param user The user who attempted to retrieve the policy.
+ * @param identifier The identifier of the policy that failed to be retrieved.
+ * @param exception The exception that caused the failure.
+ */
+ public GetPolicyFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+
+ /**
+ * Returns the operation type.
+ *
+ * @return The operation type (GET_POLICY).
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.GET_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectEvent.java
new file mode 100644
index 0000000000..bfa4c0eb13
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectEvent.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/**
+ * Represents an event that is triggered upon successfully retrieving a policy for a metadata
+ * object.
+ */
+@DeveloperApi
+public final class GetPolicyForMetadataObjectEvent extends PolicyEvent {
+ private final MetadataObject metadataObject;
+ private final PolicyInfo policyInfo;
+
+ /**
+ * Constructs an instance of {@code GetPolicyForMetadataObjectEvent}.
+ *
+ * @param user The username of the individual who initiated the policy retrieval.
+ * @param metalake The metalake from which the policy was retrieved.
+ * @param metadataObject The metadata object for which the policy was retrieved.
+ * @param policyInfo The {@link PolicyInfo} object representing the retrieved policy.
+ */
+ public GetPolicyForMetadataObjectEvent(
+ String user, String metalake, MetadataObject metadataObject, PolicyInfo policyInfo) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.metadataObject = metadataObject;
+ this.policyInfo = policyInfo;
+ }
+
+ /**
+ * Returns the metadata object for which the policy was retrieved.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the {@link PolicyInfo} object representing the retrieved policy.
+ *
+ * @return the policy information.
+ */
+ public PolicyInfo policyInfo() {
+ return policyInfo;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.GET_POLICY_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectFailureEvent.java
new file mode 100644
index 0000000000..62198c4410
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectFailureEvent.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/**
+ * Represents an event that is triggered when an attempt to retrieve a policy for a metadata object
+ * fails.
+ */
+@DeveloperApi
+public final class GetPolicyForMetadataObjectFailureEvent extends PolicyFailureEvent {
+ private final MetadataObject metadataObject;
+ private final String policyName;
+
+ /**
+ * Constructs an instance of {@code GetPolicyForMetadataObjectFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the policy retrieval.
+ * @param metalake The metalake from which the policy was to be retrieved.
+ * @param metadataObject The metadata object for which the policy was to be retrieved.
+ * @param policyName The name of the policy that was to be retrieved.
+ * @param exception The exception that was encountered during the policy retrieval attempt.
+ */
+ public GetPolicyForMetadataObjectFailureEvent(
+ String user,
+ String metalake,
+ MetadataObject metadataObject,
+ String policyName,
+ Exception exception) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject), exception);
+ this.metadataObject = metadataObject;
+ this.policyName = policyName;
+ }
+
+ /**
+ * Returns the metadata object for which the policy retrieval was attempted.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the name of the policy that was to be retrieved.
+ *
+ * @return the policy name.
+ */
+ public String policyName() {
+ return policyName;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.GET_POLICY_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectPreEvent.java
new file mode 100644
index 0000000000..a5392ba9be
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyForMetadataObjectPreEvent.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/** Represents an event triggered before retrieving a policy for a metadata object. */
+@DeveloperApi
+public final class GetPolicyForMetadataObjectPreEvent extends PolicyPreEvent {
+ private final MetadataObject metadataObject;
+ private final String policyName;
+
+ /**
+ * Constructs an instance of {@code GetPolicyForMetadataObjectPreEvent}.
+ *
+ * @param user The username of the individual who initiated the policy retrieval operation.
+ * @param metalake The metalake from which the policy will be retrieved.
+ * @param metadataObject The metadata object for which the policy will be retrieved.
+ * @param policyName The name of the policy to be retrieved.
+ */
+ public GetPolicyForMetadataObjectPreEvent(
+ String user, String metalake, MetadataObject metadataObject, String policyName) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.metadataObject = metadataObject;
+ this.policyName = policyName;
+ }
+
+ /**
+ * Returns the metadata object for which the policy will be retrieved.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the name of the policy to be retrieved.
+ *
+ * @return the policy name.
+ */
+ public String policyName() {
+ return policyName;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.GET_POLICY_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyPreEvent.java
new file mode 100644
index 0000000000..1bc97e9c3b
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/GetPolicyPreEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/** Represents an event that is triggered before retrieving a policy. */
+@DeveloperApi
+public final class GetPolicyPreEvent extends PolicyPreEvent {
+ /**
+ * Constructs an instance of {@code GetPolicyPreEvent}.
+ *
+ * @param user The username of the individual who initiated the get policy operation.
+ * @param identifier The identifier of the policy to be retrieved.
+ */
+ public GetPolicyPreEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.GET_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyEvent.java
new file mode 100644
index 0000000000..cf8f14d5dd
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyEvent.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/**
+ * Represents an event that is triggered upon successfully listing metadata objects associated with
+ * a policy.
+ */
+@DeveloperApi
+public final class ListMetadataObjectsForPolicyEvent extends PolicyEvent {
+ /**
+ * Constructs an instance of {@code ListMetadataObjectsForPolicyEvent}.
+ *
+ * @param user The username of the individual who initiated the list metadata objects operation.
+ * @param identifier The identifier of the policy.
+ */
+ public ListMetadataObjectsForPolicyEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_METADATA_OBJECTS_FOR_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyFailureEvent.java
new file mode 100644
index 0000000000..147622f162
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyFailureEvent.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/**
+ * Represents an event that is triggered when an attempt to list metadata objects associated with a
+ * policy fails.
+ */
+@DeveloperApi
+public final class ListMetadataObjectsForPolicyFailureEvent extends PolicyFailureEvent {
+ /**
+ * Constructs an instance of {@code ListMetadataObjectsForPolicyFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the list metadata objects operation.
+ * @param identifier The identifier of the policy.
+ * @param exception The exception that was encountered during the list metadata objects attempt.
+ */
+ public ListMetadataObjectsForPolicyFailureEvent(
+ String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_METADATA_OBJECTS_FOR_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyPreEvent.java
new file mode 100644
index 0000000000..d4e3e63753
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyPreEvent.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+
+/**
+ * Represents an event that is triggered before listing metadata objects associated with a policy.
+ */
+@DeveloperApi
+public final class ListMetadataObjectsForPolicyPreEvent extends PolicyPreEvent {
+ /**
+ * Constructs an instance of {@code ListMetadataObjectsForPolicyPreEvent}.
+ *
+ * @param user The username of the individual who initiated the list metadata objects operation.
+ * @param identifier The identifier of the policy.
+ */
+ public ListMetadataObjectsForPolicyPreEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_METADATA_OBJECTS_FOR_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesEvent.java
new file mode 100644
index 0000000000..667ce0d37f
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesEvent.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+
+/**
+ * Represents an event that is triggered upon successfully listing policies from a specific
+ * metalake.
+ */
+@DeveloperApi
+public class ListPoliciesEvent extends PolicyEvent {
+
+ /**
+ * Constructs an instance of {@code ListPoliciesEvent}.
+ *
+ * @param initiator The username of the individual who initiated the list-policies request.
+ * @param metalake The name of the metalake from which the policies were listed.
+ */
+ public ListPoliciesEvent(String initiator, String metalake) {
+ super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesFailureEvent.java
new file mode 100644
index 0000000000..5724c7763f
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesFailureEvent.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+
+/** Represents an event that is triggered when an attempt to list policies from a metalake fails. */
+@DeveloperApi
+public class ListPoliciesFailureEvent extends PolicyFailureEvent {
+
+ /**
+ * Constructs an instance of {@code ListPoliciesFailureEvent}.
+ *
+ * @param initiator The username of the individual who initiated the list-policies request.
+ * @param metalake The name of the metalake from which policies were to be listed.
+ * @param exception The exception that was encountered during the list-policies attempt.
+ */
+ public ListPoliciesFailureEvent(String initiator, String metalake, Exception exception) {
+ super(initiator, NameIdentifierUtil.ofMetalake(metalake), exception);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesPreEvent.java
new file mode 100644
index 0000000000..dcdfebad7d
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesPreEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+
+/** Represents an event that is triggered before listing policies from a specific metalake. */
+@DeveloperApi
+public class ListPoliciesPreEvent extends PolicyPreEvent {
+ /**
+ * Constructs an instance of {@code ListPoliciesPreEvent}.
+ *
+ * @param initiator The username of the individual who initiated the list-policies request.
+ * @param metalake The name of the metalake from which policies will be listed.
+ */
+ public ListPoliciesPreEvent(String initiator, String metalake) {
+ super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosEvent.java
new file mode 100644
index 0000000000..8e201f2457
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosEvent.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+
+/**
+ * Represents an event that is triggered upon successfully listing policy infos from a specific
+ * metalake.
+ */
+@DeveloperApi
+public class ListPolicyInfosEvent extends PolicyEvent {
+
+ /**
+ * Constructs an instance of {@code ListPolicyInfosEvent}.
+ *
+ * @param initiator The username of the individual who initiated the list-policy-infos request.
+ * @param metalake The name of the metalake from which the policy infos were listed.
+ */
+ public ListPolicyInfosEvent(String initiator, String metalake) {
+ super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY_INFO;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosFailureEvent.java
new file mode 100644
index 0000000000..12bf52a2bc
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosFailureEvent.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+
+/**
+ * Represents an event that is triggered when an attempt to list policy infos from a metalake fails.
+ */
+@DeveloperApi
+public class ListPolicyInfosFailureEvent extends PolicyFailureEvent {
+
+ /**
+ * Constructs an instance of {@code ListPolicyInfosFailureEvent}.
+ *
+ * @param initiator The username of the individual who initiated the list-policy-infos request.
+ * @param metalake The name of the metalake from which policy infos were to be listed.
+ * @param exception The exception that was encountered during the list-policy-infos attempt.
+ */
+ public ListPolicyInfosFailureEvent(String initiator, String metalake, Exception exception) {
+ super(initiator, NameIdentifierUtil.ofMetalake(metalake), exception);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY_INFO;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectEvent.java
new file mode 100644
index 0000000000..5b0d9b7e1d
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectEvent.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/**
+ * Represents an event that is triggered upon successfully listing policy infos associated with a
+ * metadata object.
+ */
+@DeveloperApi
+public final class ListPolicyInfosForMetadataObjectEvent extends PolicyEvent {
+ private final MetadataObject metadataObject;
+
+ /**
+ * Constructs an instance of {@code ListPolicyInfosForMetadataObjectEvent}.
+ *
+ * @param user The username of the individual who initiated the list policy infos operation.
+ * @param metalake The metalake from which the policy infos were listed.
+ * @param metadataObject The metadata object for which policy infos were listed.
+ */
+ public ListPolicyInfosForMetadataObjectEvent(
+ String user, String metalake, MetadataObject metadataObject) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.metadataObject = metadataObject;
+ }
+
+ /**
+ * Returns the metadata object for which policy infos were listed.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY_INFOS_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectFailureEvent.java
new file mode 100644
index 0000000000..4ee7c1d1d5
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectFailureEvent.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/**
+ * Represents an event that is triggered when an attempt to list policy infos associated with a
+ * metadata object fails.
+ */
+@DeveloperApi
+public final class ListPolicyInfosForMetadataObjectFailureEvent extends PolicyFailureEvent {
+ private final MetadataObject metadataObject;
+
+ /**
+ * Constructs an instance of {@code ListPolicyInfosForMetadataObjectFailureEvent}.
+ *
+ * @param user The username of the individual who initiated the list policy infos operation.
+ * @param metalake The metalake from which the policy infos were to be listed.
+ * @param metadataObject The metadata object for which policy infos were to be listed.
+ * @param exception The exception that was encountered during the list policy infos attempt.
+ */
+ public ListPolicyInfosForMetadataObjectFailureEvent(
+ String user, String metalake, MetadataObject metadataObject, Exception exception) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject), exception);
+ this.metadataObject = metadataObject;
+ }
+
+ /**
+ * Returns the metadata object for which policy infos were to be listed.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY_INFOS_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectPreEvent.java
new file mode 100644
index 0000000000..05eb6e5d2c
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectPreEvent.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+
+/**
+ * Represents an event that is triggered before listing policy infos associated with a metadata
+ * object.
+ */
+@DeveloperApi
+public final class ListPolicyInfosForMetadataObjectPreEvent extends PolicyPreEvent {
+ private final MetadataObject metadataObject;
+
+ /**
+ * Constructs an instance of {@code ListPolicyInfosForMetadataObjectPreEvent}.
+ *
+ * @param user The username of the individual who initiated the list policy infos operation.
+ * @param metalake The metalake from which the policy infos will be listed.
+ * @param metadataObject The metadata object for which policy infos will be listed.
+ */
+ public ListPolicyInfosForMetadataObjectPreEvent(
+ String user, String metalake, MetadataObject metadataObject) {
+ super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.metadataObject = metadataObject;
+ }
+
+ /**
+ * Returns the metadata object for which policy infos will be listed.
+ *
+ * @return the metadata object.
+ */
+ public MetadataObject metadataObject() {
+ return metadataObject;
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY_INFOS_FOR_METADATA_OBJECT;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosPreEvent.java
new file mode 100644
index 0000000000..9eee2a3e05
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosPreEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.OperationType;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+
+/** Represents an event that is triggered before listing policy infos from a specific metalake. */
+@DeveloperApi
+public class ListPolicyInfosPreEvent extends PolicyPreEvent {
+ /**
+ * Constructs an instance of {@code ListPolicyInfosPreEvent}.
+ *
+ * @param initiator The username of the individual who initiated the list-policy-infos request.
+ * @param metalake The name of the metalake from which policy infos will be listed.
+ */
+ public ListPolicyInfosPreEvent(String initiator, String metalake) {
+ super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return the operation type.
+ */
+ @Override
+ public OperationType operationType() {
+ return OperationType.LIST_POLICY_INFO;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyEvent.java
new file mode 100644
index 0000000000..3f2f719c3f
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyEvent.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.OperationStatus;
+
+/**
+ * Abstract base class for all successful policy events. This class serves as the foundation for
+ * events triggered after successful policy operations.
+ */
+@DeveloperApi
+public abstract class PolicyEvent extends Event {
+ /**
+ * Constructs a PolicyEvent.
+ *
+ * @param user The user who initiated the policy operation.
+ * @param identifier The identifier of the policy being operated on.
+ */
+ protected PolicyEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+
+ /**
+ * Returns the operation status, which is always SUCCESS for successful policy events.
+ *
+ * @return The operation status (SUCCESS).
+ */
+ @Override
+ public OperationStatus operationStatus() {
+ return OperationStatus.SUCCESS;
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyFailureEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyFailureEvent.java
new file mode 100644
index 0000000000..ee89c89ed0
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyFailureEvent.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.FailureEvent;
+
+/**
+ * Abstract base class for all failed policy events. These events are triggered when a policy
+ * operation fails with an exception.
+ */
+@DeveloperApi
+public abstract class PolicyFailureEvent extends FailureEvent {
+ /**
+ * Constructs a PolicyFailureEvent.
+ *
+ * @param user The user who initiated the policy operation.
+ * @param identifier The identifier of the policy being operated on.
+ * @param exception The exception that caused the failure.
+ */
+ protected PolicyFailureEvent(String user, NameIdentifier identifier, Exception exception) {
+ super(user, identifier, exception);
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyPreEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyPreEvent.java
new file mode 100644
index 0000000000..b50c63598d
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/PolicyPreEvent.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event.policy;
+
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.PreEvent;
+
+/**
+ * Abstract base class for all pre-operation policy events. These events are triggered before a
+ * policy operation is executed.
+ */
+@DeveloperApi
+public abstract class PolicyPreEvent extends PreEvent {
+ /**
+ * Constructs a PolicyPreEvent.
+ *
+ * @param user The user who initiated the policy operation.
+ * @param identifier The identifier of the policy being operated on.
+ */
+ protected PolicyPreEvent(String user, NameIdentifier identifier) {
+ super(user, identifier);
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/info/PolicyInfo.java b/core/src/main/java/org/apache/gravitino/listener/api/info/PolicyInfo.java
new file mode 100644
index 0000000000..b8c70e049b
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/info/PolicyInfo.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.info;
+
+import javax.annotation.Nullable;
+import org.apache.gravitino.Audit;
+import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.policy.Policy;
+import org.apache.gravitino.policy.PolicyContent;
+
+/**
+ * Provides read-only access to policy information for event listeners. This class encapsulates the
+ * essential attributes of a Policy, including its name, type, comment, enabled status, content, and
+ * audit information.
+ */
+@DeveloperApi
+public final class PolicyInfo {
+ private final String name;
+ private final String policyType;
+ @Nullable private final String comment;
+ private final boolean enabled;
+ private final PolicyContent content;
+ @Nullable private final Audit audit;
+
+ /**
+ * Constructs PolicyInfo from a Policy object.
+ *
+ * @param policy The Policy object to extract information from.
+ */
+ public PolicyInfo(Policy policy) {
+ this(
+ policy.name(),
+ policy.policyType(),
+ policy.comment(),
+ policy.enabled(),
+ policy.content(),
+ policy.auditInfo());
+ }
+
+ /**
+ * Constructs PolicyInfo with detailed parameters.
+ *
+ * @param name The name of the policy.
+ * @param policyType The type of the policy.
+ * @param comment An optional description of the policy.
+ * @param enabled Whether the policy is enabled.
+ * @param content The content of the policy.
+ * @param audit Optional audit information.
+ */
+ public PolicyInfo(
+ String name,
+ String policyType,
+ String comment,
+ boolean enabled,
+ PolicyContent content,
+ Audit audit) {
+ this.name = name;
+ this.policyType = policyType;
+ this.comment = comment;
+ this.enabled = enabled;
+ this.content = content;
+ this.audit = audit;
+ }
+
+ /**
+ * Returns the name of the policy.
+ *
+ * @return The policy name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Returns the type of the policy.
+ *
+ * @return The policy type.
+ */
+ public String policyType() {
+ return policyType;
+ }
+
+ /**
+ * Returns the optional comment describing the policy.
+ *
+ * @return The comment, or null if not provided.
+ */
+ @Nullable
+ public String comment() {
+ return comment;
+ }
+
+ /**
+ * Returns whether the policy is enabled.
+ *
+ * @return True if the policy is enabled, false otherwise.
+ */
+ public boolean enabled() {
+ return enabled;
+ }
+
+ /**
+ * Returns the content of the policy.
+ *
+ * @return The policy content.
+ */
+ public PolicyContent content() {
+ return content;
+ }
+
+ /**
+ * Returns the optional audit information.
+ *
+ * @return The audit information, or null if not provided.
+ */
+ @Nullable
+ public Audit audit() {
+ return audit;
+ }
+}
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestPolicyEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPolicyEvent.java
new file mode 100644
index 0000000000..5629d21b48
--- /dev/null
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPolicyEvent.java
@@ -0,0 +1,689 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.listener.api.event;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.Objects;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.listener.DummyEventListener;
+import org.apache.gravitino.listener.EventBus;
+import org.apache.gravitino.listener.PolicyEventDispatcher;
+import org.apache.gravitino.listener.api.event.policy.AlterPolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.AlterPolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.AlterPolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.AssociatePoliciesForMetadataObjectEvent;
+import org.apache.gravitino.listener.api.event.policy.AssociatePoliciesForMetadataObjectFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.AssociatePoliciesForMetadataObjectPreEvent;
+import org.apache.gravitino.listener.api.event.policy.CreatePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.CreatePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.CreatePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.DeletePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.DeletePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.DeletePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.DisablePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.DisablePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.DisablePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.EnablePolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.EnablePolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.EnablePolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyForMetadataObjectEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyForMetadataObjectFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyForMetadataObjectPreEvent;
+import org.apache.gravitino.listener.api.event.policy.GetPolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListMetadataObjectsForPolicyEvent;
+import org.apache.gravitino.listener.api.event.policy.ListMetadataObjectsForPolicyFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListMetadataObjectsForPolicyPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPoliciesEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPoliciesFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPoliciesPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosForMetadataObjectEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosForMetadataObjectFailureEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosForMetadataObjectPreEvent;
+import org.apache.gravitino.listener.api.event.policy.ListPolicyInfosPreEvent;
+import org.apache.gravitino.listener.api.info.PolicyInfo;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.meta.PolicyEntity;
+import org.apache.gravitino.policy.Policy;
+import org.apache.gravitino.policy.PolicyChange;
+import org.apache.gravitino.policy.PolicyContent;
+import org.apache.gravitino.policy.PolicyContents;
+import org.apache.gravitino.policy.PolicyDispatcher;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestInstance.Lifecycle;
+
+@TestInstance(Lifecycle.PER_CLASS)
+public class TestPolicyEvent {
+ private PolicyEventDispatcher failureDispatcher;
+ private PolicyEventDispatcher dispatcher;
+ private DummyEventListener dummyEventListener;
+ private PolicyEntity policy;
+
+ @BeforeAll
+ void init() {
+ this.policy = mockPolicy();
+ this.dummyEventListener = new DummyEventListener();
+ EventBus eventBus = new EventBus(Arrays.asList(dummyEventListener));
+ PolicyDispatcher policyExceptionDispatcher = mockExceptionPolicyDispatcher();
+ this.failureDispatcher = new PolicyEventDispatcher(eventBus, policyExceptionDispatcher);
+ PolicyDispatcher policyDispatcher = mockPolicyDispatcher();
+ this.dispatcher = new PolicyEventDispatcher(eventBus, policyDispatcher);
+ }
+
+ @Test
+ void testListPoliciesEvent() {
+ dispatcher.listPolicies("metalake");
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+
+ Assertions.assertEquals("metalake", Objects.requireNonNull(preEvent.identifier()).toString());
+ Assertions.assertEquals(ListPoliciesPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.LIST_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals("metalake", Objects.requireNonNull(postevent.identifier()).toString());
+ Assertions.assertEquals(ListPoliciesEvent.class, postevent.getClass());
+ Assertions.assertEquals(OperationType.LIST_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testListPolicyInfosEvent() {
+ dispatcher.listPolicyInfos("metalake");
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+
+ Assertions.assertEquals("metalake", Objects.requireNonNull(preEvent.identifier()).toString());
+ Assertions.assertEquals(ListPolicyInfosPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.LIST_POLICY_INFO, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals("metalake", Objects.requireNonNull(postevent.identifier()).toString());
+ Assertions.assertEquals(ListPolicyInfosEvent.class, postevent.getClass());
+ Assertions.assertEquals(OperationType.LIST_POLICY_INFO, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testGetPolicyEvent() {
+ dispatcher.getPolicy("metalake", policy.name());
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(GetPolicyPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.GET_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(GetPolicyEvent.class, postevent.getClass());
+ Assertions.assertEquals(OperationType.GET_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ PolicyInfo policyInfo = ((GetPolicyEvent) postevent).policyInfo();
+ checkPolicyInfo(policyInfo, policy);
+ }
+
+ @Test
+ void testCreatePolicyEvent() {
+ dispatcher.createPolicy(
+ "metalake",
+ policy.name(),
+ policy.policyType(),
+ policy.comment(),
+ policy.enabled(),
+ policy.content());
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(CreatePolicyPreEvent.class, preEvent.getClass());
+
+ PolicyInfo policyInfo = ((CreatePolicyPreEvent) preEvent).createPolicyRequest();
+ Assertions.assertEquals(policy.name(), policyInfo.name());
+ Assertions.assertEquals(policy.policyType().name(), policyInfo.policyType());
+ Assertions.assertEquals(policy.comment(), policyInfo.comment());
+ Assertions.assertEquals(policy.enabled(), policyInfo.enabled());
+ Assertions.assertEquals(policy.content(), policyInfo.content());
+
+ Assertions.assertEquals(OperationType.CREATE_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(CreatePolicyEvent.class, postevent.getClass());
+ PolicyInfo policyInfo2 = ((CreatePolicyEvent) postevent).createdPolicyInfo();
+ checkPolicyInfo(policyInfo2, policy);
+ Assertions.assertEquals(OperationType.CREATE_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testAlterPolicyEvent() {
+ PolicyChange change1 = PolicyChange.rename("newName");
+ PolicyChange[] changes = {change1};
+
+ dispatcher.alterPolicy("metalake", policy.name(), changes);
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(AlterPolicyPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.ALTER_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ PolicyChange[] eventChanges = ((AlterPolicyPreEvent) preEvent).policyChanges();
+ Assertions.assertArrayEquals(changes, eventChanges);
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(AlterPolicyEvent.class, postevent.getClass());
+ Assertions.assertEquals(OperationType.ALTER_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+
+ PolicyChange[] postChanges = ((AlterPolicyEvent) postevent).policyChanges();
+ Assertions.assertArrayEquals(changes, postChanges);
+ }
+
+ @Test
+ void testEnablePolicyEvent() {
+ dispatcher.enablePolicy("metalake", policy.name());
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(EnablePolicyPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.ENABLE_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(EnablePolicyEvent.class, postevent.getClass());
+ Assertions.assertEquals(OperationType.ENABLE_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testDisablePolicyEvent() {
+ dispatcher.disablePolicy("metalake", policy.name());
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(DisablePolicyPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.DISABLE_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(DisablePolicyEvent.class, postevent.getClass());
+ Assertions.assertEquals(OperationType.DISABLE_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testDeletePolicyEvent() {
+ dispatcher.deletePolicy("metalake", policy.name());
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(DeletePolicyPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.DELETE_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(DeletePolicyEvent.class, postevent.getClass());
+ Assertions.assertEquals(OperationType.DELETE_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testListMetadataObjectsForPolicyEvent() {
+ dispatcher.listMetadataObjectsForPolicy("metalake", policy.name());
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(ListMetadataObjectsForPolicyPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(
+ OperationType.LIST_METADATA_OBJECTS_FOR_POLICY, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(ListMetadataObjectsForPolicyEvent.class, postevent.getClass());
+ Assertions.assertEquals(
+ OperationType.LIST_METADATA_OBJECTS_FOR_POLICY, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testListPolicyInfosForMetadataObjectEvent() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+ dispatcher.listPolicyInfosForMetadataObject("metalake", metadataObject);
+
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+ NameIdentifier identifier = MetadataObjectUtil.toEntityIdent("metalake", metadataObject);
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(ListPolicyInfosForMetadataObjectPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(
+ OperationType.LIST_POLICY_INFOS_FOR_METADATA_OBJECT, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(ListPolicyInfosForMetadataObjectEvent.class, postevent.getClass());
+ Assertions.assertEquals(
+ OperationType.LIST_POLICY_INFOS_FOR_METADATA_OBJECT, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testAssociatePoliciesForMetadataObjectEvent() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+
+ String[] policiesToAdd = {"policy1", "policy2"};
+ String[] policiesToRemove = {"policy3"};
+
+ dispatcher.associatePoliciesForMetadataObject(
+ "metalake", metadataObject, policiesToAdd, policiesToRemove);
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+
+ NameIdentifier identifier = MetadataObjectUtil.toEntityIdent("metalake", metadataObject);
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(AssociatePoliciesForMetadataObjectPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(
+ MetadataObject.Type.CATALOG,
+ ((AssociatePoliciesForMetadataObjectPreEvent) preEvent).metadataObject().type());
+ Assertions.assertArrayEquals(
+ policiesToAdd, ((AssociatePoliciesForMetadataObjectPreEvent) preEvent).policiesToAdd());
+ Assertions.assertArrayEquals(
+ policiesToRemove,
+ ((AssociatePoliciesForMetadataObjectPreEvent) preEvent).policiesToRemove());
+
+ Assertions.assertEquals(
+ OperationType.ASSOCIATE_POLICIES_FOR_METADATA_OBJECT, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(AssociatePoliciesForMetadataObjectEvent.class, postevent.getClass());
+ Assertions.assertEquals(
+ MetadataObject.Type.CATALOG,
+ ((AssociatePoliciesForMetadataObjectEvent) postevent).metadataObject().type());
+ Assertions.assertArrayEquals(
+ policiesToAdd, ((AssociatePoliciesForMetadataObjectEvent) postevent).policiesToAdd());
+ Assertions.assertArrayEquals(
+ policiesToRemove, ((AssociatePoliciesForMetadataObjectEvent) postevent).policiesToRemove());
+ Assertions.assertEquals(
+ OperationType.ASSOCIATE_POLICIES_FOR_METADATA_OBJECT, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ }
+
+ @Test
+ void testGetPolicyForMetadataObjectEvent() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+
+ dispatcher.getPolicyForMetadataObject("metalake", metadataObject, policy.name());
+ PreEvent preEvent = dummyEventListener.popPreEvent();
+
+ NameIdentifier identifier = MetadataObjectUtil.toEntityIdent("metalake", metadataObject);
+
+ Assertions.assertEquals(identifier.toString(), preEvent.identifier().toString());
+ Assertions.assertEquals(GetPolicyForMetadataObjectPreEvent.class, preEvent.getClass());
+ Assertions.assertEquals(OperationType.GET_POLICY_FOR_METADATA_OBJECT, preEvent.operationType());
+ Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
+
+ Event postevent = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(identifier.toString(), postevent.identifier().toString());
+ Assertions.assertEquals(GetPolicyForMetadataObjectEvent.class, postevent.getClass());
+ Assertions.assertEquals(
+ OperationType.GET_POLICY_FOR_METADATA_OBJECT, postevent.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+
+ PolicyInfo policyInfo = ((GetPolicyForMetadataObjectEvent) postevent).policyInfo();
+ checkPolicyInfo(policyInfo, policy);
+ }
+
+ @Test
+ void testCreatePolicyFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () ->
+ failureDispatcher.createPolicy(
+ "metalake",
+ policy.name(),
+ policy.policyType(),
+ policy.comment(),
+ policy.enabled(),
+ policy.content()));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(CreatePolicyFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class, ((CreatePolicyFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(
+ policy.name(), ((CreatePolicyFailureEvent) event).createPolicyRequest().name());
+ Assertions.assertEquals(
+ policy.policyType().name(),
+ ((CreatePolicyFailureEvent) event).createPolicyRequest().policyType());
+ Assertions.assertEquals(
+ policy.comment(), ((CreatePolicyFailureEvent) event).createPolicyRequest().comment());
+ Assertions.assertEquals(
+ policy.enabled(), ((CreatePolicyFailureEvent) event).createPolicyRequest().enabled());
+ Assertions.assertEquals(
+ policy.content(), ((CreatePolicyFailureEvent) event).createPolicyRequest().content());
+ Assertions.assertEquals(OperationType.CREATE_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testGetPolicyFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () -> failureDispatcher.getPolicy("metalake", policy.name()));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(GetPolicyFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class, ((GetPolicyFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.GET_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testAlterPolicyFailureEvent() {
+ PolicyChange change1 = PolicyChange.rename("newName");
+ PolicyChange change2 = PolicyChange.updateComment("new comment");
+ PolicyChange[] changes = new PolicyChange[] {change1, change2};
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () -> failureDispatcher.alterPolicy("metalake", policy.name(), changes));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(AlterPolicyFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class, ((AlterPolicyFailureEvent) event).exception().getClass());
+ Assertions.assertArrayEquals(changes, ((AlterPolicyFailureEvent) event).policyChanges());
+ Assertions.assertEquals(OperationType.ALTER_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testDeletePolicyFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () -> failureDispatcher.deletePolicy("metalake", policy.name()));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(DeletePolicyFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class, ((DeletePolicyFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.DELETE_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testEnablePolicyFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () -> failureDispatcher.enablePolicy("metalake", policy.name()));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(EnablePolicyFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class, ((EnablePolicyFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.ENABLE_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testDisablePolicyFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () -> failureDispatcher.disablePolicy("metalake", policy.name()));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(DisablePolicyFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class,
+ ((DisablePolicyFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.DISABLE_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testListPoliciesFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class, () -> failureDispatcher.listPolicies("metalake"));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(ListPoliciesFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class, ((ListPoliciesFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.LIST_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testListPolicyInfosFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class, () -> failureDispatcher.listPolicyInfos("metalake"));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(ListPolicyInfosFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class,
+ ((ListPolicyInfosFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.LIST_POLICY_INFO, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testListMetadataObjectsForPolicyFailureEvent() {
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () -> failureDispatcher.listMetadataObjectsForPolicy("metalake", policy.name()));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(ListMetadataObjectsForPolicyFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class,
+ ((ListMetadataObjectsForPolicyFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.LIST_METADATA_OBJECTS_FOR_POLICY, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testListPolicyInfosForMetadataObjectFailureEvent() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () -> failureDispatcher.listPolicyInfosForMetadataObject("metalake", metadataObject));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(ListPolicyInfosForMetadataObjectFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class,
+ ((ListPolicyInfosForMetadataObjectFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(
+ OperationType.LIST_POLICY_INFOS_FOR_METADATA_OBJECT, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testAssociatePoliciesForMetadataObjectFailureEvent() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+
+ String[] policiesToAssociate = new String[] {"policy1", "policy2"};
+ String[] policiesToDisassociate = new String[] {"policy3", "policy4"};
+
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () ->
+ failureDispatcher.associatePoliciesForMetadataObject(
+ "metalake", metadataObject, policiesToAssociate, policiesToDisassociate));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(AssociatePoliciesForMetadataObjectFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class,
+ ((AssociatePoliciesForMetadataObjectFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(
+ MetadataObject.Type.CATALOG,
+ ((AssociatePoliciesForMetadataObjectFailureEvent) event).metadataObject().type());
+ Assertions.assertArrayEquals(
+ policiesToAssociate,
+ ((AssociatePoliciesForMetadataObjectFailureEvent) event).policiesToAdd());
+ Assertions.assertArrayEquals(
+ policiesToDisassociate,
+ ((AssociatePoliciesForMetadataObjectFailureEvent) event).policiesToRemove());
+ Assertions.assertEquals(
+ OperationType.ASSOCIATE_POLICIES_FOR_METADATA_OBJECT, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ @Test
+ void testGetPolicyForMetadataObjectFailureEvent() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class,
+ () ->
+ failureDispatcher.getPolicyForMetadataObject(
+ "metalake", metadataObject, policy.name()));
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(GetPolicyForMetadataObjectFailureEvent.class, event.getClass());
+ Assertions.assertEquals(
+ GravitinoRuntimeException.class,
+ ((GetPolicyForMetadataObjectFailureEvent) event).exception().getClass());
+ Assertions.assertEquals(OperationType.GET_POLICY_FOR_METADATA_OBJECT, event.operationType());
+ Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
+ }
+
+ private PolicyEntity mockPolicy() {
+ PolicyContent content =
+ PolicyContents.custom(
+ ImmutableMap.of("rule1", "value1"),
+ ImmutableSet.of(MetadataObject.Type.CATALOG),
+ ImmutableMap.of("property1", "value1"));
+
+ AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(java.time.Instant.now()).build();
+
+ return PolicyEntity.builder()
+ .withId(1L)
+ .withName("policy")
+ .withPolicyType(Policy.BuiltInType.CUSTOM)
+ .withComment("policy comment")
+ .withEnabled(true)
+ .withContent(content)
+ .withAuditInfo(auditInfo)
+ .build();
+ }
+
+ private PolicyDispatcher mockExceptionPolicyDispatcher() {
+ return mock(
+ PolicyDispatcher.class,
+ invocation -> {
+ throw new GravitinoRuntimeException("Exception for all methods");
+ });
+ }
+
+ private void checkPolicyInfo(PolicyInfo actualPolicyInfo, PolicyEntity expectedPolicy) {
+ Assertions.assertEquals(expectedPolicy.name(), actualPolicyInfo.name());
+ Assertions.assertEquals(expectedPolicy.policyType().name(), actualPolicyInfo.policyType());
+ Assertions.assertEquals(expectedPolicy.comment(), actualPolicyInfo.comment());
+ Assertions.assertEquals(expectedPolicy.enabled(), actualPolicyInfo.enabled());
+ Assertions.assertEquals(expectedPolicy.content(), actualPolicyInfo.content());
+ }
+
+ private PolicyDispatcher mockPolicyDispatcher() {
+ PolicyDispatcher dispatcher = mock(PolicyDispatcher.class);
+ String metalake = "metalake";
+ String[] policyNames = new String[] {"policy1", "policy2"};
+ PolicyEntity[] policies = new PolicyEntity[] {policy, policy};
+
+ when(dispatcher.createPolicy(
+ any(String.class),
+ any(String.class),
+ any(Policy.BuiltInType.class),
+ any(String.class),
+ any(Boolean.class),
+ any(PolicyContent.class)))
+ .thenReturn(policy);
+ when(dispatcher.listPolicies(metalake)).thenReturn(policyNames);
+ when(dispatcher.listPolicyInfos(metalake)).thenReturn(policies);
+ when(dispatcher.alterPolicy(any(String.class), any(String.class), any(PolicyChange[].class)))
+ .thenReturn(policy);
+ when(dispatcher.getPolicy(any(String.class), any(String.class))).thenReturn(policy);
+ when(dispatcher.deletePolicy(metalake, policy.name())).thenReturn(true);
+ when(dispatcher.getPolicyForMetadataObject(
+ any(String.class), any(MetadataObject.class), any(String.class)))
+ .thenReturn(policy);
+ MetadataObject catalog =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+ MetadataObject[] objects = new MetadataObject[] {catalog};
+
+ when(dispatcher.listMetadataObjectsForPolicy(any(String.class), any(String.class)))
+ .thenReturn(objects);
+
+ when(dispatcher.associatePoliciesForMetadataObject(
+ any(String.class), any(MetadataObject.class), any(String[].class), any(String[].class)))
+ .thenReturn(new String[] {"policy1", "policy2"});
+
+ when(dispatcher.listPolicyInfosForMetadataObject(any(String.class), any(MetadataObject.class)))
+ .thenReturn(new PolicyEntity[] {policy, policy});
+
+ return dispatcher;
+ }
+}
diff --git a/docs/gravitino-server-config.md b/docs/gravitino-server-config.md
index 6f597e72b6..cf498b8b20 100644
--- a/docs/gravitino-server-config.md
+++ b/docs/gravitino-server-config.md
@@ -190,6 +190,7 @@ Gravitino triggers a pre-event before the operation, a post-event after the comp
| Gravitino server job template operation | `RegisterJobTemplateEvent`, `GetJobTemplateEvent`, `ListJobTemplatesEvent`, `AlterJobTemplateEvent`, `DeleteJobTemplateEvent`, `RegisterJobTemplateFailureEvent`, `GetJobTemplateFailureEvent`, `ListJobTemplatesFailureEvent`, `AlterJobTemplateFailureEvent`, `DeleteJobTemplateFailureEvent` | 1.0.1 |
| Gravitino server job operation | `RunJobEvent`, `GetJobEvent`, `ListJobsEvent`, `CancelJobEvent`, `RunJobFailureEvent`, `GetJobFailureEvent`, `ListJobsFailureEvent`, `CancelJobFailureEvent` | 1.0.1 |
| Gravitino server statistics operation | `ListStatisticsEvent`, `UpdateStatisticsEvent`, `DropStatisticsEvent`, `ListPartitionStatisticsEvent`, `UpdatePartitionStatisticsEvent`, `DropPartitionStatisticsEvent`, `ListStatisticsFailureEvent`, `UpdateStatisticsFailureEvent`, `DropStatisticsFailureEvent`, `ListPartitionStatisticsFailureEvent`, `UpdatePartitionStatisticsFailureEvent`, `DropPartitionStatisticsFailureEvent` | 1.1.0 |
+| policy operation | `CreatePolicyEvent`, `AlterPolicyEvent`, `DeletePolicyEvent`, `GetPolicyEvent`, `ListPoliciesEvent`, `AssociatePoliciesForMetadataObjectEvent`, `ListAssociatedPoliciesForMetadataObjectEvent`, `CreatePolicyFailureEvent`, `AlterPolicyFailureEvent`, `DeletePolicyFailureEvent`, `GetPolicyFailureEvent`, `ListPoliciesFailureEvent`, `AssociatePoliciesForMetadataObjectFailureEvent`, `ListAssociatedPoliciesForMetadataObjectFailureEvent` | 1.1.0 |
##### Pre-event
@@ -211,6 +212,7 @@ Gravitino triggers a pre-event before the operation, a post-event after the comp
| Gravitino server job template operation | `RegisterJobTemplatePreEvent`, `GetJobTemplatePreEvent`, `ListJobTemplatesPreEvent`, `AlterJobTemplatePreEvent`, `DeleteJobTemplatePreEvent` | 1.0.1 |
| Gravitino server job operation | `RunJobPreEvent`, `GetJobPreEvent`, `ListJobsPreEvent`, `CancelJobPreEvent` | 1.0.1 |
| Gravitino server statistics operation | `ListStatisticsPreEvent`, `UpdateStatisticsPreEvent`, `DropStatisticsPreEvent`, `ListPartitionStatisticsPreEvent`, `UpdatePartitionStatisticsPreEvent`, `DropPartitionStatisticsPreEvent` | 1.1.0 |
+| policy operation | `CreatePolicyPreEvent`, `AlterPolicyPreEvent`, `DeletePolicyPreEvent`, `GetPolicyPreEvent`, `ListPoliciesPreEvent`, `AssociatePoliciesForMetadataObjectPreEvent`, `ListAssociatedPoliciesForMetadataObjectPreEvent` | 1.1.0 |
#### Event listener plugin