You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2018/11/09 15:01:19 UTC
ignite git commit: IGNITE-9970 Added ability to set node ID for visor
idle verify dump task - Fixes #5227.
Repository: ignite
Updated Branches:
refs/heads/master f6d6a47f5 -> 1fee1fd18
IGNITE-9970 Added ability to set node ID for visor idle verify dump task - Fixes #5227.
Signed-off-by: Alexey Goncharuk <al...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1fee1fd1
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1fee1fd1
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1fee1fd1
Branch: refs/heads/master
Commit: 1fee1fd18025bb8641199ce980563fa80f2f136f
Parents: f6d6a47
Author: Alexey Stelmak <sp...@gmail.com>
Authored: Fri Nov 9 17:57:17 2018 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Fri Nov 9 18:00:31 2018 +0300
----------------------------------------------------------------------
.../internal/commandline/CommandHandler.java | 73 +++++++++++++++++---
1 file changed, 62 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fee1fd1/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java
index 167a806..e37da81 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java
@@ -18,6 +18,8 @@
package org.apache.ignite.internal.commandline;
import java.io.Console;
+import java.io.IOException;
+import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -34,6 +36,7 @@ import java.util.UUID;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.compute.ComputeTask;
@@ -65,6 +68,7 @@ import org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2;
import org.apache.ignite.internal.processors.cache.verify.PartitionHashRecord;
import org.apache.ignite.internal.processors.cache.verify.PartitionKey;
import org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsTaskV2;
+import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.SB;
@@ -115,6 +119,7 @@ import org.apache.ignite.internal.visor.verify.VisorViewCacheCmd;
import org.apache.ignite.internal.visor.verify.VisorViewCacheTask;
import org.apache.ignite.internal.visor.verify.VisorViewCacheTaskArg;
import org.apache.ignite.internal.visor.verify.VisorViewCacheTaskResult;
+import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteProductVersion;
import org.apache.ignite.plugin.security.SecurityCredentials;
import org.apache.ignite.plugin.security.SecurityCredentialsBasicProvider;
@@ -582,6 +587,35 @@ public class CommandHandler {
}
/**
+ * @param client Client.
+ *
+ * @return List of hosts.
+ */
+ private Stream<IgniteBiTuple<GridClientNode, String>> listHosts(GridClient client) throws GridClientException {
+ return client.compute().nodes(GridClientNode::connectable).stream()
+ .flatMap(node -> Stream.concat(
+ node.tcpAddresses() == null ? Stream.empty() : node.tcpAddresses().stream(),
+ node.tcpHostNames() == null ? Stream.empty() : node.tcpHostNames().stream()
+ )
+ .map(addr -> new IgniteBiTuple<>(node, addr + ":" + node.tcpPort())));
+ }
+
+ /**
+ * @param client Client.
+ *
+ * @return List of hosts.
+ */
+ private Stream<IgniteBiTuple<GridClientNode, List<String>>> listHostsByClientNode(GridClient client) throws GridClientException {
+ return client.compute().nodes(GridClientNode::connectable).stream()
+ .map(node -> new IgniteBiTuple<>(node,
+ Stream.concat(
+ node.tcpAddresses() == null ? Stream.empty() : node.tcpAddresses().stream(),
+ node.tcpHostNames() == null ? Stream.empty() : node.tcpHostNames().stream()
+ )
+ .map(addr -> addr + ":" + node.tcpPort()).collect(Collectors.toList())));
+ }
+
+ /**
* @param client Client
* @param taskClsName Task class name.
* @param taskArgs Task args.
@@ -589,7 +623,12 @@ public class CommandHandler {
* @return Task result.
* @throws GridClientException If failed to execute task.
*/
- private <R> R executeTaskByNameOnNode(GridClient client, String taskClsName, Object taskArgs, UUID nodeId
+ @SuppressWarnings("unchecked")
+ private <R> R executeTaskByNameOnNode(
+ GridClient client,
+ String taskClsName,
+ Object taskArgs,
+ UUID nodeId
) throws GridClientException {
GridClientCompute compute = client.compute();
@@ -609,22 +648,34 @@ public class CommandHandler {
GridClientNode node = null;
if (nodeId == null) {
- Collection<GridClientNode> nodes = compute.nodes(GridClientNode::connectable);
-
// Prefer node from connect string.
- String origAddr = clientCfg.getServers().iterator().next();
+ final String cfgAddr = clientCfg.getServers().iterator().next();
- for (GridClientNode clientNode : nodes) {
- Iterator<String> it = F.concat(clientNode.tcpAddresses().iterator(), clientNode.tcpHostNames().iterator());
+ String[] parts = cfgAddr.split(":");
- while (it.hasNext()) {
- if (origAddr.equals(it.next() + ":" + clientNode.tcpPort())) {
- node = clientNode;
+ if (DFLT_HOST.equals(parts[0])) {
+ InetAddress addr;
- break;
- }
+ try {
+ addr = IgniteUtils.getLocalHost();
}
+ catch (IOException e) {
+ throw new GridClientException("Can't get localhost name.", e);
+ }
+
+ if (addr.isLoopbackAddress())
+ throw new GridClientException("Can't find localhost name.");
+
+ String origAddr = addr.getHostName() + ":" + parts[1];
+
+ node = listHosts(client).filter(tuple -> origAddr.equals(tuple.get2())).findFirst().map(IgniteBiTuple::get1).orElse(null);
+
+ if (node == null)
+ node = listHostsByClientNode(client).filter(tuple -> tuple.get2().size() == 1 && cfgAddr.equals(tuple.get2().get(0))).
+ findFirst().map(IgniteBiTuple::get1).orElse(null);
}
+ else
+ node = listHosts(client).filter(tuple -> cfgAddr.equals(tuple.get2())).findFirst().map(IgniteBiTuple::get1).orElse(null);
// Otherwise choose random node.
if (node == null)