# IGNITE-737. Rework Visor code to support ClusterGroup.forXXX(cacheName) on 
daemon node.


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

Branch: refs/heads/ignite-sprint-4
Commit: c756aa29d8cab904af5af4cbccacc94689c70c98
Parents: cb7347b
Author: AKuznetsov <akuznet...@gridgain.com>
Authored: Thu Apr 16 17:51:39 2015 +0700
Committer: AKuznetsov <akuznet...@gridgain.com>
Committed: Thu Apr 16 17:51:39 2015 +0700

----------------------------------------------------------------------
 .../commands/cache/VisorCacheClearCommand.scala | 15 +++---
 .../commands/cache/VisorCacheSwapCommand.scala  | 49 +++++++++-----------
 2 files changed, 32 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c756aa29/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommand.scala
----------------------------------------------------------------------
diff --git 
a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommand.scala
 
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommand.scala
index f401d15..1d5a1f6 100644
--- 
a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommand.scala
+++ 
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheClearCommand.scala
@@ -100,20 +100,23 @@ class VisorCacheClearCommand {
             case Some(name) => name
         }
 
-        val prj = projectionForNode(node)
+        val n = projectionForNode(node).node()
 
-        if (prj.nodes().isEmpty)
+        if (n == null)
             scold(messageNodeNotFound(node)).^^
 
         val t = VisorTextTable()
 
         t #= ("Node ID8(@)", "Cache Size Before", "Cache Size After")
 
-        prj.nodes().headOption.foreach(node => {
-            val res = executeOne(node.id(), classOf[VisorCacheClearTask], 
cacheName)
+        try {
+            val res = executeOne(n.id(), classOf[VisorCacheClearTask], 
cacheName)
 
-            t += (nodeId8(node.id()), res.get1(), res.get2())
-        })
+            t += (nodeId8(n.id()), res.get1(), res.get2())
+        }
+        catch {
+            case e: Throwable =>  scold(e.getMessage).^^
+        }
 
         println("Cleared cache with name: " + escapeName(cacheName))
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c756aa29/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheSwapCommand.scala
----------------------------------------------------------------------
diff --git 
a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheSwapCommand.scala
 
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheSwapCommand.scala
index 5589f8c..d48e41d 100644
--- 
a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheSwapCommand.scala
+++ 
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheSwapCommand.scala
@@ -28,9 +28,7 @@ import org.apache.ignite.visor.commands.VisorTextTable
 import org.apache.ignite.visor.visor
 import visor._
 
-import scala.collection.JavaConversions._
 import scala.language.{implicitConversions, reflectiveCalls}
-import scala.util.control.Breaks._
 
 /**
  * ==Overview==
@@ -87,7 +85,7 @@ class VisorCacheSwapCommand {
      *
      * @param argLst Command arguments.
      */
-    def swap(argLst: ArgList, node: Option[ClusterNode]) = breakable {
+    def swap(argLst: ArgList, node: Option[ClusterNode]) {
         val cacheArg = argValue("c", argLst)
 
         val cacheName = cacheArg match {
@@ -95,40 +93,39 @@ class VisorCacheSwapCommand {
 
             case Some(s) if s.startsWith("@") =>
                 warn("Can't find cache variable with specified name: " + s,
-                    "Type 'cache' to see available cache variables."
-                )
+                    "Type 'cache' to see available cache variables.")
 
-                break()
+                return
 
             case Some(name) => name
         }
 
+        val n = projectionForNode(node).node()
 
-        val prj = projectionForNode(node)
+        if (n != null) {
+            try {
+                val r = executeOne(n.id(), classOf[VisorCacheSwapBackupsTask], 
Collections.singleton(cacheName)).get(cacheName)
 
-        if (prj.nodes().isEmpty) {
-            val msg =
-                if (cacheName == null)
-                    "Can't find nodes with default cache."
-                else
-                    "Can't find nodes with specified cache: " + cacheName
-
-            scold(messageNodeNotFound(node, Some(msg))).^^
-        }
-
-        val t = VisorTextTable()
+                if (r != null) {
+                    val t = VisorTextTable()
 
-        t #= ("Node ID8(@)", "Entries Swapped", "Cache Size Before", "Cache 
Size After")
+                    t #= ("Node ID8(@)", "Entries Swapped", "Cache Size 
Before", "Cache Size After")
 
-        val nid = prj.node().id()
+                    t += (nodeId8(n.id()), r.get1() - r.get2(), r.get1(), 
r.get2())
 
-        val r = executeOne(nid, classOf[VisorCacheSwapBackupsTask], 
Collections.singleton(cacheName)).get(cacheName)
+                    println("Swapped entries in cache: " + 
escapeName(cacheName))
 
-        t += (nodeId8(nid), r.get1() - r.get2(), r.get1(), r.get2())
-
-        println("Swapped entries in cache: " + escapeName(cacheName))
-
-        t.render()
+                    t.render()
+                }
+                else
+                    scold("Can't find nodes for cache: " + 
escapeName(cacheName))
+            }
+            catch {
+                case e: Exception => scold(e.getMessage)
+            }
+        }
+        else
+            scold(messageNodeNotFound(node, Some("Can't find nodes for cache: 
" + escapeName(cacheName))))
     }
 }
 

Reply via email to