ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [1/2] incubator-ignite git commit: # ignite-185 Add batch mode for Visor console
Date Thu, 19 Feb 2015 10:07:48 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-185 [created] 5fbfea040


# ignite-185 Add batch mode for 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/65625830
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/65625830
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/65625830

Branch: refs/heads/ignite-185
Commit: 656258303605068503f75289512e3aa687efe435
Parents: d030518
Author: anovikov <anovikov@gridgain.com>
Authored: Thu Feb 19 15:12:49 2015 +0700
Committer: anovikov <anovikov@gridgain.com>
Committed: Thu Feb 19 15:12:49 2015 +0700

----------------------------------------------------------------------
 .../ignite/visor/commands/VisorConsole.scala    | 48 ++++++++++++++++++--
 .../visor/commands/ack/VisorAckCommand.scala    |  6 +--
 .../visor/commands/gc/VisorGcCommand.scala      |  2 -
 .../visor/commands/kill/VisorKillCommand.scala  |  6 +--
 .../visor/commands/ping/VisorPingCommand.scala  |  4 +-
 .../commands/tasks/VisorTasksCommand.scala      |  2 +-
 .../scala/org/apache/ignite/visor/visor.scala   | 44 ++++++++++--------
 7 files changed, 78 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/65625830/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
index 62f590e..9c36904 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala
@@ -24,7 +24,7 @@ import org.apache.ignite.startup.cmdline.AboutDialog
 
 import javax.swing.ImageIcon
 import java.awt.Image
-import java.io.File
+import java.io._
 import java.text.SimpleDateFormat
 import java.util
 
@@ -46,6 +46,7 @@ import org.apache.ignite.visor.commands.tasks.VisorTasksCommand
 import org.apache.ignite.visor.commands.top.VisorTopologyCommand
 import org.apache.ignite.visor.commands.vvm.VisorVvmCommand
 import org.apache.ignite.visor.visor
+import org.apache.ignite.visor.visor._
 
 import scala.tools.jline.console.ConsoleReader
 import scala.tools.jline.console.completer.Completer
@@ -100,7 +101,46 @@ object VisorConsole extends App {
 
     private val buf = new StringBuilder
 
-    private val reader = new ConsoleReader()
+    line = args.mkString(" ")
+
+    val argLst = parseArgs(args.mkString(" "))
+
+    val batchFile = argValue("b", argLst)
+    val batchCommand = argValue("e", argLst)
+
+    if (batchFile.isDefined && batchCommand.isDefined) {
+        visor.warn(
+            "Illegal options can't contains both command file and commands",
+            "Usage: ignitevisorcmd {-b=<batch commands file path>} {-e=command1;command2}"
+        )
+
+        visor.quit()
+    }
+
+    var inputStream: InputStream = new FileInputStream(FileDescriptor.in)
+
+    batchFile.foreach(name => {
+        val f = U.resolveIgnitePath(name)
+
+        if (f == null) {
+            visor.warn(
+                "Can't find batch commands file: " + name,
+                "Usage: ignitevisorcmd {-b=<batch command file path>} {-e=command1;command2}"
+            )
+
+            visor.quit()
+        }
+
+        inputStream = new FileInputStream(f)
+    })
+
+    batchCommand.foreach(commands => {
+        val input = commands.replace(";", "\n")
+
+        inputStream = new ByteArrayInputStream(input.getBytes("UTF-8"))
+    })
+
+    private val reader = new ConsoleReader(inputStream, System.out, null, null)
 
     reader.addCompleter(new VisorCommandCompleter(visor.commands))
     reader.addCompleter(new VisorFileNameCompleter())
@@ -145,7 +185,7 @@ object VisorConsole extends App {
                         case _ => adviseToHelp(line)
                     }
                 } catch {
-                    case ignore: Exception => ignore.printStackTrace()
+                    case ignore: Exception => adviseToHelp(line)
                 }
             }
         }
@@ -153,6 +193,8 @@ object VisorConsole extends App {
 
     def terminalWidth() = reader.getTerminal.getWidth
 
+    def consoleReader() = reader
+
     /**
      * Prints standard 'Invalid command' error message.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/65625830/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ack/VisorAckCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ack/VisorAckCommand.scala
b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ack/VisorAckCommand.scala
index be62eba..60cac88 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ack/VisorAckCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/ack/VisorAckCommand.scala
@@ -22,9 +22,9 @@ import org.apache.ignite.internal.visor.misc.VisorAckTask
 
 import java.util.{HashSet => JavaHashSet}
 
-import org.apache.ignite.visor.{VisorTag, visor}
 import org.apache.ignite.visor.commands.VisorConsoleCommand
-import visor._
+import org.apache.ignite.visor.visor._
+import org.apache.ignite.visor.{VisorTag, visor}
 
 import scala.collection.JavaConversions._
 import scala.language.implicitConversions
@@ -157,5 +157,5 @@ object VisorAckCommand {
      *
      * @param vs Visor tagging trait.
      */
-    implicit def fromAck2Visor(vs: VisorTag) = cmd
+    implicit def fromAck2Visor(vs: VisorTag): VisorAckCommand = cmd
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/65625830/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 ba5f460..5aa1f90 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
@@ -17,8 +17,6 @@
 
 package org.apache.ignite.visor.commands.gc
 
-import org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException
-
 import org.apache.ignite._
 
 import org.apache.ignite.cluster.{ClusterGroupEmptyException, ClusterNode}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/65625830/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 e066c6f..5187510 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
@@ -219,7 +219,7 @@ class VisorKillCommand {
 
         val op = if (restart) "restart" else "kill"
 
-        if (nodes.size() == ignite.nodes().size())
+        if (nodes.size == ignite.nodes().size())
             ask("Are you sure you want to " + op + " ALL nodes? (y/n) [n]: ", "n") match
{
                 case "y" | "Y" =>  ask("You are about to " + op + " ALL nodes. " +
                     "Are you 100% sure? (y/n) [n]: ", "n") match {
@@ -230,7 +230,7 @@ class VisorKillCommand {
                 case "n" | "N" => break()
                 case x => nl(); warn("Invalid answer: " + x); break()
             }
-        else if (nodes.size() > 1)
+        else if (nodes.size > 1)
             ask("Are you sure you want to " + op + " several nodes? (y/n) [n]: ", "n") match
{
                 case "y" | "Y" => ()
                 case "n" | "N" => break()
@@ -352,5 +352,5 @@ object VisorKillCommand {
      *
      * @param vs Visor tagging trait.
      */
-    implicit def fromKill2Visor(vs: VisorTag) = cmd
+    implicit def fromKill2Visor(vs: VisorTag): VisorKillCommand = cmd
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/65625830/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 f8b0608..829bea5 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
@@ -141,7 +141,7 @@ class VisorPingCommand {
                     else {
                         val ns = nodeById8(id8._2)
 
-                        if (ns.size() != 1)
+                        if (ns.size != 1)
                             scold("Unknown ID8: " + argName(id8))
                         else
                             pings +:= Pinger(ns.head, res)
@@ -224,5 +224,5 @@ object VisorPingCommand {
      *
      * @param vs Visor tagging trait.
      */
-    implicit def fromPing2Visor(vs: VisorTag) = cmd
+    implicit def fromPing2Visor(vs: VisorTag): VisorPingCommand = cmd
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/65625830/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 bc137ab..ab84e7c 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
@@ -1480,5 +1480,5 @@ object VisorTasksCommand {
      *
      * @param vs Visor tagging trait.
      */
-    implicit def fromTrace2Visor(vs: VisorTag) = cmd
+    implicit def fromTrace2Visor(vs: VisorTag): VisorTasksCommand = cmd
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/65625830/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 83abc22..2e13a60 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
@@ -17,23 +17,18 @@
 
 package org.apache.ignite.visor
 
-import java.io._
-import java.net._
-import java.text._
-import java.util.concurrent._
-import java.util.{HashSet => JHashSet, _}
-
 import org.apache.ignite.IgniteSystemProperties._
+import org.apache.ignite._
 import org.apache.ignite.cluster.{ClusterGroup, ClusterMetrics, ClusterNode}
 import org.apache.ignite.configuration.IgniteConfiguration
 import org.apache.ignite.events.EventType._
 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.processors.spring.IgniteSpringProcessor
-import org.apache.ignite.internal.{IgniteVersionUtils, IgniteEx}
-import IgniteVersionUtils._
 import org.apache.ignite.internal.util.lang.{GridFunc => F}
 import org.apache.ignite.internal.util.typedef._
 import org.apache.ignite.internal.util.{GridConfigurationFinder, IgniteUtils}
@@ -43,13 +38,20 @@ import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask.VisorN
 import org.apache.ignite.lang.{IgniteNotPeerDeployable, IgnitePredicate}
 import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi
 import org.apache.ignite.thread.IgniteThreadPoolExecutor
-import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable}
-import org.apache.ignite._
+
 import org.jetbrains.annotations.Nullable
 
+import java.io._
+import java.net._
+import java.text._
+import java.util.concurrent._
+import java.util.{HashSet => JHashSet, _}
+
+import org.apache.ignite.visor.commands.VisorConsole.consoleReader
+import org.apache.ignite.visor.commands._
+
 import scala.collection.JavaConversions._
 import scala.collection.immutable
-import scala.io.StdIn
 import scala.language.{implicitConversions, reflectiveCalls}
 import scala.util.control.Breaks._
 
@@ -2034,14 +2036,12 @@ object visor extends VisorTag {
      * @param prompt User prompt.
      * @param mask Mask character (if `None`, no masking will be applied).
      */
-    private def readLineOpt(prompt: String, mask: Option[Char]): Option[String] =
+    private def readLineOpt(prompt: String, mask: Option[Char] = None): Option[String] =
         try {
-            val reader = new scala.tools.jline.console.ConsoleReader()
-
             val s = if (mask.isDefined)
-                reader.readLine(prompt, mask.get)
+                consoleReader().readLine(prompt, mask.get)
             else
-                reader.readLine(prompt)
+                consoleReader().readLine(prompt)
 
             Option(s)
         }
@@ -2061,11 +2061,15 @@ object visor extends VisorTag {
 
         (0 until ids.size).foreach(i => println((i + 1) + ": " + ids(i)))
 
-        println("\nC: Cancel")
+        nl()
+
+        println("C: Cancel")
+
+        nl()
 
-        StdIn.readLine("\nChoose node: ") match {
-            case "c" | "C" => None
-            case idx =>
+        readLineOpt("Choose node: ") match {
+            case Some("c") | Some("C") | None => None
+            case Some(idx) =>
                 try
                     Some(ids(idx.toInt - 1))
                 catch {


Mime
View raw message