jerqi commented on code in PR #4879:
URL: https://github.com/apache/gravitino/pull/4879#discussion_r1778312033


##########
clients/client-java/src/test/java/org/apache/gravitino/client/TestUserGroup.java:
##########
@@ -327,6 +330,58 @@ public void testRemoveGroups() throws Exception {
     Assertions.assertThrows(RuntimeException.class, () -> 
gravitinoClient.removeGroup(groupName));
   }
 
+  @Test
+  public void testListGroupNames() throws JsonProcessingException {
+    String groupPath = withSlash(String.format(API_METALAKES_GROUPS_PATH, 
metalakeName, ""));
+    NameListResponse listResponse = new NameListResponse(new String[] 
{"group1", "group2"});
+    buildMockResource(Method.GET, groupPath, null, listResponse, SC_OK);
+    Assertions.assertArrayEquals(
+        new String[] {"group1", "group2"}, gravitinoClient.listGroupNames());
+    ErrorResponse errRespNoMetaLake =
+        ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), 
"metalake not found");
+    buildMockResource(Method.GET, groupPath, null, errRespNoMetaLake, 
SC_NOT_FOUND);
+    Exception ex =
+        Assertions.assertThrows(
+            NoSuchMetalakeException.class,
+            () -> {
+              gravitinoClient.listGroupNames();
+            });

Review Comment:
   OK.



##########
core/src/main/java/org/apache/gravitino/authorization/UserGroupManager.java:
##########
@@ -197,4 +198,30 @@ Group getGroup(String metalake, String group) {
       throw new RuntimeException(ioe);
     }
   }
+
+  Group[] listGroups(String metalake) {
+    return listGroupInternal(metalake, true);
+  }
+
+  private Group[] listGroupInternal(String metalake, boolean allFields) {
+    try {
+      AuthorizationUtils.checkMetalakeExists(metalake);
+      Namespace namespace = AuthorizationUtils.ofGroupNamespace(metalake);
+      return store
+          .list(namespace, GroupEntity.class, EntityType.GROUP, allFields)
+          .toArray(new Group[0]);
+    } catch (NoSuchEntityException e) {
+      LOG.error("Metalake {} does not exist", metalake, e);
+      throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, metalake);
+    } catch (IOException ioe) {
+      LOG.error("Listing group under metalake {} failed due to storage 
issues", metalake, ioe);
+      throw new RuntimeException(ioe);
+    }
+  }
+
+  String[] listGroupNames(String metalake) {
+    return Arrays.stream(listGroupInternal(metalake, false))
+        .map(Group::name)
+        .toArray(String[]::new);
+  }

Review Comment:
   OK.



-- 
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-unsubscr...@gravitino.apache.org

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

Reply via email to