Skip to content

Commit

Permalink
Remove Operations code
Browse files Browse the repository at this point in the history
  • Loading branch information
Heng Qin committed Mar 15, 2024
1 parent 47d733b commit 2808f2d
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 724 deletions.
132 changes: 0 additions & 132 deletions common/src/main/java/com/datastrato/gravitino/dto/UserDTO.java

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import com.datastrato.gravitino.Audit;
import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.Metalake;
import com.datastrato.gravitino.User;
import com.datastrato.gravitino.dto.AuditDTO;
import com.datastrato.gravitino.dto.CatalogDTO;
import com.datastrato.gravitino.dto.MetalakeDTO;
import com.datastrato.gravitino.dto.UserDTO;
import com.datastrato.gravitino.dto.file.FilesetDTO;
import com.datastrato.gravitino.dto.rel.ColumnDTO;
import com.datastrato.gravitino.dto.rel.DistributionDTO;
Expand Down Expand Up @@ -327,23 +325,6 @@ public static IndexDTO toDTO(Index index) {
.build();
}

/**
* Converts a user implementation to a UserDTO.
*
* @param user The user implementation.
* @return The user DTO.
*/
public static UserDTO toDTO(User user) {
if (user instanceof UserDTO) {
return (UserDTO) user;
}
return UserDTO.builder()
.withName(user.name())
.withAudit(toDTO(user.auditInfo()))
.withProperties(user.properties())
.build();
}

/**
* Converts a Expression to an FunctionArg DTO.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.datastrato.gravitino.dto.AuditDTO;
import com.datastrato.gravitino.dto.CatalogDTO;
import com.datastrato.gravitino.dto.MetalakeDTO;
import com.datastrato.gravitino.dto.UserDTO;
import com.datastrato.gravitino.dto.rel.ColumnDTO;
import com.datastrato.gravitino.dto.rel.SchemaDTO;
import com.datastrato.gravitino.dto.rel.TableDTO;
Expand Down Expand Up @@ -224,19 +223,4 @@ void testOAuthErrorException() throws IllegalArgumentException {
OAuth2ErrorResponse response = new OAuth2ErrorResponse();
assertThrows(IllegalArgumentException.class, () -> response.validate());
}

@Test
void testUserResponse() throws IllegalArgumentException {
AuditDTO audit =
new AuditDTO.Builder().withCreator("creator").withCreateTime(Instant.now()).build();
UserDTO user = UserDTO.builder().withName("user1").withAudit(audit).build();
UserResponse response = new UserResponse(user);
response.validate(); // No exception thrown
}

@Test
void testUserResponseException() throws IllegalArgumentException {
UserResponse user = new UserResponse();
assertThrows(IllegalArgumentException.class, () -> user.validate());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.datastrato.gravitino.server.web.ObjectMapperProvider;
import com.datastrato.gravitino.server.web.VersioningFilter;
import com.datastrato.gravitino.server.web.ui.WebUIFilter;
import com.datastrato.gravitino.tenant.AccessControlManager;
import java.io.File;
import java.util.Properties;
import javax.servlet.Servlet;
Expand Down Expand Up @@ -74,7 +73,6 @@ private void initializeRestApi() {
protected void configure() {
bind(gravitinoEnv.metalakesManager()).to(MetalakeManager.class).ranked(1);
bind(gravitinoEnv.catalogManager()).to(CatalogManager.class).ranked(1);
bind(gravitinoEnv.accessControlManager()).to(AccessControlManager.class).ranked(1);
bind(gravitinoEnv.catalogOperationDispatcher())
.to(CatalogOperationDispatcher.class)
.ranked(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.datastrato.gravitino.exceptions.PartitionAlreadyExistsException;
import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;
import com.datastrato.gravitino.exceptions.TableAlreadyExistsException;
import com.datastrato.gravitino.exceptions.UserAlreadyExistsException;
import com.datastrato.gravitino.server.web.Utils;
import com.google.common.annotations.VisibleForTesting;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -56,11 +55,6 @@ public static Response handleFilesetException(
return FilesetExceptionHandler.INSTANCE.handle(op, fileset, schema, e);
}

public static Response handleUserException(
OperationType op, String user, String metalake, Exception e) {
return UserExceptionHandler.INSTANCE.handle(op, user, metalake, e);
}

private static class PartitionExceptionHandler extends BaseExceptionHandler {

private static final ExceptionHandler INSTANCE = new PartitionExceptionHandler();
Expand Down Expand Up @@ -260,38 +254,6 @@ public Response handle(OperationType op, String fileset, String schema, Exceptio
}
}

private static class UserExceptionHandler extends BaseExceptionHandler {

private static final ExceptionHandler INSTANCE = new UserExceptionHandler();

private static String getUserErrorMsg(
String fileset, String operation, String metalake, String reason) {
return String.format(
"Failed to operate user %s operation [%s] under metalake [%s], reason [%s]",
fileset, operation, metalake, reason);
}

@Override
public Response handle(OperationType op, String user, String metalake, Exception e) {
String formatted = StringUtil.isBlank(user) ? "" : " [" + user + "]";
String errorMsg = getUserErrorMsg(formatted, op.name(), metalake, getErrorMsg(e));
LOG.warn(errorMsg, e);

if (e instanceof IllegalArgumentException) {
return Utils.illegalArguments(errorMsg, e);

} else if (e instanceof NotFoundException) {
return Utils.notFound(errorMsg, e);

} else if (e instanceof UserAlreadyExistsException) {
return Utils.alreadyExists(errorMsg, e);

} else {
return super.handle(op, user, metalake, e);
}
}
}

@VisibleForTesting
static class BaseExceptionHandler extends ExceptionHandler {

Expand Down
Loading

0 comments on commit 2808f2d

Please sign in to comment.