World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#9081] fix(catalog): use correct operation type in catalog update error handler in CatalogOperations.java (#9092)
Emmanuel Valentin4a411c86f655
diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.javaindex 093e17eff6..a12fc99ba5 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.java@@ -216,12 +216,15 @@ public class CatalogOperations {String catalogName,CatalogSetRequest request) {LOG.info("Received set request for catalog: {}.{}", metalake, catalogName);++ OperationType op = request.isInUse() ? OperationType.ENABLE : OperationType.DISABLE;+try {return Utils.doAs(httpRequest,() -> {NameIdentifier ident = NameIdentifierUtil.ofCatalog(metalake, catalogName);- if (request.isInUse()) {+ if (op == OperationType.ENABLE) {catalogDispatcher.enableCatalog(ident);} else {catalogDispatcher.disableCatalog(ident);@@ -242,8 +245,7 @@ public class CatalogOperations {request.isInUse() ? "enable" : "disable",metalake,catalogName);- return ExceptionHandlers.handleCatalogException(- OperationType.ENABLE, catalogName, metalake, e);+ return ExceptionHandlers.handleCatalogException(op, catalogName, metalake, e);}}diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.javaindex b902d7c68e..fbf462ba25 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java@@ -520,6 +520,7 @@ public class TestCatalogOperations extends BaseOperationsTest {@Testpublic void testSetCatalog() {+ // Test enable catalogCatalogSetRequest req = new CatalogSetRequest(true);doNothing().when(manager).enableCatalog(any());@@ -534,6 +535,7 @@ public class TestCatalogOperations extends BaseOperationsTest {BaseResponse baseResponse = resp.readEntity(BaseResponse.class);Assertions.assertEquals(0, baseResponse.getCode());+ // Test disable catalogreq = new CatalogSetRequest(false);doNothing().when(manager).disableCatalog(any());@@ -547,6 +549,38 @@ public class TestCatalogOperations extends BaseOperationsTest {Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());baseResponse = resp.readEntity(BaseResponse.class);Assertions.assertEquals(0, baseResponse.getCode());++ // Test throw NoSuchCatalogException when enabling catalog+ req = new CatalogSetRequest(true);+ doThrow(new RuntimeException("mock error")).when(manager).enableCatalog(any());++ resp =+ target("/metalakes/metalake1/catalogs/catalog1")+ .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .method("PATCH", Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), resp.getStatus());+ ErrorResponse errorResponse = resp.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResponse.getCode());+ Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResponse.getType());++ // Test throw NoSuchCatalogException when disabling catalog+ req = new CatalogSetRequest(false);+ doThrow(new RuntimeException("mock error")).when(manager).disableCatalog(any());++ resp =+ target("/metalakes/metalake1/catalogs/catalog1")+ .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .method("PATCH", Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), resp.getStatus());+ ErrorResponse errorResponse1 = resp.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResponse1.getCode());+ Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResponse1.getType());}private static TestCatalog buildCatalog(String metalake, String catalogName) {