Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9295B108B6 for ; Tue, 28 Apr 2015 14:34:47 +0000 (UTC) Received: (qmail 16367 invoked by uid 500); 28 Apr 2015 14:34:46 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 16319 invoked by uid 500); 28 Apr 2015 14:34:46 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 16244 invoked by uid 99); 28 Apr 2015 14:34:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Apr 2015 14:34:45 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [54.164.171.186] (HELO mx1-us-east.apache.org) (54.164.171.186) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Apr 2015 14:34:41 +0000 Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 116D245448 for ; Tue, 28 Apr 2015 14:33:53 +0000 (UTC) Received: (qmail 5436 invoked by uid 99); 28 Apr 2015 14:33:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Apr 2015 14:33:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A43DFE0772; Tue, 28 Apr 2015 14:33:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.incubator.apache.org Date: Tue, 28 Apr 2015 14:34:09 -0000 Message-Id: <6dbc4c44bfc54b439336342861303823@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [22/42] incubator-ignite git commit: # ignite-gg-9830 WIP X-Virus-Checked: Checked by ClamAV on apache.org http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala index e58518b..8eb05a4 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala @@ -20,15 +20,16 @@ package org.apache.ignite.visor.commands.disco import org.apache.ignite.cluster.ClusterNode import org.apache.ignite.events.EventType._ import org.apache.ignite.internal.util.lang.{GridFunc => F} +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.{IgniteUtils => U} +import org.apache.ignite.visor.VisorTag +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.visor._ + import org.apache.ignite.internal.visor.event.VisorGridDiscoveryEvent import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask.VisorNodeEventsCollectorTaskArg -import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} -import org.apache.ignite.visor.visor._ - import scala.collection.JavaConversions._ import scala.collection.immutable._ import scala.language.{implicitConversions, reflectiveCalls} @@ -85,23 +86,13 @@ import scala.language.{implicitConversions, reflectiveCalls} * Prints discovery events fired during last two minutes sorted chronologically. * }}} */ -class VisorDiscoveryCommand { +class VisorDiscoveryCommand extends VisorConsoleCommand { + @impl protected val name: String = "disco" + /** */ private type TimeFilter = EventFilter /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - warn(errMsgs: _*) - warn("Type 'help disco' to see how to use this command.") - } - - /** * ===Command=== * Prints all discovery events. * @@ -164,7 +155,7 @@ class VisorDiscoveryCommand { events(node, tm, hasArgFlag("r", argLst)) catch { case e: Throwable => - scold(e.getMessage) + scold(e) return } @@ -239,8 +230,11 @@ class VisorDiscoveryCommand { * Companion object that does initialization of the command. */ object VisorDiscoveryCommand { + /** Singleton command. */ + private val cmd = new VisorDiscoveryCommand + addHelp( - name = "disco", + name = cmd.name, shortInfo = "Prints topology change log.", longInfo = List( "Prints topology change log as seen from the oldest node.", @@ -257,8 +251,8 @@ object VisorDiscoveryCommand { "events on each node. Both of these defaults can be changed in configuration." ), spec = List( - "disco", - "disco {-t=s|m|h|d} {-r} {-c=}" + cmd.name, + s"${cmd.name} {-t=s|m|h|d} {-r} {-c=}" ), args = List( "-t=s|m|h|d" -> List( @@ -276,19 +270,17 @@ object VisorDiscoveryCommand { ) ), examples = List( - "disco" -> + cmd.name -> "Prints all discovery events sorted chronologically (oldest first).", - "disco -r" -> + s"${cmd.name} -r" -> "Prints all discovery events sorted chronologically in reversed order (newest first).", - "disco -t=2m" -> + s"${cmd.name} -t=2m" -> "Prints discovery events fired during last two minutes sorted chronologically." ), - ref = VisorConsoleCommand(cmd.disco, cmd.disco) + emptyArgs = cmd.disco, + withArgs = cmd.disco ) - /** Singleton command. */ - private val cmd = new VisorDiscoveryCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala index ad507c8..2299c4a 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala @@ -17,18 +17,18 @@ package org.apache.ignite.visor.commands.events -import org.apache.ignite._ import org.apache.ignite.events.EventType._ +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.{IgniteUtils => U} -import org.apache.ignite.internal.visor.event.VisorGridEvent -import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask -import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask.VisorNodeEventsCollectorTaskArg +import org.apache.ignite.visor.VisorTag +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.visor._ import java.util.UUID -import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands._ -import org.apache.ignite.visor.visor._ +import org.apache.ignite.internal.visor.event.VisorGridEvent +import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask +import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask.VisorNodeEventsCollectorTaskArg import scala.collection.JavaConversions._ import scala.collection.immutable._ @@ -112,18 +112,8 @@ import scala.language.implicitConversions * Starts command in interactive mode. * }}} */ -class VisorEventsCommand { - /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - warn(errMsgs: _*) - warn("Type 'help events' to see how to use this command.") - } +class VisorEventsCommand extends VisorConsoleCommand { + @impl protected val name: String = "events" /** * ===Command=== @@ -147,7 +137,7 @@ class VisorEventsCommand { } } - private[this] def typeFilter(typeArg: Option[String]) = { + protected def typeFilter(typeArg: Option[String]) = { if (typeArg.isEmpty) null else { @@ -203,191 +193,144 @@ class VisorEventsCommand { * @param args Command parameters. */ def events(args: String) { - if (!isConnected) - adviseToConnect() - else { + if (isConnected) { val argLst = parseArgs(args) - val typeArg = argValue("e", argLst) - val timeArg = argValue("t", argLst) - - val id8 = argValue("id8", argLst) - val id = argValue("id", argLst) - - if (!id8.isDefined && !id.isDefined) { - scold("Either '-id8' or '-id' must be provided.") - - return - } - - if (id8.isDefined && id.isDefined) { - scold("Only one of '-id8' or '-id' is allowed.") - - return - } - - val node = if (id8.isDefined) { - val ns = nodeById8(id8.get) - - if (ns.isEmpty) { - scold("Unknown 'id8' value: " + id8.get) + parseNode(argLst) match { + case Left(msg) => scold(msg) + case Right(None) => scold("Either '-id8' or '-id' must be provided.") + case Right(Some(node)) => + val nid = node.id() - return - } + val typeArg = argValue("e", argLst) + val timeArg = argValue("t", argLst) - if (ns.size != 1) { - scold("'id8' resolves to more than one node (use full 'id' instead): " + id8.get) + val evts = try + collectEvents(nid, typeArg, timeArg) + catch { + case e: Exception => + scold(e) - return - } + return + } - ns.head - } - else { - val node = try - ignite.cluster.node(UUID.fromString(id.get)) - catch { - case _: IllegalArgumentException => - scold("Invalid node 'id': " + id.get) + if (evts == null || evts.isEmpty) { + println("No events found.") return - } - - if (node == null) { - scold("'id' does not match any node: " + id.get) - - return - } - - node - } - - val nid = node.id() - - val tpFilter = try - typeFilter(typeArg) - catch { - case e: Exception => - scold(e.getMessage) + } - return - } - - val tmFilter = try - timeFilter(timeArg) - catch { - case e: Exception => - scold(e.getMessage) - - return - } + val sortedOpt = sort(evts.toList, argValue("s", argLst), hasArgName("r", argLst)) - val evts = try - executeOne(nid, classOf[VisorNodeEventsCollectorTask], - VisorNodeEventsCollectorTaskArg.createEventsArg(tpFilter, tmFilter)) - catch { - case e: IgniteException => - scold(e.getMessage) - - return - } - - if (evts == null || evts.isEmpty) { - println("No events found.") + if (!sortedOpt.isDefined) + return - return - } + val sorted = sortedOpt.get - val sortedOpt = sort(evts.toList, argValue("s", argLst), hasArgName("r", argLst)) + val cntOpt = argValue("c", argLst) - if (!sortedOpt.isDefined) - return + var cnt = Int.MaxValue - val sorted = sortedOpt.get + if (cntOpt.isDefined) + try + cnt = cntOpt.get.toInt + catch { + case e: NumberFormatException => + scold("Invalid count: " + cntOpt.get) - val cntOpt = argValue("c", argLst) + return + } - var cnt = Int.MaxValue + println("Summary:") - if (cntOpt.isDefined) - try - cnt = cntOpt.get.toInt - catch { - case e: NumberFormatException => - scold("Invalid count: " + cntOpt.get) + val st = VisorTextTable() - return - } + st += ("Node ID8(@ID)", nodeId8Addr(nid)) + st += ("Total", sorted.size) + st += ("Earliest timestamp", formatDateTime(evts.maxBy(_.timestamp).timestamp)) + st += ("Oldest timestamp", formatDateTime(evts.minBy(_.timestamp).timestamp)) - println("Summary:") + st.render() - val st = VisorTextTable() + nl() - st += ("Node ID8(@ID)", nodeId8Addr(nid)) - st += ("Total", sorted.size) - st += ("Earliest timestamp", formatDateTime(evts.maxBy(_.timestamp).timestamp)) - st += ("Oldest timestamp", formatDateTime(evts.minBy(_.timestamp).timestamp)) + println("Per-Event Summary:") - st.render() + var sum = Map[Int, (String, Int, Long, Long)]() - nl() + evts.foreach(evt => { + val info = sum.getOrElse(evt.typeId(), (null, 0, Long.MinValue, Long.MaxValue)) - println("Per-Event Summary:") + sum += (evt.typeId -> ( + "(" + mnemonic(evt) + ") " + evt.name(), + info._2 + 1, + if (evt.timestamp() > info._3) evt.timestamp() else info._3, + if (evt.timestamp() < info._4) evt.timestamp() else info._4) + ) + }) - var sum = Map[Int, (String, Int, Long, Long)]() + val et = VisorTextTable() - evts.foreach(evt => { - val info = sum.getOrElse(evt.typeId(), (null, 0, Long.MinValue, Long.MaxValue)) + et #= ( + "Event", + "Total", + ("Earliest/Oldest", "Timestamp"), + ("Rate", "events/sec") + ) - sum += (evt.typeId -> ( - "(" + mnemonic(evt) + ") " + evt.name(), - info._2 + 1, - if (evt.timestamp() > info._3) evt.timestamp() else info._3, - if (evt.timestamp() < info._4) evt.timestamp() else info._4) - ) - }) + sum.values.toList.sortBy(_._2).reverse.foreach(v => { + val range = v._3 - v._4 - val et = VisorTextTable() + et += ( + v._1, + v._2, + (formatDateTime(v._3), formatDateTime(v._4)), + formatDouble(if (range != 0) (v._2.toDouble * 1000) / range else v._2) + ) + }) - et #= ( - "Event", - "Total", - ("Earliest/Oldest", "Timestamp"), - ("Rate", "events/sec") - ) + et.render() - sum.values.toList.sortBy(_._2).reverse.foreach(v => { - val range = v._3 - v._4 + nl() - et += ( - v._1, - v._2, - (formatDateTime(v._3), formatDateTime(v._4)), - formatDouble(if (range != 0) (v._2.toDouble * 1000) / range else v._2) - ) - }) + if (sorted.size > cnt) + println("Top " + cnt + " Events:") + else + println("All Events:") - et.render() + val all = VisorTextTable() - nl() + all.maxCellWidth = 50 - if (sorted.size > cnt) - println("Top " + cnt + " Events:") - else - println("All Events:") + all #= ("Timestamp", "Description") - val all = VisorTextTable() + sorted.take(cnt).foreach(evt => + all += (formatDateTime(evt.timestamp()), U.compact(evt.shortDisplay)) + ) - all.maxCellWidth = 50 + all.render() + } + } + else + adviseToConnect() + } - all #= ("Timestamp", "Description") + /** + * Collect events. + * + * @param nid Node id. + * @param typeArg Type ids argument. + * @param timeArg Time argument. + * @return + */ + @throws[Exception]("In case of error.") + protected def collectEvents(nid: UUID, typeArg: Option[String], timeArg: Option[String]) = { + val tpFilter = typeFilter(typeArg) - sorted.take(cnt).foreach(evt => - all += (formatDateTime(evt.timestamp()), U.compact(evt.shortDisplay)) - ) + val tmFilter = timeFilter(timeArg) - all.render() - } + executeOne(nid, classOf[VisorNodeEventsCollectorTask], + VisorNodeEventsCollectorTaskArg.createEventsArg(tpFilter, tmFilter)) } /** @@ -419,8 +362,11 @@ class VisorEventsCommand { * Companion object that does initialization of the command. */ object VisorEventsCommand { + /** Singleton command. */ + private val cmd = new VisorEventsCommand + addHelp( - name = "events", + name = cmd.name, shortInfo = "Print events from a node.", longInfo = List( "Print events from a node.", @@ -436,8 +382,8 @@ object VisorEventsCommand { "events on each node. Both of these defaults can be changed in configuration." ), spec = List( - "events", - "events {-id=|-id8=} {-e=}", + cmd.name, + s"${cmd.name} {-id=|-id8=} {-e=}", " {-t=s|m|h|d} {-s=e|t} {-r} {-c=}" ), args = List( @@ -486,21 +432,19 @@ object VisorEventsCommand { ) ), examples = List( - "events -id8=12345678" -> + s"${cmd.name} -id8=12345678" -> "Queries all events from node with '12345678' id8.", - "events -id8=@n0" -> + s"${cmd.name} -id8=@n0" -> "Queries all events from node with id8 taken from 'n0' memory variable.", - "events -id8=12345678 -e=di,ca" -> + s"${cmd.name} -id8=12345678 -e=di,ca" -> "Queries discovery and cache events from node with '12345678' ID8.", - "events" -> + cmd.name -> "Starts command in interactive mode." ), - ref = VisorConsoleCommand(cmd.events, cmd.events) + emptyArgs = cmd.events, + withArgs = cmd.events ) - /** Singleton command. */ - private val cmd = new VisorEventsCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala index 9b5fc21..a9bf39f 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/gc/VisorGcCommand.scala @@ -18,18 +18,16 @@ package org.apache.ignite.visor.commands.gc import org.apache.ignite._ -import org.apache.ignite.cluster.{ClusterGroupEmptyException, ClusterNode} +import org.apache.ignite.cluster.ClusterGroupEmptyException +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} import org.apache.ignite.visor.visor._ -import java.util.UUID - import org.apache.ignite.internal.visor.node.VisorNodeGcTask import scala.collection.JavaConversions._ import scala.language.{implicitConversions, reflectiveCalls} -import scala.util.control.Breaks._ /** * ==Overview== @@ -47,7 +45,7 @@ import scala.util.control.Breaks._ * ====Specification==== * {{{ * gc - * gc "{-id8=|-id=} {-c}" + * gc "{-id8=|-id=}" * }}} * * ====Arguments==== @@ -58,8 +56,6 @@ import scala.util.control.Breaks._ * -id= * ID of the node. * Note that either '-id8' or '-id' can be specified. - * -c - * Run DGC procedure on all caches. * }}} * * ====Examples==== @@ -68,24 +64,10 @@ import scala.util.control.Breaks._ * Runs garbage collector on specified node. * gc * Runs garbage collector on all nodes in topology. - * gc "-id8=12345678 -c" - * Runs garbage collector and DGC procedure on all caches. * }}} */ -class VisorGcCommand { - /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - nl() - - warn(errMsgs: _*) - warn("Type 'help gc' to see how to use this command.") - } +class VisorGcCommand extends VisorConsoleCommand { + @impl protected val name = "gc" /** * ===Command=== @@ -94,48 +76,13 @@ class VisorGcCommand { * ===Examples=== * gc "-id8=12345678" * Runs `System.gc()` on specified node. - * - * gc "-id8=12345678 -c" - * Runs garbage collector and DGC procedure on all caches. */ - def gc(args: String) = breakable { + def gc(args: String) { assert(args != null) - if (!isConnected) - adviseToConnect() - else { + if (isConnected) { val argLst = parseArgs(args) - val id8 = argValue("id8", argLst) - val id = argValue("id", argLst) - val dgc = hasArgFlag("c", argLst) - - var node: ClusterNode = null - - if (id8.isDefined && id.isDefined) - scold("Only one of '-id8' or '-id' is allowed.").^^ - else if (id8.isDefined) { - val ns = nodeById8(id8.get) - - if (ns.isEmpty) - scold("Unknown 'id8' value: " + id8.get).^^ - else if (ns.size != 1) { - scold("'id8' resolves to more than one node (use full 'id' instead): " + id8.get).^^ - } - else - node = ns.head - } - else if (id.isDefined) - try { - node = ignite.cluster.node(UUID.fromString(id.get)) - - if (node == null) - scold("'id' does not match any node: " + id.get).^^ - } - catch { - case e: IllegalArgumentException => scold("Invalid node 'id': " + id.get).^^ - } - try { val t = VisorTextTable() @@ -143,7 +90,16 @@ class VisorGcCommand { val NULL: Void = null - executeMulti(classOf[VisorNodeGcTask], NULL).foreach { + val res = parseNode(argLst) match { + case Left(msg) => + scold(msg) + + return + case Right(None) => executeMulti(classOf[VisorNodeGcTask], NULL) + case Right(Some(node)) => executeOne(node.id, classOf[VisorNodeGcTask], NULL) + } + + res.foreach { case (nid, stat) => val roundHb = stat.get1() / (1024L * 1024L) val roundHa = stat.get2() / (1024L * 1024L) @@ -161,9 +117,11 @@ class VisorGcCommand { } catch { case e: ClusterGroupEmptyException => scold("Topology is empty.") - case e: IgniteException => scold(e.getMessage) + case e: IgniteException => scold(e) } } + else + adviseToConnect() } /** @@ -183,8 +141,11 @@ class VisorGcCommand { * Companion object that does initialization of the command. */ object VisorGcCommand { + /** Singleton command. */ + private val cmd = new VisorGcCommand + addHelp( - name = "gc", + name = cmd.name, shortInfo = "Runs GC on remote nodes.", longInfo = List( "Runs garbage collector on remote nodes.", @@ -192,8 +153,8 @@ object VisorGcCommand { "Otherwise, it will be run on all nodes in topology." ), spec = List( - "gc", - "gc {-id8=|-id=} {-c}" + cmd.name, + s"${cmd.name} {-id8=|-id=}" ), args = List( "-id8=" -> List( @@ -204,26 +165,20 @@ object VisorGcCommand { "-id=" -> List( "ID of the node.", "Note that either '-id8' or '-id' can be specified." - ), - "-c" -> List( - "Run DGC procedure on all caches." ) ), examples = List( - "gc -id8=12345678" -> + s"${cmd.name} -id8=12345678" -> "Runs garbage collector on specified node.", - "gc" -> + cmd.name -> "Runs garbage collector on all nodes in topology.", - "gc -id8=@n0 -c" -> - ("Runs garbage collector on specified node with id8 taken from 'n0' memory variable " + - "and run DGC procedure on all caches.") + s"${cmd.name} -id8=@n0" -> + "Runs garbage collector on specified node with id8 taken from 'n0' memory variable." ), - ref = VisorConsoleCommand(cmd.gc, cmd.gc) + emptyArgs = cmd.gc, + withArgs = cmd.gc ) - /** Singleton command. */ - private val cmd = new VisorGcCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala index a8263e4..f94e3ee 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/kill/VisorKillCommand.scala @@ -17,18 +17,16 @@ package org.apache.ignite.visor.commands.kill -import org.apache.ignite.internal.IgniteNodeAttributes -import IgniteNodeAttributes._ - import org.apache.ignite._ import org.apache.ignite.cluster.ClusterNode +import org.apache.ignite.internal.IgniteNodeAttributes._ +import org.apache.ignite.internal.util.scala.impl +import org.apache.ignite.visor.VisorTag +import org.apache.ignite.visor.commands.common.VisorConsoleCommand +import org.apache.ignite.visor.visor._ import java.util.{Collections, UUID} -import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.VisorConsoleCommand -import visor.visor._ - import scala.collection.JavaConversions._ import scala.language.{implicitConversions, reflectiveCalls} import scala.util.control.Breaks._ @@ -91,20 +89,8 @@ import scala.util.control.Breaks._ * Kill (stop) all nodes. * }}} */ -class VisorKillCommand { - /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - nl() - - warn(errMsgs: _*) - warn("Type 'help kill' to see how to use this command.") - } +class VisorKillCommand extends VisorConsoleCommand { + @impl protected val name = "kill" /** * ===Command=== @@ -282,14 +268,17 @@ class VisorKillCommand { * Companion object that does initialization of the command. */ object VisorKillCommand { + /** Singleton command. */ + private val cmd = new VisorKillCommand + // Adds command's help to visor. addHelp( - name = "kill", + name = cmd.name, shortInfo = "Kills or restarts node.", spec = List( - "kill", - "kill -in|-ih", - "kill {-r|-k} {-id8=|-id=}" + cmd.name, + s"${cmd.name} -in|-ih", + s"${cmd.name} {-r|-k} {-id8=|-id=}" ), args = List( "-in" -> List( @@ -327,21 +316,19 @@ object VisorKillCommand { ) ), examples = List( - "kill" -> + cmd.name -> "Starts command in interactive mode.", - "kill -id8=12345678 -r" -> + s"${cmd.name} -id8=12345678 -r" -> "Restart node with id8.", - "kill -id8=@n0 -r" -> + s"${cmd.name} -id8=@n0 -r" -> "Restart specified node with id8 taken from 'n0' memory variable.", - "kill -k" -> + s"${cmd.name} -k" -> "Kill (stop) all nodes." ), - ref = VisorConsoleCommand(cmd.kill, cmd.kill) + emptyArgs = cmd.kill, + withArgs = cmd.kill ) - /** Singleton command. */ - private val cmd = new VisorKillCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/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 eeb2a6c..064d33e 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 @@ -20,16 +20,18 @@ package org.apache.ignite.visor.commands.node import org.apache.ignite.cluster.ClusterNode import org.apache.ignite.internal.IgniteNodeAttributes._ import org.apache.ignite.internal.util.lang.{GridFunc => F} +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.typedef.X import org.apache.ignite.internal.util.{IgniteUtils => U} -import org.apache.ignite.internal.visor.util.VisorTaskUtils._ +import org.apache.ignite.visor.VisorTag +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.visor._ + import org.jetbrains.annotations._ import java.util.UUID -import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} -import org.apache.ignite.visor.visor._ +import org.apache.ignite.internal.visor.util.VisorTaskUtils._ import scala.collection.JavaConversions._ import scala.language.{implicitConversions, reflectiveCalls} @@ -75,18 +77,8 @@ import scala.util.control.Breaks._ * Prints full statistics for specified node. * }}} */ -class VisorNodeCommand { - /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - warn(errMsgs: _*) - warn("Type 'help node' to see how to use this command.") - } +class VisorNodeCommand extends VisorConsoleCommand { + @impl protected val name = "node" /** * ===Command=== @@ -280,7 +272,7 @@ class VisorNodeCommand { } } catch { - case e: Exception => scold(e.getMessage) + case e: Exception => scold(e) } } } @@ -289,13 +281,16 @@ class VisorNodeCommand { * Companion object that does initialization of the command. */ object VisorNodeCommand { + /** Singleton command. */ + private val cmd = new VisorNodeCommand + // Adds command's help to visor. addHelp( - name = "node", + name = cmd.name, shortInfo = "Prints node statistics.", spec = List( - "node {-id8=|-id=} {-a}", - "node" + cmd.name, + s"${cmd.name} {-id8=|-id=} {-a}" ), args = List( "-id8=" -> List( @@ -313,19 +308,17 @@ object VisorNodeCommand { ) ), examples = List( - "node" -> + cmd.name -> "Starts command in interactive mode.", - "node -id8=12345678" -> + s"${cmd.name} -id8=12345678" -> "Prints statistics for specified node.", - "node -id8=@n0 -a" -> + s"${cmd.name} -id8=@n0 -a" -> "Prints full statistics for specified node with id8 taken from 'n0' memory variable." ), - ref = VisorConsoleCommand(cmd.node, cmd.node) + emptyArgs = cmd.node, + withArgs = cmd.node ) - /** Singleton command. */ - private val cmd = new VisorNodeCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ping/VisorPingCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ping/VisorPingCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ping/VisorPingCommand.scala index 0466397..97be127 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ping/VisorPingCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ping/VisorPingCommand.scala @@ -18,13 +18,13 @@ package org.apache.ignite.visor.commands.ping import org.apache.ignite.cluster.ClusterNode +import org.apache.ignite.internal.util.scala.impl +import org.apache.ignite.visor.VisorTag +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.visor._ import java.util.concurrent._ -import org.apache.ignite.visor.{VisorTag, visor} -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} -import visor._ - import scala.collection.JavaConversions._ import scala.language.{implicitConversions, reflectiveCalls} import scala.util.control.Breaks._ @@ -99,18 +99,8 @@ private case class Pinger(n: ClusterNode, res: Result) extends Runnable { * Pings all nodes in the topology. * }}} */ -class VisorPingCommand { - /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - warn(errMsgs: _*) - warn("Type 'help ping' to see how to use this command.") - } +class VisorPingCommand extends VisorConsoleCommand { + @impl protected val name = "ping" /** * ===Command=== @@ -191,29 +181,30 @@ class VisorPingCommand { * Companion object that does initialization of the command. */ object VisorPingCommand { + /** Singleton command. */ + private val cmd = new VisorPingCommand + // Adds command's help to visor. addHelp( - name = "ping", + name = cmd.name, shortInfo = "Pings node.", - spec = List("ping ... "), + spec = List(s"${cmd.name} ... "), args = List( ("", "ID8 of the node to ping. Note you can also use '@n0' ... '@nn' variables as shortcut to .") ), examples = List( - "ping 12345678" -> + s"${cmd.name} 12345678" -> "Pings node with '12345678' ID8.", - "ping @n0" -> + s"${cmd.name} @n0" -> "Pings node with 'specified node with ID8 taken from 'n0' memory variable.", - "ping" -> + cmd.name -> "Pings all nodes in the topology." ), - ref = VisorConsoleCommand(cmd.ping, cmd.ping) + emptyArgs = cmd.ping, + withArgs = cmd.ping ) - /** Singleton command. */ - private val cmd = new VisorPingCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala index a6de108..9365592 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala @@ -18,9 +18,10 @@ package org.apache.ignite.visor.commands.start import org.apache.ignite._ +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.{IgniteUtils => U} import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} import org.apache.ignite.visor.visor._ import java.io._ @@ -114,7 +115,9 @@ private case class Result( * Starts topology defined in 'start-nodes.ini' file. Existing nodes are stopped. * }}} */ -class VisorStartCommand { +class VisorStartCommand extends VisorConsoleCommand { + @impl protected val name = "start" + /** Default maximum number of parallel connections. */ private final val DFLT_MAX_CONN = 5 @@ -122,20 +125,6 @@ class VisorStartCommand { private final val DFLT_TIMEOUT = 2000 /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - nl() - - warn(errMsgs: _*) - warn("Type 'help start' to see how to use this command.") - } - - /** * Catch point for missing arguments case. */ def start() { @@ -231,7 +220,7 @@ class VisorStartCommand { Result(t.getHostName, t.isSuccess, t.getError) }).toSeq catch { - case e: IgniteException => scold(e.getMessage).^^ + case e: IgniteException => scold(e).^^ case _: RejectedExecutionException => scold("Failed due to system error.").^^ } } @@ -286,7 +275,7 @@ class VisorStartCommand { res = ignite.cluster.startNodes(asJavaCollection(Seq(params)), null, restart, timeout, maxConn). map(t => Result(t.getHostName, t.isSuccess, t.getError)).toSeq catch { - case e: IgniteException => scold(e.getMessage).^^ + case e: IgniteException => scold(e).^^ case _: RejectedExecutionException => scold("Failed due to system error.").^^ } } @@ -340,6 +329,9 @@ class VisorStartCommand { * Companion object that does initialization of the command. */ object VisorStartCommand { + /** Singleton command. */ + private val cmd = new VisorStartCommand + addHelp( name = "start", shortInfo = "Starts or restarts nodes on remote hosts.", @@ -415,12 +407,10 @@ object VisorStartCommand { "start -f=start-nodes.ini -r" -> "Starts topology defined in 'start-nodes.ini' file. Existing nodes are stopped." ), - ref = VisorConsoleCommand(cmd.start, cmd.start) + emptyArgs = cmd.start, + withArgs = cmd.start ) - /** Singleton command. */ - private val cmd = new VisorStartCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/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 d7547c9..16bce29 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 @@ -19,11 +19,12 @@ package org.apache.ignite.visor.commands.tasks import org.apache.ignite._ import org.apache.ignite.events.EventType._ +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.typedef.X import org.apache.ignite.internal.util.{IgniteUtils => U} import org.apache.ignite.lang.IgniteUuid import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} import org.apache.ignite.visor.visor._ import java.util.UUID @@ -329,23 +330,13 @@ private case class VisorTask( * Traces task execution with ID taken from 's1' memory variable. * }}} */ -class VisorTasksCommand { +class VisorTasksCommand extends VisorConsoleCommand { + @impl protected val name = "tasks" + /** Limit for printing tasks and executions. */ private val SHOW_LIMIT = 100 /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - warn(errMsgs: _*) - warn("Type 'help tasks' to see how to use this command.") - } - - /** * ===Command=== * Prints statistics about executed tasks. * @@ -770,7 +761,7 @@ class VisorTasksCommand { } catch { case e: IgniteException => - scold(e.getMessage) + scold(e) break() } @@ -959,7 +950,7 @@ class VisorTasksCommand { } catch { case e: IgniteException => - scold(e.getMessage) + scold(e) break() } @@ -1085,7 +1076,7 @@ class VisorTasksCommand { } catch { case e: IgniteException => - scold(e.getMessage) + scold(e) break() } @@ -1195,7 +1186,7 @@ class VisorTasksCommand { } catch { case e: IgniteException => - scold(e.getMessage) + scold(e) break() } @@ -1309,7 +1300,7 @@ class VisorTasksCommand { } catch { case e: IgniteException => - scold(e.getMessage) + scold(e) break() } @@ -1334,6 +1325,9 @@ class VisorTasksCommand { * Companion object that does initialization of the command. */ object VisorTasksCommand { + /** Singleton command. */ + private val cmd = new VisorTasksCommand + addHelp( name = "tasks", shortInfo = "Prints tasks execution statistics.", @@ -1438,12 +1432,10 @@ object VisorTasksCommand { "tasks -e=7D5CB773-225C-4165-8162-3BB67337894B" -> "Traces task execution with ID '7D5CB773-225C-4165-8162-3BB67337894B'." ), - ref = VisorConsoleCommand(cmd.tasks, cmd.tasks) + emptyArgs = cmd.tasks, + withArgs = cmd.tasks ) - /** Singleton command. */ - private val cmd = new VisorTasksCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala index b903755..5e278ed 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala @@ -20,11 +20,12 @@ package org.apache.ignite.visor.commands.top import org.apache.ignite._ import org.apache.ignite.cluster.ClusterNode import org.apache.ignite.internal.IgniteNodeAttributes._ +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.typedef.X import org.apache.ignite.internal.util.{IgniteUtils => U} import org.apache.ignite.lang.IgnitePredicate import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} import org.apache.ignite.visor.visor._ import java.net.{InetAddress, UnknownHostException} @@ -100,18 +101,8 @@ import scala.util.control.Breaks._ * Prints full topology. * }}} */ -class VisorTopologyCommand { - /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - warn(errMsgs: _*) - warn("Type 'help top' to see how to use this command.") - } +class VisorTopologyCommand extends VisorConsoleCommand { + @impl protected val name = "top" /** * ===Command=== @@ -188,8 +179,8 @@ class VisorTopologyCommand { show(n => f(n), hosts, all) } catch { - case e: NumberFormatException => scold(e.getMessage) - case e: IgniteException => scold(e.getMessage) + case e: NumberFormatException => scold(e) + case e: IgniteException => scold(e) } } } @@ -229,11 +220,7 @@ class VisorTopologyCommand { }).nodes() if (hosts.nonEmpty) - nodes = nodes.filter(n => { - val ips = n.addresses.toSet - - ips.intersect(hosts).nonEmpty - }) + nodes = nodes.filter(n => n.addresses.toSet.intersect(hosts).nonEmpty) if (nodes.isEmpty) println("Empty topology.").^^ @@ -350,6 +337,9 @@ class VisorTopologyCommand { * Companion object that does initialization of the command. */ object VisorTopologyCommand { + /** Singleton command. */ + private val cmd = new VisorTopologyCommand + // Adds command's help to visor. addHelp( name = "top", @@ -407,12 +397,10 @@ object VisorTopologyCommand { "top" -> "Prints full topology." ), - ref = VisorConsoleCommand(cmd.top, cmd.top) + emptyArgs = cmd.top, + withArgs = cmd.top ) - /** Singleton command. */ - private val cmd = new VisorTopologyCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala index 8bc3463..ff5cf82 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala @@ -20,17 +20,18 @@ package org.apache.ignite.visor.commands.vvm import org.apache.ignite.IgniteSystemProperties import org.apache.ignite.cluster.ClusterNode import org.apache.ignite.internal.IgniteNodeAttributes._ +import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.{IgniteUtils => U} -import org.apache.ignite.internal.visor.util.{VisorTaskUtils => TU} +import org.apache.ignite.visor.VisorTag +import org.apache.ignite.visor.commands.common.VisorConsoleCommand +import org.apache.ignite.visor.visor._ import org.jetbrains.annotations.Nullable import java.io.File import java.net._ -import org.apache.ignite.visor.VisorTag -import org.apache.ignite.visor.commands.VisorConsoleCommand -import org.apache.ignite.visor.visor._ +import org.apache.ignite.internal.visor.util.{VisorTaskUtils => TU} import scala.collection.JavaConversions._ import scala.language.{implicitConversions, reflectiveCalls} @@ -77,18 +78,8 @@ import scala.util.control.Breaks._ * Opens VisualVM connected to all nodes. * }}} */ -class VisorVvmCommand { - /** - * Prints error message and advise. - * - * @param errMsgs Error messages. - */ - private def scold(errMsgs: Any*) { - assert(errMsgs != null) - - warn(errMsgs: _*) - warn("Type 'help vvm' to see how to use this command.") - } +class VisorVvmCommand extends VisorConsoleCommand { + @impl protected val name = "vvm" /** * ===Command=== @@ -254,6 +245,9 @@ class VisorVvmCommand { * Companion object that does initialization of the command. */ object VisorVvmCommand { + /** Singleton command. */ + private val cmd = new VisorVvmCommand + // Adds command's help to visor. addHelp( name = "vvm", @@ -286,12 +280,10 @@ object VisorVvmCommand { "vvm" -> "Opens VisualVM connected to all nodes." ), - ref = VisorConsoleCommand(cmd.vvm, cmd.vvm) + emptyArgs = cmd.vvm, + withArgs = cmd.vvm ) - /** Singleton command. */ - private val cmd = new VisorVvmCommand - /** * Singleton. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/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 e402162..aaf74a4 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 @@ -26,7 +26,6 @@ import org.apache.ignite.events.{DiscoveryEvent, Event} import org.apache.ignite.internal.IgniteComponentType._ import org.apache.ignite.internal.IgniteEx import org.apache.ignite.internal.IgniteNodeAttributes._ -import org.apache.ignite.internal.IgniteVersionUtils._ import org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException import org.apache.ignite.internal.util.lang.{GridFunc => F} import org.apache.ignite.internal.util.spring.IgniteSpringHelper @@ -36,8 +35,7 @@ import org.apache.ignite.lang._ import org.apache.ignite.logger.NullLogger import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi import org.apache.ignite.thread.IgniteThreadPoolExecutor -import org.apache.ignite.visor.commands.VisorConsole.consoleReader -import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} +import org.apache.ignite.visor.commands.common.VisorTextTable import org.jetbrains.annotations.Nullable @@ -56,13 +54,14 @@ import org.apache.ignite.internal.visor.{VisorMultiNodeTask, VisorTaskArgument} import scala.collection.JavaConversions._ import scala.collection.immutable +import scala.io.StdIn._ import scala.language.{implicitConversions, reflectiveCalls} import scala.util.control.Breaks._ /** * Holder for command help information. */ -sealed case class VisorConsoleCommandHolder( +sealed case class VisorCommandHolder( name: String, shortInfo: String, longInfo: Seq[String], @@ -70,7 +69,8 @@ sealed case class VisorConsoleCommandHolder( spec: Seq[String], args: Seq[(String, AnyRef)], examples: Seq[(String, AnyRef)], - impl: VisorConsoleCommand + emptyArgs: () => Unit, + withArgs: (String) => Unit ) { /** Command host with optional aliases. */ lazy val nameWithAliases: String = @@ -153,7 +153,7 @@ object visor extends VisorTag { final val NA = "" /** */ - private var cmdLst: Seq[VisorConsoleCommandHolder] = Nil + private var cmdLst: Seq[VisorCommandHolder] = Nil /** Node left listener. */ private var nodeLeftLsnr: IgnitePredicate[Event] = null @@ -316,7 +316,8 @@ object visor extends VisorTag { "mlist ac" -> "Lists variables that start with 'a' or 'c' from Visor console memory." ), - ref = VisorConsoleCommand(mlist, mlist) + emptyArgs = mlist, + withArgs = mlist ) addHelp( @@ -352,7 +353,8 @@ object visor extends VisorTag { "mclear n2" -> "Clears 'n2' Visor console variable." ), - ref = VisorConsoleCommand(mclear, mclear) + emptyArgs = mclear, + withArgs = mclear ) addHelp( @@ -372,7 +374,8 @@ object visor extends VisorTag { "mget <@v>" -> "Gets Visor console variable whose name is referenced by variable 'v'." ), - ref = VisorConsoleCommand(mget, mget) + emptyArgs = mget, + withArgs = mget ) addHelp( @@ -392,7 +395,8 @@ object visor extends VisorTag { "help" -> "Prints help for all command." ), - ref = VisorConsoleCommand(help, help) + emptyArgs = help, + withArgs = help ) addHelp( @@ -412,7 +416,8 @@ object visor extends VisorTag { "status -q" -> "Prints Visor console status in quiet mode." ), - ref = VisorConsoleCommand(status, status) + emptyArgs = status, + withArgs = status ) addHelp( @@ -447,9 +452,18 @@ object visor extends VisorTag { "open -cpath=/gg/config/mycfg.xml" -> "Connects Visor console to grid using Ignite configuration from provided file." ), - ref = VisorConsoleCommand(open, open) + emptyArgs = open, + withArgs = open ) + /** + * @param name - command name. + */ + private def wrongArgs(name: String) { + warn("Invalid arguments for command without arguments.", + s"Type 'help $name' to see how to use this command.") + } + addHelp( name = "close", shortInfo = "Disconnects Visor console from the grid.", @@ -458,7 +472,8 @@ object visor extends VisorTag { "close" -> "Disconnects Visor console from the grid." ), - ref = VisorConsoleCommand(close) + emptyArgs = close, + withArgs = _ => wrongArgs("close") ) addHelp( @@ -470,7 +485,8 @@ object visor extends VisorTag { "Quit from Visor console." ), aliases = Seq("exit"), - ref = VisorConsoleCommand(quit) + emptyArgs = quit, + withArgs = _ => wrongArgs("quit") ) addHelp( @@ -548,7 +564,8 @@ object visor extends VisorTag { "log -s" -> "Stops logging." ), - ref = VisorConsoleCommand(log, log) + emptyArgs = log, + withArgs = log ) logText("Visor started.") @@ -842,7 +859,8 @@ object visor extends VisorTag { * @param spec Command specification. * @param args List of `(host, description)` tuples for command arguments. Optional. * @param examples List of `(example, description)` tuples for command examples. - * @param ref - command implementation. + * @param emptyArgs - command implementation with empty arguments. + * @param withArgs - command implementation with arguments. */ def addHelp( name: String, @@ -852,15 +870,17 @@ object visor extends VisorTag { spec: Seq[String], @Nullable args: Seq[(String, AnyRef)] = null, examples: Seq[(String, AnyRef)], - ref: VisorConsoleCommand) { + emptyArgs: () => Unit, + withArgs: (String) => Unit) { assert(name != null) assert(shortInfo != null) assert(spec != null && spec.nonEmpty) assert(examples != null && examples.nonEmpty) - assert(ref != null) + assert(emptyArgs != null) + assert(withArgs != null) // Add and re-sort - cmdLst = (cmdLst ++ Seq(VisorConsoleCommandHolder(name, shortInfo, longInfo, aliases, spec, args, examples, ref))). + cmdLst = (cmdLst ++ Seq(VisorCommandHolder(name, shortInfo, longInfo, aliases, spec, args, examples, emptyArgs, withArgs))). sortWith((a, b) => a.name.compareTo(b.name) < 0) } @@ -1284,15 +1304,15 @@ object visor extends VisorTag { /** * Prints properly formatted error message like: * {{{ - * : err: error message + * (wrn) : warning message * }}} * - * @param errMsgs Error messages to print. If `null` - this function is no-op. + * @param warnMsgs Error messages to print. If `null` - this function is no-op. */ - def warn(errMsgs: Any*) { - assert(errMsgs != null) + def warn(warnMsgs: Any*) { + assert(warnMsgs != null) - errMsgs foreach (msg => println("(wrn) : " + msg)) + warnMsgs.foreach(line => println(s"(wrn) : $line")) } /** @@ -1324,19 +1344,6 @@ object visor extends VisorTag { * @param args Optional "-q" flag to disable ASCII logo printout. */ def status(args: String) { - val argLst = parseArgs(args) - - if (!hasArgFlag("q", argLst)) - println( - " ___ _________________________ ________" + NL + - " __ | / /____ _/__ ___/__ __ \\___ __ \\" + NL + - " __ | / / __ / _____ \\ _ / / /__ /_/ /" + NL + - " __ |/ / __/ / ____/ / / /_/ / _ _, _/" + NL + - " _____/ /___/ /____/ \\____/ /_/ |_|" + NL + NL + - " ADMIN CONSOLE" + NL + - " " + COPYRIGHT + NL - ) - val t = VisorTextTable() t += ("Status", if (isCon) "Connected" else "Disconnected") @@ -1412,7 +1419,7 @@ object visor extends VisorTag { if (opt.isEmpty) warn("Invalid command name: " + n) else { - val hlp: VisorConsoleCommandHolder = opt.get + val hlp: VisorCommandHolder = opt.get val t = VisorTextTable() @@ -1639,7 +1646,10 @@ object visor extends VisorTag { // Make sure visor starts without shutdown hook. System.setProperty(IGNITE_NO_SHUTDOWN_HOOK, "true") - cfg.setGridLogger(new NullLogger) + sys.props.get(IGNITE_QUIET).map(_.toBoolean) match { + case Some(true) => // No-op. + case _ => cfg.setGridLogger(new NullLogger) + } val startedGridName = try { Ignition.start(cfg).name @@ -1947,15 +1957,6 @@ object visor extends VisorTag { execute(ignite.cluster.forRemotes(), task, arg) /** - * Gets configuration from specified node. - * - * @param nid Node ID to collect configuration from. - * @return Grid configuration. - */ - def nodeConfiguration(nid: UUID): VisorGridConfiguration = - executeOne(nid, classOf[VisorNodeConfigurationCollectorTask], null) - - /** * Gets caches configurations from specified node. * * @param nid Node ID to collect configuration from. @@ -2181,12 +2182,7 @@ object visor extends VisorTag { */ private def readLineOpt(prompt: String, mask: Option[Char] = None): Option[String] = try { - val s = if (mask.isDefined) - consoleReader().readLine(prompt, mask.get) - else - consoleReader().readLine(prompt) - - Option(s) + Option(mask.fold(readLine(prompt))(readLine(prompt, _))) } catch { case _: Throwable => None @@ -2439,7 +2435,7 @@ object visor extends VisorTag { startLog(argValue("f", argLst), argValue("p", argLst), argValue("t", argLst), hasArgFlag("dl", argLst)) catch { - case e: Exception => scold(e.getMessage) + case e: Exception => scold(e) } else scold("Invalid arguments.") http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a2c39f2/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorTextTableSpec.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorTextTableSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorTextTableSpec.scala index 5e8030f..eec4019 100644 --- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorTextTableSpec.scala +++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorTextTableSpec.scala @@ -17,7 +17,8 @@ package org.apache.ignite.visor -import org.apache.ignite.visor.commands.VisorTextTable +import org.apache.ignite.visor.commands.common.VisorTextTable + import org.scalatest._ import scala.collection._