World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#2396] feat(all): support list all catalogs info (#2648)
mchadescc87d8613880
diff --git a/api/src/main/java/com/datastrato/gravitino/SupportsCatalogs.java b/api/src/main/java/com/datastrato/gravitino/SupportsCatalogs.javaindex a38ef13bf6..d6e36aa883 100644--- a/api/src/main/java/com/datastrato/gravitino/SupportsCatalogs.java+++ b/api/src/main/java/com/datastrato/gravitino/SupportsCatalogs.java@@ -26,6 +26,15 @@ public interface SupportsCatalogs {*/NameIdentifier[] listCatalogs(Namespace namespace) throws NoSuchMetalakeException;+ /**+ * List all catalogs with their information in the metalake under the namespace {@link Namespace}.+ *+ * @param namespace The namespace to list the catalogs under it.+ * @return The list of catalog's information.+ * @throws NoSuchMetalakeException If the metalake with namespace does not exist.+ */+ Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException;+/*** Load a catalog by its identifier.*diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.javaindex f6350ec708..84489eefbd 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClient.java@@ -59,6 +59,11 @@ public class GravitinoClient extends GravitinoClientBase implements SupportsCatareturn getMetalake().listCatalogs(namespace);}+ @Override+ public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {+ return getMetalake().listCatalogsInfo(namespace);+ }+@Overridepublic Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {return getMetalake().loadCatalog(ident);diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.javaindex 2d98438d2e..45a2fb8b7e 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.java@@ -14,6 +14,7 @@ import com.datastrato.gravitino.dto.MetalakeDTO;import com.datastrato.gravitino.dto.requests.CatalogCreateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdatesRequest;+import com.datastrato.gravitino.dto.responses.CatalogListResponse;import com.datastrato.gravitino.dto.responses.CatalogResponse;import com.datastrato.gravitino.dto.responses.DropResponse;import com.datastrato.gravitino.dto.responses.EntityListResponse;@@ -23,6 +24,7 @@ import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;import com.google.common.base.Preconditions;import java.util.Arrays;import java.util.Collections;+import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.stream.Collectors;@@ -75,6 +77,32 @@ public class GravitinoMetalake extends MetalakeDTO implements SupportsCatalogs {return resp.identifiers();}+ /**+ * List all the catalogs with their information under this metalake with specified namespace.+ *+ * @param namespace The namespace to list the catalogs under it.+ * @return A list of {@link Catalog} under the specified namespace.+ * @throws NoSuchMetalakeException if the metalake with specified namespace does not exist.+ */+ @Override+ public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {+ Namespace.checkCatalog(namespace);++ Map<String, String> params = new HashMap<>();+ params.put("details", "true");+ CatalogListResponse resp =+ restClient.get(+ String.format("api/metalakes/%s/catalogs", namespace.level(0)),+ params,+ CatalogListResponse.class,+ Collections.emptyMap(),+ ErrorHandlers.catalogErrorHandler());++ return Arrays.stream(resp.getCatalogs())+ .map(c -> DTOConverters.toCatalog(c, restClient))+ .toArray(Catalog[]::new);+ }+/*** Load the catalog with specified identifier.*diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.javaindex e8b8a16341..46d5f1c612 100644--- a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.java+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.java@@ -15,6 +15,7 @@ import com.datastrato.gravitino.dto.requests.CatalogCreateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdatesRequest;import com.datastrato.gravitino.dto.requests.MetalakeCreateRequest;+import com.datastrato.gravitino.dto.responses.CatalogListResponse;import com.datastrato.gravitino.dto.responses.CatalogResponse;import com.datastrato.gravitino.dto.responses.DropResponse;import com.datastrato.gravitino.dto.responses.EntityListResponse;@@ -103,6 +104,54 @@ public class TestGravitinoMetalake extends TestBase {Assertions.assertTrue(ex1.getMessage().contains("Error code: " + HttpStatus.SC_CONFLICT));}+ @Test+ public void testListCatalogsInfo() throws JsonProcessingException {+ String path = "/api/metalakes/" + metalakeName + "/catalogs";+ Map<String, String> params = Collections.singletonMap("details", "true");++ Namespace namespace = Namespace.of(metalakeName);++ CatalogDTO mockCatalog1 =+ CatalogDTO.builder()+ .withName("mock")+ .withComment("comment")+ .withType(Catalog.Type.RELATIONAL)+ .withProvider("test")+ .withAudit(+ AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())+ .build();+ CatalogDTO mockCatalog2 =+ CatalogDTO.builder()+ .withName("mock2")+ .withComment("comment2")+ .withType(Catalog.Type.RELATIONAL)+ .withProvider("test")+ .withAudit(+ AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build())+ .build();+ CatalogListResponse resp =+ new CatalogListResponse(new CatalogDTO[] {mockCatalog1, mockCatalog2});+ buildMockResource(Method.GET, path, null, resp, HttpStatus.SC_OK);++ Catalog[] catalogs = gravitinoClient.listCatalogsInfo(namespace);+ Assertions.assertEquals(2, catalogs.length);+ Assertions.assertEquals("mock", catalogs[0].name());+ Assertions.assertEquals("comment", catalogs[0].comment());+ Assertions.assertEquals(Catalog.Type.RELATIONAL, catalogs[0].type());+ Assertions.assertEquals("mock2", catalogs[1].name());+ Assertions.assertEquals("comment2", catalogs[1].comment());+ Assertions.assertEquals(Catalog.Type.RELATIONAL, catalogs[1].type());++ // Test return no found+ ErrorResponse errorResponse =+ ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "mock error");+ buildMockResource(Method.GET, path, params, null, errorResponse, HttpStatus.SC_NOT_FOUND);+ Throwable ex =+ Assertions.assertThrows(+ NoSuchMetalakeException.class, () -> gravitinoClient.listCatalogsInfo(namespace));+ Assertions.assertTrue(ex.getMessage().contains("mock error"));+ }+@Testpublic void testLoadCatalog() throws JsonProcessingException {String catalogName = "mock";diff --git a/common/src/main/java/com/datastrato/gravitino/dto/responses/CatalogListResponse.java b/common/src/main/java/com/datastrato/gravitino/dto/responses/CatalogListResponse.javanew file mode 100644index 0000000000..377f644540--- /dev/null+++ b/common/src/main/java/com/datastrato/gravitino/dto/responses/CatalogListResponse.java@@ -0,0 +1,40 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.dto.responses;++import com.datastrato.gravitino.dto.CatalogDTO;+import com.fasterxml.jackson.annotation.JsonProperty;+import lombok.EqualsAndHashCode;+import lombok.Getter;+import lombok.ToString;++/** Represents a response for a list of catalogs with their information. */+@Getter+@ToString+@EqualsAndHashCode(callSuper = true)+public class CatalogListResponse extends BaseResponse {++ @JsonProperty("catalogs")+ private final CatalogDTO[] catalogs;++ /**+ * Creates a new CatalogListResponse.+ *+ * @param catalogs The list of catalogs.+ */+ public CatalogListResponse(CatalogDTO[] catalogs) {+ super(0);+ this.catalogs = catalogs;+ }++ /**+ * This is the constructor that is used by Jackson deserializer to create an instance of+ * CatalogListResponse.+ */+ public CatalogListResponse() {+ super();+ this.catalogs = null;+ }+}diff --git a/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.java b/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.javaindex 1ea3cac21f..e06c3c17bc 100644--- a/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.java+++ b/common/src/main/java/com/datastrato/gravitino/dto/util/DTOConverters.java@@ -462,6 +462,19 @@ public class DTOConverters {return Arrays.stream(partitions).map(DTOConverters::toDTO).toArray(PartitionDTO[]::new);}+ /**+ * Converts an array of Catalogs to an array of CatalogDTOs.+ *+ * @param catalogs The catalogs to be converted.+ * @return The array of CatalogDTOs.+ */+ public static CatalogDTO[] toDTOs(Catalog[] catalogs) {+ if (ArrayUtils.isEmpty(catalogs)) {+ return new CatalogDTO[0];+ }+ return Arrays.stream(catalogs).map(DTOConverters::toDTO).toArray(CatalogDTO[]::new);+ }+/*** Converts a DistributionDTO to a Distribution.*diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.javaindex f1ff06331c..40bccd9130 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java@@ -211,24 +211,28 @@ public class CatalogManager implements SupportsCatalogs, Closeable {@Overridepublic NameIdentifier[] listCatalogs(Namespace namespace) throws NoSuchMetalakeException {NameIdentifier metalakeIdent = NameIdentifier.of(namespace.levels());+ checkMetalakeExists(metalakeIdent);- boolean metalakeExists;try {- metalakeExists = store.exists(metalakeIdent, EntityType.METALAKE);- } catch (IOException e) {- LOG.error("Failed to do storage operation", e);- throw new RuntimeException(e);- }+ return store.list(namespace, CatalogEntity.class, EntityType.CATALOG).stream()+ .map(entity -> NameIdentifier.of(namespace, entity.name()))+ .toArray(NameIdentifier[]::new);- if (!metalakeExists) {- throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, metalakeIdent);+ } catch (IOException ioe) {+ LOG.error("Failed to list catalogs in metalake {}", metalakeIdent, ioe);+ throw new RuntimeException(ioe);}+ }++ @Override+ public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {+ NameIdentifier metalakeIdent = NameIdentifier.of(namespace.levels());+ checkMetalakeExists(metalakeIdent);try {return store.list(namespace, CatalogEntity.class, EntityType.CATALOG).stream()- .map(entity -> NameIdentifier.of(namespace, entity.name()))- .toArray(NameIdentifier[]::new);-+ .map(CatalogEntity::toCatalogInfo)+ .toArray(Catalog[]::new);} catch (IOException ioe) {LOG.error("Failed to list catalogs in metalake {}", metalakeIdent, ioe);throw new RuntimeException(ioe);@@ -456,6 +460,17 @@ public class CatalogManager implements SupportsCatalogs, Closeable {return catalogCache.get(ident, this::loadCatalogInternal);}+ private void checkMetalakeExists(NameIdentifier ident) throws NoSuchMetalakeException {+ try {+ if (!store.exists(ident, EntityType.METALAKE)) {+ throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, ident);+ }+ } catch (IOException e) {+ LOG.error("Failed to do storage operation", e);+ throw new RuntimeException(e);+ }+ }+private CatalogWrapper loadCatalogInternal(NameIdentifier ident) throws NoSuchCatalogException {try {CatalogEntity entity = store.get(ident, EntityType.CATALOG, CatalogEntity.class);diff --git a/core/src/main/java/com/datastrato/gravitino/connector/CatalogInfo.java b/core/src/main/java/com/datastrato/gravitino/connector/CatalogInfo.javaindex 043edb3e0e..f95ca6c7fa 100644--- a/core/src/main/java/com/datastrato/gravitino/connector/CatalogInfo.java+++ b/core/src/main/java/com/datastrato/gravitino/connector/CatalogInfo.java@@ -18,7 +18,7 @@ import java.util.Map;* CatalogInfo)}, users can leverage this object to get the information about the catalog.*/@Evolving-public final class CatalogInfo {+public final class CatalogInfo implements Catalog {private final Long id;@@ -61,31 +61,37 @@ public final class CatalogInfo {}/** @return The name of the catalog. */+ @Overridepublic String name() {return name;}/** @return The type of the catalog. */+ @Overridepublic Catalog.Type type() {return type;}/** @return The provider of the catalog. */+ @Overridepublic String provider() {return provider;}/** @return The comment or description for the catalog. */+ @Overridepublic String comment() {return comment;}/** @return The associated properties of the catalog. */+ @Overridepublic Map<String, String> properties() {return properties;}/** @return The audit details of the catalog. */+ @Overridepublic Audit auditInfo() {return auditInfo;}diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogManager.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogManager.javaindex 42d2f28e5d..bd7d66ad28 100644--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogManager.java+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogManager.java@@ -358,6 +358,39 @@ public class TestCatalogManager {Assertions.assertTrue(exception.getMessage().contains("Metalake metalake1 does not exist"));}+ @Test+ public void testListCatalogsInfo() {+ NameIdentifier relIdent = NameIdentifier.of("metalake", "catalog_rel");+ NameIdentifier fileIdent = NameIdentifier.of("metalake", "catalog_file");+ Map<String, String> props = ImmutableMap.of("provider", "test");++ catalogManager.createCatalog(relIdent, Catalog.Type.RELATIONAL, provider, "comment", props);+ catalogManager.createCatalog(fileIdent, Catalog.Type.FILESET, provider, "comment", props);++ Catalog[] catalogs = catalogManager.listCatalogsInfo(relIdent.namespace());+ Assertions.assertEquals(2, catalogs.length);+ for (Catalog catalog : catalogs) {+ Assertions.assertTrue(+ catalog.name().equals("catalog_rel") || catalog.name().equals("catalog_file"));+ Assertions.assertEquals("comment", catalog.comment());+ testProperties(props, catalog.properties());++ if (catalog.name().equals("catalog_rel")) {+ Assertions.assertEquals(Catalog.Type.RELATIONAL, catalog.type());+ } else {+ Assertions.assertEquals(Catalog.Type.FILESET, catalog.type());+ }+ }++ // Test list under non-existed metalake+ NameIdentifier ident2 = NameIdentifier.of("metalake1", "test1");+ Namespace namespace = ident2.namespace();+ Throwable exception =+ Assertions.assertThrows(+ NoSuchMetalakeException.class, () -> catalogManager.listCatalogsInfo(namespace));+ Assertions.assertTrue(exception.getMessage().contains("Metalake metalake1 does not exist"));+ }+@Testpublic void testLoadCatalog() {NameIdentifier ident = NameIdentifier.of("metalake", "test21");diff --git a/docs/manage-metadata-using-gravitino.md b/docs/manage-metadata-using-gravitino.mdindex 88c12b7a4d..6d178017ac 100644--- a/docs/manage-metadata-using-gravitino.md+++ b/docs/manage-metadata-using-gravitino.md@@ -392,6 +392,36 @@ NameIdentifier[] catalogsIdents = gravitinoMetaLake.listCatalogs(Namespace.ofCat</TabItem></Tabs>+### List all catalogs' information in a metalake++You can list all catalogs' information under a metalake by sending a `GET` request to the `/api/metalakes/{metalake_name}/catalogs?detail=true` endpoint or just use the Gravitino Java client. The following is an example of listing all catalogs' information in a metalake:++<Tabs>+<TabItem value="shell" label="Shell">++```shell+curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \+-H "Content-Type: application/json" \+http://localhost:8090/api/metalakes/metalake/catalogs?detail=true+```++</TabItem>+<TabItem value="java" label="Java">++```java+// ...+// Assuming you have just created a metalake named `metalake`+GravitinoMetaLake gravitinoMetaLake =+ gravitinoClient.loadMetalake(NameIdentifier.of("metalake"));++Catalog[] catalogsInfos = gravitinoMetaLake.listCatalogsInfo(Namespace.ofCatalog("metalake"));+// ...+```++</TabItem>+</Tabs>++## Schema operations:::tipdiff --git a/docs/open-api/catalogs.yaml b/docs/open-api/catalogs.yamlindex de4bc2ae8c..fe9221a1d1 100644--- a/docs/open-api/catalogs.yaml+++ b/docs/open-api/catalogs.yaml@@ -13,11 +13,24 @@ paths:get:tags:- catalog- summary: List catalogs+ summary: List catalogs (names)operationId: listCatalogs+ parameters:+ - $ref: "#/components/parameters/details"responses:"200":- $ref: "./openapi.yaml#/components/responses/EntityListResponse"+ description: Returns the list of catalog objects if {details} is true, otherwise returns the list of catalog identifiers+ content:+ application/vnd.gravitino.v1+json:+ schema:+ oneOf:+ - $ref: "#/components/schemas/CatalogListResponse"+ - $ref: "#/components/schemas/CatalogInfoListResponse"+ examples:+ CatalogListResponse:+ $ref: "#/components/examples/CatalogListResponse"+ CatalogInfoListResponse:+ $ref: "#/components/examples/CatalogInfoListResponse""400":$ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse""5xx":@@ -133,6 +146,15 @@ paths:components:+ parameters:+ details:+ name: details+ in: query+ description: Include detailed information about the catalogs+ required: false+ schema:+ type: boolean+ default: falseschemas:@@ -153,8 +175,8 @@ components:description: The type of the catalogenum:- relational- - file- - stream+ - fileset+ - messagingprovider:type: stringdescription: The provider of the catalog@@ -163,6 +185,7 @@ components:- lakehouse-iceberg- jdbc-mysql- jdbc-postgresql+ - hadoopcomment:type: stringdescription: A comment about the catalog@@ -176,6 +199,35 @@ components:additionalProperties:type: string+ CatalogListResponse:+ type: object+ properties:+ code:+ type: integer+ format: int32+ description: Status code of the response+ enum:+ - 0+ identifiers:+ type: array+ items:+ $ref: "./openapi.yaml#/components/schemas/NameIdentifier"++ CatalogInfoListResponse:+ type: object+ properties:+ code:+ type: integer+ format: int32+ description: Status code of the response+ enum:+ - 0+ catalogs:+ type: array+ description: A list of catalog objects+ items:+ $ref: "#/components/schemas/Catalog"+CatalogCreateRequest:type: objectrequired:@@ -191,7 +243,7 @@ components:description: The type of the catalogenum:- relational- - file+ - fileset- streamprovider:type: string@@ -351,6 +403,41 @@ components:]}+ CatalogInfoListResponse:+ value: {+ "code": 0,+ "catalogs": [+ {+ "name": "my_hive_catalog",+ "type": "relational",+ "provider": "hive",+ "comment": "This is my hive catalog",+ "properties": {+ "key1": "value1",+ "gravitino.bypass.hive.metastore.client.capability.check": "false",+ "metastore.uris": "thrift://127.0.0.1:9083"+ },+ "audit": {+ "creator": "gravitino",+ "createTime": "2023-12-08T03:41:25.595Z"+ }+ },+ {+ "name": "my_hadoop_catalog",+ "type": "fileset",+ "provider": "hadoop",+ "comment": "This is my hadoop catalog",+ "properties": {+ "key2": "value2"+ },+ "audit": {+ "creator": "gravitino",+ "createTime": "2023-12-08T06:41:25.595Z"+ }+ }+ ]+ }+CatalogCreate:value: {"name": "my_hive_catalog",diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.javaindex 670b6e8006..212d86c3ae 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.java@@ -91,6 +91,50 @@ public class CatalogIT extends AbstractIT {metalake.dropCatalog(catalogIdent);}+ @Test+ public void testListCatalogsInfo() {+ String relCatalogName = GravitinoITUtils.genRandomName("rel_catalog_");+ NameIdentifier relCatalogIdent = NameIdentifier.of(metalakeName, relCatalogName);+ Map<String, String> properties = Maps.newHashMap();+ properties.put("metastore.uris", hmsUri);+ Catalog relCatalog =+ metalake.createCatalog(+ relCatalogIdent,+ Catalog.Type.RELATIONAL,+ "hive",+ "relational catalog comment",+ properties);++ String fileCatalogName = GravitinoITUtils.genRandomName("file_catalog_");+ NameIdentifier fileCatalogIdent = NameIdentifier.of(metalakeName, fileCatalogName);+ Catalog fileCatalog =+ metalake.createCatalog(+ fileCatalogIdent,+ Catalog.Type.FILESET,+ "hadoop",+ "file catalog comment",+ Collections.emptyMap());++ Catalog[] catalogs = metalake.listCatalogsInfo(relCatalogIdent.namespace());+ for (Catalog catalog : catalogs) {+ if (catalog.name().equals(relCatalogName)) {+ assertCatalogEquals(relCatalog, catalog);+ } else if (catalog.name().equals(fileCatalogName)) {+ assertCatalogEquals(fileCatalog, catalog);+ }+ }+ // TODO: uncomment this after fixing hidden properties+ // Assertions.assertTrue(ArrayUtils.contains(catalogs, relCatalog));+ // Assertions.assertTrue(ArrayUtils.contains(catalogs, fileCatalog));+ }++ private void assertCatalogEquals(Catalog catalog1, Catalog catalog2) {+ Assertions.assertEquals(catalog1.name(), catalog2.name());+ Assertions.assertEquals(catalog1.type(), catalog2.type());+ Assertions.assertEquals(catalog1.provider(), catalog2.provider());+ Assertions.assertEquals(catalog1.comment(), catalog2.comment());+ }+@Test@DisabledIfSystemProperty(named = "testMode", matches = "embedded")public void testCreateCatalogWithPackage() {diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.javaindex db6cd4e7c4..8795192bc9 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java@@ -12,6 +12,7 @@ import com.datastrato.gravitino.catalog.CatalogManager;import com.datastrato.gravitino.dto.requests.CatalogCreateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdatesRequest;+import com.datastrato.gravitino.dto.responses.CatalogListResponse;import com.datastrato.gravitino.dto.responses.CatalogResponse;import com.datastrato.gravitino.dto.responses.DropResponse;import com.datastrato.gravitino.dto.responses.EntityListResponse;@@ -23,12 +24,14 @@ import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;import javax.ws.rs.Consumes;import javax.ws.rs.DELETE;+import javax.ws.rs.DefaultValue;import javax.ws.rs.GET;import javax.ws.rs.POST;import javax.ws.rs.PUT;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.Produces;+import javax.ws.rs.QueryParam;import javax.ws.rs.core.Context;import javax.ws.rs.core.MediaType;import javax.ws.rs.core.Response;@@ -53,19 +56,27 @@ public class CatalogOperations {@GET@Produces("application/vnd.gravitino.v1+json")- public Response listCatalogs(@PathParam("metalake") String metalake) {+ public Response listCatalogs(+ @PathParam("metalake") String metalake,+ @QueryParam("details") @DefaultValue("false") boolean verbose) {try {return Utils.doAs(httpRequest,() -> {Namespace catalogNS = Namespace.ofCatalog(metalake);// Lock the root and the metalake with WRITE lock to ensure the consistency of the list.- NameIdentifier[] idents =- TreeLockUtils.doWithTreeLock(- NameIdentifier.of(metalake),- LockType.WRITE,- () -> manager.listCatalogs(catalogNS));- return Utils.ok(new EntityListResponse(idents));+ return TreeLockUtils.doWithTreeLock(+ NameIdentifier.of(metalake),+ LockType.WRITE,+ () -> {+ if (verbose) {+ Catalog[] catalogs = manager.listCatalogsInfo(catalogNS);+ return Utils.ok(new CatalogListResponse(DTOConverters.toDTOs(catalogs)));+ } else {+ NameIdentifier[] idents = manager.listCatalogs(catalogNS);+ return Utils.ok(new EntityListResponse(idents));+ }+ });});} catch (Exception e) {return ExceptionHandlers.handleCatalogException(OperationType.LIST, "", metalake, e);diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.javaindex 541bc8ded5..009b824e8a 100644--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.java+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalogOperations.java@@ -22,6 +22,7 @@ import com.datastrato.gravitino.dto.CatalogDTO;import com.datastrato.gravitino.dto.requests.CatalogCreateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdateRequest;import com.datastrato.gravitino.dto.requests.CatalogUpdatesRequest;+import com.datastrato.gravitino.dto.responses.CatalogListResponse;import com.datastrato.gravitino.dto.responses.CatalogResponse;import com.datastrato.gravitino.dto.responses.DropResponse;import com.datastrato.gravitino.dto.responses.EntityListResponse;@@ -137,6 +138,57 @@ public class TestCatalogOperations extends JerseyTest {Assertions.assertEquals(NoSuchMetalakeException.class.getSimpleName(), errorResponse.getType());}+ @Test+ public void testListCatalogsInfo() {+ TestCatalog catalog1 = buildCatalog("metalake1", "catalog1");+ TestCatalog catalog2 = buildCatalog("metalake1", "catalog2");++ when(manager.listCatalogsInfo(any())).thenReturn(new Catalog[] {catalog1, catalog2});++ Response resp =+ target("/metalakes/metalake1/catalogs")+ .queryParam("details", "true")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());+ Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType());++ CatalogListResponse catalogResponse = resp.readEntity(CatalogListResponse.class);+ Assertions.assertEquals(0, catalogResponse.getCode());++ CatalogDTO[] catalogDTOs = catalogResponse.getCatalogs();+ Assertions.assertEquals(2, catalogDTOs.length);++ CatalogDTO catalogDTO1 = catalogDTOs[0];+ Assertions.assertEquals("catalog1", catalogDTO1.name());+ Assertions.assertEquals(Catalog.Type.RELATIONAL, catalogDTO1.type());+ Assertions.assertEquals("comment", catalogDTO1.comment());+ Assertions.assertEquals(ImmutableMap.of("key", "value"), catalogDTO1.properties());++ CatalogDTO catalogDTO2 = catalogDTOs[1];+ Assertions.assertEquals("catalog2", catalogDTO2.name());+ Assertions.assertEquals(Catalog.Type.RELATIONAL, catalogDTO2.type());+ Assertions.assertEquals("comment", catalogDTO2.comment());+ Assertions.assertEquals(ImmutableMap.of("key", "value"), catalogDTO2.properties());++ doThrow(new NoSuchMetalakeException("mock error")).when(manager).listCatalogsInfo(any());+ Response resp1 =+ target("/metalakes/metalake1/catalogs")+ .queryParam("details", "true")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ 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());+ }+@Testpublic void testCreateCatalog() {CatalogCreateRequest req =