diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java index 1077f437c9..48b9bc2382 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java @@ -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 VALID_COMMANDS = new HashSet<>(); @@ -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); } /** diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java index 66e6793046..12d869c429 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java @@ -31,6 +31,9 @@ public class CommandEntities { public static final String SCHEMA = "schema"; public static final String TABLE = "table"; public static final String COLUMN = "column"; + public static final String USER = "user"; + public static final String GROUP = "group"; + public static final String TAG = "tag"; private static final HashSet VALID_ENTITIES = new HashSet<>(); @@ -40,6 +43,9 @@ public class CommandEntities { VALID_ENTITIES.add(SCHEMA); VALID_ENTITIES.add(TABLE); VALID_ENTITIES.add(COLUMN); + VALID_ENTITIES.add(USER); + VALID_ENTITIES.add(GROUP); + VALID_ENTITIES.add(TAG); } /** diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java index 847b96516c..6a6d4e5bbe 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java @@ -23,10 +23,20 @@ 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."; + public static final String UNKNOWN_USER = "Unknown user."; + public static final String USER_EXISTS = "User already exists."; + public static final String UNKNOWN_GROUP = "Unknown group."; + public static final String GROUP_EXISTS = "Group already exists."; + public static final String UNKNOWN_TAG = "Unknown tag."; + public static final String TAG_EXISTS = "Tag already exists."; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java index 32df42f48c..168feb7a1a 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java @@ -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); @@ -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; @@ -115,4 +129,59 @@ public String getNamePart(int position) { System.err.println(ErrorMessages.MISSING_NAME); return null; } + + /** + * Helper method to determine a specific part of the full name exits. + * + * @param partNo The part of the name to obtain. + * @return True if the part exitsts. + */ + public boolean hasNamePart(int partNo) { + /* Extract the name part from the full name if available. */ + if (line.hasOption(GravitinoOptions.NAME)) { + String[] names = line.getOptionValue(GravitinoOptions.NAME).split("\\."); + int length = names.length; + int position = partNo; + + return position <= length; + } + + return false; + } + + /** + * Does the metalake name exist? + * + * @return True if the catalog name exists, or false if it does not. + */ + public boolean hasMetalakeName() { + return hasNamePart(1); + } + + /** + * Does the catalog name exist? + * + * @return True if the catalog name exists, or false if it does not. + */ + public boolean hasCatalogName() { + return hasNamePart(2); + } + + /** + * Does the schema name exist? + * + * @return True if the schema name exists, or false if it does not. + */ + public boolean hasSchemaName() { + return hasNamePart(3); + } + + /** + * Does the table name exist? + * + * @return True if the table name exists, or false if it does not. + */ + public boolean hasTableName() { + return hasNamePart(4); + } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java index e60c7662dc..2beec34b52 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java @@ -24,15 +24,60 @@ 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.CreateGroup; +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.CreateTag; +import org.apache.gravitino.cli.commands.CreateUser; +import org.apache.gravitino.cli.commands.DeleteCatalog; +import org.apache.gravitino.cli.commands.DeleteGroup; +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.DeleteTag; +import org.apache.gravitino.cli.commands.DeleteUser; +import org.apache.gravitino.cli.commands.GroupDetails; +import org.apache.gravitino.cli.commands.ListAllTags; +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.ListEntityTags; +import org.apache.gravitino.cli.commands.ListGroups; +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.ListTagProperties; +import org.apache.gravitino.cli.commands.ListUsers; 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.RemoveTagProperty; 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.SetTagProperty; import org.apache.gravitino.cli.commands.TableDetails; +import org.apache.gravitino.cli.commands.TagDetails; +import org.apache.gravitino.cli.commands.TagEntity; +import org.apache.gravitino.cli.commands.UntagEntity; +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; +import org.apache.gravitino.cli.commands.UpdateTagComment; +import org.apache.gravitino.cli.commands.UpdateTagName; +import org.apache.gravitino.cli.commands.UserDetails; /* Gravitino Command line */ public class GravitinoCommandLine { @@ -44,6 +89,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"; @@ -65,9 +112,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(); @@ -126,6 +190,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(); + } } } @@ -137,11 +224,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(); + } } } @@ -154,11 +301,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(); } } @@ -172,11 +337,104 @@ 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.CREATE.equals(command)) { + // TODO + } else if (CommandActions.DELETE.equals(command)) { + new DeleteTable(url, ignore, metalake, catalog, schema, table).handle(); + } + } + + /** Handles the command execution for Users based on command type and the command line options. */ + protected void handleUserCommand() { + String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + String user = line.getOptionValue(GravitinoOptions.USER); + + if (CommandActions.DETAILS.equals(command)) { + new UserDetails(url, ignore, metalake, user).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListTables(url, ignore, metalake, catalog, schema).handle(); + new ListUsers(url, ignore, metalake).handle(); + } else if (CommandActions.CREATE.equals(command)) { + new CreateUser(url, ignore, metalake, user).handle(); + } else if (CommandActions.DELETE.equals(command)) { + new DeleteUser(url, ignore, metalake, user).handle(); + } + } + + /** Handles the command execution for Group based on command type and the command line options. */ + protected void handleGroupCommand() { + String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + String group = line.getOptionValue(GravitinoOptions.GROUP); + + if (CommandActions.DETAILS.equals(command)) { + new GroupDetails(url, ignore, metalake, group).handle(); + } else if (CommandActions.LIST.equals(command)) { + new ListGroups(url, ignore, metalake).handle(); + } else if (CommandActions.CREATE.equals(command)) { + new CreateGroup(url, ignore, metalake, group).handle(); + } else if (CommandActions.DELETE.equals(command)) { + new DeleteGroup(url, ignore, metalake, group).handle(); + } + } + + /** Handles the command execution for Tags based on command type and the command line options. */ + protected void handleTagCommand() { + String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + String tag = line.getOptionValue(GravitinoOptions.TAG); + + if (CommandActions.DETAILS.equals(command)) { + new TagDetails(url, ignore, metalake, tag).handle(); + } else if (CommandActions.LIST.equals(command)) { + if (name.hasMetalakeName() && !name.hasCatalogName()) { + new ListAllTags(url, ignore, metalake).handle(); + } else { + new ListEntityTags(url, ignore, metalake, name).handle(); + } + } else if (CommandActions.CREATE.equals(command)) { + String comment = line.getOptionValue(GravitinoOptions.COMMENT); + new CreateTag(url, ignore, metalake, tag, comment).handle(); + } else if (CommandActions.DELETE.equals(command)) { + new DeleteTag(url, ignore, metalake, tag).handle(); + } else if (CommandActions.SET.equals(command)) { + String property = line.getOptionValue(GravitinoOptions.PROPERTY); + String value = line.getOptionValue(GravitinoOptions.VALUE); + if (property != null && value != null) { + new SetTagProperty(url, ignore, metalake, tag, property, value).handle(); + } else { + new TagEntity(url, ignore, metalake, name, tag).handle(); + } + } else if (CommandActions.REMOVE.equals(command)) { + String property = line.getOptionValue(GravitinoOptions.PROPERTY); + if (property != null) { + new RemoveTagProperty(url, ignore, metalake, tag, property).handle(); + } else { + new UntagEntity(url, ignore, metalake, name, tag).handle(); + } + } else if (CommandActions.PROPERTIES.equals(command)) { + new ListTagProperties(url, ignore, metalake, tag).handle(); + } else if (CommandActions.UPDATE.equals(command)) { + if (line.hasOption(GravitinoOptions.COMMENT)) { + String comment = line.getOptionValue(GravitinoOptions.COMMENT); + new UpdateTagComment(url, ignore, metalake, tag, comment).handle(); + } + if (line.hasOption(GravitinoOptions.RENAME)) { + String newName = line.getOptionValue(GravitinoOptions.RENAME); + new UpdateTagName(url, ignore, metalake, tag, newName).handle(); + } } } @@ -189,20 +447,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); @@ -219,6 +479,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; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoConfig.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoConfig.java new file mode 100644 index 0000000000..da837c21e5 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoConfig.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; + +/** + * GravitinoConfig is a configuration class used to read and manage Gravitino settings. It supports + * setting a configuration file, reading properties like 'metalake' and 'URL', and verifying if the + * config file exists. + */ +public class GravitinoConfig { + private static String defaultFile = ".gravitino"; + private final String configFile; + private String metalake; + private String url; + private boolean ignore; + + /** + * Creates a GravitinoConfig object with a specified config file. If no file is provided, it + * defaults to `.gravitino` the user's home directory. + * + * @param file The path to the config file or null to use the default. + */ + public GravitinoConfig(String file) { + if (file == null) { + configFile = System.getProperty("user.home") + "/" + defaultFile; + } else { + configFile = file; + } + } + + /** + * Checks if the configuration file exists. + * + * @return true if the config file exists, false otherwise. + */ + public boolean fileExists() { + File file = new File(configFile); + return file.exists(); + } + + /** + * Reads the configuration file and loads the 'metalake' and 'URL' properties. If the file is not + * found, it is ignored as the config file is optional. + */ + public void read() { + String metalakeKey = "metalake"; + String urlKey = "URL"; + String ignoreKey = "ignore"; + Properties prop = new Properties(); + + try (FileInputStream stream = new FileInputStream(configFile)) { + prop.load(stream); + } catch (FileNotFoundException ex) { + // ignore as config file is optional + return; + } catch (IOException exp) { + System.err.println(exp.getMessage()); + } + + if (prop.containsKey(metalakeKey)) { + metalake = prop.getProperty(metalakeKey); + } + if (prop.containsKey(urlKey)) { + url = prop.getProperty(urlKey); + } + if (prop.containsKey(ignoreKey)) { + ignore = prop.getProperty(ignoreKey).equals("true"); + } + } + + /** + * Retrieves the metalake name stored in the configuration. + * + * @return The metalake name or null if not set. + */ + public String getMetalakeName() { + return metalake; + } + + /** + * Retrieves the Gravitino URL stored in the configuration. + * + * @return The Gravitino URL or null if not set. + */ + public String getGravitinoURL() { + return url; + } + + /** + * Retrieves the ignore options stored in the configuration. + * + * @return The config file path. + */ + public boolean getIgnore() { + return ignore; + } + + /** + * Retrieves the path to the configuration file being used. + * + * @return The config file path. + */ + public String getConfigFile() { + return configFile; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java index 9f8d1579a8..eba0e06750 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java @@ -31,6 +31,21 @@ public class GravitinoOptions { public static final String NAME = "name"; public static final String METALAKE = "metalake"; public static final String IGNORE = "ignore"; + public static final String COMMENT = "comment"; + public static final String RENAME = "rename"; + public static final String PROPERTY = "property"; + public static final String VALUE = "value"; + public static final String PROPERTIES = "properties"; + public static final String PROVIDER = "provider"; + public static final String METASTORE = "metastore"; + public static final String WAREHOUSE = "warehouse"; + public static final String JDBCURL = "jdbcurl"; + public static final String USER = "user"; + public static final String PASSWORD = "password"; + public static final String DATABASE = "database"; + public static final String BOOTSTRAP = "bootstrap"; + public static final String GROUP = "group"; + public static final String TAG = "tag"; /** * Builds and returns the CLI options for Gravitino. @@ -45,10 +60,28 @@ public Options options() { options.addOption(createSimpleOption("v", VERSION, "Gravitino client version")); options.addOption(createSimpleOption("r", SERVER, "Gravitino server version")); options.addOption(createArgOption("u", URL, "Gravitino URL (default: http://localhost:8090)")); - options.addOption(createArgOption("f", NAME, "full entity name (dot separated)")); + options.addOption(createArgOption("n", NAME, "full entity name (dot separated)")); options.addOption(createArgOption("m", METALAKE, "Metalake name")); options.addOption(createSimpleOption("i", IGNORE, "Ignore client/sever version check")); + // Create/update options + options.addOption(createArgOption("r", RENAME, "new entity name")); + options.addOption(createArgOption("c", COMMENT, "entity comment")); + options.addOption(createArgOption("p", PROPERTY, "property name")); + options.addOption(createArgOption("v", VALUE, "property value")); + options.addOption( + createArgOption( + "p", PROVIDER, "the provider one of hadoop, hive, mysql, postgres, iceberg or kafka")); + options.addOption(createArgOption("m", METASTORE, "Hive metastore URI")); + options.addOption(createArgOption("w", WAREHOUSE, "warehouse name")); + options.addOption(createArgOption("b", BOOTSTRAP, "Kafka bootstrap servers")); + options.addOption(createArgOption("j", JDBCURL, "JDBC URL")); + options.addOption(createArgOption("l", USER, "database username")); + options.addOption(createArgOption("z", PASSWORD, "database password")); + options.addOption(createArgOption("d", DATABASE, "database name")); + options.addOption(createArgOption("g", GROUP, "group name")); + options.addOption(createArgOption("a", TAG, "tag name")); + return options; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java index 68db676c58..0d0eaddf75 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java @@ -35,6 +35,11 @@ public static void main(String[] args) { try { CommandLine line = parser.parse(options, args); String entity = resolveEntity(line); + String[] extra = line.getArgs(); + if (extra.length > 2) { + System.err.println(ErrorMessages.TOO_MANY_ARGUMENTS); + return; + } String command = resolveCommand(line); GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Providers.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Providers.java new file mode 100644 index 0000000000..a03861c39a --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Providers.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli; + +import java.util.HashSet; +import org.apache.gravitino.Catalog; + +/** + * The {@code CommandEntities} class defines a set of standard entities that can be used in the + * Gravitino CLI. It also can validate if a given entity is a valid entity. + */ +public class Providers { + public static final String HIVE = "hive"; + public static final String HADOOP = "hadoop"; + public static final String ICEBERG = "iceberg"; + public static final String MYSQL = "mysql"; + public static final String POSTGRES = "postgres"; + public static final String KAFKA = "kafka"; + + private static final HashSet VALID_PROVIDERS = new HashSet<>(); + + static { + VALID_PROVIDERS.add(HIVE); + VALID_PROVIDERS.add(HADOOP); + VALID_PROVIDERS.add(ICEBERG); + VALID_PROVIDERS.add(MYSQL); + VALID_PROVIDERS.add(POSTGRES); + VALID_PROVIDERS.add(KAFKA); + } + + /** + * Checks if a given provider is a valid provider. + * + * @param provider The provider to check. + * @return true if the provider is valid, false otherwise. + */ + public static boolean isValidProvider(String provider) { + return VALID_PROVIDERS.contains(provider); + } + + public static String internal(String provider) { + switch (provider) { + case HIVE: + return "hive"; + case HADOOP: + return "hadoop"; + case MYSQL: + return "jdbc-mysql"; + case POSTGRES: + return "jdbc-postgresql"; + case ICEBERG: + return "lakehouse-iceberg"; + case KAFKA: + return "kafka"; + } + + return null; + } + + public static Catalog.Type catalogType(String provider) { + switch (provider) { + case HADOOP: + return Catalog.Type.FILESET; + case HIVE: + case MYSQL: + case POSTGRES: + case ICEBERG: + return Catalog.Type.RELATIONAL; + case KAFKA: + return Catalog.Type.MESSAGING; + } + + return null; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateCatalog.java new file mode 100644 index 0000000000..972e50c1a5 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateCatalog.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.HashMap; +import java.util.Map; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.Providers; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.CatalogAlreadyExistsException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +public class CreateCatalog extends Command { + protected final String metalake; + protected final String catalog; + protected final String provider; + protected final String comment; + protected final Map properties; + + /** + * Create a new catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param provider The provider/type of catalog. + * @param comment The catalog's comment. + */ + public CreateCatalog( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String provider, + String comment) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.provider = provider; + this.comment = comment; + properties = new HashMap<>(); + } + + /** Create a new catalog. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + client.createCatalog( + catalog, + Providers.catalogType(provider), + Providers.internal(provider), + comment, + properties); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.METALAKE_EXISTS); + return; + } catch (CatalogAlreadyExistsException err) { + System.err.println(ErrorMessages.CATALOG_EXISTS); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(catalog + " created"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java new file mode 100644 index 0000000000..da65e295a4 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.GroupAlreadyExistsException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +public class CreateGroup extends Command { + protected final String metalake; + protected final String group; + + /** + * Create a new group. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param group The name of the group. + */ + public CreateGroup(String url, boolean ignoreVersions, String metalake, String group) { + super(url, ignoreVersions); + this.metalake = metalake; + this.group = group; + } + + /** Create a new group. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + client.addGroup(group); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (GroupAlreadyExistsException err) { + System.err.println(ErrorMessages.USER_EXISTS); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(group + " created"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateHadoopCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateHadoopCatalog.java new file mode 100644 index 0000000000..464cdc0887 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateHadoopCatalog.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +public class CreateHadoopCatalog extends CreateCatalog { + + /** + * Create a new Hadoop catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param provider The provider/type of catalog. + * @param comment The catalog's comment. + */ + public CreateHadoopCatalog( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String provider, + String comment) { + super(url, ignoreVersions, metalake, catalog, provider, comment); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateHiveCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateHiveCatalog.java new file mode 100644 index 0000000000..da75532da0 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateHiveCatalog.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +public class CreateHiveCatalog extends CreateCatalog { + + /** + * Create a new Hive catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param provider The provider/type of catalog. + * @param comment The catalog's comment. + * @param metastore The Hive metastore URL. + */ + public CreateHiveCatalog( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String provider, + String comment, + String metastore) { + super(url, ignoreVersions, metalake, catalog, provider, comment); + properties.put("metastore.uris", metastore); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateIcebergCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateIcebergCatalog.java new file mode 100644 index 0000000000..d608ffa3f3 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateIcebergCatalog.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +public class CreateIcebergCatalog extends CreateCatalog { + + /** + * Create a new Iceberg catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param provider The provider/type of catalog. + * @param comment The catalog's comment. + * @param metastore The Hive metastore URL. + * @param warehouse The Iceberg warehouse. + */ + public CreateIcebergCatalog( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String provider, + String comment, + String metastore, + String warehouse) { + super(url, ignoreVersions, metalake, catalog, provider, comment); + properties.put("uri", metastore); + properties.put("catalog-backend", "hive"); + properties.put("warehouse", warehouse); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateKafkaCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateKafkaCatalog.java new file mode 100644 index 0000000000..043ec3d11a --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateKafkaCatalog.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +public class CreateKafkaCatalog extends CreateCatalog { + + /** + * Create a new Kafka catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param provider The provider/type of catalog. + * @param comment The catalog's comment. + * @param bootstrap The Hive metastore URL. + */ + public CreateKafkaCatalog( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String provider, + String comment, + String bootstrap) { + super(url, ignoreVersions, metalake, catalog, provider, comment); + properties.put("bootstrap.servers", bootstrap); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java new file mode 100644 index 0000000000..cb46c91a81 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.exceptions.MetalakeAlreadyExistsException; + +public class CreateMetalake extends Command { + protected final String metalake; + protected final String comment; + + /** + * Create a new metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param comment The metalake's comment. + */ + public CreateMetalake(String url, boolean ignoreVersions, String metalake, String comment) { + super(url, ignoreVersions); + this.metalake = metalake; + this.comment = comment; + } + + /** Create a new metalake. */ + public void handle() { + try { + GravitinoAdminClient client = buildAdminClient(); + client.createMetalake(metalake, comment, null); + } catch (MetalakeAlreadyExistsException err) { + System.err.println(ErrorMessages.METALAKE_EXISTS); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(metalake + " created"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMySQLCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMySQLCatalog.java new file mode 100644 index 0000000000..a7e7af52c2 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMySQLCatalog.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +public class CreateMySQLCatalog extends CreateCatalog { + + /** + * Create a new MySQL catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param provider The provider/type of catalog. + * @param comment The catalog's comment. + * @param jdbcurl The MySQL JDBC URL. + * @param user The MySQL user. + * @param password The MySQL user's password. + */ + public CreateMySQLCatalog( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String provider, + String comment, + String jdbcurl, + String user, + String password) { + super(url, ignoreVersions, metalake, catalog, provider, comment); + properties.put("jdbc-url", jdbcurl); + properties.put("jdbc-user", user); + properties.put("jdbc-password", password); + properties.put("jdbc-driver", "com.mysql.cj.jdbc.Driver"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreatePostgresCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreatePostgresCatalog.java new file mode 100644 index 0000000000..3c79346379 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreatePostgresCatalog.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +public class CreatePostgresCatalog extends CreateCatalog { + + /** + * Create a new Postgres catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param provider The provider/type of catalog. + * @param comment The catalog's comment. + * @param jdbcurl The MySQL JDBC URL. + * @param user The Posgres user. + * @param password The Postgres user's password. + * @param database The Postgres database. + */ + public CreatePostgresCatalog( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String provider, + String comment, + String jdbcurl, + String user, + String password, + String database) { + super(url, ignoreVersions, metalake, catalog, provider, comment); + properties.put("jdbc-url", jdbcurl); + properties.put("jdbc-user", user); + properties.put("jdbc-password", password); + properties.put("jdbc-database", database); + properties.put("jdbc-driver", "org.postgresql.Driver"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateSchema.java new file mode 100644 index 0000000000..4a55e83ac0 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateSchema.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; + +public class CreateSchema extends Command { + protected final String metalake; + protected final String catalog; + protected final String schema; + protected final String comment; + + /** + * Create a new schema. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schema. + * @param comment The schema's comment. + */ + public CreateSchema( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String schema, + String comment) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.schema = schema; + this.comment = comment; + } + + /** Create a new schema. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + client.loadCatalog(catalog).asSchemas().createSchema(schema, comment, null); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (SchemaAlreadyExistsException err) { + System.err.println(ErrorMessages.SCHEMA_EXISTS); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(schema + " created"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java new file mode 100644 index 0000000000..7adc9cc257 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.TagAlreadyExistsException; + +public class CreateTag extends Command { + protected final String metalake; + protected final String tag; + protected final String comment; + + /** + * Create a new tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param tag The name of the tag. + * @param comment The comment of the tag. + */ + public CreateTag( + String url, boolean ignoreVersions, String metalake, String tag, String comment) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + this.comment = comment; + } + + /** Create a new tag. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + client.createTag(tag, comment, null); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (TagAlreadyExistsException err) { + System.err.println(ErrorMessages.TAG_EXISTS); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(tag + " created"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java new file mode 100644 index 0000000000..02c9d97515 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.UserAlreadyExistsException; + +public class CreateUser extends Command { + protected final String metalake; + protected final String user; + + /** + * Create a new User. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param user The name of the user. + */ + public CreateUser(String url, boolean ignoreVersions, String metalake, String user) { + super(url, ignoreVersions); + this.metalake = metalake; + this.user = user; + } + + /** Create a new user. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + client.addUser(user); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (UserAlreadyExistsException err) { + System.err.println(ErrorMessages.USER_EXISTS); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(user + " created"); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java new file mode 100644 index 0000000000..f70e916f53 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +public class DeleteCatalog extends Command { + + protected final String metalake; + protected final String catalog; + + /** + * Delete a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + */ + public DeleteCatalog(String url, boolean ignoreVersions, String metalake, String catalog) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + } + + /** Delete a catalog. */ + public void handle() { + boolean deleted = false; + + try { + GravitinoClient client = buildClient(metalake); + deleted = client.dropCatalog(catalog); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (deleted) { + System.out.println(catalog + " deleted."); + } else { + System.out.println(catalog + " not deleted."); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java new file mode 100644 index 0000000000..d025cd64cc --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchGroupException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +public class DeleteGroup extends Command { + + protected final String metalake; + protected final String group; + + /** + * Delete a group. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param group The name of the group. + */ + public DeleteGroup(String url, boolean ignoreVersions, String metalake, String group) { + super(url, ignoreVersions); + this.metalake = metalake; + this.group = group; + } + + /** Delete a group. */ + public void handle() { + boolean deleted = false; + + try { + GravitinoClient client = buildClient(metalake); + deleted = client.removeUser(group); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchGroupException err) { + System.err.println(ErrorMessages.UNKNOWN_GROUP); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (deleted) { + System.out.println(group + " deleted."); + } else { + System.out.println(group + " not deleted."); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java new file mode 100644 index 0000000000..d86f1acaa6 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +public class DeleteMetalake extends Command { + protected final String metalake; + + /** + * Delete a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + */ + public DeleteMetalake(String url, boolean ignoreVersions, String metalake) { + super(url, ignoreVersions); + this.metalake = metalake; + } + + /** Delete a metalake. */ + public void handle() { + boolean deleted = false; + try { + GravitinoAdminClient client = buildAdminClient(); + deleted = client.dropMetalake(metalake); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (deleted) { + System.out.println(metalake + " deleted."); + } else { + System.out.println(metalake + " not deleted."); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteSchema.java new file mode 100644 index 0000000000..461e25a40e --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteSchema.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; + +public class DeleteSchema extends Command { + + protected final String metalake; + protected final String catalog; + protected final String schema; + + /** + * Delete a schema. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schema. + */ + public DeleteSchema( + String url, boolean ignoreVersions, String metalake, String catalog, String schema) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.schema = schema; + } + + /** Delete a schema. */ + public void handle() { + boolean deleted = false; + + try { + GravitinoClient client = buildClient(metalake); + deleted = client.loadCatalog(catalog).asSchemas().dropSchema(schema, false); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (deleted) { + System.out.println(schema + " deleted."); + } else { + System.out.println(schema + " not deleted."); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java new file mode 100644 index 0000000000..fe485b329f --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; + +public class DeleteTable extends Command { + + protected final String metalake; + protected final String catalog; + protected final String schema; + protected final String table; + + /** + * Delete a table. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schema. + * @param table The name of the table. + */ + public DeleteTable( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String schema, + String table) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.schema = schema; + this.table = table; + } + + /** Delete a table. */ + public void handle() { + boolean deleted = false; + + try { + GravitinoClient client = buildClient(metalake); + NameIdentifier name = NameIdentifier.of(schema, table); + deleted = client.loadCatalog(catalog).asTableCatalog().dropTable(name); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (NoSuchTableException err) { + System.err.println(ErrorMessages.UNKNOWN_TABLE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (deleted) { + System.out.println(table + " deleted."); + } else { + System.out.println(table + " not deleted."); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java new file mode 100644 index 0000000000..92ace6fdc8 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchTagException; + +public class DeleteTag extends Command { + + protected final String metalake; + protected final String tag; + + /** + * Delete a tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param tag The name of the tag. + */ + public DeleteTag(String url, boolean ignoreVersions, String metalake, String tag) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + } + + /** Delete a catalog. */ + public void handle() { + boolean deleted = false; + + try { + GravitinoClient client = buildClient(metalake); + deleted = client.deleteTag(tag); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchTagException err) { + System.err.println(ErrorMessages.UNKNOWN_TAG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (deleted) { + System.out.println(tag + " deleted."); + } else { + System.out.println(tag + " not deleted."); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java new file mode 100644 index 0000000000..49e9929d3f --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchUserException; + +public class DeleteUser extends Command { + + protected final String metalake; + protected final String user; + + /** + * Delete a user. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param user The name of the user. + */ + public DeleteUser(String url, boolean ignoreVersions, String metalake, String user) { + super(url, ignoreVersions); + this.metalake = metalake; + this.user = user; + } + + /** Delete a user. */ + public void handle() { + boolean deleted = false; + + try { + GravitinoClient client = buildClient(metalake); + deleted = client.removeUser(user); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchUserException err) { + System.err.println(ErrorMessages.UNKNOWN_USER); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (deleted) { + System.out.println(user + " deleted."); + } else { + System.out.println(user + " not deleted."); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java new file mode 100644 index 0000000000..fb32963edf --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/GroupDetails.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.List; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchUserException; + +public class GroupDetails extends Command { + + protected final String metalake; + protected final String group; + + /** + * Displays the users in a group. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param group The name of the group. + */ + public GroupDetails(String url, boolean ignoreVersions, String metalake, String group) { + super(url, ignoreVersions); + this.metalake = metalake; + this.group = group; + } + + /** Displays the roles of a specified user. */ + public void handle() { + List roles = null; + + try { + GravitinoClient client = buildClient(metalake); + roles = client.getGroup(group).roles(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchUserException err) { + System.err.println(ErrorMessages.UNKNOWN_GROUP); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + String all = String.join(",", roles); + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java new file mode 100644 index 0000000000..b983293f95 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/* Lists all tags in a metalake. */ +public class ListAllTags extends Command { + + protected final String metalake; + + /** + * Lists all tags in a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + */ + public ListAllTags(String url, boolean ignoreVersions, String metalake) { + super(url, ignoreVersions); + this.metalake = metalake; + } + + /** Lists all tags in a metalake. */ + public void handle() { + String[] tags = new String[0]; + try { + GravitinoClient client = buildClient(metalake); + tags = client.listTags(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + String all = String.join(",", tags); + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java new file mode 100644 index 0000000000..3aa9cfb7dd --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.Map; +import org.apache.gravitino.Catalog; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** List the properties of a catalog. */ +public class ListCatalogProperties extends ListProperties { + + protected final String metalake; + protected final String catalog; + + /** + * List the properties of a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + */ + public ListCatalogProperties( + String url, boolean ignoreVersions, String metalake, String catalog) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + } + + /** List the properties of a catalog. */ + public void handle() { + Catalog gCatalog = null; + try { + GravitinoClient client = buildClient(metalake); + gCatalog = client.loadCatalog(catalog); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + Map properties = gCatalog.properties(); + printProperties(properties); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java new file mode 100644 index 0000000000..e26aef4e03 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListEntityTags.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.Catalog; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Schema; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; +import org.apache.gravitino.rel.Table; + +/* Lists all tags in a metalake. */ +public class ListEntityTags extends Command { + + protected String metalake; + protected FullName name; + + /** + * Lists all tags in a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param name The name of the entity. + */ + public ListEntityTags(String url, boolean ignoreVersions, String metalake, FullName name) { + super(url, ignoreVersions); + this.metalake = metalake; + this.name = name; + } + + /** Lists all tags in a metalake. */ + public void handle() { + String[] tags = new String[0]; + try { + GravitinoClient client = buildClient(metalake); + + // TODO fileset and topic + if (name.hasTableName()) { + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + String table = name.getTableName(); + Table gTable = + client + .loadCatalog(catalog) + .asTableCatalog() + .loadTable(NameIdentifier.of(schema, table)); + tags = gTable.supportsTags().listTags(); + } else if (name.hasSchemaName()) { + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); + tags = gSchema.supportsTags().listTags(); + } else if (name.hasCatalogName()) { + String catalog = name.getCatalogName(); + Catalog gCatalog = client.loadCatalog(catalog); + tags = gCatalog.supportsTags().listTags(); + } + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (NoSuchTableException err) { + System.err.println(ErrorMessages.UNKNOWN_TABLE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + StringBuilder all = new StringBuilder(); + for (int i = 0; i < tags.length; i++) { + if (i > 0) { + all.append(","); + } + all.append(tags[i]); + } + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java new file mode 100644 index 0000000000..f9c2ff1c46 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/* Lists all groups in a metalake. */ +public class ListGroups extends Command { + + protected final String metalake; + + /** + * Lists all groups in a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + */ + public ListGroups(String url, boolean ignoreVersions, String metalake) { + super(url, ignoreVersions); + this.metalake = metalake; + } + + /** Lists all groups in a metalake. */ + public void handle() { + String[] groups = new String[0]; + try { + GravitinoClient client = buildClient(metalake); + groups = client.listGroupNames(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + String all = String.join(",", groups); + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java new file mode 100644 index 0000000000..2114e79224 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.Map; +import org.apache.gravitino.Metalake; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** List the properties of a metalake. */ +public class ListMetalakeProperties extends ListProperties { + + protected final String metalake; + + /** + * List the properties of a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + */ + public ListMetalakeProperties(String url, boolean ignoreVersions, String metalake) { + super(url, ignoreVersions); + this.metalake = metalake; + } + + /** List the properties of a metalake. */ + public void handle() { + Metalake gMetalake = null; + try { + GravitinoAdminClient client = buildAdminClient(); + gMetalake = client.loadMetalake(metalake); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + Map properties = gMetalake.properties(); + + printProperties(properties); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListProperties.java new file mode 100644 index 0000000000..5ace9e602c --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListProperties.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.Map; + +/** List the properties of a metalake. */ +public class ListProperties extends Command { + + /** + * List the properties of an entity. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + */ + public ListProperties(String url, boolean ignoreVersions) { + super(url, ignoreVersions); + } + + public void handle() { + /* Do nothing */ + } + + /** + * List the properties of an entity. + * + * @param properties The name, value pairs of properties. + */ + public void printProperties(Map properties) { + StringBuilder all = new StringBuilder(); + + for (Map.Entry property : properties.entrySet()) { + all.append(property.getKey() + "," + property.getValue() + System.lineSeparator()); + } + + System.out.print(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java new file mode 100644 index 0000000000..bbd71c516e --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.Map; +import org.apache.gravitino.Schema; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; + +/** List the properties of a catalog. */ +public class ListSchemaProperties extends ListProperties { + + protected final String metalake; + protected final String catalog; + protected final String schema; + + /** + * List the properties of a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schema. + */ + public ListSchemaProperties( + String url, boolean ignoreVersions, String metalake, String catalog, String schema) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.schema = schema; + } + + /** List the properties of a catalog. */ + public void handle() { + Schema gSchema = null; + try { + GravitinoClient client = buildClient(metalake); + gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + Map properties = gSchema.properties(); + printProperties(properties); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java new file mode 100644 index 0000000000..a438ee4168 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.Map; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchTagException; +import org.apache.gravitino.tag.Tag; + +/** List the properties of a tag. */ +public class ListTagProperties extends ListProperties { + + protected final String metalake; + protected final String tag; + + /** + * List the properties of a tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param tag The name of the tag. + */ + public ListTagProperties(String url, boolean ignoreVersions, String metalake, String tag) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + } + + /** List the properties of a tag. */ + public void handle() { + Tag gTag = null; + try { + GravitinoClient client = buildClient(metalake); + gTag = client.getTag(tag); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchTagException err) { + System.err.println(ErrorMessages.UNKNOWN_TAG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + Map properties = gTag.properties(); + printProperties(properties); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java new file mode 100644 index 0000000000..d6f6c23299 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/* Lists all users in a metalake. */ +public class ListUsers extends Command { + + protected final String metalake; + + /** + * Lists all users in a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + */ + public ListUsers(String url, boolean ignoreVersions, String metalake) { + super(url, ignoreVersions); + this.metalake = metalake; + } + + /** Lists all users in a metalake. */ + public void handle() { + String[] users = new String[0]; + try { + GravitinoClient client = buildClient(metalake); + users = client.listUserNames(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + String all = String.join(",", users); + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveCatalogProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveCatalogProperty.java new file mode 100644 index 0000000000..4651baecee --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveCatalogProperty.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.CatalogChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Remove a property of a catalog. */ +public class RemoveCatalogProperty extends Command { + + protected final String metalake; + protected final String catalog; + protected final String property; + + /** + * Remove a property of a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param property The name of the property. + */ + public RemoveCatalogProperty( + String url, boolean ignoreVersions, String metalake, String catalog, String property) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.property = property; + } + + /** Remove a property of a catalog. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + CatalogChange change = CatalogChange.removeProperty(property); + client.alterCatalog(catalog, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(property + " property removed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java new file mode 100644 index 0000000000..0ac14f202f --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.MetalakeChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Remove a property of a metalake. */ +public class RemoveMetalakeProperty extends Command { + + protected final String metalake; + protected final String property; + + /** + * Remove a property of a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param property The name of the property. + */ + public RemoveMetalakeProperty( + String url, boolean ignoreVersions, String metalake, String property) { + super(url, ignoreVersions); + this.metalake = metalake; + this.property = property; + } + + /** Remove a property of a metalake. */ + public void handle() { + try { + GravitinoAdminClient client = buildAdminClient(); + MetalakeChange change = MetalakeChange.removeProperty(property); + client.alterMetalake(metalake, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(property + " property removed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveSchemaProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveSchemaProperty.java new file mode 100644 index 0000000000..9cccf983d2 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveSchemaProperty.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.SchemaChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; + +/** Remove a property of a schema. */ +public class RemoveSchemaProperty extends Command { + + protected final String metalake; + protected final String catalog; + protected final String schema; + protected final String property; + + /** + * Remove a property of a schema. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schema. + * @param property The name of the property. + */ + public RemoveSchemaProperty( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String schema, + String property) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.schema = schema; + this.property = property; + } + + /** Remove a property of a schema. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + SchemaChange change = SchemaChange.removeProperty(property); + client.loadCatalog(catalog).asSchemas().alterSchema(schema, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(property + " property removed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java new file mode 100644 index 0000000000..3d2745768d --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTagProperty.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchTagException; +import org.apache.gravitino.tag.TagChange; + +/** Remove a property of a tag. */ +public class RemoveTagProperty extends Command { + + protected final String metalake; + protected final String tag; + protected final String property; + + /** + * Remove a property of a tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param tag The name of the tag. + * @param property The name of the property. + */ + public RemoveTagProperty( + String url, boolean ignoreVersions, String metalake, String tag, String property) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + this.property = property; + } + + /** Remove a property of a catalog. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + TagChange change = TagChange.removeProperty(property); + client.alterTag(tag, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchTagException err) { + System.err.println(ErrorMessages.UNKNOWN_TAG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(property + " property removed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetCatalogProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetCatalogProperty.java new file mode 100644 index 0000000000..54dd5bae66 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetCatalogProperty.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.CatalogChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Set a property of a catalog. */ +public class SetCatalogProperty extends Command { + + protected final String metalake; + protected final String catalog; + protected final String property; + protected final String value; + + /** + * Set a property of a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param property The name of the property. + * @param value The value of the property. + */ + public SetCatalogProperty( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String property, + String value) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.property = property; + this.value = value; + } + + /** Set a property of a catalog. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + CatalogChange change = CatalogChange.setProperty(property, value); + client.alterCatalog(catalog, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(catalog + " property set."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java new file mode 100644 index 0000000000..5ed69fd4a0 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.MetalakeChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Set a property of a metalake. */ +public class SetMetalakeProperty extends Command { + + protected final String metalake; + protected final String property; + protected final String value; + + /** + * Set a property of a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param property The name of the property. + * @param value The value of the property. + */ + public SetMetalakeProperty( + String url, boolean ignoreVersions, String metalake, String property, String value) { + super(url, ignoreVersions); + this.metalake = metalake; + this.property = property; + this.value = value; + } + + /** Set a property of a metalake. */ + public void handle() { + try { + GravitinoAdminClient client = buildAdminClient(); + MetalakeChange change = MetalakeChange.setProperty(property, value); + client.alterMetalake(metalake, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(metalake + " property set."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetSchemaProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetSchemaProperty.java new file mode 100644 index 0000000000..f311f6c87c --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetSchemaProperty.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.SchemaChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; + +/** Set a property of a schema. */ +public class SetSchemaProperty extends Command { + + protected final String metalake; + protected final String catalog; + protected final String schema; + protected final String property; + protected final String value; + + /** + * Set a property of a schema. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schema. + * @param property The name of the property. + * @param value The value of the property. + */ + public SetSchemaProperty( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String schema, + String property, + String value) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.schema = schema; + this.property = property; + this.value = value; + } + + /** Set a property of a schema. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + SchemaChange change = SchemaChange.setProperty(property, value); + client.loadCatalog(catalog).asSchemas().alterSchema(schema, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(schema + " property set."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java new file mode 100644 index 0000000000..975d020374 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTagProperty.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchTagException; +import org.apache.gravitino.tag.TagChange; + +/** Set a property of a tag. */ +public class SetTagProperty extends Command { + + protected final String metalake; + protected final String tag; + protected final String property; + protected final String value; + + /** + * Set a property of a tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param tag The name of the tag. + * @param property The name of the property. + * @param value The value of the property. + */ + public SetTagProperty( + String url, + boolean ignoreVersions, + String metalake, + String tag, + String property, + String value) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + this.property = property; + this.value = value; + } + + /** Set a property of a tag. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + TagChange change = TagChange.setProperty(property, value); + client.alterTag(tag, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchTagException err) { + System.err.println(ErrorMessages.UNKNOWN_TAG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(tag + " property set."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java new file mode 100644 index 0000000000..0211c50cec --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagDetails.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.tag.Tag; + +public class TagDetails extends Command { + + protected final String metalake; + protected final String tag; + + /** + * Displays the name and comment of a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param tag The name of the tag. + */ + public TagDetails(String url, boolean ignoreVersions, String metalake, String tag) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + } + + /** Displays the name and details of a specified tag. */ + public void handle() { + Tag result = null; + + try { + GravitinoClient client = buildClient(metalake); + result = client.getTag(tag); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (result != null) { + System.out.println(result.name() + "," + result.comment()); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java new file mode 100644 index 0000000000..d1cee3d95a --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.Catalog; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Schema; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; +import org.apache.gravitino.rel.Table; + +public class TagEntity extends Command { + protected final String metalake; + protected final FullName name; + protected final String tag; + + /** + * Tag an entity with an existing tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param name The name of the entity. + * @param tag The name of the tag. + */ + public TagEntity(String url, boolean ignoreVersions, String metalake, FullName name, String tag) { + super(url, ignoreVersions); + this.metalake = metalake; + this.name = name; + this.tag = tag; + } + + /** Create a new tag. */ + public void handle() { + String entity = "unknown"; + String[] tags = new String[0]; + + try { + GravitinoClient client = buildClient(metalake); + + // TODO fileset and topic + if (name.hasTableName()) { + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + String table = name.getTableName(); + Table gTable = + client + .loadCatalog(catalog) + .asTableCatalog() + .loadTable(NameIdentifier.of(schema, table)); + tags = gTable.supportsTags().associateTags(new String[] {tag}, null); + entity = table; + } else if (name.hasSchemaName()) { + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); + tags = gSchema.supportsTags().associateTags(new String[] {tag}, null); + entity = schema; + } else if (name.hasCatalogName()) { + String catalog = name.getCatalogName(); + Catalog gCatalog = client.loadCatalog(catalog); + tags = gCatalog.supportsTags().associateTags(new String[] {tag}, null); + entity = catalog; + } + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (NoSuchTableException err) { + System.err.println(ErrorMessages.UNKNOWN_TABLE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + String all = String.join(",", tags); + + System.out.println(entity + " tagged with " + all); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java new file mode 100644 index 0000000000..52fb31ec8e --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.Catalog; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Schema; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; +import org.apache.gravitino.rel.Table; + +public class UntagEntity extends Command { + protected final String metalake; + protected final FullName name; + protected final String tag; + + /** + * Untag an entity with an existing tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param name The name of the entity. + * @param tag The name of the tag. + */ + public UntagEntity( + String url, boolean ignoreVersions, String metalake, FullName name, String tag) { + super(url, ignoreVersions); + this.metalake = metalake; + this.name = name; + this.tag = tag; + } + + /** Create a new tag. */ + public void handle() { + String entity = "unknown"; + String[] tags = new String[0]; + + try { + GravitinoClient client = buildClient(metalake); + + // TODO fileset and topic + if (name.hasTableName()) { + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + String table = name.getTableName(); + Table gTable = + client + .loadCatalog(catalog) + .asTableCatalog() + .loadTable(NameIdentifier.of(schema, table)); + tags = gTable.supportsTags().associateTags(null, new String[] {tag}); + entity = table; + } else if (name.hasSchemaName()) { + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); + tags = gSchema.supportsTags().associateTags(null, new String[] {tag}); + entity = schema; + } else if (name.hasCatalogName()) { + String catalog = name.getCatalogName(); + Catalog gCatalog = client.loadCatalog(catalog); + tags = gCatalog.supportsTags().associateTags(null, new String[] {tag}); + entity = catalog; + } + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_TABLE); + return; + } catch (NoSuchTableException err) { + System.err.println(ErrorMessages.UNKNOWN_TABLE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + String all = String.join(",", tags); + + System.out.println(entity + " untagged, tagged with " + all); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogComment.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogComment.java new file mode 100644 index 0000000000..1adcabafc0 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogComment.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.CatalogChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Update the comment of a catalog. */ +public class UpdateCatalogComment extends Command { + + protected final String metalake; + protected final String catalog; + protected final String comment; + + /** + * Update the comment of a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param comment New metalake comment. + */ + public UpdateCatalogComment( + String url, boolean ignoreVersions, String metalake, String catalog, String comment) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.comment = comment; + } + + /** Update the comment of a catalog. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + CatalogChange change = CatalogChange.updateComment(comment); + client.alterCatalog(catalog, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(catalog + " comment changed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogName.java new file mode 100644 index 0000000000..77c2137551 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateCatalogName.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.CatalogChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Update the name of a catalog. */ +public class UpdateCatalogName extends Command { + + protected final String metalake; + protected final String catalog; + protected final String name; + + /** + * Update the name of a catalog. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param name The new metalake name. + */ + public UpdateCatalogName( + String url, boolean ignoreVersions, String metalake, String catalog, String name) { + super(url, ignoreVersions); + this.metalake = metalake; + this.catalog = catalog; + this.name = name; + } + + /** Update the name of a catalog. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + CatalogChange change = CatalogChange.rename(name); + client.alterCatalog(catalog, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(catalog + " name changed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java new file mode 100644 index 0000000000..7ad58da734 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.MetalakeChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Update the comment of a metalake. */ +public class UpdateMetalakeComment extends Command { + + protected final String metalake; + protected final String comment; + + /** + * Update the comment of a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param comment New metalake comment. + */ + public UpdateMetalakeComment( + String url, boolean ignoreVersions, String metalake, String comment) { + super(url, ignoreVersions); + this.metalake = metalake; + this.comment = comment; + } + + /** Update the comment of a metalake. */ + public void handle() { + try { + GravitinoAdminClient client = buildAdminClient(); + MetalakeChange change = MetalakeChange.updateComment(comment); + client.alterMetalake(metalake, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(metalake + " comment changed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java new file mode 100644 index 0000000000..0cb76e3642 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.MetalakeChange; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Update the name of a metalake. */ +public class UpdateMetalakeName extends Command { + + protected final String metalake; + protected final String name; + + /** + * Update the name of a metalake. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param name The new metalake name. + */ + public UpdateMetalakeName(String url, boolean ignoreVersions, String metalake, String name) { + super(url, ignoreVersions); + this.metalake = metalake; + this.name = name; + } + + /** Update the name of a metalake. */ + public void handle() { + try { + GravitinoAdminClient client = buildAdminClient(); + MetalakeChange change = MetalakeChange.rename(name); + client.alterMetalake(metalake, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(metalake + " name changed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java new file mode 100644 index 0000000000..5e8aad9dda --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagComment.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchTagException; +import org.apache.gravitino.tag.TagChange; + +/** Update the comment of a tag. */ +public class UpdateTagComment extends Command { + + protected final String metalake; + protected final String tag; + protected final String comment; + + /** + * Update the comment of a tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param tag The name of the tag. + * @param comment New metalake comment. + */ + public UpdateTagComment( + String url, boolean ignoreVersions, String metalake, String tag, String comment) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + this.comment = comment; + } + + /** Update the comment of a tag. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + TagChange change = TagChange.updateComment(comment); + client.alterTag(tag, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchTagException err) { + System.err.println(ErrorMessages.UNKNOWN_TAG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(tag + " comment changed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java new file mode 100644 index 0000000000..28e652776b --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTagName.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchTagException; +import org.apache.gravitino.tag.TagChange; + +/** Update the name of a tag. */ +public class UpdateTagName extends Command { + + protected final String metalake; + protected final String tag; + protected final String name; + + /** + * Update the name of a tag. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the tag. + * @param tag The name of the catalog. + * @param name The new metalake name. + */ + public UpdateTagName( + String url, boolean ignoreVersions, String metalake, String tag, String name) { + super(url, ignoreVersions); + this.metalake = metalake; + this.tag = tag; + this.name = name; + } + + /** Update the name of a catalog. */ + public void handle() { + try { + GravitinoClient client = buildClient(metalake); + TagChange change = TagChange.rename(name); + client.alterTag(tag, change); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchTagException err) { + System.err.println(ErrorMessages.UNKNOWN_TAG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(tag + " name changed."); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java new file mode 100644 index 0000000000..f038a8948e --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli.commands; + +import java.util.List; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchUserException; + +public class UserDetails extends Command { + + protected final String metalake; + protected final String user; + + /** + * Displays the roles of a user. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param user The name of the user. + */ + public UserDetails(String url, boolean ignoreVersions, String metalake, String user) { + super(url, ignoreVersions); + this.metalake = metalake; + this.user = user; + } + + /** Displays the roles of a specified user. */ + public void handle() { + List roles = null; + + try { + GravitinoClient client = buildClient(metalake); + roles = client.getUser(user).roles(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchUserException err) { + System.err.println(ErrorMessages.UNKNOWN_USER); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + String all = String.join(",", roles); + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java index a79f9961fb..58f7f97737 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java @@ -27,7 +27,7 @@ public class TestCommandActions { @Test - public void ValidCommands() { + public void validCommands() { assertTrue( CommandActions.isValidCommand(CommandActions.DETAILS), "DETAILS should be a valid command"); assertTrue( @@ -38,6 +38,12 @@ public void ValidCommands() { CommandActions.isValidCommand(CommandActions.CREATE), "CREATE should be a valid command"); assertTrue( CommandActions.isValidCommand(CommandActions.DELETE), "DELETE should be a valid command"); + assertTrue(CommandActions.isValidCommand(CommandActions.SET), "SET should be a valid command"); + assertTrue( + CommandActions.isValidCommand(CommandActions.REMOVE), "REMOVE should be a valid command"); + assertTrue( + CommandActions.isValidCommand(CommandActions.PROPERTIES), + "PROPERTIES should be a valid command"); } @Test @@ -62,8 +68,6 @@ public void emptyCommand() { @Test public void caseSensitive() { - assertFalse( - CommandActions.isValidCommand("DETAILS".toUpperCase()), - "Commands should be case-sensitive"); + assertFalse(CommandActions.isValidCommand("DETAILS"), "Commands should be case-sensitive"); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java index 423834bfcc..cd2a55e2a3 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java @@ -37,8 +37,7 @@ public void validEntities() { CommandEntities.isValidEntity(CommandEntities.SCHEMA), "SCHEMA should be a valid entity"); assertTrue( CommandEntities.isValidEntity(CommandEntities.TABLE), "TABLE should be a valid entity"); - assertTrue( - CommandEntities.isValidEntity(CommandEntities.COLUMN), "COLUMN should be a valid entity"); + assertTrue(CommandEntities.isValidEntity(CommandEntities.TAG), "TAG should be a valid entity"); } @Test @@ -62,8 +61,6 @@ public void emptyEntity() { @Test public void caseSensitive() { - assertFalse( - CommandEntities.isValidEntity("DETAILS".toUpperCase()), - "Entities should be case-sensitive"); + assertFalse(CommandEntities.isValidEntity("METALAKE"), "Entities should be case-sensitive"); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java index a537784372..d7381f890d 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java @@ -17,14 +17,18 @@ * under the License. */ +package org.apache.gravitino.cli; + import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.MissingArgumentException; import org.apache.commons.cli.Options; -import org.apache.gravitino.cli.FullName; -import org.apache.gravitino.cli.GravitinoOptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -65,7 +69,7 @@ public void entityNotFound() throws Exception { @Test public void malformedName() throws Exception { - String[] args = {"--name", "metalake.catalog"}; + String[] args = {"--name", "catalog.schema"}; CommandLine commandLine = new DefaultParser().parse(options, args); FullName fullName = new FullName(commandLine); String tableName = fullName.getTableName(); @@ -74,6 +78,12 @@ public void malformedName() throws Exception { @Test public void missingName() throws Exception { + String[] args = {"catalog", "--name"}; + assertThrows(MissingArgumentException.class, () -> new DefaultParser().parse(options, args)); + } + + @Test + public void missingArgs() throws Exception { String[] args = {}; // No name provided CommandLine commandLine = new DefaultParser().parse(options, args); FullName fullName = new FullName(commandLine); @@ -81,4 +91,48 @@ public void missingName() throws Exception { String namePart = fullName.getNamePart(3); assertNull(namePart); } + + @Test + public void hasPartNameMetalake() throws Exception { + String[] args = {"metalake", "details", "--name", "metalake"}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + assertTrue(fullName.hasMetalakeName()); + assertFalse(fullName.hasCatalogName()); + assertFalse(fullName.hasSchemaName()); + assertFalse(fullName.hasTableName()); + } + + @Test + public void hasPartNameCatalog() throws Exception { + String[] args = {"catalog", "details", "--name", "metalake.catalog"}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + assertTrue(fullName.hasMetalakeName()); + assertTrue(fullName.hasCatalogName()); + assertFalse(fullName.hasSchemaName()); + assertFalse(fullName.hasTableName()); + } + + @Test + public void hasPartNameSchema() throws Exception { + String[] args = {"schema", "details", "--name", "metalake.catalog.schema"}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + assertTrue(fullName.hasMetalakeName()); + assertTrue(fullName.hasCatalogName()); + assertTrue(fullName.hasSchemaName()); + assertFalse(fullName.hasTableName()); + } + + @Test + public void hasPartNameTable() throws Exception { + String[] args = {"table", "details", "--name", "metalake.catalog.schema.table"}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + assertTrue(fullName.hasMetalakeName()); + assertTrue(fullName.hasCatalogName()); + assertTrue(fullName.hasSchemaName()); + assertTrue(fullName.hasTableName()); + } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoConfig.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoConfig.java new file mode 100644 index 0000000000..b2c1ce7d5f --- /dev/null +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoConfig.java @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Properties; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class TestGravitinoConfig { + + private static final String TEMP_FILE_PATH = + System.getProperty("java.io.tmpdir") + "/gravitino.properties"; + private static final String NON_EXISTENT_FILE_PATH = + System.getProperty("java.io.tmpdir") + "/non_existent.properties"; + private static final String METALAKE_KEY = "metalake"; + private static final String METALAKE_VALUE = "metalake_demo"; + private static final String URL_KEY = "URL"; + private static final String URL_VALUE = "http://10.0.0.1:8090"; + private static final String IGNORE_KEY = "ignore"; + private static final String IGNORE_VALUE = "true"; + + @BeforeEach + public void setUp() throws IOException { + // Set up a temporary config file + File tempFile = new File(TEMP_FILE_PATH); + if (tempFile.exists()) { + tempFile.delete(); + } + + Properties props = new Properties(); + props.setProperty(METALAKE_KEY, METALAKE_VALUE); + props.setProperty(URL_KEY, URL_VALUE); + props.setProperty(IGNORE_KEY, IGNORE_VALUE); + + try (Writer writer = Files.newBufferedWriter(tempFile.toPath(), StandardCharsets.UTF_8)) { + props.store(writer, "Test Config"); + } + } + + @Test + public void defaultPath() { + GravitinoConfig config = new GravitinoConfig(null); + String expectedFilePath = System.getProperty("user.home") + "/.gravitino"; + assertEquals( + expectedFilePath, + config.getConfigFile(), + "Config file path should default to the home directory with '.gravitino'"); + } + + @Test + public void fileDoesExist() { + GravitinoConfig config = new GravitinoConfig(TEMP_FILE_PATH); + assertTrue(config.fileExists(), "Config file should exist"); + } + + @Test + public void fileDoesNotExist() { + GravitinoConfig config = new GravitinoConfig(NON_EXISTENT_FILE_PATH); + assertFalse(config.fileExists(), "Config file should not exist"); + } + + @Test + public void validConfigFile() { + GravitinoConfig config = new GravitinoConfig(TEMP_FILE_PATH); + config.read(); + assertEquals( + METALAKE_VALUE, + config.getMetalakeName(), + "Should read the metalake value from the config file"); + assertEquals( + URL_VALUE, config.getGravitinoURL(), "Should read the URL value from the config file"); + assertTrue(config.getIgnore(), "Should read the ignore value from the config file"); + } + + @Test + public void fileNotFound() { + GravitinoConfig config = new GravitinoConfig(NON_EXISTENT_FILE_PATH); + config.read(); // No exception should be thrown, config file is optional + assertNull(config.getMetalakeName(), "Metalake should be null if config file is not found"); + } + + @Test + public void configFileMissingMetalake() throws IOException { + // Create a config file without the "metalake" key + File tempFileWithoutMetalake = + new File(System.getProperty("java.io.tmpdir") + "/no_metalake.properties"); + try (Writer writer = + Files.newBufferedWriter(tempFileWithoutMetalake.toPath(), StandardCharsets.UTF_8)) { + writer.write("# This config file has no metalake key\n"); + } + + GravitinoConfig config = new GravitinoConfig(tempFileWithoutMetalake.getAbsolutePath()); + config.read(); + assertNull( + config.getMetalakeName(), + "Metalake should be null if the key is missing in the config file"); + + tempFileWithoutMetalake.delete(); + } + + @Test + public void configFileMissingURL() throws IOException { + // Create a config file without the "url" key + File tempFileWithoutURL = new File(System.getProperty("java.io.tmpdir") + "/no_url.properties"); + try (Writer writer = + Files.newBufferedWriter(tempFileWithoutURL.toPath(), StandardCharsets.UTF_8)) { + writer.write("# This config file has no url key\n"); + } + + GravitinoConfig config = new GravitinoConfig(tempFileWithoutURL.getAbsolutePath()); + config.read(); + assertNull( + config.getGravitinoURL(), "URL should be null if the key is missing in the config file"); + + tempFileWithoutURL.delete(); + } + + @Test + public void configFileMissingIgnore() throws IOException { + // Create a config file without the "ignore" key + File tempFileWithoutIgnore = + new File(System.getProperty("java.io.tmpdir") + "/no_url.properties"); + try (Writer writer = + Files.newBufferedWriter(tempFileWithoutIgnore.toPath(), StandardCharsets.UTF_8)) { + writer.write("# This config file has no ignore key\n"); + } + + GravitinoConfig config = new GravitinoConfig(tempFileWithoutIgnore.getAbsolutePath()); + config.read(); + assertFalse( + config.getIgnore(), "Ignore should be false if the key is missing in the config file"); + + tempFileWithoutIgnore.delete(); + } + + @Test + public void invalidConfigFile() throws IOException { + // Create a corrupt config file + File corruptConfigFile = + new File(System.getProperty("java.io.tmpdir") + "/config_corrupt.properties"); + try (Writer writer = + Files.newBufferedWriter(corruptConfigFile.toPath(), StandardCharsets.UTF_8)) { + writer.write("corrupt content = @@%@"); + } + + GravitinoConfig config = new GravitinoConfig(corruptConfigFile.getAbsolutePath()); + config.read(); // Should not throw an exception but handle it gracefully + assertNull(config.getMetalakeName(), "Metalake should be null if the config file is corrupt"); + + corruptConfigFile.delete(); + } + + @Test + public void withoutReadingConfig() { + GravitinoConfig config = new GravitinoConfig(TEMP_FILE_PATH); + assertNull(config.getMetalakeName(), "Metalake should be null before reading the config file"); + assertNull(config.getGravitinoURL(), "URL should be null before reading the config file"); + assertFalse(config.getIgnore(), "Ignore should be null before reading the config file"); + } +} diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java index 6fd12276d1..879283aafa 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java @@ -29,7 +29,7 @@ public class TestGravitinoOptions { @Test - public void testCreateSimpleOption() { + public void createSimpleOption() { GravitinoOptions gravitinoOptions = new GravitinoOptions(); Option helpOption = gravitinoOptions.createSimpleOption("h", GravitinoOptions.HELP, "help message"); @@ -44,7 +44,7 @@ public void testCreateSimpleOption() { } @Test - public void testCreateArgOption() { + public void createArgOption() { GravitinoOptions gravitinoOptions = new GravitinoOptions(); Option urlOption = gravitinoOptions.createArgOption("u", GravitinoOptions.URL, "url argument"); diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java index 388d5da739..c6d1bacdb1 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java @@ -55,7 +55,7 @@ public void restoreStreams() { } @Test - public void withTwoArgsOnly() throws ParseException { + public void withTwoArgs() throws ParseException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); String[] args = {"metalake", "details"}; @@ -93,6 +93,19 @@ public void withNoArgs() throws ParseException { assertNull(entity); } + @Test + public void withNoArgsAndOptions() throws ParseException { + Options options = new GravitinoOptions().options(); + CommandLineParser parser = new DefaultParser(); + String[] args = {"--name", "metalake_demo"}; + CommandLine line = parser.parse(options, args); + + String command = Main.resolveCommand(line); + assertNull(command); + String entity = Main.resolveEntity(line); + assertNull(entity); + } + @Test @SuppressWarnings("DefaultCharset") public void withHelpOption() throws ParseException, UnsupportedEncodingException { @@ -117,4 +130,17 @@ public void parseError() throws UnsupportedEncodingException { assertTrue(errContent.toString().contains("Error parsing command line")); // Expect error assertTrue(outContent.toString().contains("usage:")); // Expect help output } + + @Test + public void catalogWithOneArg() throws ParseException { + Options options = new GravitinoOptions().options(); + CommandLineParser parser = new DefaultParser(); + String[] args = {"catalog", "--name", "catalog_postgres"}; + CommandLine line = parser.parse(options, args); + + String command = Main.resolveCommand(line); + assertEquals(CommandActions.DETAILS, command); + String entity = Main.resolveEntity(line); + assertEquals(CommandEntities.CATALOG, entity); + } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestProviders.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestProviders.java new file mode 100644 index 0000000000..056b643990 --- /dev/null +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestProviders.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.cli; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +public class TestProviders { + + @Test + public void validProviders() { + assertTrue(Providers.isValidProvider(Providers.HIVE), "HIVE should be a valid entity"); + assertTrue(Providers.isValidProvider(Providers.HADOOP), "HADOOP should be a valid entity"); + assertTrue(Providers.isValidProvider(Providers.ICEBERG), "ICEBERG should be a valid entity"); + assertTrue(Providers.isValidProvider(Providers.MYSQL), "MYSQL should be a valid entity"); + assertTrue(Providers.isValidProvider(Providers.POSTGRES), "POSTGRES should be a valid entity"); + assertTrue(Providers.isValidProvider(Providers.KAFKA), "KAFKA should be a valid entity"); + } + + @Test + public void invalidProvider() { + assertFalse( + Providers.isValidProvider("invalidEntity"), "An invalid provider should return false"); + } + + @Test + public void nullEntity() { + assertFalse( + Providers.isValidProvider(null), "Null should return false as it's not a valid provider"); + } + + @Test + public void emptyEntity() { + assertFalse( + Providers.isValidProvider(""), + "Empty string should return false as it's not a valid entity"); + } + + @Test + public void caseSensitive() { + assertFalse(Providers.isValidProvider("HIVE"), "Providers should be case-sensitive"); + } + + @Test + public void internalNotNull() { + assertNotNull(Providers.internal(Providers.HIVE), "Internal string should not be null"); + assertNotNull(Providers.internal(Providers.HADOOP), "Internal string should not be null"); + assertNotNull(Providers.internal(Providers.ICEBERG), "Internal string should not be null"); + assertNotNull(Providers.internal(Providers.MYSQL), "Internal string should not be null"); + assertNotNull(Providers.internal(Providers.POSTGRES), "Internal string should not be null"); + assertNotNull(Providers.internal(Providers.KAFKA), "Internal string should not be null"); + } + + @Test + public void internalNull() { + assertNull(Providers.internal("unknown"), "Internal string should be null"); + } + + @Test + public void catalogTypeNotNull() { + assertNotNull(Providers.catalogType(Providers.HIVE), "Catalog type should not be null"); + assertNotNull(Providers.catalogType(Providers.HADOOP), "Catalog type should not be null"); + assertNotNull(Providers.catalogType(Providers.ICEBERG), "Catalog type should not be null"); + assertNotNull(Providers.catalogType(Providers.MYSQL), "Catalog type should not be null"); + assertNotNull(Providers.catalogType(Providers.POSTGRES), "Catalog type should not be null"); + assertNotNull(Providers.catalogType(Providers.KAFKA), "Catalog type should not be null"); + } + + @Test + public void catalogTypeNull() { + assertNull(Providers.internal("unknown"), "Catalog type should be null"); + } +} diff --git a/docs/cli.md b/docs/cli.md index 98a311fefe..66525d8a81 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -8,52 +8,65 @@ last_update: license: 'This software is licensed under the Apache License version 2.' --- -This document primarily outlines how users can manage metadata within Apache Gravitino using the Command Line Interface (CLI). The CLI is accessible via a terminal window as an alternative to writing code or using the REST interface. +This document provides guidance on managing metadata within Apache Gravitino using the Command Line Interface (CLI). The CLI offers a terminal based alternative to using code or the REST interface for metadata management. -Currently, you can view basic metadata information for metalakes, catalogs, schema, and tables. The ability to create, update, and delete metalakes and support additional entities in planned in the near future. +Currently, the CLI allows users to view metadata information for metalakes, catalogs, schemas, and tables. Future updates will expand on these capabilities to include roles, users, and tags. ## Running the CLI -You can set up an alias for the command like so: +You can configure an alias for the CLI for ease of use, with the following command: ```bash alias gcli='java -jar ../../cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar' ``` -Or use the `gcli.sh` script found in the `clients/cli/bin/` directory to run the CLI. +Or you use the `gcli.sh` script found in the `clients/cli/bin/` directory to run the CLI. ## Usage - To run the Gravitino CLI, use the following command structure: +The general structure for running commands with the Gravitino CLI is `gcli entity command [options]`. ```bash - usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update] [options] + usage: gcli [metalake|catalog|schema|table|column] [list|details|create|delete|update|set|remove|properties] [options] Options - -f,--name full entity name (dot separated) - -h,--help command help information - -i,--ignore Ignore client/sever version check - -m,--metalake Metalake name - -r,--server Gravitino server version - -u,--url Gravitino URL (default: http://localhost:8090) - -v,--version Gravitino client version + -b,--bootstrap Kafka bootstrap servers + -c,--comment entity comment + -d,--database database name + -h,--help command help information + -i,--ignore Ignore client/sever version check + -j,--jdbcurl JDBC URL + -l,--user database username + -m,--metastore Hive metastore URI + -n,--name full entity name (dot separated) + -p,--provider provider one of hadoop, hive, mysql, postgres, + iceberg, kafka + -r,--rename new entity name + -u,--url Gravitino URL (default: http://localhost:8090) + -v,--value property value + -w,--warehouse warehouse name + -z,--password database password ``` ## Commands -The following commands are available for entity management: +The following commands are used for entity management: - list: List available entities - details: Show detailed information about an entity - create: Create a new entity - delete: Delete an existing entity - update: Update an existing entity +- set: Set an entities property +- remove: Remove an entities property +- properties: Display an entities properties ### Setting the Metalake name -As dealing with one Metalake is a typical scenario, you can set the Metalake name in several ways. +As dealing with one Metalake is a typical scenario, you can set the Metalake name in several ways so it doesn't need to be passed on the command line. 1. Passed in on the command line via the `--metalake` parameter. 2. Set via the `GRAVITINO_METALAKE` environment variable. +3. Stored in the Gravitino CLI configuration file. The command line option overrides the environment variable. @@ -63,9 +76,31 @@ As you need to set the Gravitino URL for every command, you can set the URL in s 1. Passed in on the command line via the `--url` parameter. 2. Set via the 'GRAVITINO_URL' environment variable. +3. Stored in the Gravitino CLI configuration file. The command line option overrides the environment variable. +## Gravitino CLI configuration file + +The gravitino CLI can read commonly used CLI options from a configuration file. By default, the file is `.gravitino` in the user's home directory. The metalake, URL and ignore parameters can be set in this file. + +```text +# +# Gravitino CLI configuration file +# + +# Metalake to use +metalake=metalake_demo + +# Gravitino server to connect to +URL=http://localhost:8090 + +# Ignore client/server version mismatch +ignore=true + +``` + + ## Manage metadata All the commands are performed by using the [Java API](api/java-api) internally. @@ -96,9 +131,13 @@ gcli --server ### Client/server version mismatch -If the client and server are running different versions of the Gravitino software then you need an additional `--ignore` option for the command to run. +If the client and server are running different versions of the Gravitino software then you may need to ignore the client/server version check for the command to run. This can be done in several ways: + +1. Passed in on the command line via the `--ignore` parameter. +2. Set via the `GRAVITINO_IGNORE` environment variable. +3. Stored in the Gravitino CLI configuration file. -### Metalake +### Metalake commands #### Show all metalakes @@ -109,7 +148,49 @@ gcli metalake list #### Show a metalake details ```bash -gcli metalake details --metalake metalake_demo +gcli metalake details --metalake metalake_demo +``` + +#### Create a metalake + +```bash +gcli metalake create --metalake my_metalake --comment "This is my metalake" +``` + +#### Delete a metalake + +```bash +gcli metalake delete --metalake my_metalake +``` + +#### Rename a metalake + +```bash +gcli metalake update --metalake metalake_demo --rename demo +``` + +#### Update a metalake's comment + +```bash +gcli metalake update --metalake metalake_demo --comment "new comment" +``` + +#### Display a metalake's properties + +```bash +gcli metalake properties --metalake metalake_demo +``` + +#### Set a metalake's property + +```bash +gcli metalake set --metalake metalake_demo --property test --value value +``` + +#### Remove a metalake's property + +```bash +gcli metalake remove --metalake metalake_demo --property test ``` ### Catalog @@ -120,12 +201,82 @@ gcli metalake details --metalake metalake_demo gcli catalog list --metalake metalake_demo ``` -#### Show a catalogs details +#### Show a catalog details ```bash gcli catalog details --metalake metalake_demo --name catalog_postgres ``` +#### Creating a catalog + +The type of catalog to be created is specified by the `--provider` option. Different catalogs require different options, for example, a Hive catalog requires a metastore URI to be passed in as an option. + +##### Create a Hive catalog + +```bash +gcli catalog create --metalake metalake_demo --name hive --provider hive --metastore thrift://hive-host:9083 +``` + +##### Create an Iceberg catalog + +```bash +gcli catalog create --metalake metalake_demo --name iceberg --provider iceberg --metastore thrift://hive-host:9083 --warehouse hdfs://hdfs-host:9000/user/iceberg/warehouse +``` + +##### Create a MySQL catalog + +```bash +gcli catalog create --metalake metalake_demo --name mysql --provider mysql --jdbcurl "jdbc:mysql://mysql-host:3306?useSSL=false" --user user --password password +``` + +##### Create a Postgres catalog + +```bash +gcli catalog create --metalake metalake_demo --name postgres --provider postgres --jdbcurl jdbc:postgresql://postgresql-host/mydb --user user --password password -database db +``` + +##### Create a Kafka catalog + +```bash +gcli catalog create --metalake metalake_demo --name kafka --provider kafka --bootstrap 127.0.0.1:9092,127.0.0.2:9092 +``` + +#### Delete a catalog + +```bash +gcli catalog delete --metalake metalake_demo --name hive +``` + +#### Rename a catalog + +```bash +gcli catalog update --metalake metalake_demo --name catalog_mysql --rename mysql +``` + +#### Change a catalog comment + +```bash +gcli catalog update --metalake metalake_demo --name catalog_mysql --comment "new comment" +``` + +#### Display a catalog's properties + +```bash +gcli catalog properties --metalake metalake_demo --name catalog_mysql +``` + +#### Set a catalog's property + +```bash +gcli catalog set --metalake metalake_demo --name catalog_mysql --property test --value value +``` + +#### Remove a catalog's property + +```bash +gcli catalog remove --metalake metalake_demo --name catalog_mysql --property test +``` + ### Schema #### Show all schemas in a catalog @@ -134,12 +285,26 @@ gcli catalog details --metalake metalake_demo --name catalog_postgres gcli schema list --metalake metalake_demo --name catalog_postgres ``` -#### Show a schema details +#### Show schema details ```bash gcli schema details --metalake metalake_demo --name catalog_postgres.hr ``` +#### Create a schema + +```bash +gcli schema create --metalake metalake_demo --name catalog_postgres.new_db +``` + +#### Display schema properties + +```bash +gcli schema properties --metalake metalake_demo --name catalog_postgres.hr -i +``` + +Setting and removing schema properties is not currently supported by the Java API or the Gravitino CLI. + ### Table #### Show all tables @@ -153,3 +318,9 @@ gcli table list --metalake metalake_demo --name catalog_postgres.hr ```bash gcli column list --metalake metalake_demo --name catalog_postgres.hr.departments ``` + +#### Delete a table + +```bash +gcli table delete --metalake metalake_demo --name catalog_postgres.hr.salaries +```