This is an automated email from the ASF dual-hosted git repository.

NSAmelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 60bae2c1cdb IGNITE-29298 Fix null cluster name in the control.sh 
--set-state confirmation prompt (#13835)
60bae2c1cdb is described below

commit 60bae2c1cdbbd833c9802e65ead7396194594d17
Author: Nikita Amelchev <[email protected]>
AuthorDate: Wed Nov 18 17:13:32 2026 +0300

    IGNITE-29298 Fix null cluster name in the control.sh --set-state 
confirmation prompt (#13835)
---
 .../apache/ignite/util/GridCommandHandlerTest.java | 30 ++++++++++++---------
 .../internal/management/DeactivateCommand.java     | 22 +--------------
 .../internal/management/SetStateCommand.java       | 31 +++++++++++++++++++++-
 3 files changed, 49 insertions(+), 34 deletions(-)

diff --git 
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
 
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
index fae36b6a938..2b57441caa6 100644
--- 
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
+++ 
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
@@ -698,12 +698,22 @@ public class GridCommandHandlerTest extends 
GridCommandHandlerClusterPerMethodAb
         IgniteEx igniteEx,
         String clusterName
     ) {
-        deactivateWithCheckClusterNameInConfirmation(igniteEx, clusterName);
+        String prompt = "Warning: the command will deactivate a cluster \"" + 
clusterName + "\".";
+
+        deactivateWithCheckClusterNameInConfirmation(igniteEx, prompt, 
"--deactivate");
 
         igniteEx.cluster().state(ACTIVE);
         assertTrue(igniteEx.cluster().state().active());
 
-        deactivateWithCheckClusterNameInConfirmation(igniteEx, clusterName);
+        deactivateWithCheckClusterNameInConfirmation(igniteEx, prompt, 
"--deactivate");
+
+        igniteEx.cluster().state(ACTIVE);
+
+        deactivateWithCheckClusterNameInConfirmation(
+            igniteEx,
+            "Warning: the command will change state of cluster with name \"" + 
clusterName + "\" to INACTIVE.",
+            "--set-state", "INACTIVE"
+        );
     }
 
     /**
@@ -711,23 +721,19 @@ public class GridCommandHandlerTest extends 
GridCommandHandlerClusterPerMethodAb
      * confirmation.
      *
      * @param igniteEx Node.
-     * @param clusterName Cluster name to check in the confirmation message.
+     * @param prompt Confirmation message with the cluster name.
+     * @param cmd Deactivation command.
      * */
-    private void deactivateWithCheckClusterNameInConfirmation(IgniteEx 
igniteEx, String clusterName) {
+    private void deactivateWithCheckClusterNameInConfirmation(IgniteEx 
igniteEx, String prompt, String... cmd) {
         autoConfirmation = false;
         injectTestSystemOut();
         injectTestSystemIn(CONFIRM_MSG);
 
-        assertEquals(EXIT_CODE_OK, execute("--deactivate"));
+        assertEquals(EXIT_CODE_OK, execute(cmd));
         assertFalse(igniteEx.cluster().state().active());
 
-        if (cliCommandHandler()) {
-            assertContains(
-                log,
-                testOut.toString(),
-                "Warning: the command will deactivate a cluster \"" + 
clusterName + "\"."
-            );
-        }
+        if (cliCommandHandler())
+            assertContains(log, testOut.toString(), prompt);
     }
 
     /**
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java
index ccd60139e39..348c0706be3 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/management/DeactivateCommand.java
@@ -17,21 +17,14 @@
 
 package org.apache.ignite.internal.management;
 
-import java.util.Collections;
 import java.util.function.Consumer;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.client.IgniteClient;
-import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.client.thin.ClientClusterImpl;
 import org.apache.ignite.internal.cluster.IgniteClusterEx;
-import org.apache.ignite.internal.management.api.CommandUtils;
 import org.apache.ignite.internal.management.api.NativeCommand;
 import org.apache.ignite.internal.management.api.NoArg;
 import org.apache.ignite.internal.management.api.PreparableCommand;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.visor.misc.VisorIdAndTagViewTask;
-import org.apache.ignite.internal.visor.misc.VisorIdAndTagViewTaskResult;
 import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.cluster.ClusterState.INACTIVE;
@@ -83,20 +76,7 @@ public class DeactivateCommand implements 
NativeCommand<DeactivateCommandArg, No
         DeactivateCommandArg arg,
         Consumer<String> printer
     ) throws Exception {
-        String clusterName;
-
-        if (ignite != null)
-            clusterName = ((IgniteEx)ignite).context().cluster().clusterName();
-        else {
-            ClusterNode node = F.first(CommandUtils.nodes(client, ignite));
-
-            VisorIdAndTagViewTaskResult idAndTag = 
CommandUtils.execute(client, ignite,
-                VisorIdAndTagViewTask.class, null, 
Collections.singleton(node));
-
-            clusterName = idAndTag.clusterName();
-        }
-
-        arg.clusterName(clusterName);
+        arg.clusterName(SetStateCommand.clusterName(client, ignite));
 
         return true;
     }
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java
index ce27f63f074..588feed3fe9 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/management/SetStateCommand.java
@@ -17,17 +17,23 @@
 
 package org.apache.ignite.internal.management;
 
+import java.util.Collections;
 import java.util.function.Consumer;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.client.IgniteClient;
 import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.client.thin.ClientClusterImpl;
 import org.apache.ignite.internal.cluster.IgniteClusterEx;
+import org.apache.ignite.internal.management.api.CommandUtils;
 import org.apache.ignite.internal.management.api.NativeCommand;
+import org.apache.ignite.internal.management.api.PreparableCommand;
+import org.apache.ignite.internal.visor.misc.VisorIdAndTagViewTask;
+import org.apache.ignite.internal.visor.misc.VisorIdAndTagViewTaskResult;
 import org.jetbrains.annotations.Nullable;
 
 /** */
-public class SetStateCommand implements NativeCommand<SetStateCommandArg, 
Boolean> {
+public class SetStateCommand implements NativeCommand<SetStateCommandArg, 
Boolean>, PreparableCommand<SetStateCommandArg, Boolean> {
     /** {@inheritDoc} */
     @Override public String description() {
         return "Change cluster state";
@@ -70,4 +76,27 @@ public class SetStateCommand implements 
NativeCommand<SetStateCommandArg, Boolea
         return "Warning: the command will change state of cluster " +
             "with name \"" + arg.clusterName() + "\" to " + arg.state() + ".";
     }
+
+    /** {@inheritDoc} */
+    @Override public boolean prepare(
+        @Nullable IgniteClient client,
+        @Nullable Ignite ignite,
+        SetStateCommandArg arg,
+        Consumer<String> printer
+    ) throws Exception {
+        arg.clusterName(clusterName(client, ignite));
+
+        return true;
+    }
+
+    /** */
+    static String clusterName(@Nullable IgniteClient client, @Nullable Ignite 
ignite) throws Exception {
+        if (ignite != null)
+            return ((IgniteEx)ignite).context().cluster().clusterName();
+
+        VisorIdAndTagViewTaskResult idAndTag = CommandUtils.execute(client, 
null,
+            VisorIdAndTagViewTask.class, null, 
Collections.singleton(client.cluster().forServers().node()));
+
+        return idAndTag.clusterName();
+    }
 }

Reply via email to