Skip to content

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

[#2835] improvement(server,core): Refactor the check code and lock for authorization module (#2831)

qqqttt123f7f4a3cef64c
diff --git a/core/src/main/java/com/datastrato/gravitino/authorization/AccessControlManager.java b/core/src/main/java/com/datastrato/gravitino/authorization/AccessControlManager.java
index ede33c6e5c..44882f3ce8 100644
--- a/core/src/main/java/com/datastrato/gravitino/authorization/AccessControlManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/authorization/AccessControlManager.java
@@ -11,15 +11,22 @@ import com.datastrato.gravitino.exceptions.NoSuchGroupException;
import com.datastrato.gravitino.exceptions.NoSuchUserException;
import com.datastrato.gravitino.exceptions.UserAlreadyExistsException;
import com.datastrato.gravitino.storage.IdGenerator;
+import com.datastrato.gravitino.utils.Executable;
/**
* AccessControlManager is used for manage users, roles, admin, grant information, this class is an
- * entrance class for tenant management.
+ * entrance class for tenant management. This lock policy about this is as follows: First, admin
+ * operations are prevented by one lock. Then, other operations are prevented by the other lock. For
+ * non-admin operations, Gravitino doesn't choose metalake level lock. There are some reasons
+ * mainly: First, the metalake can be renamed by users. It's hard to maintain a map with metalake as
+ * the key. Second, the lock will be couped with life cycle of the metalake.
*/
public class AccessControlManager {
private final UserGroupManager userGroupManager;
private final AdminManager adminManager;
+ private final Object adminOperationLock = new Object();
+ private final Object nonAdminOperationLock = new Object();
public AccessControlManager(EntityStore store, IdGenerator idGenerator, Config config) {
this.userGroupManager = new UserGroupManager(store, idGenerator);
@@ -36,7 +43,7 @@ public class AccessControlManager {
* @throws RuntimeException If adding the User encounters storage issues.
*/
public User addUser(String metalake, String name) throws UserAlreadyExistsException {
- return userGroupManager.addUser(metalake, name);
+ return doWithNonAdminLock(() -> userGroupManager.addUser(metalake, name));
}
/**
@@ -48,7 +55,7 @@ public class AccessControlManager {
* @throws RuntimeException If removing the User encounters storage issues.
*/
public boolean removeUser(String metalake, String user) {
- return userGroupManager.removeUser(metalake, user);
+ return doWithNonAdminLock(() -> userGroupManager.removeUser(metalake, user));
}
/**
@@ -61,7 +68,7 @@ public class AccessControlManager {
* @throws RuntimeException If getting the User encounters storage issues.
*/
public User getUser(String metalake, String user) throws NoSuchUserException {
- return userGroupManager.getUser(metalake, user);
+ return doWithNonAdminLock(() -> userGroupManager.getUser(metalake, user));
}
/**
@@ -74,7 +81,7 @@ public class AccessControlManager {
* @throws RuntimeException If adding the Group encounters storage issues.
*/
public Group addGroup(String metalake, String group) throws GroupAlreadyExistsException {
- return userGroupManager.addGroup(metalake, group);
+ return doWithNonAdminLock(() -> userGroupManager.addGroup(metalake, group));
}
/**
@@ -86,7 +93,7 @@ public class AccessControlManager {
* @throws RuntimeException If removing the Group encounters storage issues.
*/
public boolean removeGroup(String metalake, String group) {
- return userGroupManager.removeGroup(metalake, group);
+ return doWithNonAdminLock(() -> userGroupManager.removeGroup(metalake, group));
}
/**
@@ -99,7 +106,7 @@ public class AccessControlManager {
* @throws RuntimeException If getting the Group encounters storage issues.
*/
public Group getGroup(String metalake, String group) throws NoSuchGroupException {
- return userGroupManager.getGroup(metalake, group);
+ return doWithNonAdminLock(() -> userGroupManager.getGroup(metalake, group));
}
/**
@@ -111,7 +118,7 @@ public class AccessControlManager {
* @throws RuntimeException If adding the User encounters storage issues.
*/
public User addMetalakeAdmin(String user) {
- return adminManager.addMetalakeAdmin(user);
+ return doWithAdminLock(() -> adminManager.addMetalakeAdmin(user));
}
/**
@@ -122,7 +129,7 @@ public class AccessControlManager {
* @throws RuntimeException If removing the User encounters storage issues.
*/
public boolean removeMetalakeAdmin(String user) {
- return adminManager.removeMetalakeAdmin(user);
+ return doWithAdminLock(() -> adminManager.removeMetalakeAdmin(user));
}
/**
@@ -142,6 +149,18 @@ public class AccessControlManager {
* @return true, if the user is metalake admin, otherwise false.
*/
public boolean isMetalakeAdmin(String user) {
- return adminManager.isMetalakeAdmin(user);
+ return doWithAdminLock(() -> adminManager.isMetalakeAdmin(user));
+ }
+
+ private <R, E extends Exception> R doWithNonAdminLock(Executable<R, E> executable) throws E {
+ synchronized (nonAdminOperationLock) {
+ return executable.execute();
+ }
+ }
+
+ private <R, E extends Exception> R doWithAdminLock(Executable<R, E> executable) throws E {
+ synchronized (adminOperationLock) {
+ return executable.execute();
+ }
}
}
diff --git a/core/src/main/java/com/datastrato/gravitino/authorization/AdminManager.java b/core/src/main/java/com/datastrato/gravitino/authorization/AdminManager.java
index 3198ca1080..55a3940da5 100644
--- a/core/src/main/java/com/datastrato/gravitino/authorization/AdminManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/authorization/AdminManager.java
@@ -52,7 +52,7 @@ public class AdminManager {
* @throws UserAlreadyExistsException If a User with the same identifier already exists.
* @throws RuntimeException If adding the User encounters storage issues.
*/
- public synchronized User addMetalakeAdmin(String user) {
+ public User addMetalakeAdmin(String user) {
UserEntity userEntity =
UserEntity.builder()
@@ -89,7 +89,7 @@ public class AdminManager {
* @return `true` if the User was successfully removed, `false` otherwise.
* @throws RuntimeException If removing the User encounters storage issues.
*/
- public synchronized boolean removeMetalakeAdmin(String user) {
+ public boolean removeMetalakeAdmin(String user) {
try {
return store.delete(ofMetalakeAdmin(user), Entity.EntityType.USER);
} catch (IOException ioe) {
@@ -115,7 +115,7 @@ public class AdminManager {
* @param user the name of the user
* @return true, if the user is metalake admin, otherwise false.
*/
- public synchronized boolean isMetalakeAdmin(String user) {
+ public boolean isMetalakeAdmin(String user) {
try {
return store.exists(ofMetalakeAdmin(user), Entity.EntityType.USER);
} catch (IOException ioe) {
diff --git a/core/src/main/java/com/datastrato/gravitino/authorization/AuthorizationUtils.java b/core/src/main/java/com/datastrato/gravitino/authorization/AuthorizationUtils.java
new file mode 100644
index 0000000000..e5fa100b25
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/authorization/AuthorizationUtils.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.authorization;
+
+import com.datastrato.gravitino.Entity;
+import com.datastrato.gravitino.EntityStore;
+import com.datastrato.gravitino.NameIdentifier;
+import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
+import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/* The utilization class of authorization module*/
+class AuthorizationUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuthorizationUtils.class);
+ private static final String METALAKE_DOES_NOT_EXIST_MSG = "Metalake %s does not exist";
+
+ private AuthorizationUtils() {}
+
+ static void checkMetalakeExists(EntityStore store, String metalake)
+ throws NoSuchMetalakeException {
+ try {
+ NameIdentifier metalakeIdent = NameIdentifier.ofMetalake(metalake);
+ if (!store.exists(metalakeIdent, Entity.EntityType.METALAKE)) {
+ LOG.warn("Metalake {} does not exist", metalakeIdent);
+ throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, metalakeIdent);
+ }
+ } catch (IOException e) {
+ LOG.error("Failed to do storage operation", e);
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/authorization/UserGroupManager.java b/core/src/main/java/com/datastrato/gravitino/authorization/UserGroupManager.java
index e036030382..967c55a969 100644
--- a/core/src/main/java/com/datastrato/gravitino/authorization/UserGroupManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/authorization/UserGroupManager.java
@@ -58,21 +58,22 @@ public class UserGroupManager {
* @throws RuntimeException If adding the User encounters storage issues.
*/
public User addUser(String metalake, String name) throws UserAlreadyExistsException {
- UserEntity userEntity =
- UserEntity.builder()
- .withId(idGenerator.nextId())
- .withName(name)
- .withNamespace(
- Namespace.of(
- metalake, Entity.SYSTEM_CATALOG_RESERVED_NAME, Entity.USER_SCHEMA_NAME))
- .withRoles(Lists.newArrayList())
- .withAuditInfo(
- AuditInfo.builder()
- .withCreator(PrincipalUtils.getCurrentPrincipal().getName())
- .withCreateTime(Instant.now())
- .build())
- .build();
try {
+ AuthorizationUtils.checkMetalakeExists(store, metalake);
+ UserEntity userEntity =
+ UserEntity.builder()
+ .withId(idGenerator.nextId())
+ .withName(name)
+ .withNamespace(
+ Namespace.of(
+ metalake, Entity.SYSTEM_CATALOG_RESERVED_NAME, Entity.USER_SCHEMA_NAME))
+ .withRoles(Lists.newArrayList())
+ .withAuditInfo(
+ AuditInfo.builder()
+ .withCreator(PrincipalUtils.getCurrentPrincipal().getName())
+ .withCreateTime(Instant.now())
+ .build())
+ .build();
store.put(userEntity, false /* overwritten */);
return userEntity;
} catch (EntityAlreadyExistsException e) {
@@ -97,6 +98,7 @@ public class UserGroupManager {
public boolean removeUser(String metalake, String user) {
try {
+ AuthorizationUtils.checkMetalakeExists(store, metalake);
return store.delete(ofUser(metalake, user), Entity.EntityType.USER);
} catch (IOException ioe) {
LOG.error(
@@ -116,6 +118,7 @@ public class UserGroupManager {
*/
public User getUser(String metalake, String user) throws NoSuchUserException {
try {
+ AuthorizationUtils.checkMetalakeExists(store, metalake);
return store.get(ofUser(metalake, user), Entity.EntityType.USER, UserEntity.class);
} catch (NoSuchEntityException e) {
LOG.warn("User {} does not exist in the metalake {}", user, metalake, e);
@@ -136,21 +139,22 @@ public class UserGroupManager {
* @throws RuntimeException If adding the Group encounters storage issues.
*/
public Group addGroup(String metalake, String group) throws GroupAlreadyExistsException {
- GroupEntity groupEntity =
- GroupEntity.builder()
- .withId(idGenerator.nextId())
- .withName(group)
- .withNamespace(
- Namespace.of(
- metalake, Entity.SYSTEM_CATALOG_RESERVED_NAME, Entity.GROUP_SCHEMA_NAME))
- .withRoles(Collections.emptyList())
- .withAuditInfo(
- AuditInfo.builder()
- .withCreator(PrincipalUtils.getCurrentPrincipal().getName())
- .withCreateTime(Instant.now())
- .build())
- .build();
try {
+ AuthorizationUtils.checkMetalakeExists(store, metalake);
+ GroupEntity groupEntity =
+ GroupEntity.builder()
+ .withId(idGenerator.nextId())
+ .withName(group)
+ .withNamespace(
+ Namespace.of(
+ metalake, Entity.SYSTEM_CATALOG_RESERVED_NAME, Entity.GROUP_SCHEMA_NAME))
+ .withRoles(Collections.emptyList())
+ .withAuditInfo(
+ AuditInfo.builder()
+ .withCreator(PrincipalUtils.getCurrentPrincipal().getName())
+ .withCreateTime(Instant.now())
+ .build())
+ .build();
store.put(groupEntity, false /* overwritten */);
return groupEntity;
} catch (EntityAlreadyExistsException e) {
@@ -174,6 +178,7 @@ public class UserGroupManager {
*/
public boolean removeGroup(String metalake, String group) {
try {
+ AuthorizationUtils.checkMetalakeExists(store, metalake);
return store.delete(ofGroup(metalake, group), Entity.EntityType.GROUP);
} catch (IOException ioe) {
LOG.error(
@@ -196,6 +201,7 @@ public class UserGroupManager {
*/
public Group getGroup(String metalake, String group) {
try {
+ AuthorizationUtils.checkMetalakeExists(store, metalake);
return store.get(ofGroup(metalake, group), Entity.EntityType.GROUP, GroupEntity.class);
} catch (NoSuchEntityException e) {
LOG.warn("Group {} does not exist in the metalake {}", group, metalake, e);
diff --git a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
index d73b0afa4d..5c708c9909 100644
--- a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
+++ b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
@@ -10,6 +10,7 @@ import com.datastrato.gravitino.Config;
import com.datastrato.gravitino.EntityStore;
import com.datastrato.gravitino.exceptions.GroupAlreadyExistsException;
import com.datastrato.gravitino.exceptions.NoSuchGroupException;
+import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
import com.datastrato.gravitino.exceptions.NoSuchUserException;
import com.datastrato.gravitino.exceptions.UserAlreadyExistsException;
import com.datastrato.gravitino.meta.AuditInfo;
@@ -77,6 +78,10 @@ public class TestAccessControlManager {
Assertions.assertEquals("testAddWithOptionalField", user.name());
Assertions.assertTrue(user.roles().isEmpty());
+ // Test with NoSuchMetalakeException
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> accessControlManager.addUser("no-exist", "testAdd"));
+
// Test with UserAlreadyExistsException
Assertions.assertThrows(
UserAlreadyExistsException.class,
@@ -90,6 +95,10 @@ public class TestAccessControlManager {
User user = accessControlManager.getUser("metalake", "testGet");
Assertions.assertEquals("testGet", user.name());
+ // Test with NoSuchMetalakeException
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> accessControlManager.addUser("no-exist", "testAdd"));
+
// Test to get non-existed user
Throwable exception =
Assertions.assertThrows(
@@ -101,6 +110,10 @@ public class TestAccessControlManager {
public void testRemoveUser() {
accessControlManager.addUser("metalake", "testRemove");
+ // Test with NoSuchMetalakeException
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> accessControlManager.addUser("no-exist", "testAdd"));
+
// Test to remove user
boolean removed = accessControlManager.removeUser("metalake", "testRemove");
Assertions.assertTrue(removed);
@@ -121,6 +134,10 @@ public class TestAccessControlManager {
Assertions.assertEquals("testAddWithOptionalField", group.name());
Assertions.assertTrue(group.roles().isEmpty());
+ // Test with NoSuchMetalakeException
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> accessControlManager.addUser("no-exist", "testAdd"));
+
// Test with GroupAlreadyExistsException
Assertions.assertThrows(
GroupAlreadyExistsException.class,
@@ -134,6 +151,10 @@ public class TestAccessControlManager {
Group group = accessControlManager.getGroup("metalake", "testGet");
Assertions.assertEquals("testGet", group.name());
+ // Test with NoSuchMetalakeException
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> accessControlManager.addUser("no-exist", "testAdd"));
+
// Test to get non-existed group
Throwable exception =
Assertions.assertThrows(
@@ -146,6 +167,10 @@ public class TestAccessControlManager {
public void testRemoveGroup() {
accessControlManager.addGroup("metalake", "testRemove");
+ // Test with NoSuchMetalakeException
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> accessControlManager.addUser("no-exist", "testAdd"));
+
// Test to remove group
boolean removed = accessControlManager.removeGroup("metalake", "testRemove");
Assertions.assertTrue(removed);
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/GroupOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/GroupOperations.java
index a49382431a..e0c74a426f 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/GroupOperations.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/GroupOperations.java
@@ -6,15 +6,11 @@ package com.datastrato.gravitino.server.web.rest;
import com.codahale.metrics.annotation.ResponseMetered;
import com.codahale.metrics.annotation.Timed;
-import com.datastrato.gravitino.Entity;
-import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.authorization.AccessControlManager;
import com.datastrato.gravitino.dto.requests.GroupAddRequest;
import com.datastrato.gravitino.dto.responses.GroupResponse;
import com.datastrato.gravitino.dto.responses.RemoveResponse;
import com.datastrato.gravitino.dto.util.DTOConverters;
-import com.datastrato.gravitino.lock.LockType;
-import com.datastrato.gravitino.lock.TreeLockUtils;
import com.datastrato.gravitino.metrics.MetricNames;
import com.datastrato.gravitino.server.web.Utils;
import javax.inject.Inject;
@@ -52,17 +48,12 @@ public class GroupOperations {
public Response getGroup(
@PathParam("metalake") String metalake, @PathParam("group") String group) {
try {
- NameIdentifier ident = ofGroup(metalake, group);
return Utils.doAs(
httpRequest,
() ->
Utils.ok(
new GroupResponse(
- DTOConverters.toDTO(
- TreeLockUtils.doWithTreeLock(
- ident,
- LockType.READ,
- () -> accessControlManager.getGroup(metalake, group))))));
+ DTOConverters.toDTO(accessControlManager.getGroup(metalake, group)))));
} catch (Exception e) {
return ExceptionHandlers.handleGroupException(OperationType.GET, group, metalake, e);
}
@@ -74,17 +65,13 @@ public class GroupOperations {
@ResponseMetered(name = "add-group", absolute = true)
public Response addGroup(@PathParam("metalake") String metalake, GroupAddRequest request) {
try {
- NameIdentifier ident = ofGroup(metalake, request.getName());
return Utils.doAs(
httpRequest,
() ->
Utils.ok(
new GroupResponse(
DTOConverters.toDTO(
- TreeLockUtils.doWithTreeLock(
- ident,
- LockType.WRITE,
- () -> accessControlManager.addGroup(metalake, request.getName()))))));
+ accessControlManager.addGroup(metalake, request.getName())))));
} catch (Exception e) {
return ExceptionHandlers.handleGroupException(
OperationType.ADD, request.getName(), metalake, e);
@@ -102,10 +89,7 @@ public class GroupOperations {
return Utils.doAs(
httpRequest,
() -> {
- NameIdentifier ident = ofGroup(metalake, group);
- boolean removed =
- TreeLockUtils.doWithTreeLock(
- ident, LockType.WRITE, () -> accessControlManager.removeGroup(metalake, group));
+ boolean removed = accessControlManager.removeGroup(metalake, group);
if (!removed) {
LOG.warn("Failed to remove group {} under metalake {}", group, metalake);
}
@@ -115,9 +99,4 @@ public class GroupOperations {
return ExceptionHandlers.handleGroupException(OperationType.REMOVE, group, metalake, e);
}
}
-
- private NameIdentifier ofGroup(String metalake, String group) {
- return NameIdentifier.of(
- metalake, Entity.SYSTEM_CATALOG_RESERVED_NAME, Entity.GROUP_SCHEMA_NAME, group);
- }
}
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/UserOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/UserOperations.java
index 5c5cbaac87..39d0a270ad 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/UserOperations.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/UserOperations.java
@@ -6,15 +6,11 @@ package com.datastrato.gravitino.server.web.rest;
import com.codahale.metrics.annotation.ResponseMetered;
import com.codahale.metrics.annotation.Timed;
-import com.datastrato.gravitino.Entity;
-import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.authorization.AccessControlManager;
import com.datastrato.gravitino.dto.requests.UserAddRequest;
import com.datastrato.gravitino.dto.responses.RemoveResponse;
import com.datastrato.gravitino.dto.responses.UserResponse;
import com.datastrato.gravitino.dto.util.DTOConverters;
-import com.datastrato.gravitino.lock.LockType;
-import com.datastrato.gravitino.lock.TreeLockUtils;
import com.datastrato.gravitino.metrics.MetricNames;
import com.datastrato.gravitino.server.web.Utils;
import javax.inject.Inject;
@@ -51,17 +47,12 @@ public class UserOperations {
@ResponseMetered(name = "get-user", absolute = true)
public Response getUser(@PathParam("metalake") String metalake, @PathParam("user") String user) {
try {
- NameIdentifier ident = ofUser(metalake, user);
return Utils.doAs(
httpRequest,
() ->
Utils.ok(
new UserResponse(
- DTOConverters.toDTO(
- TreeLockUtils.doWithTreeLock(
- ident,
- LockType.READ,
- () -> accessControlManager.getUser(metalake, user))))));
+ DTOConverters.toDTO(accessControlManager.getUser(metalake, user)))));
} catch (Exception e) {
return ExceptionHandlers.handleUserException(OperationType.GET, user, metalake, e);
}
@@ -73,17 +64,13 @@ public class UserOperations {
@ResponseMetered(name = "add-user", absolute = true)
public Response addUser(@PathParam("metalake") String metalake, UserAddRequest request) {
try {
- NameIdentifier ident = ofUser(metalake, request.getName());
return Utils.doAs(
httpRequest,
() ->
Utils.ok(
new UserResponse(
DTOConverters.toDTO(
- TreeLockUtils.doWithTreeLock(
- ident,
- LockType.WRITE,
- () -> accessControlManager.addUser(metalake, request.getName()))))));
+ accessControlManager.addUser(metalake, request.getName())))));
} catch (Exception e) {
return ExceptionHandlers.handleUserException(
OperationType.ADD, request.getName(), metalake, e);
@@ -101,10 +88,7 @@ public class UserOperations {
return Utils.doAs(
httpRequest,
() -> {
- NameIdentifier ident = ofUser(metalake, user);
- boolean removed =
- TreeLockUtils.doWithTreeLock(
- ident, LockType.WRITE, () -> accessControlManager.removeUser(metalake, user));
+ boolean removed = accessControlManager.removeUser(metalake, user);
if (!removed) {
LOG.warn("Failed to remove user {} under metalake {}", user, metalake);
}
@@ -114,9 +98,4 @@ public class UserOperations {
return ExceptionHandlers.handleUserException(OperationType.REMOVE, user, metalake, e);
}
}
-
- private NameIdentifier ofUser(String metalake, String user) {
- return NameIdentifier.of(
- metalake, Entity.SYSTEM_CATALOG_RESERVED_NAME, Entity.USER_SCHEMA_NAME, user);
- }
}
diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeAdminOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeAdminOperations.java
index 1bd08e62b6..040af6c4bc 100644
--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeAdminOperations.java
+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeAdminOperations.java
@@ -19,7 +19,6 @@ import com.datastrato.gravitino.dto.responses.ErrorConstants;
import com.datastrato.gravitino.dto.responses.ErrorResponse;
import com.datastrato.gravitino.dto.responses.RemoveResponse;
import com.datastrato.gravitino.dto.responses.UserResponse;
-import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
import com.datastrato.gravitino.exceptions.UserAlreadyExistsException;
import com.datastrato.gravitino.lock.LockManager;
import com.datastrato.gravitino.meta.AuditInfo;
@@ -111,23 +110,6 @@ public class TestMetalakeAdminOperations extends JerseyTest {
Assertions.assertNotNull(userDTO.roles());
Assertions.assertTrue(userDTO.roles().isEmpty());
- // Test to throw NoSuchMetalakeException
- Mockito.doThrow(new NoSuchMetalakeException("mock error"))
- .when(manager)
- .addMetalakeAdmin(any());
- Response resp1 =
- target("/admins")
- .request(MediaType.APPLICATION_JSON_TYPE)
- .accept("application/vnd.gravitino.v1+json")
- .post(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));
-
- Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp1.getStatus());
- Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp1.getMediaType());
-
- ErrorResponse errorResponse = resp1.readEntity(ErrorResponse.class);
- Assertions.assertEquals(ErrorConstants.NOT_FOUND_CODE, errorResponse.getCode());
- Assertions.assertEquals(NoSuchMetalakeException.class.getSimpleName(), errorResponse.getType());
-
// Test to throw UserAlreadyExistsException
Mockito.doThrow(new UserAlreadyExistsException("mock error"))
.when(manager)