This is an automated email from the ASF dual-hosted git repository. ptupitsyn pushed a commit to branch ignite-16771 in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/ignite-16771 by this push: new 9916a2f81 Add IgniteClient.connections 9916a2f81 is described below commit 9916a2f81c0e8a016397ba18f4d2573aa48f029f Author: Pavel Tupitsyn <ptupit...@apache.org> AuthorDate: Thu Apr 14 18:52:45 2022 +0300 Add IgniteClient.connections --- .../java/org/apache/ignite/client/IgniteClient.java | 9 +++++++++ .../ignite/internal/client/ReliableChannel.java | 20 ++++++++++++++++++++ .../ignite/internal/client/TcpIgniteClient.java | 6 ++++++ .../org/apache/ignite/client/ClientComputeTest.java | 2 ++ .../app/client/ItThinClientConnectionTest.java | 7 +++++++ 5 files changed, 44 insertions(+) diff --git a/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java b/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java index f7c0908f1..afa48b7fc 100644 --- a/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java +++ b/modules/client/src/main/java/org/apache/ignite/client/IgniteClient.java @@ -23,6 +23,7 @@ import static org.apache.ignite.client.IgniteClientConfiguration.DFLT_RECONNECT_ import static org.apache.ignite.client.IgniteClientConfiguration.DFLT_RECONNECT_THROTTLING_RETRIES; import static org.apache.ignite.internal.client.ClientUtils.sync; +import java.util.List; import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; @@ -31,6 +32,7 @@ import java.util.function.Function; import org.apache.ignite.Ignite; import org.apache.ignite.internal.client.IgniteClientConfigurationImpl; import org.apache.ignite.internal.client.TcpIgniteClient; +import org.apache.ignite.network.ClusterNode; /** * Ignite client entry point. @@ -43,6 +45,13 @@ public interface IgniteClient extends Ignite { */ IgniteClientConfiguration configuration(); + /** + * Gets active client connections. + * + * @return List of connected cluster nodes. + */ + List<ClusterNode> connections(); + /** * Gets a new client builder. * diff --git a/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java b/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java index 49cda0aac..621551af7 100644 --- a/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java +++ b/modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java @@ -45,6 +45,7 @@ import org.apache.ignite.client.RetryPolicy; import org.apache.ignite.client.RetryPolicyContext; import org.apache.ignite.internal.client.io.ClientConnectionMultiplexer; import org.apache.ignite.internal.client.io.netty.NettyClientConnectionMultiplexer; +import org.apache.ignite.network.ClusterNode; /** * Communication channel with failover and partition awareness. @@ -122,6 +123,25 @@ public final class ReliableChannel implements AutoCloseable { } } + /** + * Gets active client connections. + * + * @return List of connected cluster nodes. + */ + public List<ClusterNode> connections() { + List<ClusterNode> res = new ArrayList<>(channels.size()); + + for (var holder : channels) { + var ch = holder.ch; + + if (ch != null) { + res.add(ch.protocolContext().clusterNode()); + } + } + + return res; + } + /** * Sends request and handles response asynchronously. * diff --git a/modules/client/src/main/java/org/apache/ignite/internal/client/TcpIgniteClient.java b/modules/client/src/main/java/org/apache/ignite/internal/client/TcpIgniteClient.java index fbcee240b..06510ed33 100644 --- a/modules/client/src/main/java/org/apache/ignite/internal/client/TcpIgniteClient.java +++ b/modules/client/src/main/java/org/apache/ignite/internal/client/TcpIgniteClient.java @@ -183,6 +183,12 @@ public class TcpIgniteClient implements IgniteClient { return cfg; } + /** {@inheritDoc} */ + @Override + public List<ClusterNode> connections() { + return ch.connections(); + } + /** * Sends ClientMessage request to server side asynchronously and returns result future. * diff --git a/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java b/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java index bf9504028..b4c72f8ef 100644 --- a/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java +++ b/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java @@ -48,6 +48,8 @@ public class ClientComputeTest { initServers(reqId -> false); try (var client = getClient()) { + Thread.sleep(500); + String res1 = client.compute().<String>execute(getClusterNodes("s1"), "job").join(); String res2 = client.compute().<String>execute(getClusterNodes("s2"), "job").join(); String res3 = client.compute().<String>execute(getClusterNodes("s3"), "job").join(); diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java index 7a482904d..13d2896bb 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java @@ -17,12 +17,15 @@ package org.apache.ignite.internal.runner.app.client; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import org.apache.ignite.client.IgniteClient; import org.apache.ignite.internal.testframework.WorkDirectoryExtension; +import org.apache.ignite.network.ClusterNode; import org.apache.ignite.table.RecordView; import org.apache.ignite.table.Table; import org.apache.ignite.table.Tuple; @@ -62,6 +65,10 @@ public class ItThinClientConnectionTest extends ItAbstractThinClientTest { assertEquals("Hello", pojoView.get(null, new TestPojo(1)).val); assertTrue(recView.delete(null, keyTuple)); + + List<ClusterNode> nodes = client.connections(); + assertEquals(1, nodes.size()); + assertThat(nodes.get(0).name(), startsWith("ItThinClientConnectionTest_null_")); } } }