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

namelchev 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 a09b821cb13 IGNITE-24216 Fixed default node in the control.sh utility 
(#11817)
a09b821cb13 is described below

commit a09b821cb1338517018cec6ca15da0c141c1de71
Author: Sergey Korotkov <[email protected]>
AuthorDate: Thu Jan 16 21:20:26 2025 +0700

    IGNITE-24216 Fixed default node in the control.sh utility (#11817)
---
 .../commandline/CliIgniteClientInvoker.java        | 14 +++-
 .../testsuites/IgniteControlUtilityTestSuite2.java |  5 +-
 .../util/GridCommandHandlerClusterByClassTest.java |  2 +-
 .../org/apache/ignite/util/IdleVerifyDumpTest.java | 78 ++++++++++++++++++++++
 4 files changed, 96 insertions(+), 3 deletions(-)

diff --git 
a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java
 
b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java
index 637b4dd7b1d..19e56ec50cb 100644
--- 
a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java
+++ 
b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.java
@@ -17,9 +17,11 @@
 
 package org.apache.ignite.internal.commandline;
 
+import java.util.Collection;
 import java.util.function.Consumer;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.ClientConfiguration;
 import org.apache.ignite.internal.client.GridClientNode;
 import org.apache.ignite.internal.client.GridClientNodeStateBeforeStart;
@@ -34,6 +36,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import org.jetbrains.annotations.Nullable;
 
 import static 
org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.MANAGEMENT_CLIENT_ATTR;
+import static 
org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT;
 
 /**
  * Adapter of new management API command for {@code control.sh} execution flow.
@@ -54,7 +57,16 @@ public class CliIgniteClientInvoker<A extends 
IgniteDataTransferObject> extends
 
     /** {@inheritDoc} */
     @Override protected GridClientNode defaultNode() {
-        return 
CommandUtils.clusterToClientNode(igniteClient().cluster().forOldest().node());
+        String[] addr = cfg.getAddresses()[0].split(":");
+
+        String host = addr[0];
+        String port = addr[1];
+
+        Collection<ClusterNode> nodes = igniteClient().cluster().nodes();
+
+        return CommandUtils.clusterToClientNode(F.find(nodes, U.oldest(nodes, 
null), node ->
+            (node.hostNames().contains(host) || 
node.addresses().contains(host))
+                && 
port.equals(node.attribute(CLIENT_LISTENER_PORT).toString())));
     }
 
     /** {@inheritDoc} */
diff --git 
a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite2.java
 
b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite2.java
index 3c9d373bb4a..4d6feb57851 100644
--- 
a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite2.java
+++ 
b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite2.java
@@ -34,6 +34,7 @@ import 
org.apache.ignite.util.GridCommandHandlerIndexRebuildStatusTest;
 import org.apache.ignite.util.GridCommandHandlerPropertiesTest;
 import org.apache.ignite.util.GridCommandHandlerScheduleIndexRebuildTest;
 import org.apache.ignite.util.GridCommandHandlerTracingConfigurationTest;
+import org.apache.ignite.util.IdleVerifyDumpTest;
 import org.apache.ignite.util.MetricCommandTest;
 import org.apache.ignite.util.PerformanceStatisticsCommandTest;
 import org.apache.ignite.util.SystemViewCommandTest;
@@ -72,7 +73,9 @@ import org.junit.runners.Suite;
     CdcCommandTest.class,
     CdcResendCommandTest.class,
 
-    SecurityCommandHandlerPermissionsTest.class
+    SecurityCommandHandlerPermissionsTest.class,
+
+    IdleVerifyDumpTest.class
 })
 public class IgniteControlUtilityTestSuite2 {
 }
diff --git 
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
 
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
index e9fd8090a17..478984e55d2 100644
--- 
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
+++ 
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
@@ -1250,7 +1250,7 @@ public class GridCommandHandlerClusterByClassTest extends 
GridCommandHandlerClus
     /**
      * @return Build matcher for dump file name.
      */
-    @NotNull private Matcher dumpFileNameMatcher() {
+    @NotNull static Matcher dumpFileNameMatcher() {
         Pattern fileNamePattern = Pattern.compile(".*" + 
IdleVerifyDumpTask.class.getSimpleName()
             + " successfully written output to '(.*)'");
         return fileNamePattern.matcher(testOut.toString());
diff --git 
a/modules/control-utility/src/test/java/org/apache/ignite/util/IdleVerifyDumpTest.java
 
b/modules/control-utility/src/test/java/org/apache/ignite/util/IdleVerifyDumpTest.java
new file mode 100644
index 00000000000..de3996bb172
--- /dev/null
+++ 
b/modules/control-utility/src/test/java/org/apache/ignite/util/IdleVerifyDumpTest.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.ignite.util;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.regex.Matcher;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.junit.Test;
+
+import static 
org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
+import static org.apache.ignite.testframework.GridTestUtils.assertContains;
+import static 
org.apache.ignite.util.GridCommandHandlerClusterByClassTest.dumpFileNameMatcher;
+
+/** */
+public class IdleVerifyDumpTest extends 
GridCommandHandlerClusterByClassAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setWorkDirectory(nodeWorkDirectory(igniteInstanceName));
+    }
+
+    /**
+     * Test ensuring that idle verify dump output file is created exactly
+     * on server node specified via the --host parameter.
+     */
+    @Test
+    public void testDumpResultMatchesConnection() throws Exception {
+        injectTestSystemOut();
+
+        client.createCache(DEFAULT_CACHE_NAME).put(1, 1);
+
+        checkDump(0);
+
+        checkDump(1);
+    }
+
+    /** */
+    private void checkDump(int nodeIdx) throws Exception {
+        assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump", 
"--port", connectorPort(grid(nodeIdx))));
+
+        Matcher fileNameMatcher = dumpFileNameMatcher();
+
+        assertTrue(fileNameMatcher.find());
+
+        Path dumpFileName = Paths.get(fileNameMatcher.group(1));
+
+        String dumpRes = new String(Files.readAllBytes(dumpFileName));
+
+        assertContains(log, dumpRes, "The check procedure has finished, no 
conflicts have been found.");
+
+        assertContains(log, dumpFileName.toString(), 
nodeWorkDirectory(getTestIgniteInstanceName(nodeIdx)));
+    }
+
+    /** */
+    private String nodeWorkDirectory(String igniteInstanceName) throws 
IgniteCheckedException {
+        return new File(U.defaultWorkDirectory(), 
igniteInstanceName).getAbsolutePath();
+    }
+}

Reply via email to