# ignite-737 Fixed for data 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/ce0d9dcf Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ce0d9dcf Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ce0d9dcf Branch: refs/heads/ignite-sprint-4 Commit: ce0d9dcf122a5ff6e675bf80cd31862489f97cc1 Parents: 876b3a1 Author: Andrey <anovi...@gridgain.com> Authored: Wed Apr 22 15:41:25 2015 +0700 Committer: Andrey <anovi...@gridgain.com> Committed: Wed Apr 22 15:41:25 2015 +0700 ---------------------------------------------------------------------- .../ignite/visor/commands/VisorTextTable.scala | 2 + .../commands/cache/VisorCacheClearCommand.scala | 31 +++++------- .../commands/cache/VisorCacheCommand.scala | 15 +++--- .../commands/cache/VisorCacheScanCommand.scala | 28 ++++------- .../commands/cache/VisorCacheStopCommand.scala | 16 +++--- .../commands/cache/VisorCacheSwapCommand.scala | 53 ++++++++++---------- .../scala/org/apache/ignite/visor/visor.scala | 32 ++++++------ 7 files changed, 83 insertions(+), 94 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce0d9dcf/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorTextTable.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorTextTable.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorTextTable.scala index 5f02b42..5cb40b9 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorTextTable.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorTextTable.scala @@ -507,6 +507,8 @@ class VisorTextTable { print(tbl.toString) } + + def nonEmpty = rows.nonEmpty } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce0d9dcf/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 5603f8f..2588551 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 @@ -20,7 +20,7 @@ package org.apache.ignite.visor.commands.cache import org.apache.ignite.internal.visor.cache.VisorCacheClearTask import org.apache.ignite.internal.visor.util.VisorTaskUtils._ -import org.apache.ignite.cluster.ClusterNode +import org.apache.ignite.cluster.{ClusterGroupEmptyException, ClusterNode} import org.apache.ignite.visor.commands.VisorTextTable import org.apache.ignite.visor.visor @@ -98,29 +98,24 @@ class VisorCacheClearCommand { case Some(name) => name } - val grp = groupForDataNode(node, cacheName) + try { + val nid = groupForDataNode(node, cacheName).forRandom().node().id() - if (grp.nodes().isEmpty) - scold("Can't find nodes with specified cache: " + escapeName(cacheName)) - else { - try { - val t = VisorTextTable() + val t = VisorTextTable() - t #= ("Node ID8(@)", "Cache Size Before", "Cache Size After") + t #= ("Node ID8(@)", "Cache Size Before", "Cache Size After") - val nid = grp.forRandom().node().id() + val res = executeOne(nid, classOf[VisorCacheClearTask], cacheName) - val res = executeOne(nid, classOf[VisorCacheClearTask], cacheName) + t += (nodeId8(nid), res.get1(), res.get2()) - t += (nodeId8(nid), res.get1(), res.get2()) + println("Cleared cache with name: " + escapeName(cacheName)) - println("Cleared cache with name: " + escapeName(cacheName)) - - t.render() - } - catch { - case e: Throwable => scold(e.getMessage) - } + t.render() + } + catch { + case e: ClusterGroupEmptyException => scold(messageNodeNotFound(node, cacheName)) + case e: Throwable => scold(e.getMessage) } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce0d9dcf/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala index c3b6462..2115535 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala @@ -29,7 +29,7 @@ import org.apache.ignite.visor.visor._ import org.jetbrains.annotations._ import java.lang.{Boolean => JavaBoolean} -import java.util.{ArrayList => JavaList, Collection => JavaCollection, UUID} +import java.util.{Collection => JavaCollection, Collections, UUID} import org.apache.ignite.internal.visor.cache._ import org.apache.ignite.internal.visor.util.VisorTaskUtils._ @@ -495,15 +495,14 @@ class VisorCacheCommand { assert(node != null) try { - val prj = groupForNode(node) + val caches: JavaCollection[String] = name.fold(Collections.emptyList[String]())(Collections.singletonList) - val nids = prj.nodes().map(_.id()) + val arg = new IgniteBiTuple(JavaBoolean.valueOf(systemCaches), caches) - val caches: JavaCollection[String] = new JavaList[String](1) - name.foreach(caches.add) - - executeMulti(nids, classOf[VisorCacheMetricsCollectorTask], - new IgniteBiTuple(JavaBoolean.valueOf(systemCaches), caches)).toList + node match { + case Some(n) => executeOne(n.id(), classOf[VisorCacheMetricsCollectorTask], arg).toList + case None => executeMulti(classOf[VisorCacheMetricsCollectorTask], arg).toList + } } catch { case e: IgniteException => Nil http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce0d9dcf/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala index f2b1924..2ff0262 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheScanCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.cache -import org.apache.ignite.cluster.ClusterNode +import org.apache.ignite.cluster.{ClusterGroupEmptyException, ClusterNode} import org.apache.ignite.lang.IgniteBiTuple import org.apache.ignite.visor.commands._ import org.apache.ignite.visor.visor._ @@ -72,7 +72,7 @@ class VisorCacheScanCommand { warn("Type 'help cache' to see how to use this command.") } - private def error(e: Exception) { + private def error(e: Throwable) { var cause: Throwable = e while (cause.getCause != null) @@ -136,20 +136,11 @@ class VisorCacheScanCommand { case Some(name) => name } - val grp = groupForDataNode(node, cacheName) - - if (grp.nodes().isEmpty) { - scold(messageNodeNotFound(node)) - - return - } - - val nid = grp.forRandom().node().id() - val firstPage = try - executeOne(nid, classOf[VisorQueryTask], new VisorQueryArg(cacheName, "SCAN", pageSize)) - match { + val grp = groupForDataNode(node, cacheName) + + executeRandom(grp, classOf[VisorQueryTask], new VisorQueryArg(cacheName, "SCAN", pageSize)) match { case x if x.get1() != null => error(x.get1()) @@ -157,14 +148,18 @@ class VisorCacheScanCommand { case x => x.get2() } catch { - case e: Exception => + case e: ClusterGroupEmptyException => + scold(messageNodeNotFound(node, cacheName)) + + return + case e: Throwable => error(e) return } if (firstPage.rows.isEmpty) { - println("Cache: " + escapeName(cacheName) + " is empty") + println(s"Cache: ${escapeName(cacheName)} is empty") return } @@ -199,7 +194,6 @@ class VisorCacheScanCommand { } case _ => return } - } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce0d9dcf/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala index 56c2e79..bf81f73 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.cache -import org.apache.ignite.cluster.ClusterNode +import org.apache.ignite.cluster.{ClusterGroupEmptyException, ClusterNode} import org.apache.ignite.visor.visor._ import org.apache.ignite.internal.visor.cache.VisorCacheStopTask @@ -92,13 +92,14 @@ class VisorCacheStopCommand { case Some(name) => name } - val grp = groupForDataNode(node, cacheName) - - if (grp.nodes().isEmpty) { - warn("Can't find nodes with specified cache: " + escapeName(cacheName), - "Type 'cache' to see available cache names.") + val grp = try { + groupForDataNode(node, cacheName) + } + catch { + case _: ClusterGroupEmptyException => + scold(messageNodeNotFound(node, cacheName)) - return + return } ask(s"Are you sure you want to stop cache: ${escapeName(cacheName)}? (y/n) [n]: ", "n") match { @@ -109,6 +110,7 @@ class VisorCacheStopCommand { println("Visor successfully stop cache: " + escapeName(cacheName)) } catch { + case _: ClusterGroupEmptyException => scold(messageNodeNotFound(node, cacheName)) case e: Exception => error(e) } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce0d9dcf/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 c475f90..f43d668 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 @@ -17,17 +17,16 @@ package org.apache.ignite.visor.commands.cache -import org.apache.ignite.internal.visor.cache.VisorCacheSwapBackupsTask -import org.apache.ignite.internal.visor.util.VisorTaskUtils._ - -import org.apache.ignite.cluster.ClusterNode +import org.apache.ignite.cluster.{ClusterGroupEmptyException, ClusterNode} +import org.apache.ignite.visor.commands.VisorTextTable +import org.apache.ignite.visor.visor._ import java.util.Collections -import org.apache.ignite.visor.commands.VisorTextTable -import org.apache.ignite.visor.visor -import visor._ +import org.apache.ignite.internal.visor.cache.VisorCacheSwapBackupsTask +import org.apache.ignite.internal.visor.util.VisorTaskUtils._ +import scala.collection.JavaConversions._ import scala.language.{implicitConversions, reflectiveCalls} /** @@ -100,33 +99,33 @@ class VisorCacheSwapCommand { case Some(name) => name } - val grp = groupForDataNode(node, cacheName) - - if (grp.nodes().isEmpty) - scold(messageNodeNotFound(node, Some("Can't find nodes for cache: " + escapeName(cacheName)))) - else - try { - val nid = grp.forRandom().node().id() + try { + val grp = groupForDataNode(node, cacheName) - val r = executeOne(nid, classOf[VisorCacheSwapBackupsTask], Collections.singleton(cacheName)).get(cacheName) + 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") + for (node <- grp.nodes(); nid <- node.id()) { + val r = executeOne(nid, classOf[VisorCacheSwapBackupsTask], Collections.singleton(cacheName)). + get(cacheName) - t += (nodeId8(nid), r.get1() - r.get2(), r.get1(), r.get2()) + if (r != null) + t +=(nodeId8(nid), r.get1() - r.get2(), r.get1(), r.get2()) + } - println("Swapped entries in cache: " + escapeName(cacheName)) + if (t.nonEmpty) { + println("Swapped entries in cache: " + escapeName(cacheName)) - t.render() - } - else - scold("Can't find nodes for cache: " + escapeName(cacheName)) - } - catch { - case e: Exception => scold(e.getMessage) + t.render() } + else + scold(messageNodeNotFound(node, cacheName)) + } + catch { + case e: ClusterGroupEmptyException => scold(messageNodeNotFound(node, cacheName)) + case e: Throwable => scold(e.getMessage) + } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce0d9dcf/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 2f2fdaf..e402162 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 @@ -260,31 +260,29 @@ object visor extends VisorTag { /** * @param node Optional node. - * @return Cluster group with specified node or projection with all remote nodes. - */ - def groupForNode(node: Option[ClusterNode]): ClusterGroup = node match { - case Some(n) => ignite.cluster.forNode(n) - case None => ignite.cluster.forRemotes() - } - - /** - * @param node Optional node. * @param cacheName Cache name to take cluster group for. * @return Cluster group with data nodes for specified cache or cluster group for specified node. */ - def groupForDataNode(node: Option[ClusterNode], cacheName: String): ClusterGroup = node match { - case Some(n) => ignite.cluster.forNode(n) - case None => ignite.cluster.forNodeIds(executeRandom(classOf[VisorCacheNodesTask], cacheName)) + def groupForDataNode(node: Option[ClusterNode], cacheName: String) = { + val grp = node match { + case Some(n) => ignite.cluster.forNode(n) + case None => ignite.cluster.forNodeIds(executeRandom(classOf[VisorCacheNodesTask], cacheName)) + } + + if (grp.nodes().isEmpty) + throw new ClusterGroupEmptyException("Topology is empty.") + + grp } /** - * @param node Node. - * @param msg Optional message. + * @param nodeOpt Node. + * @param cacheName Cache name. * @return Message about why node was not found. */ - def messageNodeNotFound(node: Option[ClusterNode], msg: Option[String] = None): String = node match { - case Some(n) => msg.getOrElse("Can't find node with specified id: " + n.id()) - case None => "Topology is empty." + def messageNodeNotFound(nodeOpt: Option[ClusterNode], cacheName: String) = nodeOpt match { + case Some(node) => "Can't find node with specified id: " + node.id() + case None => "Can't find nodes for cache: " + escapeName(cacheName) } Runtime.getRuntime.addShutdownHook(new Thread() {