ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [02/22] incubator-ignite git commit: # ignite-830 Add sort for node addresses in Visor console.
Date Tue, 26 May 2015 08:16:53 GMT
# ignite-830 Add sort for node addresses in Visor console.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/195839c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/195839c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/195839c7

Branch: refs/heads/ignite-471-2
Commit: 195839c745c64e3b7f7a23f1cefaad2e59601ec1
Parents: d617759
Author: Andrey <anovikov@gridgain.com>
Authored: Thu Apr 30 13:57:22 2015 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Thu Apr 30 13:57:22 2015 +0700

----------------------------------------------------------------------
 .../visor/commands/node/VisorNodeCommand.scala  |  2 +-
 .../commands/tasks/VisorTasksCommand.scala      |  2 +-
 .../scala/org/apache/ignite/visor/visor.scala   | 61 ++++++++++++++++++--
 3 files changed, 57 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/195839c7/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
index 064d33e..f4a1f87 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala
@@ -159,7 +159,7 @@ class VisorNodeCommand extends VisorConsoleCommand {
                         t += ("ID8", nid8(node))
                         t += ("Order", node.order)
 
-                        (0 /: node.addresses())((b, a) => { t += ("Address (" + b + ")",
a); b + 1 })
+                        (0 /: sortAddresses(node.addresses))((b, a) => { t += ("Address
(" + b + ")", a); b + 1 })
 
                         val m = node.metrics
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/195839c7/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
index 16bce29..e158506 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala
@@ -1216,7 +1216,7 @@ class VisorTasksCommand extends VisorConsoleCommand {
 
                 eLst.foreach(e => {
                     e.nodeIds.foreach(id => {
-                        val host = ignite.cluster.node(id).addresses.headOption
+                        val host = sortAddresses(ignite.cluster.node(id).addresses).headOption
 
                         if (host.isDefined) {
                             var eSet = hMap.getOrElse(host.get, Set.empty[VisorExecution])

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/195839c7/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
index 356c80a..293fe58 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
@@ -1699,7 +1699,7 @@ object visor extends VisorTag {
         ignite.cluster.nodes().foreach(n => {
             setVarIfAbsent(nid8(n), "n")
 
-            val ip = n.addresses().headOption
+            val ip = sortAddresses(n.addresses()).headOption
 
             if (ip.isDefined)
                 setVarIfAbsent(ip.get, "h")
@@ -1714,7 +1714,7 @@ object visor extends VisorTag {
                         val node = ignite.cluster.node(de.eventNode().id())
 
                         if (node != null) {
-                            val ip = node.addresses().headOption
+                            val ip = sortAddresses(node.addresses).headOption
 
                             if (ip.isDefined)
                                 setVarIfAbsent(ip.get, "h")
@@ -1743,11 +1743,11 @@ object visor extends VisorTag {
                         if (nv.isDefined)
                             mem.remove(nv.get._1)
 
-                        val ip = de.eventNode().addresses.headOption
+                        val ip = sortAddresses(de.eventNode().addresses).headOption
 
                         if (ip.isDefined) {
                             val last = !ignite.cluster.nodes().exists(n =>
-                                n.addresses.size > 0 && n.addresses.head == ip.get
+                                n.addresses.size > 0 && sortAddresses(n.addresses).head
== ip.get
                             )
 
                             if (last) {
@@ -1858,7 +1858,7 @@ object visor extends VisorTag {
             id8 +
                 (if (v.isDefined) "(@" + v.get._1 + ")" else "") +
                 ", " +
-                (if (n == null) NA else n.addresses().headOption.getOrElse(NA))
+                (if (n == null) NA else sortAddresses(n.addresses).headOption.getOrElse(NA))
         }
     }
 
@@ -2099,7 +2099,7 @@ object visor extends VisorTag {
                 neighbors.foreach(n => {
                     id8s = id8s :+ nodeId8(n.id)
 
-                    ips = ips ++ n.addresses()
+                    ips = ips ++ n.addresses
 
                     cpuLoadSum += n.metrics().getCurrentCpuLoad
 
@@ -2834,4 +2834,53 @@ object visor extends VisorTag {
         else
             Long.MaxValue
     }
+
+    /**
+     * Sort addresses to properly display in Visor.
+     *
+     * @param addrs Addresses to sort.
+     * @return Sorted list.
+     */
+    def sortAddresses(addrs: Iterable[String]) = {
+        def ipToLong(ip: String) = {
+            try {
+                val octets = if (ip.contains(".")) ip.split('.') else ip.split(':')
+
+                var dec = BigDecimal.valueOf(0L)
+
+                for (i <- 0 until octets.length) dec += octets(i).toLong * math.pow(256,
octets.length - 1 - i).toLong
+
+                dec
+            }
+            catch {
+                case _: Exception => BigDecimal.valueOf(0L)
+            }
+        }
+
+        /**
+         * Sort addresses to properly display in Visor.
+         *
+         * @param addr Address to detect type for.
+         * @return IP class type for sorting in order: public addresses IPv4 + private IPv4
+ localhost + IPv6.
+         */
+        def addrType(addr: String) = {
+            if (addr.contains(':'))
+                4 // IPv6
+            else {
+                try {
+                    InetAddress.getByName(addr) match {
+                        case ip if ip.isLoopbackAddress => 3 // localhost
+                        case ip if ip.isSiteLocalAddress => 2 // private IPv4
+                        case _ => 1 // other IPv4
+                    }
+                }
+                catch {
+                    case ignore: UnknownHostException => 5
+                }
+            }
+        }
+
+        addrs.map(addr => (addrType(addr), ipToLong(addr), addr)).toSeq.
+            sortWith((l, r) => if (l._1 == r._1) l._2.compare(r._2) < 0 else l._1 <
r._1).map(_._3)
+    }
 }


Mime
View raw message