Skip to content
Permalink
Browse files
support graph-create and graph-drop subcommand (#2) (#95)
  • Loading branch information
zhoney committed Dec 28, 2021
1 parent 11a817e commit 668333a877106a9028174ca239655e491dcb2c5f
Showing 3 changed files with 118 additions and 5 deletions.
@@ -57,7 +57,8 @@

public class HugeGraphCommand {

private static final int DEFAULT_CLEAR_TIMEOUT = 300;
private static final int DEFAULT_GRAPH_CLEAR_TIMEOUT = 300;
private static final int DEFAULT_GRAPH_CREATE_TIMEOUT = 300;

private SubCommands subCommands;

@@ -267,6 +268,26 @@ private void execute(String subCmd, JCommander jCommander) {
dumpManager.dumpFormatter(dump.formatter());
dumpManager.dump();
break;
case "graph-create":
SubCommands.GraphCreate graphCreate = this.subCommand(subCmd);
if (timeout() < DEFAULT_GRAPH_CREATE_TIMEOUT) {
this.timeout(DEFAULT_GRAPH_CREATE_TIMEOUT);
}
graphsManager = manager(GraphsManager.class);
graphsManager.create(graphCreate.name(), graphCreate.config());
Printer.print("Graph '%s' is created", graphCreate.name());
break;
case "graph-clone":
SubCommands.GraphClone graphClone = this.subCommand(subCmd);
if (timeout() < DEFAULT_GRAPH_CREATE_TIMEOUT) {
this.timeout(DEFAULT_GRAPH_CREATE_TIMEOUT);
}
graphsManager = manager(GraphsManager.class);
graphsManager.clone(graphClone.name(),
graphClone.cloneGraphName());
Printer.print("Graph '%s' is created(cloned from '%s')",
graphClone.name(), graphClone.cloneGraphName());
break;
case "graph-list":
graphsManager = manager(GraphsManager.class);
Printer.printList("Graphs", graphsManager.list());
@@ -278,13 +299,22 @@ private void execute(String subCmd, JCommander jCommander) {
break;
case "graph-clear":
SubCommands.GraphClear graphClear = this.subCommand(subCmd);
if (timeout() < DEFAULT_CLEAR_TIMEOUT) {
this.timeout(DEFAULT_CLEAR_TIMEOUT);
if (timeout() < DEFAULT_GRAPH_CLEAR_TIMEOUT) {
this.timeout(DEFAULT_GRAPH_CLEAR_TIMEOUT);
}
graphsManager = manager(GraphsManager.class);
graphsManager.clear(this.graph(), graphClear.confirmMessage());
Printer.print("Graph '%s' is cleared", this.graph());
break;
case "graph-drop":
SubCommands.GraphDrop graphDrop = this.subCommand(subCmd);
if (timeout() < DEFAULT_GRAPH_CLEAR_TIMEOUT) {
this.timeout(DEFAULT_GRAPH_CLEAR_TIMEOUT);
}
graphsManager = manager(GraphsManager.class);
graphsManager.drop(this.graph(), graphDrop.confirmMessage());
Printer.print("Graph '%s' is dropped", this.graph());
break;
case "graph-mode-set":
SubCommands.GraphModeSet graphModeSet = this.subCommand(subCmd);
graphsManager = manager(GraphsManager.class);
@@ -59,9 +59,12 @@ public SubCommands() {
}

private void initSubCommands() {
this.commands.put("graph-create", new GraphCreate());
this.commands.put("graph-clone", new GraphClone());
this.commands.put("graph-list", new GraphList());
this.commands.put("graph-get", new GraphGet());
this.commands.put("graph-clear", new GraphClear());
this.commands.put("graph-drop", new GraphDrop());
this.commands.put("graph-mode-set", new GraphModeSet());
this.commands.put("graph-mode-get", new GraphModeGet());

@@ -370,6 +373,45 @@ public boolean keepData() {
}
}

@Parameters(commandDescription = "Create graph with config")
public static class GraphCreate {

@Parameter(names = {"--name", "-n"}, arity = 1,
description = "The name of new created graph, default is g")
public String name = "g";

@ParametersDelegate
private ConfigFile configFile = new ConfigFile();

public String name() {
return this.name;
}

public String config() {
return this.configFile.config;
}
}

@Parameters(commandDescription = "Clone graph")
public static class GraphClone {

@Parameter(names = {"--name", "-n"}, arity = 1,
description = "The name of new created graph, default is g")
public String name = "g";

@Parameter(names = {"--clone-graph-name"}, arity = 1,
description = "The name of cloned graph, default is hugegraph")
public String cloneGraphName = "hugegraph";

public String name() {
return this.name;
}

public String cloneGraphName() {
return this.cloneGraphName;
}
}

@Parameters(commandDescription = "List all graphs")
public static class GraphList {
}
@@ -381,7 +423,18 @@ public static class GraphGet {}
public static class GraphClear {

@ParametersDelegate
private ConfirmMessage message = new ConfirmMessage();
private ClearConfirmMessage message = new ClearConfirmMessage();

public String confirmMessage() {
return this.message.confirmMessage;
}
}

@Parameters(commandDescription = "Drop graph")
public static class GraphDrop {

@ParametersDelegate
private DropConfirmMessage message = new DropConfirmMessage();

public String confirmMessage() {
return this.message.confirmMessage;
@@ -736,7 +789,7 @@ public static class DownloadURL {
public String url = null;
}

public static class ConfirmMessage {
public static class ClearConfirmMessage {

@Parameter(names = {"--confirm-message", "-c"}, arity = 1,
description = "Confirm message of graph clear is " +
@@ -746,6 +799,16 @@ public static class ConfirmMessage {
public String confirmMessage;
}

public static class DropConfirmMessage {

@Parameter(names = {"--confirm-message", "-c"}, arity = 1,
description = "Confirm message of graph clear is " +
"\"I'm sure to drop the graph\". " +
"(Note: include \"\")",
required = true)
public String confirmMessage;
}

public static class Mode {

@Parameter(names = {"--graph-mode", "-m"}, arity = 1,
@@ -765,6 +828,14 @@ public static class FileScript {
public String script;
}

public static class ConfigFile {

@Parameter(names = {"--file", "-f"}, arity = 1,
converter = FileNameToContentConverter.class,
description = "Creating graph config file")
public String config;
}

public static class GremlinScript {

@Parameter(names = {"--script", "-s"}, arity = 1,
@@ -32,6 +32,14 @@ public GraphsManager(ToolClient.ConnectionInfo info) {
super(info, "graphs");
}

public Map<String, String> create(String name, String config) {
return this.client.graphs().createGraph(name, config);
}

public Map<String, String> clone(String name, String cloneGraphName) {
return this.client.graphs().cloneGraph(name, cloneGraphName);
}

public List<String> list() {
return this.client.graphs().listGraph();
}
@@ -44,6 +52,10 @@ public void clear(String graph, String confirmMessage) {
this.client.graphs().clearGraph(graph, confirmMessage);
}

public void drop(String graph, String confirmMessage) {
this.client.graphs().dropGraph(graph, confirmMessage);
}

public void mode(String graph, GraphMode mode) {
this.client.graphs().mode(graph, mode);
}

0 comments on commit 668333a

Please sign in to comment.