You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jerqi (via GitHub)" <gi...@apache.org> on 2024/08/08 02:59:53 UTC

[PR] Add hook dispatcher [gravitino]

jerqi opened a new pull request, #4429:
URL: https://github.com/apache/gravitino/pull/4429

   <!--
   1. Title: [#<issue>] <type>(<scope>): <subject>
      Examples:
        - "[#123] feat(operator): support xxx"
        - "[#233] fix: check null before access result in xxx"
        - "[MINOR] refactor: fix typo in variable name"
        - "[MINOR] docs: fix typo in README"
        - "[#255] test: fix flaky test NameOfTheTest"
      Reference: https://www.conventionalcommits.org/en/v1.0.0/
   2. If the PR is unfinished, please mark this PR as draft.
   -->
   
   ### What changes were proposed in this pull request?
   
   (Please outline the changes and how this PR fixes the issue.)
   
   ### Why are the changes needed?
   
   (Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, describe the bug.)
   
   Fix: # (issue)
   
   ### Does this PR introduce _any_ user-facing change?
   
   (Please list the user-facing changes introduced by your change, including
     1. Change in user-facing APIs.
     2. Addition or removal of property keys.)
   
   ### How was this patch tested?
   
   (Please test your changes, and provide instructions on how to test it:
     1. If you add a feature or fix a bug, add a test to cover your changes.
     2. If you fix a flaky test, repeat it for many times to prove it works.)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi closed pull request #4429: [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher
URL: https://github.com/apache/gravitino/pull/4429


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu merged PR #4429:
URL: https://github.com/apache/gravitino/pull/4429


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1708959951


##########
api/src/main/java/org/apache/gravitino/authorization/SecurableObjects.java:
##########
@@ -33,6 +33,17 @@ public class SecurableObjects {
 
   private static final Splitter DOT_SPLITTER = Splitter.on('.');
 
+  /**
+   * Create the metalake {@link SecurableObject} with the given metalake name.

Review Comment:
   With the given metalake name and privileges?



##########
core/src/main/java/org/apache/gravitino/hook/AccessControlHookDispatcher.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.hook;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.authorization.AccessControlDispatcher;
+import org.apache.gravitino.authorization.AuthorizationUtils;
+import org.apache.gravitino.authorization.Group;
+import org.apache.gravitino.authorization.Owner;
+import org.apache.gravitino.authorization.OwnerManager;
+import org.apache.gravitino.authorization.Role;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.User;
+import org.apache.gravitino.exceptions.GroupAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchGroupException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchRoleException;
+import org.apache.gravitino.exceptions.NoSuchUserException;
+import org.apache.gravitino.exceptions.RoleAlreadyExistsException;
+import org.apache.gravitino.exceptions.UserAlreadyExistsException;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.PrincipalUtils;
+
+/**
+ * {@code AccessControlHookDispatcher} is a decorator for {@link AccessControlDispatcher} that not
+ * only delegates access control operations to the underlying access control dispatcher but also
+ * executes some hook operations before or after the underlying operations.
+ */
+public class AccessControlHookDispatcher implements AccessControlDispatcher {

Review Comment:
   I can't get why do we name it `Hook` here? 



##########
core/src/main/java/org/apache/gravitino/GravitinoEnv.java:
##########
@@ -348,28 +352,30 @@ private void initGravitinoServerComponents() {
 
     // Create and initialize metalake related modules
     MetalakeDispatcher metalakeManager = new MetalakeManager(entityStore, idGenerator);
+    MetalakeHookDispatcher metalakeHookDispatcher = new MetalakeHookDispatcher(metalakeManager);
     MetalakeNormalizeDispatcher metalakeNormalizeDispatcher =
-        new MetalakeNormalizeDispatcher(installDispatcherHooks(metalakeManager));
+        new MetalakeNormalizeDispatcher(metalakeHookDispatcher);
     this.metalakeDispatcher = new MetalakeEventDispatcher(eventBus, metalakeNormalizeDispatcher);
 
     // Create and initialize Catalog related modules
     this.catalogManager = new CatalogManager(config, entityStore, idGenerator);
+    CatalogHookDispatcher catalogHookDispatcher = new CatalogHookDispatcher(catalogManager);
     CatalogNormalizeDispatcher catalogNormalizeDispatcher =
-        new CatalogNormalizeDispatcher(installDispatcherHooks((CatalogDispatcher) catalogManager));
+        new CatalogNormalizeDispatcher(catalogHookDispatcher);

Review Comment:
   It seems that we have wrapped the dispatcher too many times. 



##########
core/src/main/java/org/apache/gravitino/hook/AccessControlHookDispatcher.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.hook;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.authorization.AccessControlDispatcher;
+import org.apache.gravitino.authorization.AuthorizationUtils;
+import org.apache.gravitino.authorization.Group;
+import org.apache.gravitino.authorization.Owner;
+import org.apache.gravitino.authorization.OwnerManager;
+import org.apache.gravitino.authorization.Role;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.User;
+import org.apache.gravitino.exceptions.GroupAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchGroupException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchRoleException;
+import org.apache.gravitino.exceptions.NoSuchUserException;
+import org.apache.gravitino.exceptions.RoleAlreadyExistsException;
+import org.apache.gravitino.exceptions.UserAlreadyExistsException;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.PrincipalUtils;
+
+/**
+ * {@code AccessControlHookDispatcher} is a decorator for {@link AccessControlDispatcher} that not

Review Comment:
   What the meaning of `decorator` in this context?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1709323732


##########
core/src/main/java/org/apache/gravitino/hook/AccessControlHookDispatcher.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.hook;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.authorization.AccessControlDispatcher;
+import org.apache.gravitino.authorization.AuthorizationUtils;
+import org.apache.gravitino.authorization.Group;
+import org.apache.gravitino.authorization.Owner;
+import org.apache.gravitino.authorization.OwnerManager;
+import org.apache.gravitino.authorization.Role;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.User;
+import org.apache.gravitino.exceptions.GroupAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchGroupException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchRoleException;
+import org.apache.gravitino.exceptions.NoSuchUserException;
+import org.apache.gravitino.exceptions.RoleAlreadyExistsException;
+import org.apache.gravitino.exceptions.UserAlreadyExistsException;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.PrincipalUtils;
+
+/**
+ * {@code AccessControlHookDispatcher} is a decorator for {@link AccessControlDispatcher} that not
+ * only delegates access control operations to the underlying access control dispatcher but also
+ * executes some hook operations before or after the underlying operations.
+ */
+public class AccessControlHookDispatcher implements AccessControlDispatcher {

Review Comment:
   This class provide the hook operations for every dispatcher.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1708798481


##########
core/src/main/java/org/apache/gravitino/hook/CatalogHookDispatcher.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.hook;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.CatalogChange;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.catalog.CatalogDispatcher;
+import org.apache.gravitino.exceptions.CatalogAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+
+public class CatalogHookDispatcher implements CatalogDispatcher {
+  private final CatalogDispatcher dispatcher;
+  private final List<CatalogCreatePostHook> createPostHooks;
+
+  public CatalogHookDispatcher(CatalogDispatcher dispatcher) {
+    this.dispatcher = dispatcher;
+    this.createPostHooks = Lists.newArrayList();
+  }
+
+  @Override
+  public NameIdentifier[] listCatalogs(Namespace namespace) throws NoSuchMetalakeException {
+    return dispatcher.listCatalogs(namespace);
+  }
+
+  @Override
+  public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {
+    return dispatcher.listCatalogsInfo(namespace);
+  }
+
+  @Override
+  public Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {
+    return dispatcher.loadCatalog(ident);
+  }
+
+  @Override
+  public Catalog createCatalog(
+      NameIdentifier ident,
+      Catalog.Type type,
+      String provider,
+      String comment,
+      Map<String, String> properties)
+      throws NoSuchMetalakeException, CatalogAlreadyExistsException {
+    Catalog catalog = dispatcher.createCatalog(ident, type, provider, comment, properties);
+    for (CatalogCreatePostHook hook : createPostHooks) {
+      hook.execute(ident);
+    }

Review Comment:
   I think we can directly execute the here, didn't need to call `hook.execute()`.
   ```
           ownerManager.setOwner(
               ident.name(),
               NameIdentifierUtil.toMetadataObject(ident, Entity.EntityType.METALAKE),
               PrincipalUtils.getCurrentUserName(),
               Owner.Type.USER);
   ```
   
   
   



##########
core/src/main/java/org/apache/gravitino/authorization/AuthorizationHookRegistry.java:
##########


Review Comment:
   I think we didn't need this class.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1709325389


##########
api/src/main/java/org/apache/gravitino/authorization/SecurableObjects.java:
##########
@@ -33,6 +33,17 @@ public class SecurableObjects {
 
   private static final Splitter DOT_SPLITTER = Splitter.on('.');
 
+  /**
+   * Create the metalake {@link SecurableObject} with the given metalake name.

Review Comment:
   OK. I can change it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1709401985


##########
core/src/main/java/org/apache/gravitino/GravitinoEnv.java:
##########
@@ -348,28 +352,30 @@ private void initGravitinoServerComponents() {
 
     // Create and initialize metalake related modules
     MetalakeDispatcher metalakeManager = new MetalakeManager(entityStore, idGenerator);
+    MetalakeHookDispatcher metalakeHookDispatcher = new MetalakeHookDispatcher(metalakeManager);
     MetalakeNormalizeDispatcher metalakeNormalizeDispatcher =
-        new MetalakeNormalizeDispatcher(installDispatcherHooks(metalakeManager));
+        new MetalakeNormalizeDispatcher(metalakeHookDispatcher);
     this.metalakeDispatcher = new MetalakeEventDispatcher(eventBus, metalakeNormalizeDispatcher);
 
     // Create and initialize Catalog related modules
     this.catalogManager = new CatalogManager(config, entityStore, idGenerator);
+    CatalogHookDispatcher catalogHookDispatcher = new CatalogHookDispatcher(catalogManager);
     CatalogNormalizeDispatcher catalogNormalizeDispatcher =
-        new CatalogNormalizeDispatcher(installDispatcherHooks((CatalogDispatcher) catalogManager));
+        new CatalogNormalizeDispatcher(catalogHookDispatcher);

Review Comment:
   I also feel the current `Dispatcher` mechanism inelegant.
   I create a issue track it 
   - https://github.com/apache/gravitino/issues/4446



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#issuecomment-2276084455

   I don't like the current package name "hook", it doesn't have any meaning. Besides, the changes are related to authorization, why don't you move to authorization?
   
   Anyway, please refactor this code.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1709331840


##########
core/src/main/java/org/apache/gravitino/GravitinoEnv.java:
##########
@@ -348,28 +352,30 @@ private void initGravitinoServerComponents() {
 
     // Create and initialize metalake related modules
     MetalakeDispatcher metalakeManager = new MetalakeManager(entityStore, idGenerator);
+    MetalakeHookDispatcher metalakeHookDispatcher = new MetalakeHookDispatcher(metalakeManager);
     MetalakeNormalizeDispatcher metalakeNormalizeDispatcher =
-        new MetalakeNormalizeDispatcher(installDispatcherHooks(metalakeManager));
+        new MetalakeNormalizeDispatcher(metalakeHookDispatcher);
     this.metalakeDispatcher = new MetalakeEventDispatcher(eventBus, metalakeNormalizeDispatcher);
 
     // Create and initialize Catalog related modules
     this.catalogManager = new CatalogManager(config, entityStore, idGenerator);
+    CatalogHookDispatcher catalogHookDispatcher = new CatalogHookDispatcher(catalogManager);
     CatalogNormalizeDispatcher catalogNormalizeDispatcher =
-        new CatalogNormalizeDispatcher(installDispatcherHooks((CatalogDispatcher) catalogManager));
+        new CatalogNormalizeDispatcher(catalogHookDispatcher);

Review Comment:
   Maybe we can put normalizeDispatcher to HookDispatcher in the future.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1709324775


##########
core/src/main/java/org/apache/gravitino/GravitinoEnv.java:
##########
@@ -348,28 +352,30 @@ private void initGravitinoServerComponents() {
 
     // Create and initialize metalake related modules
     MetalakeDispatcher metalakeManager = new MetalakeManager(entityStore, idGenerator);
+    MetalakeHookDispatcher metalakeHookDispatcher = new MetalakeHookDispatcher(metalakeManager);
     MetalakeNormalizeDispatcher metalakeNormalizeDispatcher =
-        new MetalakeNormalizeDispatcher(installDispatcherHooks(metalakeManager));
+        new MetalakeNormalizeDispatcher(metalakeHookDispatcher);
     this.metalakeDispatcher = new MetalakeEventDispatcher(eventBus, metalakeNormalizeDispatcher);
 
     // Create and initialize Catalog related modules
     this.catalogManager = new CatalogManager(config, entityStore, idGenerator);
+    CatalogHookDispatcher catalogHookDispatcher = new CatalogHookDispatcher(catalogManager);
     CatalogNormalizeDispatcher catalogNormalizeDispatcher =
-        new CatalogNormalizeDispatcher(installDispatcherHooks((CatalogDispatcher) catalogManager));
+        new CatalogNormalizeDispatcher(catalogHookDispatcher);

Review Comment:
   Known issues. But we don't have better solution.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi closed pull request #4429: [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher
URL: https://github.com/apache/gravitino/pull/4429


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1709321806


##########
core/src/main/java/org/apache/gravitino/hook/AccessControlHookDispatcher.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.hook;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.authorization.AccessControlDispatcher;
+import org.apache.gravitino.authorization.AuthorizationUtils;
+import org.apache.gravitino.authorization.Group;
+import org.apache.gravitino.authorization.Owner;
+import org.apache.gravitino.authorization.OwnerManager;
+import org.apache.gravitino.authorization.Role;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.authorization.User;
+import org.apache.gravitino.exceptions.GroupAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchGroupException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+import org.apache.gravitino.exceptions.NoSuchRoleException;
+import org.apache.gravitino.exceptions.NoSuchUserException;
+import org.apache.gravitino.exceptions.RoleAlreadyExistsException;
+import org.apache.gravitino.exceptions.UserAlreadyExistsException;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.PrincipalUtils;
+
+/**
+ * {@code AccessControlHookDispatcher} is a decorator for {@link AccessControlDispatcher} that not

Review Comment:
   You can refer to decorator design pattern.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#discussion_r1708841578


##########
core/src/main/java/org/apache/gravitino/hook/CatalogHookDispatcher.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.hook;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.CatalogChange;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.catalog.CatalogDispatcher;
+import org.apache.gravitino.exceptions.CatalogAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchCatalogException;
+import org.apache.gravitino.exceptions.NoSuchMetalakeException;
+
+public class CatalogHookDispatcher implements CatalogDispatcher {
+  private final CatalogDispatcher dispatcher;
+  private final List<CatalogCreatePostHook> createPostHooks;
+
+  public CatalogHookDispatcher(CatalogDispatcher dispatcher) {
+    this.dispatcher = dispatcher;
+    this.createPostHooks = Lists.newArrayList();
+  }
+
+  @Override
+  public NameIdentifier[] listCatalogs(Namespace namespace) throws NoSuchMetalakeException {
+    return dispatcher.listCatalogs(namespace);
+  }
+
+  @Override
+  public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {
+    return dispatcher.listCatalogsInfo(namespace);
+  }
+
+  @Override
+  public Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {
+    return dispatcher.loadCatalog(ident);
+  }
+
+  @Override
+  public Catalog createCatalog(
+      NameIdentifier ident,
+      Catalog.Type type,
+      String provider,
+      String comment,
+      Map<String, String> properties)
+      throws NoSuchMetalakeException, CatalogAlreadyExistsException {
+    Catalog catalog = dispatcher.createCatalog(ident, type, provider, comment, properties);
+    for (CatalogCreatePostHook hook : createPostHooks) {
+      hook.execute(ident);
+    }

Review Comment:
   I feel that we should extract the abstraction of the hook. It will be convenient to extend more post hooks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4236] feat(core): Rework of post hook for dispatcher [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on PR #4429:
URL: https://github.com/apache/gravitino/pull/4429#issuecomment-2277016916

   > I don't like the current package name "hook", it doesn't have any meaning. Besides, the changes are related to authorization, why don't you move to authorization?
   > 
   > Anyway, please refactor this code.
   
   Normalizing the names may be a pre-hook. I plan to add some authorization unrelated hooks to this class to reduce the number of dispatcher.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org