Skip to content

Commit

Permalink
apache#4873 support list group
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuQhahah committed Sep 26, 2024
1 parent 95034a3 commit ed9cc9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ public Group[] listGroups() {
Map<String,String> params = new HashMap<>();
GroupListResponse resp =
restClient.get(
String.format(API_METALAKES_GROUPS_PATH,name(),BLANK_PLACE_HOLDER),
String.format(API_METALAKES_GROUPS_PATH,name(),BLANK_PLACEHOLDER),
params,
GroupListResponse.class,
Collections.emptyMap(),
Expand All @@ -652,7 +652,7 @@ public Group[] listGroups() {
public String[] listGroupNames(){
NameListResponse resp = restClient.get(
String.format(API_METALAKES_GROUPS_PATH,name(),
BLANK_PLACE_HOLDER),
BLANK_PLACEHOLDER),
NameListResponse.class,
Collections.emptyMap(),
ErrorHandlers.groupErrorHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.gravitino.Entity.EntityType;
import org.apache.gravitino.EntityAlreadyExistsException;
import org.apache.gravitino.EntityStore;
import org.apache.gravitino.Field;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.exceptions.GroupAlreadyExistsException;
Expand Down Expand Up @@ -213,23 +212,28 @@ private void checkMetalakeExists(NameIdentifier ident) throws NoSuchMetalakeExce
}

Group[] listGroups(String metalake) {
AuthorizationUtils.checkMetalakeExists(metalake);
Namespace namespace = AuthorizationUtils.ofGroupNamespace(metalake);
return listGroupInternal(metalake, true);
}

Set<Field> skippingFields = Sets.newHashSet();
skippingFields.add(GroupEntity.ROLE_IDS);
skippingFields.add(GroupEntity.ROLE_NAMES);
private Group[] listGroupInternal(String metalake, boolean allFields) {
try {
AuthorizationUtils.checkMetalakeExists(metalake);
Namespace namespace = AuthorizationUtils.ofUserNamespace(metalake);
return store
.list(namespace, GroupEntity.class, EntityType.GROUP, skippingFields)
.list(namespace, GroupEntity.class, EntityType.GROUP, allFields)
.toArray(new Group[0]);
} catch (Exception ioe) {
LOG.error("Listing Groups failed due to storage issues.", ioe);
} 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(listGroups(metalake)).map(Group::name).toArray(String[]::new);
return Arrays.stream(listGroupInternal(metalake, false))
.map(Group::name)
.toArray(String[]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ public static String listGroupsByRoleId(@Param("roleId") Long roleId) {
return getProvider().listGroupsByRoleId(roleId);
}

public static String listGroupsByMetalake(@Param("metalakeId") Long metalakeId) {

return getProvider().listGroupsByMetalakeId(metalakeId);
public static String listGroupsByMetalake(@Param("metalakeName") String metalakeName) {
return getProvider().listGroupsByMetalake(metalakeName);
}

public static String deleteGroupMetasByLegacyTimeline(
Expand Down

0 comments on commit ed9cc9d

Please sign in to comment.