Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5059] Add commands to create, delete and modify metalakes, catalogs and schema in CLI. #5117

Merged
merged 85 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
b5e08c0
Added firest part of CLI code.
justinmclean Oct 2, 2024
655d133
update CLI option with output
justinmclean Oct 2, 2024
4a29c8b
Add missing license header
justinmclean Oct 2, 2024
1b12eff
Add default
justinmclean Oct 2, 2024
75de71e
Spotless on Java 11
justinmclean Oct 2, 2024
5172afa
Ignore warnings in test with Java 11
justinmclean Oct 2, 2024
0dc8856
Disable two tests on JAVA 17
justinmclean Oct 2, 2024
24dee9e
disabling two tests for now
justinmclean Oct 2, 2024
0ddbb7d
fix disabled tests
justinmclean Oct 2, 2024
4b95dd3
Still having issues on Java 17
justinmclean Oct 2, 2024
f76fa16
remove two tests as Java 17 is still giving issues
justinmclean Oct 2, 2024
8cbc605
No need to copy CLI for IT tests
justinmclean Oct 2, 2024
0ec7ecb
create catalogs and other entities
justinmclean Oct 9, 2024
fa2cdaf
remove unneeded call
justinmclean Oct 9, 2024
1e05853
Merge branch 'CLI' into CLI_II
justinmclean Oct 10, 2024
3df9f11
add more tests
justinmclean Oct 11, 2024
5e611be
add more tests
justinmclean Oct 11, 2024
68f7fa2
change version command into client and server version commands
justinmclean Oct 11, 2024
e2ebb7a
list entities and commands
justinmclean Oct 11, 2024
0e82c8f
Cache the metalake environment variable
justinmclean Oct 11, 2024
7b97750
use libs
justinmclean Oct 11, 2024
a562ed7
Merge branch 'main' into CLI
justinmclean Oct 11, 2024
47364fd
Merge branch 'CLI' into CLI_II
justinmclean Oct 12, 2024
d678b99
Trino Connector uses old deprecated CLI
justinmclean Oct 12, 2024
c201ef5
Merge branch 'CLI' into CLI_II
justinmclean Oct 12, 2024
253a2b4
fix test
justinmclean Oct 12, 2024
f90a086
fix spelling error
justinmclean Oct 16, 2024
3c87c3d
add examples not using metalake
justinmclean Oct 16, 2024
10af3d2
remove duplication and clarify
justinmclean Oct 16, 2024
f955db2
use client shadow jar
justinmclean Oct 16, 2024
80aef91
wrong file
justinmclean Oct 16, 2024
6d897c0
new -> 19
justinmclean Oct 17, 2024
76aa1fe
fix example command
justinmclean Oct 17, 2024
affd6ad
revert as the suggested name is not value
justinmclean Oct 17, 2024
abc2da8
simplify command options
justinmclean Oct 17, 2024
a7c2a88
Merge branch 'CLI' into CLI_II
justinmclean Oct 17, 2024
055678b
fix merge issue and tests
justinmclean Oct 17, 2024
9808022
update command options
justinmclean Oct 17, 2024
464a74b
fix imports
justinmclean Oct 17, 2024
05bc9ed
update command options
justinmclean Oct 17, 2024
423219c
Merge branch 'main' into CLI
justinmclean Oct 17, 2024
954b351
Make executable and runnable from bin directory. update command format.
justinmclean Oct 22, 2024
808fffc
revert back to using two args and fix command format
justinmclean Oct 22, 2024
848a381
remove meatlake form name and add back metalake option
justinmclean Oct 22, 2024
2fe9a80
add Gravitino URL as an environment variable
justinmclean Oct 22, 2024
526d305
update README to mention environment variables
justinmclean Oct 22, 2024
d2ded4c
improved description of met lake name and add to options docs
justinmclean Oct 22, 2024
cb5a5d7
remove version number from alias
justinmclean Oct 22, 2024
71107fd
order in alphabetical order
justinmclean Oct 22, 2024
a6aeb42
add final where needed
justinmclean Oct 22, 2024
ce3ddc1
made private
justinmclean Oct 22, 2024
70aaaf9
use Joiner instead of StringBuilder
justinmclean Oct 22, 2024
22ca191
update commands
justinmclean Oct 23, 2024
ab52cf2
improve command line error handling
justinmclean Oct 23, 2024
bd57944
add executable shell script
justinmclean Oct 23, 2024
445cd41
put back README and make it developer focused
justinmclean Oct 23, 2024
7ea7125
support ignore option to ignore client/server version mismatch
justinmclean Oct 23, 2024
0a8844e
move list commands up one entity
justinmclean Oct 23, 2024
c342d7e
add comment
justinmclean Oct 23, 2024
d2b28af
no need for class
justinmclean Oct 23, 2024
038e1f6
fix command error handling and unwanted output
justinmclean Oct 23, 2024
ce5fa18
remove example scripts
justinmclean Oct 23, 2024
069f425
add CLI documentation
justinmclean Oct 23, 2024
5ed49fa
Merge branch 'CLI' into CLI_II
justinmclean Oct 23, 2024
4d68055
update tests
justinmclean Oct 23, 2024
f8c1f9b
update commands to use ignore parameter
justinmclean Oct 23, 2024
33efd6e
made variables final
justinmclean Oct 23, 2024
82ba035
remove user-facing content
justinmclean Oct 23, 2024
a4ac180
add URL to config file
justinmclean Oct 24, 2024
1ea9e12
list commands need to run first or warning in output occurs
justinmclean Oct 24, 2024
c3fc55c
add javadocs
justinmclean Oct 24, 2024
4b60ea4
Merge branch 'main' into CLI_II
justinmclean Oct 24, 2024
20e550f
reset files
justinmclean Oct 24, 2024
eeefccc
restore test files
justinmclean Oct 24, 2024
9f073ac
add ignore to the config file
justinmclean Oct 24, 2024
64f18ef
update documentation
justinmclean Oct 24, 2024
74452c9
minor English updates
justinmclean Oct 25, 2024
d8c111f
add override annotation
justinmclean Oct 31, 2024
09a5d55
add expections
justinmclean Oct 31, 2024
3a64a1d
add @Override
justinmclean Oct 31, 2024
ccb5e01
update tests
justinmclean Oct 31, 2024
7ab5666
update documentation
justinmclean Oct 31, 2024
366de9e
Remove different catalog options and classes and add the ability to s…
justinmclean Nov 4, 2024
e133aff
update documentation
justinmclean Nov 4, 2024
81bf84b
Merge branch 'main' into CLI_II
justinmclean Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class CommandActions {
public static final String UPDATE = "update";
public static final String CREATE = "create";
public static final String DELETE = "delete";
public static final String SET = "set";
public static final String REMOVE = "remove";
public static final String PROPERTIES = "properties";

private static final HashSet<String> VALID_COMMANDS = new HashSet<>();

Expand All @@ -40,6 +43,9 @@ public class CommandActions {
VALID_COMMANDS.add(UPDATE);
VALID_COMMANDS.add(CREATE);
VALID_COMMANDS.add(DELETE);
VALID_COMMANDS.add(SET);
VALID_COMMANDS.add(REMOVE);
VALID_COMMANDS.add(PROPERTIES);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
public class ErrorMessages {
public static final String UNSUPPORTED_COMMAND = "Unsupported or unknown command.";
public static final String UNKNOWN_ENTITY = "Unknown entity.";
public static final String TOO_MANY_ARGUMENTS = "Too many arguments.";
public static final String UNKNOWN_METALAKE = "Unknown metalake name.";
public static final String UNKNOWN_CATALOG = "Unknown catalog name.";
public static final String UNKNOWN_SCHEMA = "Unknown schema name.";
public static final String UNKNOWN_TABLE = "Unknown table name.";
public static final String MALFORMED_NAME = "Malformed entity name.";
public static final String MISSING_NAME = "Missing name.";
public static final String METALAKE_EXISTS = "Metalake already exists.";
public static final String CATALOG_EXISTS = "Catalog already exists.";
public static final String SCHEMA_EXISTS = "Schema already exists.";
}
16 changes: 15 additions & 1 deletion clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public FullName(CommandLine line) {

/**
* Retrieves the metalake name from the command line options, the GRAVITINO_METALAKE environment
* variable.
* variable or the Gravitino config file.
*
* @return The metalake name, or null if not found.
*/
public String getMetalakeName() {
GravitinoConfig config = new GravitinoConfig(null);

// If specified on the command line use that
if (line.hasOption(GravitinoOptions.METALAKE)) {
return line.getOptionValue(GravitinoOptions.METALAKE);
Expand All @@ -60,6 +62,18 @@ public String getMetalakeName() {
// Check if the metalake name is set as an environment variable
if (metalakeEnv != null) {
return metalakeEnv;
// Check if the metalake name is specified in the configuration file
} else if (config.fileExists()) {
config.read();
String configName = config.getMetalakeName();
if (configName != null) {
return configName;
}
}

// Extract the metalake name from the full name option
if (line.hasOption(GravitinoOptions.NAME)) {
return line.getOptionValue(GravitinoOptions.NAME).split("\\.")[0];
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,40 @@
import org.apache.commons.cli.Options;
import org.apache.gravitino.cli.commands.CatalogDetails;
import org.apache.gravitino.cli.commands.ClientVersion;
import org.apache.gravitino.cli.commands.CreateHadoopCatalog;
import org.apache.gravitino.cli.commands.CreateHiveCatalog;
import org.apache.gravitino.cli.commands.CreateIcebergCatalog;
import org.apache.gravitino.cli.commands.CreateKafkaCatalog;
import org.apache.gravitino.cli.commands.CreateMetalake;
import org.apache.gravitino.cli.commands.CreateMySQLCatalog;
import org.apache.gravitino.cli.commands.CreatePostgresCatalog;
import org.apache.gravitino.cli.commands.CreateSchema;
import org.apache.gravitino.cli.commands.DeleteCatalog;
import org.apache.gravitino.cli.commands.DeleteMetalake;
import org.apache.gravitino.cli.commands.DeleteSchema;
import org.apache.gravitino.cli.commands.DeleteTable;
import org.apache.gravitino.cli.commands.ListCatalogProperties;
import org.apache.gravitino.cli.commands.ListCatalogs;
import org.apache.gravitino.cli.commands.ListColumns;
import org.apache.gravitino.cli.commands.ListMetalakeProperties;
import org.apache.gravitino.cli.commands.ListMetalakes;
import org.apache.gravitino.cli.commands.ListSchema;
import org.apache.gravitino.cli.commands.ListSchemaProperties;
import org.apache.gravitino.cli.commands.ListTables;
import org.apache.gravitino.cli.commands.MetalakeDetails;
import org.apache.gravitino.cli.commands.RemoveCatalogProperty;
import org.apache.gravitino.cli.commands.RemoveMetalakeProperty;
import org.apache.gravitino.cli.commands.RemoveSchemaProperty;
import org.apache.gravitino.cli.commands.SchemaDetails;
import org.apache.gravitino.cli.commands.ServerVersion;
import org.apache.gravitino.cli.commands.SetCatalogProperty;
import org.apache.gravitino.cli.commands.SetMetalakeProperty;
import org.apache.gravitino.cli.commands.SetSchemaProperty;
import org.apache.gravitino.cli.commands.TableDetails;
import org.apache.gravitino.cli.commands.UpdateCatalogComment;
import org.apache.gravitino.cli.commands.UpdateCatalogName;
import org.apache.gravitino.cli.commands.UpdateMetalakeComment;
import org.apache.gravitino.cli.commands.UpdateMetalakeName;

/* Gravitino Command line */
public class GravitinoCommandLine {
Expand All @@ -44,6 +69,8 @@ public class GravitinoCommandLine {
private String urlEnv;
private boolean urlSet = false;
private boolean ignore = false;
private String ignoreEnv;
private boolean ignoreSet = false;

public static final String CMD = "gcli"; // recommended name
public static final String DEFAULT_URL = "http://localhost:8090";
Expand All @@ -65,9 +92,26 @@ public GravitinoCommandLine(CommandLine line, Options options, String entity, St

/** Handles the parsed command line arguments and executes the corresponding actions. */
public void handleCommandLine() {
GravitinoConfig config = new GravitinoConfig(null);

/* Check if you should ignore client/version versions */
if (line.hasOption(GravitinoOptions.IGNORE)) {
ignore = true;
} else {
// Cache the ignore environment variable
if (ignoreEnv == null && !ignoreSet) {
ignoreEnv = System.getenv("GRAVITINO_IGNORE");
ignore = ignoreEnv != null && ignoreEnv.equals("true");
ignoreSet = true;
}

// Check if the ignore name is specified in the configuration file
if (ignoreEnv == null) {
if (config.fileExists()) {
config.read();
ignore = config.getIgnore();
}
}
}

executeCommand();
Expand Down Expand Up @@ -126,6 +170,29 @@ private void handleMetalakeCommand() {
new MetalakeDetails(url, ignore, metalake).handle();
} else if (CommandActions.LIST.equals(command)) {
new ListMetalakes(url, ignore).handle();
} else if (CommandActions.CREATE.equals(command)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
new CreateMetalake(url, ignore, metalake, comment).handle();
} else if (CommandActions.DELETE.equals(command)) {
new DeleteMetalake(url, ignore, metalake).handle();
} else if (CommandActions.SET.equals(command)) {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
new SetMetalakeProperty(url, ignore, metalake, property, value).handle();
} else if (CommandActions.REMOVE.equals(command)) {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
new RemoveMetalakeProperty(url, ignore, metalake, property).handle();
} else if (CommandActions.PROPERTIES.equals(command)) {
new ListMetalakeProperties(url, ignore, metalake).handle();
} else if (CommandActions.UPDATE.equals(command)) {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
new UpdateMetalakeComment(url, ignore, metalake, comment).handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
new UpdateMetalakeName(url, ignore, metalake, newName).handle();
}
}
}

Expand All @@ -137,11 +204,71 @@ private void handleCatalogCommand() {
FullName name = new FullName(line);
String metalake = name.getMetalakeName();

if (CommandActions.LIST.equals(command)) {
new ListCatalogs(url, ignore, metalake).handle();
return;
}

String catalog = name.getCatalogName();

if (CommandActions.DETAILS.equals(command)) {
String catalog = name.getCatalogName();
new CatalogDetails(url, ignore, metalake, catalog).handle();
} else if (CommandActions.LIST.equals(command)) {
new ListCatalogs(url, ignore, metalake).handle();
} else if (CommandActions.CREATE.equals(command)) {
String provider = line.getOptionValue(GravitinoOptions.PROVIDER);
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
if (provider.equals(Providers.HIVE)) {
String metastore = line.getOptionValue(GravitinoOptions.METASTORE);
new CreateHiveCatalog(url, ignore, metalake, catalog, provider, comment, metastore)
.handle();
} else if (provider.equals(Providers.ICEBERG)) {
String metastore = line.getOptionValue(GravitinoOptions.METASTORE);
String warehouse = line.getOptionValue(GravitinoOptions.WAREHOUSE);
new CreateIcebergCatalog(
url, ignore, metalake, catalog, provider, comment, metastore, warehouse)
.handle();
} else if (provider.equals(Providers.MYSQL)) {
String jdbcurl = line.getOptionValue(GravitinoOptions.JDBCURL);
String user = line.getOptionValue(GravitinoOptions.USER);
String password = line.getOptionValue(GravitinoOptions.PASSWORD);
new CreateMySQLCatalog(
url, ignore, metalake, catalog, provider, comment, jdbcurl, user, password)
.handle();
} else if (provider.equals(Providers.POSTGRES)) {
String jdbcurl = line.getOptionValue(GravitinoOptions.JDBCURL);
String user = line.getOptionValue(GravitinoOptions.USER);
String password = line.getOptionValue(GravitinoOptions.PASSWORD);
String database = line.getOptionValue(GravitinoOptions.DATABASE);
new CreatePostgresCatalog(
url, ignore, metalake, catalog, provider, comment, jdbcurl, user, password,
database)
.handle();
} else if (provider.equals(Providers.HADOOP)) {
new CreateHadoopCatalog(url, ignore, metalake, catalog, provider, comment).handle();
} else if (provider.equals(Providers.KAFKA)) {
String bootstrap = line.getOptionValue(GravitinoOptions.BOOTSTRAP);
new CreateKafkaCatalog(url, ignore, metalake, catalog, provider, comment, bootstrap)
.handle();
}
} else if (CommandActions.DELETE.equals(command)) {
new DeleteCatalog(url, ignore, metalake, catalog).handle();
} else if (CommandActions.SET.equals(command)) {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
new SetCatalogProperty(url, ignore, metalake, catalog, property, value).handle();
} else if (CommandActions.REMOVE.equals(command)) {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
new RemoveCatalogProperty(url, ignore, metalake, catalog, property).handle();
} else if (CommandActions.PROPERTIES.equals(command)) {
new ListCatalogProperties(url, ignore, metalake, catalog).handle();
} else if (CommandActions.UPDATE.equals(command)) {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
new UpdateCatalogComment(url, ignore, metalake, catalog, comment).handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
new UpdateCatalogName(url, ignore, metalake, catalog, newName).handle();
}
}
}

Expand All @@ -154,11 +281,29 @@ private void handleSchemaCommand() {
String metalake = name.getMetalakeName();
String catalog = name.getCatalogName();

if (CommandActions.LIST.equals(command)) {
new ListSchema(url, ignore, metalake, catalog).handle();
return;
}

String schema = name.getSchemaName();

if (CommandActions.DETAILS.equals(command)) {
String schema = name.getSchemaName();
new SchemaDetails(url, ignore, metalake, catalog, schema).handle();
} else if (CommandActions.LIST.equals(command)) {
new ListSchema(url, ignore, metalake, catalog).handle();
} else if (CommandActions.CREATE.equals(command)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
new CreateSchema(url, ignore, metalake, catalog, schema, comment).handle();
} else if (CommandActions.DELETE.equals(command)) {
new DeleteSchema(url, ignore, metalake, catalog, schema).handle();
} else if (CommandActions.SET.equals(command)) {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
new SetSchemaProperty(url, ignore, metalake, catalog, schema, property, value).handle();
} else if (CommandActions.REMOVE.equals(command)) {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
new RemoveSchemaProperty(url, ignore, metalake, catalog, schema, property).handle();
} else if (CommandActions.PROPERTIES.equals(command)) {
new ListSchemaProperties(url, ignore, metalake, catalog, schema).handle();
}
}

Expand All @@ -172,11 +317,19 @@ private void handleTableCommand() {
String catalog = name.getCatalogName();
String schema = name.getSchemaName();

if (CommandActions.LIST.equals(command)) {
new ListTables(url, ignore, metalake, catalog, schema).handle();
return;
}

String table = name.getTableName();

if (CommandActions.DETAILS.equals(command)) {
String table = name.getTableName();
new TableDetails(url, ignore, metalake, catalog, schema, table).handle();
} else if (CommandActions.LIST.equals(command)) {
new ListTables(url, ignore, metalake, catalog, schema).handle();
} else if (CommandActions.CREATE.equals(command)) {
// TODO
} else if (CommandActions.DELETE.equals(command)) {
new DeleteTable(url, ignore, metalake, catalog, schema, table).handle();
}
}

Expand All @@ -189,20 +342,22 @@ private void handleColumnCommand() {
String metalake = name.getMetalakeName();
String catalog = name.getCatalogName();
String schema = name.getSchemaName();
String table = name.getTableName();

if (CommandActions.LIST.equals(command)) {
String table = name.getTableName();
new ListColumns(url, ignore, metalake, catalog, schema, table).handle();
}
}

/**
* Retrieves the Gravitinno URL from the command line options or the GRAVITINO_URL environment
* variable.
* variable or the Gravitio config file.
*
* @return The Gravitinno URL, or null if not found.
*/
public String getUrl() {
GravitinoConfig config = new GravitinoConfig(null);

// If specified on the command line use that
if (line.hasOption(GravitinoOptions.URL)) {
return line.getOptionValue(GravitinoOptions.URL);
Expand All @@ -219,6 +374,15 @@ public String getUrl() {
return urlEnv;
}

// Check if the metalake name is specified in the configuration file
if (config.fileExists()) {
config.read();
String configURL = config.getGravitinoURL();
if (configURL != null) {
return configURL;
}
}

// Return the default localhost URL
return DEFAULT_URL;
}
Expand Down
Loading
Loading