You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/02/16 21:17:36 UTC

[GitHub] [ignite] ololo3000 commented on a change in pull request #9760: IGNITE-15450 Add special option to run snapshot commands synchronously.

ololo3000 commented on a change in pull request #9760:
URL: https://github.com/apache/ignite/pull/9760#discussion_r808460976



##########
File path: modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/snapshot/SnapshotSubcommand.java
##########
@@ -17,64 +17,71 @@
 
 package org.apache.ignite.internal.commandline.snapshot;
 
-import org.apache.ignite.internal.visor.snapshot.VisorSnapshotCancelTask;
-import org.apache.ignite.internal.visor.snapshot.VisorSnapshotCheckTask;
-import org.apache.ignite.internal.visor.snapshot.VisorSnapshotCreateTask;
-import org.apache.ignite.internal.visor.snapshot.VisorSnapshotRestoreTask;
-import org.jetbrains.annotations.Nullable;
+import java.util.Map;
+import java.util.logging.Logger;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.commandline.AbstractCommand;
+import org.apache.ignite.internal.commandline.Command;
+import org.apache.ignite.internal.commandline.CommandArgIterator;
+import org.apache.ignite.internal.util.typedef.F;
+
+import static org.apache.ignite.internal.commandline.TaskExecutor.executeTaskByNameOnNode;
 
 /**
- * Set of snapshot sub-commands.
- *
- * @see SnapshotCommand
+ * Snapshot sub-command base.
  */
-public enum SnapshotSubcommand {
-    /** Sub-command to create a cluster snapshot. */
-    CREATE("create", VisorSnapshotCreateTask.class.getName()),
-
-    /** Sub-command to cancel running snapshot. */
-    CANCEL("cancel", VisorSnapshotCancelTask.class.getName()),
+public abstract class SnapshotSubcommand extends AbstractCommand<Object> {
+    /** Snapshot name argument. */
+    protected static final String SNAPSHOT_NAME_ARG = "snapshot_name";
 
-    /** Sub-command to check snapshot. */
-    CHECK("check", VisorSnapshotCheckTask.class.getName()),
-
-    /** Sub-command to restore snapshot. */
-    RESTORE("restore", VisorSnapshotRestoreTask.class.getName());
+    /** Command argument. */
+    protected Object cmdArg;
 
     /** Sub-command name. */
     private final String name;
 
-    /** Task class name to execute. */
-    private final String taskName;
+    /** Snapshot visor task class. */
+    private final Class<?> taskCls;
 
-    /** @param name Snapshot sub-command name. */
-    SnapshotSubcommand(String name, String taskName) {
+    /**
+     * @param name Sub-command name.
+     * @param taskCls Visor compute task class.
+     */
+    protected SnapshotSubcommand(String name, Class<?> taskCls) {
         this.name = name;
-        this.taskName = taskName;
+        this.taskCls = taskCls;
     }
 
-    /**
-     * @param text Command text (case insensitive).
-     * @return Command for the text. {@code Null} if there is no such command.
-     */
-    @Nullable public static SnapshotSubcommand of(String text) {
-        for (SnapshotSubcommand cmd : values()) {
-            if (cmd.name.equalsIgnoreCase(text))
-                return cmd;
+    /** {@inheritDoc} */
+    @Override public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
+        try (GridClient client = Command.startClient(clientCfg)) {
+            return executeTaskByNameOnNode(client, taskCls.getName(), arg(), null, clientCfg);
         }
+    }
 
-        throw new IllegalArgumentException("Expected correct action: " + text);
+    /** {@inheritDoc} */
+    @Override public Object arg() {
+        return cmdArg;
     }
 
-    /**
-     * @return Task class name to execute.
-     */
-    public String taskName() {
-        return taskName;
+    /** {@inheritDoc} */
+    @Override public void parseArguments(CommandArgIterator argIter) {
+        cmdArg = argIter.nextArg("Expected snapshot name.");
+
+        if (argIter.hasNextSubArg())
+            throw new IllegalArgumentException("Invalid argument: " + argIter.peekNextArg() + '.');

Review comment:
       May be it is more clear to change 'Invalid argument` -> `Unexpected argument`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org