Skip to content

Commit

Permalink
[apache#6415] improve(CLI): Add Fileset command context CLI (apache#6431
Browse files Browse the repository at this point in the history
)

### What changes were proposed in this pull request?

Add Fileset command context CLI

### Why are the changes needed?

Fix: apache#6415 

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

local test
  • Loading branch information
Abyss-lord authored and youngyjd committed Feb 14, 2025
1 parent 294505e commit 3ac1fe5
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class FilesetCommandHandler extends CommandHandler {
private final GravitinoCommandLine gravitinoCommandLine;
private final CommandLine line;
private final String command;
private final boolean ignore;
private final String url;
private final CommandContext context;
private final FullName name;
private final String metalake;
private final String catalog;
Expand All @@ -45,16 +44,19 @@ public class FilesetCommandHandler extends CommandHandler {
* @param gravitinoCommandLine The Gravitino command line instance.
* @param line The command line arguments.
* @param command The command to execute.
* @param ignore Ignore server version mismatch.
* @param context The command context.
*/
public FilesetCommandHandler(
GravitinoCommandLine gravitinoCommandLine, CommandLine line, String command, boolean ignore) {
GravitinoCommandLine gravitinoCommandLine,
CommandLine line,
String command,
CommandContext context) {
this.gravitinoCommandLine = gravitinoCommandLine;
this.line = line;
this.command = command;
this.ignore = ignore;
this.context = context;

this.url = getUrl(line);
this.context.setUrl(getUrl(line));
this.name = new FullName(line);
this.metalake = name.getMetalakeName();
this.catalog = name.getCatalogName();
Expand Down Expand Up @@ -130,7 +132,7 @@ private boolean executeCommand() {
/** Handles the "DETAILS" command. */
private void handleDetailsCommand() {
gravitinoCommandLine
.newFilesetDetails(url, ignore, metalake, catalog, schema, fileset)
.newFilesetDetails(context, metalake, catalog, schema, fileset)
.validate()
.handle();
}
Expand All @@ -141,16 +143,15 @@ private void handleCreateCommand() {
String[] properties = line.getOptionValues(CommandActions.PROPERTIES);
Map<String, String> propertyMap = new Properties().parse(properties);
gravitinoCommandLine
.newCreateFileset(url, ignore, metalake, catalog, schema, fileset, comment, propertyMap)
.newCreateFileset(context, metalake, catalog, schema, fileset, comment, propertyMap)
.validate()
.handle();
}

/** Handles the "DELETE" command. */
private void handleDeleteCommand() {
boolean force = line.hasOption(GravitinoOptions.FORCE);
gravitinoCommandLine
.newDeleteFileset(url, ignore, force, metalake, catalog, schema, fileset)
.newDeleteFileset(context, metalake, catalog, schema, fileset)
.validate()
.handle();
}
Expand All @@ -160,7 +161,7 @@ private void handleSetCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
gravitinoCommandLine
.newSetFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property, value)
.newSetFilesetProperty(context, metalake, catalog, schema, fileset, property, value)
.validate()
.handle();
}
Expand All @@ -169,40 +170,37 @@ private void handleSetCommand() {
private void handleRemoveCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
gravitinoCommandLine
.newRemoveFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property)
.newRemoveFilesetProperty(context, metalake, catalog, schema, fileset, property)
.validate()
.handle();
}

/** Handles the "PROPERTIES" command. */
private void handlePropertiesCommand() {
gravitinoCommandLine
.newListFilesetProperties(url, ignore, metalake, catalog, schema, fileset)
.newListFilesetProperties(context, metalake, catalog, schema, fileset)
.validate()
.handle();
}

/** Handles the "LIST" command. */
private void handleListCommand() {
gravitinoCommandLine
.newListFilesets(url, ignore, metalake, catalog, schema)
.validate()
.handle();
gravitinoCommandLine.newListFilesets(context, metalake, catalog, schema).validate().handle();
}

/** Handles the "UPDATE" command. */
private void handleUpdateCommand() {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
.newUpdateFilesetComment(url, ignore, metalake, catalog, schema, fileset, comment)
.newUpdateFilesetComment(context, metalake, catalog, schema, fileset, comment)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
gravitinoCommandLine
.newUpdateFilesetName(url, ignore, metalake, catalog, schema, fileset, newName)
.newUpdateFilesetName(context, metalake, catalog, schema, fileset, newName)
.validate()
.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void executeCommand() {
} else if (entity.equals(CommandEntities.TOPIC)) {
new TopicCommandHandler(this, line, command, ignore).handle();
} else if (entity.equals(CommandEntities.FILESET)) {
new FilesetCommandHandler(this, line, command, ignore).handle();
new FilesetCommandHandler(this, line, command, context).handle();
} else if (entity.equals(CommandEntities.USER)) {
new UserCommandHandler(this, line, command, ignore).handle();
} else if (entity.equals(CommandEntities.GROUP)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,86 +645,75 @@ protected ListTopicProperties newListTopicProperties(
}

protected FilesetDetails newFilesetDetails(
String url, boolean ignore, String metalake, String catalog, String schema, String fileset) {
return new FilesetDetails(url, ignore, metalake, catalog, schema, fileset);
CommandContext context, String metalake, String catalog, String schema, String fileset) {
return new FilesetDetails(context, metalake, catalog, schema, fileset);
}

protected ListFilesets newListFilesets(
String url, boolean ignore, String metalake, String catalog, String schema) {
return new ListFilesets(url, ignore, metalake, catalog, schema);
CommandContext context, String metalake, String catalog, String schema) {
return new ListFilesets(context, metalake, catalog, schema);
}

protected CreateFileset newCreateFileset(
String url,
boolean ignore,
CommandContext context,
String metalake,
String catalog,
String schema,
String fileset,
String comment,
Map<String, String> propertyMap) {
return new CreateFileset(url, ignore, metalake, catalog, schema, fileset, comment, propertyMap);
return new CreateFileset(context, metalake, catalog, schema, fileset, comment, propertyMap);
}

protected DeleteFileset newDeleteFileset(
String url,
boolean ignore,
boolean force,
String metalake,
String catalog,
String schema,
String fileset) {
return new DeleteFileset(url, ignore, force, metalake, catalog, schema, fileset);
CommandContext context, String metalake, String catalog, String schema, String fileset) {
return new DeleteFileset(context, metalake, catalog, schema, fileset);
}

protected UpdateFilesetComment newUpdateFilesetComment(
String url,
boolean ignore,
CommandContext context,
String metalake,
String catalog,
String schema,
String fileset,
String comment) {
return new UpdateFilesetComment(url, ignore, metalake, catalog, schema, fileset, comment);
return new UpdateFilesetComment(context, metalake, catalog, schema, fileset, comment);
}

protected UpdateFilesetName newUpdateFilesetName(
String url,
boolean ignore,
CommandContext context,
String metalake,
String catalog,
String schema,
String fileset,
String rename) {
return new UpdateFilesetName(url, ignore, metalake, catalog, schema, fileset, rename);
return new UpdateFilesetName(context, metalake, catalog, schema, fileset, rename);
}

protected ListFilesetProperties newListFilesetProperties(
String url, boolean ignore, String metalake, String catalog, String schema, String fileset) {
return new ListFilesetProperties(url, ignore, metalake, catalog, schema, fileset);
CommandContext context, String metalake, String catalog, String schema, String fileset) {
return new ListFilesetProperties(context, metalake, catalog, schema, fileset);
}

protected SetFilesetProperty newSetFilesetProperty(
String url,
boolean ignore,
CommandContext context,
String metalake,
String catalog,
String schema,
String fileset,
String property,
String value) {
return new SetFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property, value);
return new SetFilesetProperty(context, metalake, catalog, schema, fileset, property, value);
}

protected RemoveFilesetProperty newRemoveFilesetProperty(
String url,
boolean ignore,
CommandContext context,
String metalake,
String catalog,
String schema,
String fileset,
String property) {
return new RemoveFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property);
return new RemoveFilesetProperty(context, metalake, catalog, schema, fileset, property);
}

protected AddColumn newAddColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.FilesetAlreadyExistsException;
Expand All @@ -40,8 +41,7 @@ public class CreateFileset extends Command {
/**
* Create a new fileset.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
* @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
Expand All @@ -50,15 +50,14 @@ public class CreateFileset extends Command {
* @param properties The catalog's properties.
*/
public CreateFileset(
String url,
boolean ignoreVersions,
CommandContext context,
String metalake,
String catalog,
String schema,
String fileset,
String comment,
Map<String, String> properties) {
super(url, ignoreVersions);
super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
Expand Down Expand Up @@ -93,6 +92,6 @@ public void handle() {
exitWithError(exp.getMessage());
}

System.out.println(fileset + " created");
printInformation(fileset + " created");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.cli.AreYouSure;
import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
Expand All @@ -39,24 +40,16 @@ public class DeleteFileset extends Command {
/**
* Delete a fileset.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
* @param force Force operation.
* @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
* @param fileset The name of the fileset.
*/
public DeleteFileset(
String url,
boolean ignoreVersions,
boolean force,
String metalake,
String catalog,
String schema,
String fileset) {
super(url, ignoreVersions);
this.force = force;
CommandContext context, String metalake, String catalog, String schema, String fileset) {
super(context);
this.force = context.force();
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
Expand Down Expand Up @@ -89,9 +82,9 @@ public void handle() {
}

if (deleted) {
System.out.println(fileset + " deleted.");
printInformation(fileset + " deleted.");
} else {
System.out.println(fileset + " not deleted.");
printInformation(fileset + " not deleted.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;

import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
Expand All @@ -39,21 +40,15 @@ public class FilesetDetails extends Command {
/**
* Displays the details of a fileset.
*
* @param url The URL of the Gravitino server.
* @param ignoreVersions If true don't check the client/server versions match.
* @param context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schenma.
* @param fileset The name of the fileset.
*/
public FilesetDetails(
String url,
boolean ignoreVersions,
String metalake,
String catalog,
String schema,
String fileset) {
super(url, ignoreVersions);
CommandContext context, String metalake, String catalog, String schema, String fileset) {
super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
Expand Down Expand Up @@ -83,7 +78,7 @@ public void handle() {

if (result != null) {
String filesetType = (result.type() == Fileset.Type.MANAGED) ? "managed" : "external";
System.out.println(
printResults(
result.name()
+ ","
+ filesetType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
Expand All @@ -39,21 +40,15 @@ public class ListFilesetProperties extends ListProperties {
/**
* 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 context The command context.
* @param metalake The name of the metalake.
* @param catalog The name of the catalog.
* @param schema The name of the schema.
* @param fileset The name of the fileset.
*/
public ListFilesetProperties(
String url,
boolean ignoreVersions,
String metalake,
String catalog,
String schema,
String fileset) {
super(url, ignoreVersions);
CommandContext context, String metalake, String catalog, String schema, String fileset) {
super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
Expand Down
Loading

0 comments on commit 3ac1fe5

Please sign in to comment.