Skip to content

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

[#2246] feat(client): Add the client for user, group,admin and role (#3000)

qqqttt123629c0d373ed6
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/ErrorHandlers.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/ErrorHandlers.java
index a18d3febcd..d140b0c2a7 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/ErrorHandlers.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/ErrorHandlers.java
@@ -10,22 +10,28 @@ import com.datastrato.gravitino.dto.responses.OAuth2ErrorResponse;
import com.datastrato.gravitino.exceptions.BadRequestException;
import com.datastrato.gravitino.exceptions.CatalogAlreadyExistsException;
import com.datastrato.gravitino.exceptions.FilesetAlreadyExistsException;
+import com.datastrato.gravitino.exceptions.GroupAlreadyExistsException;
import com.datastrato.gravitino.exceptions.MetalakeAlreadyExistsException;
import com.datastrato.gravitino.exceptions.NoSuchCatalogException;
import com.datastrato.gravitino.exceptions.NoSuchFilesetException;
+import com.datastrato.gravitino.exceptions.NoSuchGroupException;
import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
import com.datastrato.gravitino.exceptions.NoSuchPartitionException;
+import com.datastrato.gravitino.exceptions.NoSuchRoleException;
import com.datastrato.gravitino.exceptions.NoSuchSchemaException;
import com.datastrato.gravitino.exceptions.NoSuchTableException;
import com.datastrato.gravitino.exceptions.NoSuchTopicException;
+import com.datastrato.gravitino.exceptions.NoSuchUserException;
import com.datastrato.gravitino.exceptions.NonEmptySchemaException;
import com.datastrato.gravitino.exceptions.NotFoundException;
import com.datastrato.gravitino.exceptions.PartitionAlreadyExistsException;
import com.datastrato.gravitino.exceptions.RESTException;
+import com.datastrato.gravitino.exceptions.RoleAlreadyExistsException;
import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;
import com.datastrato.gravitino.exceptions.TableAlreadyExistsException;
import com.datastrato.gravitino.exceptions.TopicAlreadyExistsException;
import com.datastrato.gravitino.exceptions.UnauthorizedException;
+import com.datastrato.gravitino.exceptions.UserAlreadyExistsException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import java.util.List;
@@ -123,6 +129,33 @@ public class ErrorHandlers {
return TopicErrorHandler.INSTANCE;
}
+ /**
+ * Creates an error handler specific to User operations.
+ *
+ * @return A Consumer representing the User error handler.
+ */
+ public static Consumer<ErrorResponse> userErrorHandler() {
+ return UserErrorHandler.INSTANCE;
+ }
+
+ /**
+ * Creates an error handler specific to Group operations.
+ *
+ * @return A Consumer representing the Group error handler.
+ */
+ public static Consumer<ErrorResponse> groupErrorHandler() {
+ return GroupErrorHandler.INSTANCE;
+ }
+
+ /**
+ * Creates an error handler specific to Role operations.
+ *
+ * @return A Consumer representing the Role error handler.
+ */
+ public static Consumer<ErrorResponse> roleErrorHandler() {
+ return RoleErrorHandler.INSTANCE;
+ }
+
private ErrorHandlers() {}
/**
@@ -459,6 +492,111 @@ public class ErrorHandlers {
}
}
+ /** Error handler specific to User operations. */
+ @SuppressWarnings("FormatStringAnnotation")
+ private static class UserErrorHandler extends RestErrorHandler {
+
+ private static final UserErrorHandler INSTANCE = new UserErrorHandler();
+
+ @Override
+ public void accept(ErrorResponse errorResponse) {
+ String errorMessage = formatErrorMessage(errorResponse);
+
+ switch (errorResponse.getCode()) {
+ case ErrorConstants.ILLEGAL_ARGUMENTS_CODE:
+ throw new IllegalArgumentException(errorMessage);
+
+ case ErrorConstants.NOT_FOUND_CODE:
+ if (errorResponse.getType().equals(NoSuchMetalakeException.class.getSimpleName())) {
+ throw new NoSuchMetalakeException(errorMessage);
+ } else if (errorResponse.getType().equals(NoSuchUserException.class.getSimpleName())) {
+ throw new NoSuchUserException(errorMessage);
+ } else {
+ throw new NotFoundException(errorMessage);
+ }
+
+ case ErrorConstants.ALREADY_EXISTS_CODE:
+ throw new UserAlreadyExistsException(errorMessage);
+
+ case ErrorConstants.INTERNAL_ERROR_CODE:
+ throw new RuntimeException(errorMessage);
+
+ default:
+ super.accept(errorResponse);
+ }
+ }
+ }
+
+ /** Error handler specific to Group operations. */
+ @SuppressWarnings("FormatStringAnnotation")
+ private static class GroupErrorHandler extends RestErrorHandler {
+
+ private static final GroupErrorHandler INSTANCE = new GroupErrorHandler();
+
+ @Override
+ public void accept(ErrorResponse errorResponse) {
+ String errorMessage = formatErrorMessage(errorResponse);
+
+ switch (errorResponse.getCode()) {
+ case ErrorConstants.ILLEGAL_ARGUMENTS_CODE:
+ throw new IllegalArgumentException(errorMessage);
+
+ case ErrorConstants.NOT_FOUND_CODE:
+ if (errorResponse.getType().equals(NoSuchMetalakeException.class.getSimpleName())) {
+ throw new NoSuchMetalakeException(errorMessage);
+ } else if (errorResponse.getType().equals(NoSuchGroupException.class.getSimpleName())) {
+ throw new NoSuchGroupException(errorMessage);
+ } else {
+ throw new NotFoundException(errorMessage);
+ }
+
+ case ErrorConstants.ALREADY_EXISTS_CODE:
+ throw new GroupAlreadyExistsException(errorMessage);
+
+ case ErrorConstants.INTERNAL_ERROR_CODE:
+ throw new RuntimeException(errorMessage);
+
+ default:
+ super.accept(errorResponse);
+ }
+ }
+ }
+
+ /** Error handler specific to Role operations. */
+ @SuppressWarnings("FormatStringAnnotation")
+ private static class RoleErrorHandler extends RestErrorHandler {
+
+ private static final RoleErrorHandler INSTANCE = new RoleErrorHandler();
+
+ @Override
+ public void accept(ErrorResponse errorResponse) {
+ String errorMessage = formatErrorMessage(errorResponse);
+
+ switch (errorResponse.getCode()) {
+ case ErrorConstants.ILLEGAL_ARGUMENTS_CODE:
+ throw new IllegalArgumentException(errorMessage);
+
+ case ErrorConstants.NOT_FOUND_CODE:
+ if (errorResponse.getType().equals(NoSuchMetalakeException.class.getSimpleName())) {
+ throw new NoSuchMetalakeException(errorMessage);
+ } else if (errorResponse.getType().equals(NoSuchRoleException.class.getSimpleName())) {
+ throw new NoSuchRoleException(errorMessage);
+ } else {
+ throw new NotFoundException(errorMessage);
+ }
+
+ case ErrorConstants.ALREADY_EXISTS_CODE:
+ throw new RoleAlreadyExistsException(errorMessage);
+
+ case ErrorConstants.INTERNAL_ERROR_CODE:
+ throw new RuntimeException(errorMessage);
+
+ default:
+ super.accept(errorResponse);
+ }
+ }
+ }
+
/** Generic error handler for REST requests. */
private static class RestErrorHandler extends ErrorHandler {
private static final ErrorHandler INSTANCE = new RestErrorHandler();
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
index 797991c7dd..07675037f2 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
@@ -8,19 +8,39 @@ package com.datastrato.gravitino.client;
import com.datastrato.gravitino.MetalakeChange;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.SupportsMetalakes;
+import com.datastrato.gravitino.authorization.Group;
+import com.datastrato.gravitino.authorization.Privilege;
+import com.datastrato.gravitino.authorization.Role;
+import com.datastrato.gravitino.authorization.SecurableObject;
+import com.datastrato.gravitino.authorization.User;
+import com.datastrato.gravitino.dto.requests.GroupAddRequest;
import com.datastrato.gravitino.dto.requests.MetalakeCreateRequest;
import com.datastrato.gravitino.dto.requests.MetalakeUpdateRequest;
import com.datastrato.gravitino.dto.requests.MetalakeUpdatesRequest;
+import com.datastrato.gravitino.dto.requests.RoleCreateRequest;
+import com.datastrato.gravitino.dto.requests.UserAddRequest;
+import com.datastrato.gravitino.dto.responses.DeleteResponse;
import com.datastrato.gravitino.dto.responses.DropResponse;
+import com.datastrato.gravitino.dto.responses.GroupResponse;
import com.datastrato.gravitino.dto.responses.MetalakeListResponse;
import com.datastrato.gravitino.dto.responses.MetalakeResponse;
+import com.datastrato.gravitino.dto.responses.RemoveResponse;
+import com.datastrato.gravitino.dto.responses.RoleResponse;
+import com.datastrato.gravitino.dto.responses.UserResponse;
+import com.datastrato.gravitino.exceptions.GroupAlreadyExistsException;
import com.datastrato.gravitino.exceptions.MetalakeAlreadyExistsException;
+import com.datastrato.gravitino.exceptions.NoSuchGroupException;
import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
+import com.datastrato.gravitino.exceptions.NoSuchRoleException;
+import com.datastrato.gravitino.exceptions.NoSuchUserException;
+import com.datastrato.gravitino.exceptions.RoleAlreadyExistsException;
+import com.datastrato.gravitino.exceptions.UserAlreadyExistsException;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,6 +54,10 @@ import org.slf4j.LoggerFactory;
public class GravitinoAdminClient extends GravitinoClientBase implements SupportsMetalakes {
private static final Logger LOG = LoggerFactory.getLogger(GravitinoAdminClient.class);
+ private static final String API_METALAKES_USERS_PATH = "api/metalakes/%s/users/%s";
+ private static final String API_METALAKES_GROUPS_PATH = "api/metalakes/%s/groups/%s";
+ private static final String API_METALAKES_ROLES_PATH = "api/metalakes/%s/roles/%s";
+ private static final String API_ADMIN_PATH = "api/admins/%s";
/**
* Constructs a new GravitinoClient with the given URI, authenticator and AuthDataProvider.
@@ -162,6 +186,282 @@ public class GravitinoAdminClient extends GravitinoClientBase implements Support
}
}
+ /**
+ * Adds a new User.
+ *
+ * @param metalake The Metalake of the User.
+ * @param user The name of the User.
+ * @return The added User instance.
+ * @throws UserAlreadyExistsException If a User with the same name already exists.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If adding the User encounters storage issues.
+ */
+ public User addUser(String metalake, String user)
+ throws UserAlreadyExistsException, NoSuchMetalakeException {
+ UserAddRequest req = new UserAddRequest(user);
+ req.validate();
+
+ UserResponse resp =
+ restClient.post(
+ String.format(API_METALAKES_USERS_PATH, metalake, ""),
+ req,
+ UserResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.userErrorHandler());
+ resp.validate();
+
+ return resp.getUser();
+ }
+
+ /**
+ * Removes a User.
+ *
+ * @param metalake The Metalake of the User.
+ * @param user The name of the User.
+ * @return `true` if the User was successfully removed, `false` only when there's no such user,
+ * otherwise it will throw an exception.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If removing the User encounters storage issues.
+ */
+ public boolean removeUser(String metalake, String user) throws NoSuchMetalakeException {
+ RemoveResponse resp =
+ restClient.delete(
+ String.format(API_METALAKES_USERS_PATH, metalake, user),
+ RemoveResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.userErrorHandler());
+ resp.validate();
+
+ return resp.removed();
+ }
+
+ /**
+ * Gets a User.
+ *
+ * @param metalake The Metalake of the User.
+ * @param user The name of the User.
+ * @return The getting User instance.
+ * @throws NoSuchUserException If the User with the given name does not exist.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If getting the User encounters storage issues.
+ */
+ public User getUser(String metalake, String user)
+ throws NoSuchUserException, NoSuchMetalakeException {
+ UserResponse resp =
+ restClient.get(
+ String.format(API_METALAKES_USERS_PATH, metalake, user),
+ UserResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.userErrorHandler());
+ resp.validate();
+
+ return resp.getUser();
+ }
+
+ /**
+ * Adds a new Group.
+ *
+ * @param metalake The Metalake of the Group.
+ * @param group The name of the Group.
+ * @return The Added Group instance.
+ * @throws GroupAlreadyExistsException If a Group with the same name already exists.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If adding the Group encounters storage issues.
+ */
+ public Group addGroup(String metalake, String group)
+ throws GroupAlreadyExistsException, NoSuchMetalakeException {
+ GroupAddRequest req = new GroupAddRequest(group);
+ req.validate();
+
+ GroupResponse resp =
+ restClient.post(
+ String.format(API_METALAKES_GROUPS_PATH, metalake, ""),
+ req,
+ GroupResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.groupErrorHandler());
+ resp.validate();
+
+ return resp.getGroup();
+ }
+
+ /**
+ * Removes a Group.
+ *
+ * @param metalake The Metalake of the Group.
+ * @param group THe name of the Group.
+ * @return `true` if the Group was successfully removed, `false` only when there's no such group,
+ * otherwise it will throw an exception.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If removing the Group encounters storage issues.
+ */
+ public boolean removeGroup(String metalake, String group) throws NoSuchMetalakeException {
+ RemoveResponse resp =
+ restClient.delete(
+ String.format(API_METALAKES_GROUPS_PATH, metalake, group),
+ RemoveResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.groupErrorHandler());
+ resp.validate();
+
+ return resp.removed();
+ }
+
+ /**
+ * Gets a Group.
+ *
+ * @param metalake The Metalake of the Group.
+ * @param group The name of the Group.
+ * @return The getting Group instance.
+ * @throws NoSuchGroupException If the Group with the given name does not exist.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If getting the Group encounters storage issues.
+ */
+ public Group getGroup(String metalake, String group)
+ throws NoSuchGroupException, NoSuchMetalakeException {
+ GroupResponse resp =
+ restClient.get(
+ String.format(API_METALAKES_GROUPS_PATH, metalake, group),
+ GroupResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.groupErrorHandler());
+ resp.validate();
+
+ return resp.getGroup();
+ }
+
+ /**
+ * Adds a new metalake admin.
+ *
+ * @param user The name of the User.
+ * @return The added User instance.
+ * @throws UserAlreadyExistsException If a metalake admin with the same name already exists.
+ * @throws RuntimeException If adding the User encounters storage issues.
+ */
+ public User addMetalakeAdmin(String user) throws UserAlreadyExistsException {
+ UserAddRequest req = new UserAddRequest(user);
+ req.validate();
+
+ UserResponse resp =
+ restClient.post(
+ String.format(API_ADMIN_PATH, ""),
+ req,
+ UserResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.userErrorHandler());
+ resp.validate();
+
+ return resp.getUser();
+ }
+
+ /**
+ * Removes a metalake admin.
+ *
+ * @param user The name of the User.
+ * @return `true` if the User was successfully removed, `false` only when there's no such metalake
+ * admin, otherwise it will throw an exception.
+ * @throws RuntimeException If removing the User encounters storage issues.
+ */
+ public boolean removeMetalakeAdmin(String user) {
+ RemoveResponse resp =
+ restClient.delete(
+ String.format(API_ADMIN_PATH, user),
+ RemoveResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.userErrorHandler());
+ resp.validate();
+
+ return resp.removed();
+ }
+
+ /**
+ * Gets a Role.
+ *
+ * @param metalake The Metalake of the Role.
+ * @param role The name of the Role.
+ * @return The getting Role instance.
+ * @throws NoSuchRoleException If the Role with the given name does not exist.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If getting the Role encounters storage issues.
+ */
+ public Role getRole(String metalake, String role)
+ throws NoSuchRoleException, NoSuchMetalakeException {
+ RoleResponse resp =
+ restClient.get(
+ String.format(API_METALAKES_ROLES_PATH, metalake, role),
+ RoleResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.roleErrorHandler());
+ resp.validate();
+
+ return resp.getRole();
+ }
+
+ /**
+ * Deletes a Role.
+ *
+ * @param metalake The Metalake of the Role.
+ * @param role The name of the Role.
+ * @return `true` if the Role was successfully deleted, `false` only when there's no such role,
+ * otherwise it will throw an exception.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If deleting the Role encounters storage issues.
+ */
+ public boolean deleteRole(String metalake, String role) throws NoSuchMetalakeException {
+ DeleteResponse resp =
+ restClient.delete(
+ String.format(API_METALAKES_ROLES_PATH, metalake, role),
+ DeleteResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.roleErrorHandler());
+ resp.validate();
+
+ return resp.deleted();
+ }
+
+ /**
+ * Creates a new Role.
+ *
+ * @param metalake The Metalake of the Role.
+ * @param role The name of the Role.
+ * @param properties The properties of the Role.
+ * @param securableObject The securable object of the Role.
+ * @param privileges The privileges of the Role.
+ * @return The created Role instance.
+ * @throws RoleAlreadyExistsException If a Role with the same name already exists.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If creating the Role encounters storage issues.
+ */
+ public Role createRole(
+ String metalake,
+ String role,
+ Map<String, String> properties,
+ SecurableObject securableObject,
+ List<Privilege> privileges)
+ throws RoleAlreadyExistsException, NoSuchMetalakeException {
+ RoleCreateRequest req =
+ new RoleCreateRequest(
+ role,
+ properties,
+ privileges.stream()
+ .map(Privilege::name)
+ .map(Objects::toString)
+ .collect(Collectors.toList()),
+ securableObject.toString());
+ req.validate();
+
+ RoleResponse resp =
+ restClient.post(
+ String.format(API_METALAKES_ROLES_PATH, metalake, ""),
+ req,
+ RoleResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.roleErrorHandler());
+ resp.validate();
+
+ return resp.getRole();
+ }
+
/**
* Creates a new builder for constructing a GravitinoClient.
*
diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestMetalakeAdmin.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestMetalakeAdmin.java
new file mode 100644
index 0000000000..66096b7f7b
--- /dev/null
+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestMetalakeAdmin.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.client;
+
+import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.apache.hc.core5.http.HttpStatus.SC_SERVER_ERROR;
+
+import com.datastrato.gravitino.authorization.User;
+import com.datastrato.gravitino.dto.AuditDTO;
+import com.datastrato.gravitino.dto.authorization.UserDTO;
+import com.datastrato.gravitino.dto.requests.UserAddRequest;
+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.UserAlreadyExistsException;
+import java.time.Instant;
+import org.apache.hc.core5.http.Method;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class TestMetalakeAdmin extends TestBase {
+
+ private static final String API_ADMINS_PATH = "api/admins/%s";
+
+ @BeforeAll
+ public static void setUp() throws Exception {
+ TestBase.setUp();
+ }
+
+ @Test
+ public void testAddMetalakeAdmin() throws Exception {
+ String username = "user";
+ String userPath = withSlash(String.format(API_ADMINS_PATH, ""));
+ UserAddRequest request = new UserAddRequest(username);
+
+ UserDTO mockUser = mockUserDTO(username);
+ UserResponse userResponse = new UserResponse(mockUser);
+ buildMockResource(Method.POST, userPath, request, userResponse, SC_OK);
+
+ User addedUser = client.addMetalakeAdmin(username);
+ Assertions.assertNotNull(addedUser);
+ assertUser(addedUser, mockUser);
+
+ // test UserAlreadyExistsException
+ ErrorResponse errResp1 =
+ ErrorResponse.alreadyExists(
+ UserAlreadyExistsException.class.getSimpleName(), "user already exists");
+ buildMockResource(Method.POST, userPath, request, errResp1, SC_CONFLICT);
+ Exception ex =
+ Assertions.assertThrows(
+ UserAlreadyExistsException.class, () -> client.addMetalakeAdmin(username));
+ Assertions.assertEquals("user already exists", ex.getMessage());
+
+ // test RuntimeException
+ ErrorResponse errResp3 = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.POST, userPath, request, errResp3, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.addMetalakeAdmin(username), "internal error");
+ }
+
+ @Test
+ public void testRemoveMetalakeAdmin() throws Exception {
+ String username = "user";
+ String rolePath = withSlash(String.format(API_ADMINS_PATH, username));
+
+ RemoveResponse removeResponse = new RemoveResponse(true);
+ buildMockResource(Method.DELETE, rolePath, null, removeResponse, SC_OK);
+
+ Assertions.assertTrue(client.removeMetalakeAdmin(username));
+
+ removeResponse = new RemoveResponse(false);
+ buildMockResource(Method.DELETE, rolePath, null, removeResponse, SC_OK);
+ Assertions.assertFalse(client.removeMetalakeAdmin(username));
+
+ // test RuntimeException
+ ErrorResponse errResp = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.DELETE, rolePath, null, errResp, SC_SERVER_ERROR);
+ Assertions.assertThrows(RuntimeException.class, () -> client.removeMetalakeAdmin(username));
+ }
+
+ private UserDTO mockUserDTO(String name) {
+ return UserDTO.builder()
+ .withName(name)
+ .withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())
+ .build();
+ }
+
+ private void assertUser(User expected, User actual) {
+ Assertions.assertEquals(expected.name(), actual.name());
+ Assertions.assertEquals(expected.roles(), actual.roles());
+ }
+}
diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRole.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRole.java
new file mode 100644
index 0000000000..560bb52e49
--- /dev/null
+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRole.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.client;
+
+import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.apache.hc.core5.http.HttpStatus.SC_SERVER_ERROR;
+
+import com.datastrato.gravitino.authorization.Privileges;
+import com.datastrato.gravitino.authorization.Role;
+import com.datastrato.gravitino.authorization.SecurableObjects;
+import com.datastrato.gravitino.dto.AuditDTO;
+import com.datastrato.gravitino.dto.authorization.RoleDTO;
+import com.datastrato.gravitino.dto.requests.RoleCreateRequest;
+import com.datastrato.gravitino.dto.responses.DeleteResponse;
+import com.datastrato.gravitino.dto.responses.ErrorResponse;
+import com.datastrato.gravitino.dto.responses.RoleResponse;
+import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
+import com.datastrato.gravitino.exceptions.NoSuchRoleException;
+import com.datastrato.gravitino.exceptions.RoleAlreadyExistsException;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import java.time.Instant;
+import org.apache.hc.core5.http.Method;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class TestRole extends TestBase {
+
+ private static final String API_METALAKES_ROLES_PATH = "api/metalakes/%s/roles/%s";
+ protected static final String metalakeName = "testMetalake";
+
+ @BeforeAll
+ public static void setUp() throws Exception {
+ TestBase.setUp();
+ }
+
+ @Test
+ public void testCreateRoles() throws Exception {
+ String roleName = "role";
+ String rolePath = withSlash(String.format(API_METALAKES_ROLES_PATH, metalakeName, ""));
+ RoleCreateRequest request =
+ new RoleCreateRequest(
+ roleName, ImmutableMap.of("k1", "v1"), Lists.newArrayList("LOAD_CATALOG"), "catalog");
+
+ RoleDTO mockRole = mockRoleDTO(roleName);
+ RoleResponse roleResponse = new RoleResponse(mockRole);
+ buildMockResource(Method.POST, rolePath, request, roleResponse, SC_OK);
+
+ Role createdRole =
+ client.createRole(
+ metalakeName,
+ roleName,
+ ImmutableMap.of("k1", "v1"),
+ SecurableObjects.ofCatalog("catalog"),
+ Lists.newArrayList(Privileges.LoadCatalog.get()));
+ Assertions.assertNotNull(createdRole);
+ assertRole(createdRole, mockRole);
+
+ // test RoleAlreadyExistsException
+ ErrorResponse errResp1 =
+ ErrorResponse.alreadyExists(
+ RoleAlreadyExistsException.class.getSimpleName(), "role already exists");
+ buildMockResource(Method.POST, rolePath, request, errResp1, SC_CONFLICT);
+ Exception ex =
+ Assertions.assertThrows(
+ RoleAlreadyExistsException.class,
+ () ->
+ client.createRole(
+ metalakeName,
+ roleName,
+ ImmutableMap.of("k1", "v1"),
+ SecurableObjects.ofCatalog("catalog"),
+ Lists.newArrayList(Privileges.LoadCatalog.get())));
+ Assertions.assertEquals("role already exists", ex.getMessage());
+
+ // test NoSuchMetalakeException
+ ErrorResponse errResp2 =
+ ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "metalake not found");
+ buildMockResource(Method.POST, rolePath, request, errResp2, SC_NOT_FOUND);
+ ex =
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class,
+ () ->
+ client.createRole(
+ metalakeName,
+ roleName,
+ ImmutableMap.of("k1", "v1"),
+ SecurableObjects.ofCatalog("catalog"),
+ Lists.newArrayList(Privileges.LoadCatalog.get())));
+ Assertions.assertEquals("metalake not found", ex.getMessage());
+
+ // test RuntimeException
+ ErrorResponse errResp3 = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.POST, rolePath, request, errResp3, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () ->
+ client.createRole(
+ metalakeName,
+ roleName,
+ ImmutableMap.of("k1", "v1"),
+ SecurableObjects.ofCatalog("catalog"),
+ Lists.newArrayList(Privileges.LoadCatalog.get())),
+ "internal error");
+ }
+
+ @Test
+ public void testGetRoles() throws Exception {
+ String roleName = "role";
+ String rolePath = withSlash(String.format(API_METALAKES_ROLES_PATH, metalakeName, roleName));
+
+ RoleDTO mockRole = mockRoleDTO(roleName);
+ RoleResponse roleResponse = new RoleResponse(mockRole);
+ buildMockResource(Method.GET, rolePath, null, roleResponse, SC_OK);
+
+ Role loadedRole = client.getRole(metalakeName, roleName);
+ Assertions.assertNotNull(loadedRole);
+ assertRole(mockRole, loadedRole);
+
+ // test NoSuchRoleException
+ ErrorResponse errResp1 =
+ ErrorResponse.notFound(NoSuchRoleException.class.getSimpleName(), "role not found");
+ buildMockResource(Method.GET, rolePath, null, errResp1, SC_NOT_FOUND);
+ Exception ex =
+ Assertions.assertThrows(
+ NoSuchRoleException.class, () -> client.getRole(metalakeName, roleName));
+ Assertions.assertEquals("role not found", ex.getMessage());
+
+ // test NoSuchMetalakeException
+ ErrorResponse errResp2 =
+ ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "metalake not found");
+ buildMockResource(Method.GET, rolePath, null, errResp2, SC_NOT_FOUND);
+ ex =
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> client.getRole(metalakeName, roleName));
+ Assertions.assertEquals("metalake not found", ex.getMessage());
+
+ // test RuntimeException
+ ErrorResponse errResp3 = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.GET, rolePath, null, errResp3, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.getRole(metalakeName, roleName), "internal error");
+ }
+
+ @Test
+ public void testDeleteRoles() throws Exception {
+ String roleName = "role";
+ String rolePath = withSlash(String.format(API_METALAKES_ROLES_PATH, metalakeName, roleName));
+
+ DeleteResponse deleteResponse = new DeleteResponse(true);
+ buildMockResource(Method.DELETE, rolePath, null, deleteResponse, SC_OK);
+
+ Assertions.assertTrue(client.deleteRole(metalakeName, roleName));
+
+ deleteResponse = new DeleteResponse(false);
+ buildMockResource(Method.DELETE, rolePath, null, deleteResponse, SC_OK);
+ Assertions.assertFalse(client.deleteRole(metalakeName, roleName));
+
+ // test RuntimeException
+ ErrorResponse errResp = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.DELETE, rolePath, null, errResp, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.deleteRole(metalakeName, roleName));
+ }
+
+ private RoleDTO mockRoleDTO(String name) {
+ return RoleDTO.builder()
+ .withName(name)
+ .withProperties(ImmutableMap.of("k1", "v1"))
+ .withSecurableObject(SecurableObjects.of("catalog"))
+ .withPrivileges(Lists.newArrayList(Privileges.LoadCatalog.get()))
+ .withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())
+ .build();
+ }
+
+ private void assertRole(Role expected, Role actual) {
+ Assertions.assertEquals(expected.name(), actual.name());
+ Assertions.assertEquals(expected.privileges(), actual.privileges());
+ Assertions.assertEquals(
+ expected.securableObject().toString(), actual.securableObject().toString());
+ }
+}
diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestUserGroup.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestUserGroup.java
new file mode 100644
index 0000000000..beb37fdf81
--- /dev/null
+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestUserGroup.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.client;
+
+import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.apache.hc.core5.http.HttpStatus.SC_SERVER_ERROR;
+
+import com.datastrato.gravitino.authorization.Group;
+import com.datastrato.gravitino.authorization.User;
+import com.datastrato.gravitino.dto.AuditDTO;
+import com.datastrato.gravitino.dto.authorization.GroupDTO;
+import com.datastrato.gravitino.dto.authorization.UserDTO;
+import com.datastrato.gravitino.dto.requests.GroupAddRequest;
+import com.datastrato.gravitino.dto.requests.UserAddRequest;
+import com.datastrato.gravitino.dto.responses.ErrorResponse;
+import com.datastrato.gravitino.dto.responses.GroupResponse;
+import com.datastrato.gravitino.dto.responses.RemoveResponse;
+import com.datastrato.gravitino.dto.responses.UserResponse;
+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 java.time.Instant;
+import org.apache.hc.core5.http.Method;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class TestUserGroup extends TestBase {
+
+ private static final String API_METALAKES_USERS_PATH = "api/metalakes/%s/users/%s";
+ private static final String API_METALAKES_GROUPS_PATH = "api/metalakes/%s/groups/%s";
+ protected static final String metalakeName = "testMetalake";
+
+ @BeforeAll
+ public static void setUp() throws Exception {
+ TestBase.setUp();
+ }
+
+ @Test
+ public void testAddUsers() throws Exception {
+ String username = "user";
+ String userPath = withSlash(String.format(API_METALAKES_USERS_PATH, metalakeName, ""));
+ UserAddRequest request = new UserAddRequest(username);
+
+ UserDTO mockUser = mockUserDTO(username);
+ UserResponse userResponse = new UserResponse(mockUser);
+ buildMockResource(Method.POST, userPath, request, userResponse, SC_OK);
+
+ User addedUser = client.addUser(metalakeName, username);
+ Assertions.assertNotNull(addedUser);
+ assertUser(addedUser, mockUser);
+
+ // test UserAlreadyExistsException
+ ErrorResponse errResp1 =
+ ErrorResponse.alreadyExists(
+ UserAlreadyExistsException.class.getSimpleName(), "user already exists");
+ buildMockResource(Method.POST, userPath, request, errResp1, SC_CONFLICT);
+ Exception ex =
+ Assertions.assertThrows(
+ UserAlreadyExistsException.class, () -> client.addUser(metalakeName, username));
+ Assertions.assertEquals("user already exists", ex.getMessage());
+
+ // test NoSuchMetalakeException
+ ErrorResponse errResp2 =
+ ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "metalake not found");
+ buildMockResource(Method.POST, userPath, request, errResp2, SC_NOT_FOUND);
+ ex =
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> client.addUser(metalakeName, username));
+ Assertions.assertEquals("metalake not found", ex.getMessage());
+
+ // test RuntimeException
+ ErrorResponse errResp3 = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.POST, userPath, request, errResp3, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.addUser(metalakeName, username), "internal error");
+ }
+
+ @Test
+ public void testGetUsers() throws Exception {
+ String username = "user";
+ String userPath = withSlash(String.format(API_METALAKES_USERS_PATH, metalakeName, username));
+
+ UserDTO mockUser = mockUserDTO(username);
+ UserResponse userResponse = new UserResponse(mockUser);
+ buildMockResource(Method.GET, userPath, null, userResponse, SC_OK);
+
+ User loadedUser = client.getUser(metalakeName, username);
+ Assertions.assertNotNull(loadedUser);
+ assertUser(mockUser, loadedUser);
+
+ // test NoSuchUserException
+ ErrorResponse errResp1 =
+ ErrorResponse.notFound(NoSuchUserException.class.getSimpleName(), "user not found");
+ buildMockResource(Method.GET, userPath, null, errResp1, SC_NOT_FOUND);
+ Exception ex =
+ Assertions.assertThrows(
+ NoSuchUserException.class, () -> client.getUser(metalakeName, username));
+ Assertions.assertEquals("user not found", ex.getMessage());
+
+ // test NoSuchMetalakeException
+ ErrorResponse errResp2 =
+ ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "metalake not found");
+ buildMockResource(Method.GET, userPath, null, errResp2, SC_NOT_FOUND);
+ ex =
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> client.getUser(metalakeName, username));
+ Assertions.assertEquals("metalake not found", ex.getMessage());
+
+ // test RuntimeException
+ ErrorResponse errResp3 = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.GET, userPath, null, errResp3, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.getUser(metalakeName, username), "internal error");
+ }
+
+ @Test
+ public void testRemoveUsers() throws Exception {
+ String username = "user";
+ String userPath = withSlash(String.format(API_METALAKES_USERS_PATH, metalakeName, username));
+
+ RemoveResponse removeResponse = new RemoveResponse(true);
+ buildMockResource(Method.DELETE, userPath, null, removeResponse, SC_OK);
+
+ Assertions.assertTrue(client.removeUser(metalakeName, username));
+
+ removeResponse = new RemoveResponse(false);
+ buildMockResource(Method.DELETE, userPath, null, removeResponse, SC_OK);
+ Assertions.assertFalse(client.removeUser(metalakeName, username));
+
+ // test RuntimeException
+ ErrorResponse errResp = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.DELETE, userPath, null, errResp, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.removeUser(metalakeName, username));
+ }
+
+ @Test
+ public void testAddGroups() throws Exception {
+ String groupName = "group";
+ String groupPath = withSlash(String.format(API_METALAKES_GROUPS_PATH, metalakeName, ""));
+ GroupAddRequest request = new GroupAddRequest(groupName);
+
+ GroupDTO mockGroup = mockGroupDTO(groupName);
+ GroupResponse groupResponse = new GroupResponse(mockGroup);
+ buildMockResource(Method.POST, groupPath, request, groupResponse, SC_OK);
+
+ Group addedGroup = client.addGroup(metalakeName, groupName);
+ Assertions.assertNotNull(addedGroup);
+ assertGroup(addedGroup, mockGroup);
+
+ // test GroupAlreadyExistsException
+ ErrorResponse errResp1 =
+ ErrorResponse.alreadyExists(
+ GroupAlreadyExistsException.class.getSimpleName(), "group already exists");
+ buildMockResource(Method.POST, groupPath, request, errResp1, SC_CONFLICT);
+ Exception ex =
+ Assertions.assertThrows(
+ GroupAlreadyExistsException.class, () -> client.addGroup(metalakeName, groupName));
+ Assertions.assertEquals("group already exists", ex.getMessage());
+
+ // test NoSuchMetalakeException
+ ErrorResponse errResp2 =
+ ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "metalake not found");
+ buildMockResource(Method.POST, groupPath, request, errResp2, SC_NOT_FOUND);
+ ex =
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> client.addGroup(metalakeName, groupName));
+ Assertions.assertEquals("metalake not found", ex.getMessage());
+
+ // test RuntimeException
+ ErrorResponse errResp3 = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.POST, groupPath, request, errResp3, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.addGroup(metalakeName, groupName), "internal error");
+ }
+
+ @Test
+ public void testGetGroups() throws Exception {
+ String groupName = "group";
+ String groupPath = withSlash(String.format(API_METALAKES_GROUPS_PATH, metalakeName, groupName));
+
+ GroupDTO mockGroup = mockGroupDTO(groupName);
+ GroupResponse groupResponse = new GroupResponse(mockGroup);
+ buildMockResource(Method.GET, groupPath, null, groupResponse, SC_OK);
+
+ Group loadedGroup = client.getGroup(metalakeName, groupName);
+ Assertions.assertNotNull(loadedGroup);
+ assertGroup(mockGroup, loadedGroup);
+
+ // test NoSuchGroupException
+ ErrorResponse errResp1 =
+ ErrorResponse.notFound(NoSuchGroupException.class.getSimpleName(), "group not found");
+ buildMockResource(Method.GET, groupPath, null, errResp1, SC_NOT_FOUND);
+ Exception ex =
+ Assertions.assertThrows(
+ NoSuchGroupException.class, () -> client.getGroup(metalakeName, groupName));
+ Assertions.assertEquals("group not found", ex.getMessage());
+
+ // test NoSuchMetalakeException
+ ErrorResponse errResp2 =
+ ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "metalake not found");
+ buildMockResource(Method.GET, groupPath, null, errResp2, SC_NOT_FOUND);
+ ex =
+ Assertions.assertThrows(
+ NoSuchMetalakeException.class, () -> client.getGroup(metalakeName, groupName));
+ Assertions.assertEquals("metalake not found", ex.getMessage());
+
+ // test RuntimeException
+ ErrorResponse errResp3 = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.GET, groupPath, null, errResp3, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.getGroup(metalakeName, groupName), "internal error");
+ }
+
+ @Test
+ public void testRemoveGroups() throws Exception {
+ String groupName = "user";
+ String groupPath = withSlash(String.format(API_METALAKES_GROUPS_PATH, metalakeName, groupName));
+
+ RemoveResponse removeResponse = new RemoveResponse(true);
+ buildMockResource(Method.DELETE, groupPath, null, removeResponse, SC_OK);
+
+ Assertions.assertTrue(client.removeGroup(metalakeName, groupName));
+
+ removeResponse = new RemoveResponse(false);
+ buildMockResource(Method.DELETE, groupPath, null, removeResponse, SC_OK);
+ Assertions.assertFalse(client.removeGroup(metalakeName, groupName));
+
+ // test RuntimeException
+ ErrorResponse errResp = ErrorResponse.internalError("internal error");
+ buildMockResource(Method.DELETE, groupPath, null, errResp, SC_SERVER_ERROR);
+ Assertions.assertThrows(
+ RuntimeException.class, () -> client.removeGroup(metalakeName, groupName));
+ }
+
+ private UserDTO mockUserDTO(String name) {
+ return UserDTO.builder()
+ .withName(name)
+ .withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())
+ .build();
+ }
+
+ private GroupDTO mockGroupDTO(String name) {
+ return GroupDTO.builder()
+ .withName(name)
+ .withAudit(AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())
+ .build();
+ }
+
+ private void assertUser(User expected, User actual) {
+ Assertions.assertEquals(expected.name(), actual.name());
+ Assertions.assertEquals(expected.roles(), actual.roles());
+ }
+
+ private void assertGroup(Group expected, Group actual) {
+ Assertions.assertEquals(expected.name(), actual.name());
+ Assertions.assertEquals(expected.roles(), actual.roles());
+ }
+}
diff --git a/common/src/main/java/com/datastrato/gravitino/dto/responses/DeleteResponse.java b/common/src/main/java/com/datastrato/gravitino/dto/responses/DeleteResponse.java
new file mode 100644
index 0000000000..a524520f25
--- /dev/null
+++ b/common/src/main/java/com/datastrato/gravitino/dto/responses/DeleteResponse.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2023 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.dto.responses;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
+/** Represents a response for a delete operation. */
+@ToString
+@EqualsAndHashCode(callSuper = true)
+public class DeleteResponse extends BaseResponse {
+
+ @JsonProperty("deleted")
+ private final boolean deleted;
+
+ /**
+ * Constructor for DeleteResponse.
+ *
+ * @param deleted Whether the delete operation was successful.
+ */
+ public DeleteResponse(boolean deleted) {
+ super(0);
+ this.deleted = deleted;
+ }
+
+ /** Default constructor for DeleteResponse (used by Jackson deserializer). */
+ public DeleteResponse() {
+ super();
+ this.deleted = false;
+ }
+
+ /**
+ * Returns whether the delete operation was successful.
+ *
+ * @return True if the delete operation was successful, otherwise false.
+ */
+ public boolean deleted() {
+ return deleted;
+ }
+}
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 131153f451..35c3ea99f4 100644
--- a/core/src/main/java/com/datastrato/gravitino/authorization/AccessControlManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/authorization/AccessControlManager.java
@@ -8,6 +8,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.NoSuchRoleException;
import com.datastrato.gravitino.exceptions.NoSuchUserException;
import com.datastrato.gravitino.exceptions.RoleAlreadyExistsException;
@@ -46,13 +47,15 @@ public class AccessControlManager {
* Adds a new User.
*
* @param metalake The Metalake of the User.
- * @param name The name of the User.
+ * @param user The name of the User.
* @return The added User instance.
- * @throws UserAlreadyExistsException If a User with the same identifier already exists.
+ * @throws UserAlreadyExistsException If a User with the same name already exists.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
* @throws RuntimeException If adding the User encounters storage issues.
*/
- public User addUser(String metalake, String name) throws UserAlreadyExistsException {
- return doWithNonAdminLock(() -> userGroupManager.addUser(metalake, name));
+ public User addUser(String metalake, String user)
+ throws UserAlreadyExistsException, NoSuchMetalakeException {
+ return doWithNonAdminLock(() -> userGroupManager.addUser(metalake, user));
}
/**
@@ -60,10 +63,12 @@ public class AccessControlManager {
*
* @param metalake The Metalake of the User.
* @param user The name of the User.
- * @return `true` if the User was successfully removed, `false` otherwise.
+ * @return `true` if the User was successfully removed, `false` only when there's no such user,
+ * otherwise it will throw an exception.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
* @throws RuntimeException If removing the User encounters storage issues.
*/
- public boolean removeUser(String metalake, String user) {
+ public boolean removeUser(String metalake, String user) throws NoSuchMetalakeException {
return doWithNonAdminLock(() -> userGroupManager.removeUser(metalake, user));
}
@@ -73,10 +78,12 @@ public class AccessControlManager {
* @param metalake The Metalake of the User.
* @param user The name of the User.
* @return The getting User instance.
- * @throws NoSuchUserException If the User with the given identifier does not exist.
+ * @throws NoSuchUserException If the User with the given name does not exist.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
* @throws RuntimeException If getting the User encounters storage issues.
*/
- public User getUser(String metalake, String user) throws NoSuchUserException {
+ public User getUser(String metalake, String user)
+ throws NoSuchUserException, NoSuchMetalakeException {
return doWithNonAdminLock(() -> userGroupManager.getUser(metalake, user));
}
@@ -86,10 +93,12 @@ public class AccessControlManager {
* @param metalake The Metalake of the Group.
* @param group The name of the Group.
* @return The Added Group instance.
- * @throws GroupAlreadyExistsException If a Group with the same identifier already exists.
+ * @throws GroupAlreadyExistsException If a Group with the same name already exists.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
* @throws RuntimeException If adding the Group encounters storage issues.
*/
- public Group addGroup(String metalake, String group) throws GroupAlreadyExistsException {
+ public Group addGroup(String metalake, String group)
+ throws GroupAlreadyExistsException, NoSuchMetalakeException {
return doWithNonAdminLock(() -> userGroupManager.addGroup(metalake, group));
}
@@ -98,10 +107,12 @@ public class AccessControlManager {
*
* @param metalake The Metalake of the Group.
* @param group THe name of the Group.
- * @return `true` if the Group was successfully removed, `false` otherwise.
+ * @return `true` if the Group was successfully removed, `false` only when there's no such group,
+ * otherwise it will throw an exception.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
* @throws RuntimeException If removing the Group encounters storage issues.
*/
- public boolean removeGroup(String metalake, String group) {
+ public boolean removeGroup(String metalake, String group) throws NoSuchMetalakeException {
return doWithNonAdminLock(() -> userGroupManager.removeGroup(metalake, group));
}
@@ -111,10 +122,12 @@ public class AccessControlManager {
* @param metalake The Metalake of the Group.
* @param group The name of the Group.
* @return The getting Group instance.
- * @throws NoSuchGroupException If the Group with the given identifier does not exist.
+ * @throws NoSuchGroupException If the Group with the given name does not exist.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
* @throws RuntimeException If getting the Group encounters storage issues.
*/
- public Group getGroup(String metalake, String group) throws NoSuchGroupException {
+ public Group getGroup(String metalake, String group)
+ throws NoSuchGroupException, NoSuchMetalakeException {
return doWithNonAdminLock(() -> userGroupManager.getGroup(metalake, group));
}
@@ -187,10 +200,10 @@ public class AccessControlManager {
*
* @param user The name of the User.
* @return The added User instance.
- * @throws UserAlreadyExistsException If a User with the same identifier already exists.
+ * @throws UserAlreadyExistsException If a metalake admin with the same name already exists.
* @throws RuntimeException If adding the User encounters storage issues.
*/
- public User addMetalakeAdmin(String user) {
+ public User addMetalakeAdmin(String user) throws UserAlreadyExistsException {
return doWithAdminLock(() -> adminManager.addMetalakeAdmin(user));
}
@@ -198,7 +211,8 @@ public class AccessControlManager {
* Removes a metalake admin.
*
* @param user The name of the User.
- * @return `true` if the User was successfully removed, `false` otherwise.
+ * @return `true` if the User was successfully removed, `false` only when there's no such metalake
+ * admin, otherwise it will throw an exception.
* @throws RuntimeException If removing the User encounters storage issues.
*/
public boolean removeMetalakeAdmin(String user) {
@@ -234,7 +248,8 @@ public class AccessControlManager {
* @param securableObject The securable object of the Role.
* @param privileges The privileges of the Role.
* @return The created Role instance.
- * @throws RoleAlreadyExistsException If a Role with the same identifier already exists.
+ * @throws RoleAlreadyExistsException If a Role with the same name already exists.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
* @throws RuntimeException If creating the Role encounters storage issues.
*/
public Role createRole(
@@ -243,34 +258,38 @@ public class AccessControlManager {
Map<String, String> properties,
SecurableObject securableObject,
List<Privilege> privileges)
- throws RoleAlreadyExistsException {
+ throws RoleAlreadyExistsException, NoSuchMetalakeException {
return doWithNonAdminLock(
() -> roleManager.createRole(metalake, role, properties, securableObject, privileges));
}
/**
- * Loads a Role.
+ * Gets a Role.
*
* @param metalake The Metalake of the Role.
* @param role The name of the Role.
- * @return The loading Role instance.
- * @throws NoSuchRoleException If the Role with the given identifier does not exist.
- * @throws RuntimeException If loading the Role encounters storage issues.
+ * @return The getting Role instance.
+ * @throws NoSuchRoleException If the Role with the given name does not exist.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If getting the Role encounters storage issues.
*/
- public Role loadRole(String metalake, String role) throws NoSuchRoleException {
- return doWithNonAdminLock(() -> roleManager.loadRole(metalake, role));
+ public Role getRole(String metalake, String role)
+ throws NoSuchRoleException, NoSuchMetalakeException {
+ return doWithNonAdminLock(() -> roleManager.getRole(metalake, role));
}
/**
- * Drops a Role.
+ * Deletes a Role.
*
* @param metalake The Metalake of the Role.
* @param role The name of the Role.
- * @return `true` if the Role was successfully dropped, `false` otherwise.
- * @throws RuntimeException If dropping the User encounters storage issues.
+ * @return `true` if the Role was successfully deleted, `false` only when there's no such role,
+ * otherwise it will throw an exception.
+ * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+ * @throws RuntimeException If deleting the Role encounters storage issues.
*/
- public boolean dropRole(String metalake, String role) {
- return doWithNonAdminLock(() -> roleManager.dropRole(metalake, role));
+ public boolean deleteRole(String metalake, String role) throws NoSuchMetalakeException {
+ return doWithNonAdminLock(() -> roleManager.deleteRole(metalake, role));
}
@VisibleForTesting
diff --git a/core/src/main/java/com/datastrato/gravitino/authorization/PermissionManager.java b/core/src/main/java/com/datastrato/gravitino/authorization/PermissionManager.java
index 4453e68d25..a77eb19133 100644
--- a/core/src/main/java/com/datastrato/gravitino/authorization/PermissionManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/authorization/PermissionManager.java
@@ -44,7 +44,7 @@ class PermissionManager {
boolean grantRoleToUser(String metalake, String role, String user) {
try {
- RoleEntity roleEntity = roleManager.loadRole(metalake, role);
+ RoleEntity roleEntity = roleManager.getRole(metalake, role);
store.update(
AuthorizationUtils.ofUser(metalake, user),
@@ -98,7 +98,7 @@ class PermissionManager {
boolean grantRoleToGroup(String metalake, String role, String group) {
try {
- RoleEntity roleEntity = roleManager.loadRole(metalake, role);
+ RoleEntity roleEntity = roleManager.getRole(metalake, role);
store.update(
AuthorizationUtils.ofGroup(metalake, group),
@@ -152,7 +152,7 @@ class PermissionManager {
boolean revokeRoleFromGroup(String metalake, String role, String group) {
try {
- RoleEntity roleEntity = roleManager.loadRole(metalake, role);
+ RoleEntity roleEntity = roleManager.getRole(metalake, role);
AtomicBoolean removed = new AtomicBoolean(true);
@@ -212,7 +212,7 @@ class PermissionManager {
boolean revokeRoleFromUser(String metalake, String role, String user) {
try {
- RoleEntity roleEntity = roleManager.loadRole(metalake, role);
+ RoleEntity roleEntity = roleManager.getRole(metalake, role);
AtomicBoolean removed = new AtomicBoolean(true);
store.update(
diff --git a/core/src/main/java/com/datastrato/gravitino/authorization/RoleManager.java b/core/src/main/java/com/datastrato/gravitino/authorization/RoleManager.java
index ce39659996..71d72c36e4 100644
--- a/core/src/main/java/com/datastrato/gravitino/authorization/RoleManager.java
+++ b/core/src/main/java/com/datastrato/gravitino/authorization/RoleManager.java
@@ -108,7 +108,7 @@ class RoleManager {
}
}
- RoleEntity loadRole(String metalake, String role) throws NoSuchRoleException {
+ RoleEntity getRole(String metalake, String role) throws NoSuchRoleException {
try {
AuthorizationUtils.checkMetalakeExists(metalake);
return getRoleEntity(AuthorizationUtils.ofRole(metalake, role));
@@ -118,7 +118,7 @@ class RoleManager {
}
}
- boolean dropRole(String metalake, String role) {
+ boolean deleteRole(String metalake, String role) {
try {
AuthorizationUtils.checkMetalakeExists(metalake);
NameIdentifier ident = AuthorizationUtils.ofRole(metalake, role);
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 e65115c3c5..6b69395be5 100644
--- a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
+++ b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManager.java
@@ -245,9 +245,9 @@ public class TestAccessControlManager {
accessControlManager.createRole(
"metalake", "loadRole", props, SecurableObjects.ofAllCatalogs(), Lists.newArrayList());
- Role cachedRole = accessControlManager.loadRole("metalake", "loadRole");
+ Role cachedRole = accessControlManager.getRole("metalake", "loadRole");
accessControlManager.getRoleManager().getCache().invalidateAll();
- Role role = accessControlManager.loadRole("metalake", "loadRole");
+ Role role = accessControlManager.getRole("metalake", "loadRole");
// Verify the cached roleEntity is correct
Assertions.assertEquals(role, cachedRole);
@@ -258,8 +258,7 @@ public class TestAccessControlManager {
// Test load non-existed group
Throwable exception =
Assertions.assertThrows(
- NoSuchRoleException.class,
- () -> accessControlManager.loadRole("metalake", "not-exist"));
+ NoSuchRoleException.class, () -> accessControlManager.getRole("metalake", "not-exist"));
Assertions.assertTrue(exception.getMessage().contains("Role not-exist does not exist"));
}
@@ -271,11 +270,11 @@ public class TestAccessControlManager {
"metalake", "testDrop", props, SecurableObjects.ofAllCatalogs(), Lists.newArrayList());
// Test drop role
- boolean dropped = accessControlManager.dropRole("metalake", "testDrop");
+ boolean dropped = accessControlManager.deleteRole("metalake", "testDrop");
Assertions.assertTrue(dropped);
// Test drop non-existed role
- boolean dropped1 = accessControlManager.dropRole("metalake", "no-exist");
+ boolean dropped1 = accessControlManager.deleteRole("metalake", "no-exist");
Assertions.assertFalse(dropped1);
}
diff --git a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java
index 00dd6127bc..cf38825fe3 100644
--- a/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java
+++ b/core/src/test/java/com/datastrato/gravitino/authorization/TestAccessControlManagerForPermissions.java
@@ -117,7 +117,7 @@ public class TestAccessControlManagerForPermissions {
}
@Test
- public void testAddRoleToUser() {
+ public void testGrantRoleToUser() {
String notExist = "not-exist";
User user = accessControlManager.getUser(METALAKE, USER);
@@ -153,7 +153,7 @@ public class TestAccessControlManagerForPermissions {
}
@Test
- public void testRemoveRoleFromUser() {
+ public void testRevokeRoleFromUser() {
String notExist = "not-exist";
Assertions.assertTrue(accessControlManager.grantRoleToUser(METALAKE, ROLE, USER));
@@ -179,7 +179,7 @@ public class TestAccessControlManagerForPermissions {
}
@Test
- public void testAddRoleToGroup() {
+ public void testGrantRoleToGroup() {
String notExist = "not-exist";
Group group = accessControlManager.getGroup(METALAKE, GROUP);
@@ -216,7 +216,7 @@ public class TestAccessControlManagerForPermissions {
}
@Test
- public void testRemoveRoleFormGroup() {
+ public void testRevokeRoleFormGroup() {
String notExist = "not-exist";
Assertions.assertTrue(accessControlManager.grantRoleToGroup(METALAKE, ROLE, GROUP));
@@ -261,7 +261,7 @@ public class TestAccessControlManagerForPermissions {
entityStore.put(roleEntity, true);
Assertions.assertTrue(accessControlManager.grantRoleToUser(METALAKE, anotherRole, USER));
Assertions.assertTrue(accessControlManager.grantRoleToGroup(METALAKE, anotherRole, GROUP));
- accessControlManager.dropRole(METALAKE, anotherRole);
+ accessControlManager.deleteRole(METALAKE, anotherRole);
Group group = accessControlManager.getGroup(METALAKE, GROUP);
Assertions.assertTrue(group.roles().isEmpty());
}
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/OperationType.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/OperationType.java
index 78a4f56aa0..6daacfc822 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/OperationType.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/OperationType.java
@@ -13,5 +13,6 @@ public enum OperationType {
/** This is a special operation type that is used to get a partition from a table. */
GET,
ADD,
- REMOVE
+ REMOVE,
+ DELETE
}
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java
index c89f27d0a7..14b8d33117 100644
--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java
+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/RoleOperations.java
@@ -11,7 +11,7 @@ import com.datastrato.gravitino.authorization.AccessControlManager;
import com.datastrato.gravitino.authorization.Privileges;
import com.datastrato.gravitino.authorization.SecurableObjects;
import com.datastrato.gravitino.dto.requests.RoleCreateRequest;
-import com.datastrato.gravitino.dto.responses.DropResponse;
+import com.datastrato.gravitino.dto.responses.DeleteResponse;
import com.datastrato.gravitino.dto.responses.RoleResponse;
import com.datastrato.gravitino.dto.util.DTOConverters;
import com.datastrato.gravitino.metrics.MetricNames;
@@ -44,18 +44,18 @@ public class RoleOperations {
@GET
@Path("{role}")
@Produces("application/vnd.gravitino.v1+json")
- @Timed(name = "load-role." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
- @ResponseMetered(name = "load-role", absolute = true)
- public Response loadRole(@PathParam("metalake") String metalake, @PathParam("role") String role) {
+ @Timed(name = "get-role." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
+ @ResponseMetered(name = "get-role", absolute = true)
+ public Response getRole(@PathParam("metalake") String metalake, @PathParam("role") String role) {
try {
return Utils.doAs(
httpRequest,
() ->
Utils.ok(
new RoleResponse(
- DTOConverters.toDTO(accessControlManager.loadRole(metalake, role)))));
+ DTOConverters.toDTO(accessControlManager.getRole(metalake, role)))));
} catch (Exception e) {
- return ExceptionHandlers.handleRoleException(OperationType.LOAD, role, metalake, e);
+ return ExceptionHandlers.handleRoleException(OperationType.GET, role, metalake, e);
}
}
@@ -63,7 +63,7 @@ public class RoleOperations {
@Produces("application/vnd.gravitino.v1+json")
@Timed(name = "create-role." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
@ResponseMetered(name = "create-role", absolute = true)
- public Response creatRole(@PathParam("metalake") String metalake, RoleCreateRequest request) {
+ public Response createRole(@PathParam("metalake") String metalake, RoleCreateRequest request) {
try {
return Utils.doAs(
httpRequest,
@@ -88,21 +88,22 @@ public class RoleOperations {
@DELETE
@Path("{role}")
@Produces("application/vnd.gravitino.v1+json")
- @Timed(name = "drop-role." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
- @ResponseMetered(name = "drop-role", absolute = true)
- public Response dropRole(@PathParam("metalake") String metalake, @PathParam("role") String role) {
+ @Timed(name = "delete-role." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
+ @ResponseMetered(name = "delete-role", absolute = true)
+ public Response deleteRole(
+ @PathParam("metalake") String metalake, @PathParam("role") String role) {
try {
return Utils.doAs(
httpRequest,
() -> {
- boolean dropped = accessControlManager.dropRole(metalake, role);
- if (!dropped) {
- LOG.warn("Failed to drop role {} under metalake {}", role, metalake);
+ boolean deteted = accessControlManager.deleteRole(metalake, role);
+ if (!deteted) {
+ LOG.warn("Failed to delete role {} under metalake {}", role, metalake);
}
- return Utils.ok(new DropResponse(dropped));
+ return Utils.ok(new DeleteResponse(deteted));
});
} catch (Exception e) {
- return ExceptionHandlers.handleRoleException(OperationType.DROP, role, metalake, e);
+ return ExceptionHandlers.handleRoleException(OperationType.DELETE, role, metalake, e);
}
}
}
diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java
index 17d74cc02b..59397bce66 100644
--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java
+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestRoleOperations.java
@@ -20,7 +20,7 @@ import com.datastrato.gravitino.authorization.Role;
import com.datastrato.gravitino.authorization.SecurableObjects;
import com.datastrato.gravitino.dto.authorization.RoleDTO;
import com.datastrato.gravitino.dto.requests.RoleCreateRequest;
-import com.datastrato.gravitino.dto.responses.DropResponse;
+import com.datastrato.gravitino.dto.responses.DeleteResponse;
import com.datastrato.gravitino.dto.responses.ErrorConstants;
import com.datastrato.gravitino.dto.responses.ErrorResponse;
import com.datastrato.gravitino.dto.responses.RoleResponse;
@@ -176,10 +176,10 @@ public class TestRoleOperations extends JerseyTest {
}
@Test
- public void testLoadRole() {
+ public void testGetRole() {
Role role = buildRole("role1");
- when(manager.loadRole(any(), any())).thenReturn(role);
+ when(manager.getRole(any(), any())).thenReturn(role);
Response resp =
target("/metalakes/metalake1/roles/role1")
@@ -198,7 +198,7 @@ public class TestRoleOperations extends JerseyTest {
Assertions.assertEquals(Lists.newArrayList(Privileges.LoadCatalog.get()), roleDTO.privileges());
// Test to throw NoSuchMetalakeException
- doThrow(new NoSuchMetalakeException("mock error")).when(manager).loadRole(any(), any());
+ doThrow(new NoSuchMetalakeException("mock error")).when(manager).getRole(any(), any());
Response resp1 =
target("/metalakes/metalake1/roles/role1")
.request(MediaType.APPLICATION_JSON_TYPE)
@@ -212,7 +212,7 @@ public class TestRoleOperations extends JerseyTest {
Assertions.assertEquals(NoSuchMetalakeException.class.getSimpleName(), errorResponse.getType());
// Test to throw NoSuchRoleException
- doThrow(new NoSuchRoleException("mock error")).when(manager).loadRole(any(), any());
+ doThrow(new NoSuchRoleException("mock error")).when(manager).getRole(any(), any());
Response resp2 =
target("/metalakes/metalake1/roles/role1")
.request(MediaType.APPLICATION_JSON_TYPE)
@@ -226,7 +226,7 @@ public class TestRoleOperations extends JerseyTest {
Assertions.assertEquals(NoSuchRoleException.class.getSimpleName(), errorResponse1.getType());
// Test to throw internal RuntimeException
- doThrow(new RuntimeException("mock error")).when(manager).loadRole(any(), any());
+ doThrow(new RuntimeException("mock error")).when(manager).getRole(any(), any());
Response resp3 =
target("/metalakes/metalake1/roles/role1")
.request(MediaType.APPLICATION_JSON_TYPE)
@@ -254,8 +254,8 @@ public class TestRoleOperations extends JerseyTest {
}
@Test
- public void testDropRole() {
- when(manager.dropRole(any(), any())).thenReturn(true);
+ public void testDeleteRole() {
+ when(manager.deleteRole(any(), any())).thenReturn(true);
Response resp =
target("/metalakes/metalake1/roles/role1")
@@ -264,12 +264,12 @@ public class TestRoleOperations extends JerseyTest {
.delete();
Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- DropResponse dropResponse = resp.readEntity(DropResponse.class);
- Assertions.assertEquals(0, dropResponse.getCode());
- Assertions.assertTrue(dropResponse.dropped());
+ DeleteResponse deleteResponse = resp.readEntity(DeleteResponse.class);
+ Assertions.assertEquals(0, deleteResponse.getCode());
+ Assertions.assertTrue(deleteResponse.deleted());
- // Test when failed to drop role
- when(manager.dropRole(any(), any())).thenReturn(false);
+ // Test when failed to delete role
+ when(manager.deleteRole(any(), any())).thenReturn(false);
Response resp2 =
target("/metalakes/metalake1/roles/role1")
.request(MediaType.APPLICATION_JSON_TYPE)
@@ -277,11 +277,11 @@ public class TestRoleOperations extends JerseyTest {
.delete();
Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp2.getStatus());
- DropResponse dropResponse2 = resp2.readEntity(DropResponse.class);
- Assertions.assertEquals(0, dropResponse2.getCode());
- Assertions.assertFalse(dropResponse2.dropped());
+ DeleteResponse deleteResponse2 = resp2.readEntity(DeleteResponse.class);
+ Assertions.assertEquals(0, deleteResponse2.getCode());
+ Assertions.assertFalse(deleteResponse2.deleted());
- doThrow(new RuntimeException("mock error")).when(manager).dropRole(any(), any());
+ doThrow(new RuntimeException("mock error")).when(manager).deleteRole(any(), any());
Response resp3 =
target("/metalakes/metalake1/roles/role1")
.request(MediaType.APPLICATION_JSON_TYPE)