Skip to content

Commit a6afb07

Browse files
authored
[#2479] refactor: separate API for client using: SupportsMetalakes and SupportsCatalogs (#3390)
### What changes were proposed in this pull request? Today Gravitino java client and server sides share the same interfaces, like SupportsMetalakes, SupportsCatalogs, SupportsSchemas, etc. These interfaces are good for server side, but not good for client side. After some discussion with Jerry and others, if we want to make it easier to use, and still keep server side code stable, the only way is to separate the APIs: create individual APIs for the java client. This PR will introduce the simplified API for client: SupportsMetalakes and SupportsCatalogs (in the package com.datastrato.gravitino.client.api). Their method signatures have been changed, so the client code will be clear. The integration tests which uses Java client to manipulate metadata also be updated. (If we don't want to use the same classname, I can refactor them later in a batch) ### Why are the changes needed? To make the client API simple and easy to use. Fix: #2479 ### Does this PR introduce _any_ user-facing change? Will change the Java client API, mainly on the method signatures; for example, "listCatalogs()" won't need an input parameter, "loadCatalog()" will use a String value as the input parameter instead of a NameIdentifier object, etc. ### How was this patch tested? All existing integration test will cover the API change.
1 parent aa00b60 commit a6afb07

File tree

43 files changed

+606
-539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+606
-539
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2024 Datastrato Pvt Ltd.
3+
* This software is licensed under the Apache License version 2.
4+
*/
5+
package com.datastrato.gravitino.rel;
6+
7+
import com.datastrato.gravitino.Catalog;
8+
import com.datastrato.gravitino.CatalogChange;
9+
import com.datastrato.gravitino.CatalogProvider;
10+
import com.datastrato.gravitino.NameIdentifier;
11+
import com.datastrato.gravitino.annotation.Evolving;
12+
import com.datastrato.gravitino.exceptions.CatalogAlreadyExistsException;
13+
import com.datastrato.gravitino.exceptions.NoSuchCatalogException;
14+
import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
15+
import java.util.Map;
16+
17+
/**
18+
* Client interface for supporting catalogs. It includes methods for listing, loading, creating,
19+
* altering and dropping catalogs.
20+
*/
21+
@Evolving
22+
public interface SupportsCatalogs {
23+
24+
/**
25+
* List all catalogs in the metalake.
26+
*
27+
* @return The list of catalog's name identifiers.
28+
* @throws NoSuchMetalakeException If the metalake with namespace does not exist.
29+
*/
30+
NameIdentifier[] listCatalogs() throws NoSuchMetalakeException;
31+
32+
/**
33+
* List all catalogs with their information in the metalake.
34+
*
35+
* @return The list of catalog's information.
36+
* @throws NoSuchMetalakeException If the metalake with namespace does not exist.
37+
*/
38+
Catalog[] listCatalogsInfo() throws NoSuchMetalakeException;
39+
40+
/**
41+
* Load a catalog by its identifier.
42+
*
43+
* @param catalogName the identifier of the catalog.
44+
* @return The catalog.
45+
* @throws NoSuchCatalogException If the catalog does not exist.
46+
*/
47+
Catalog loadCatalog(String catalogName) throws NoSuchCatalogException;
48+
49+
/**
50+
* Check if a catalog exists.
51+
*
52+
* @param catalogName The identifier of the catalog.
53+
* @return True if the catalog exists, false otherwise.
54+
*/
55+
default boolean catalogExists(String catalogName) {
56+
try {
57+
loadCatalog(catalogName);
58+
return true;
59+
} catch (NoSuchCatalogException e) {
60+
return false;
61+
}
62+
}
63+
64+
/**
65+
* Create a catalog with specified identifier.
66+
*
67+
* <p>The parameter "provider" is a short name of the catalog, used to tell Gravitino which
68+
* catalog should be created. The short name should be the same as the {@link CatalogProvider}
69+
* interface provided.
70+
*
71+
* @param catalogName the name of the catalog.
72+
* @param type the type of the catalog.
73+
* @param provider the provider of the catalog.
74+
* @param comment the comment of the catalog.
75+
* @param properties the properties of the catalog.
76+
* @return The created catalog.
77+
* @throws NoSuchMetalakeException If the metalake does not exist.
78+
* @throws CatalogAlreadyExistsException If the catalog already exists.
79+
*/
80+
Catalog createCatalog(
81+
String catalogName,
82+
Catalog.Type type,
83+
String provider,
84+
String comment,
85+
Map<String, String> properties)
86+
throws NoSuchMetalakeException, CatalogAlreadyExistsException;
87+
88+
/**
89+
* Alter a catalog with specified identifier.
90+
*
91+
* @param catalogName the identifier of the catalog.
92+
* @param changes the changes to apply to the catalog.
93+
* @return The altered catalog.
94+
* @throws NoSuchCatalogException If the catalog does not exist.
95+
* @throws IllegalArgumentException If the changes cannot be applied to the catalog.
96+
*/
97+
Catalog alterCatalog(String catalogName, CatalogChange... changes)
98+
throws NoSuchCatalogException, IllegalArgumentException;
99+
100+
/**
101+
* Drop a catalog with specified identifier.
102+
*
103+
* @param catalogName the name of the catalog.
104+
* @return True if the catalog was dropped, false otherwise.
105+
*/
106+
boolean dropCatalog(String catalogName);
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2024 Datastrato Pvt Ltd.
3+
* This software is licensed under the Apache License version 2.
4+
*/
5+
package com.datastrato.gravitino.rel;
6+
7+
import com.datastrato.gravitino.Metalake;
8+
import com.datastrato.gravitino.MetalakeChange;
9+
import com.datastrato.gravitino.annotation.Evolving;
10+
import com.datastrato.gravitino.exceptions.MetalakeAlreadyExistsException;
11+
import com.datastrato.gravitino.exceptions.NoSuchMetalakeException;
12+
import java.util.Map;
13+
14+
/**
15+
* Client interface for supporting metalakes. It includes methods for listing, loading, creating,
16+
* altering and dropping metalakes.
17+
*/
18+
@Evolving
19+
public interface SupportsMetalakes {
20+
21+
/**
22+
* List all metalakes.
23+
*
24+
* @return The list of metalakes.
25+
*/
26+
Metalake[] listMetalakes();
27+
28+
/**
29+
* Load a metalake by its identifier.
30+
*
31+
* @param name the name of the metalake.
32+
* @return The metalake.
33+
* @throws NoSuchMetalakeException If the metalake does not exist.
34+
*/
35+
Metalake loadMetalake(String name) throws NoSuchMetalakeException;
36+
37+
/**
38+
* Check if a metalake exists.
39+
*
40+
* @param name The name of the metalake.
41+
* @return True if the metalake exists, false otherwise.
42+
*/
43+
default boolean metalakeExists(String name) {
44+
try {
45+
loadMetalake(name);
46+
return true;
47+
} catch (NoSuchMetalakeException e) {
48+
return false;
49+
}
50+
}
51+
52+
/**
53+
* Create a metalake with specified identifier.
54+
*
55+
* @param name The name of the metalake.
56+
* @param comment The comment of the metalake.
57+
* @param properties The properties of the metalake.
58+
* @return The created metalake.
59+
* @throws MetalakeAlreadyExistsException If the metalake already exists.
60+
*/
61+
Metalake createMetalake(String name, String comment, Map<String, String> properties)
62+
throws MetalakeAlreadyExistsException;
63+
64+
/**
65+
* Alter a metalake with specified identifier.
66+
*
67+
* @param name The name of the metalake.
68+
* @param changes The changes to apply.
69+
* @return The altered metalake.
70+
* @throws NoSuchMetalakeException If the metalake does not exist.
71+
* @throws IllegalArgumentException If the changes cannot be applied to the metalake.
72+
*/
73+
Metalake alterMetalake(String name, MetalakeChange... changes)
74+
throws NoSuchMetalakeException, IllegalArgumentException;
75+
76+
/**
77+
* Drop a metalake with specified identifier.
78+
*
79+
* @param name The identifier of the metalake.
80+
* @return True if the metalake was dropped, false otherwise.
81+
*/
82+
boolean dropMetalake(String name);
83+
}

catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java

+8-18
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void setup() throws IOException {
6767

6868
@AfterAll
6969
public static void stop() throws IOException {
70-
client.dropMetalake(NameIdentifier.of(metalakeName));
70+
client.dropMetalake(metalakeName);
7171

7272
if (hdfs != null) {
7373
hdfs.close();
@@ -85,22 +85,18 @@ private static void createMetalake() {
8585
Assertions.assertEquals(0, gravitinoMetalakes.length);
8686

8787
GravitinoMetalake createdMetalake =
88-
client.createMetalake(NameIdentifier.of(metalakeName), "comment", Collections.emptyMap());
89-
GravitinoMetalake loadMetalake = client.loadMetalake(NameIdentifier.of(metalakeName));
88+
client.createMetalake(metalakeName, "comment", Collections.emptyMap());
89+
GravitinoMetalake loadMetalake = client.loadMetalake(metalakeName);
9090
Assertions.assertEquals(createdMetalake, loadMetalake);
9191

9292
metalake = loadMetalake;
9393
}
9494

9595
private static void createCatalog() {
9696
metalake.createCatalog(
97-
NameIdentifier.of(metalakeName, catalogName),
98-
Catalog.Type.FILESET,
99-
provider,
100-
"comment",
101-
ImmutableMap.of());
97+
catalogName, Catalog.Type.FILESET, provider, "comment", ImmutableMap.of());
10298

103-
catalog = metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName));
99+
catalog = metalake.loadCatalog(catalogName);
104100
}
105101

106102
private static void createSchema() {
@@ -547,11 +543,7 @@ public void testDropCatalogWithEmptySchema() {
547543
// Create a catalog without specifying location.
548544
Catalog filesetCatalog =
549545
metalake.createCatalog(
550-
NameIdentifier.of(metalakeName, catalogName),
551-
Catalog.Type.FILESET,
552-
provider,
553-
"comment",
554-
ImmutableMap.of());
546+
catalogName, Catalog.Type.FILESET, provider, "comment", ImmutableMap.of());
555547

556548
// Create a schema without specifying location.
557549
String schemaName =
@@ -574,11 +566,9 @@ public void testDropCatalogWithEmptySchema() {
574566
"schema should not be exists");
575567

576568
// Drop the catalog.
577-
dropped = metalake.dropCatalog(NameIdentifier.of(metalakeName, catalogName));
569+
dropped = metalake.dropCatalog(catalogName);
578570
Assertions.assertTrue(dropped, "catalog should be dropped");
579-
Assertions.assertFalse(
580-
metalake.catalogExists(NameIdentifier.of(metalakeName, catalogName)),
581-
"catalog should not be exists");
571+
Assertions.assertFalse(metalake.catalogExists(catalogName), "catalog should not be exists");
582572
}
583573

584574
private Fileset createFileset(

0 commit comments

Comments
 (0)