IGNITE-6999 Visor CMD: Added support for "-quiet" option in batch mode.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1e8b5501 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1e8b5501 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1e8b5501 Branch: refs/heads/ignite-zk Commit: 1e8b5501ee9fde61f979c104b4d271a1a458eb1d Parents: 93e133c Author: vsisko <[email protected]> Authored: Sun Dec 10 20:13:05 2017 +0700 Committer: Alexey Kuznetsov <[email protected]> Committed: Sun Dec 10 20:13:05 2017 +0700 ---------------------------------------------------------------------- .../ignite/visor/commands/VisorConsole.scala | 25 ++++++++------ .../visor/commands/open/VisorOpenCommand.scala | 34 +++++++++++++------- .../scala/org/apache/ignite/visor/visor.scala | 25 ++++++++------ 3 files changed, 54 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/1e8b5501/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 d53a0d5..ce8b313 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 @@ -84,7 +84,7 @@ class VisorConsole { if (hasArgFlag("?", argLst) || hasArgFlag("help", argLst)) { println("Usage:") - println(s" $progName [? | -help]|[{-v}{-np} {-cfg=<path>}]|[{-b=<path>} {-e=command1;command2;...}]") + println(s" $progName [? | -help]|[{-v}{-np} {-cfg=<path>}]|[{-b=<path>} {-e=command1;command2;...} -quiet]") println(" Where:") println(" ?, /help, -help - show this message.") println(" -v - verbose mode (quiet by default).") @@ -93,6 +93,7 @@ class VisorConsole { println(" -b=<path> - batch mode with file.") println(" -e=cmd1;cmd2;... - batch mode with commands.") println(" -nq - batch mode will not quit after execution (useful for alerts monitoring).") + println(" -quiet - batch mode will not print inform message and node log.") visor.quit() } @@ -100,15 +101,19 @@ class VisorConsole { argLst } - protected def buildReader(argLst: ArgList) = { + protected def buildReader(argLst: ArgList): ConsoleReader = { val cfgFile = argValue("cfg", argLst) val batchFile = argValue("b", argLst) val batchCommand = argValue("e", argLst) val noBatchQuit = hasArgName("nq", argLst) + val quiet = hasArgName("quiet", argLst) if (noBatchQuit && batchFile.isEmpty && batchCommand.isEmpty) visor.warn("Option \"-nq\" will be ignored because batch mode options \"-b\" or \"-e\" were not specified.") + if (quiet && batchFile.isEmpty && batchCommand.isEmpty) + visor.warn("Option \"-quiet\" will be ignored because batch mode options \"-b\" or \"-e\" were not specified.") + cfgFile.foreach(cfg => { if (cfg.trim.isEmpty) { visor.warn("Expected path to configuration after \"-cfg\" option.") @@ -153,6 +158,7 @@ class VisorConsole { val inputStream = batchStream match { case Some(cmd) => visor.batchMode = true + visor.quiet = quiet val script = if (noBatchQuit) cmd else cmd + "\nquit\n" @@ -179,7 +185,8 @@ class VisorConsole { } protected def mainLoop(reader: ConsoleReader) { - welcomeMessage() + if (!visor.quiet) + welcomeMessage() var ok = true @@ -194,7 +201,7 @@ class VisorConsole { val buf = new StringBuilder while (ok) { - line = reader.readLine("visor> ") + line = reader.readLine(if (visor.quiet) null else "visor> ") ok = line != null @@ -253,11 +260,11 @@ class VisorConsole { * Print banner, hint message on start. */ protected def welcomeMessage() { - println("___ _________________________ ________" + NL + - "__ | / /____ _/__ ___/__ __ \\___ __ \\" + NL + - "__ | / / __ / _____ \\ _ / / /__ /_/ /" + NL + - "__ |/ / __/ / ____/ / / /_/ / _ _, _/" + NL + - "_____/ /___/ /____/ \\____/ /_/ |_|" + NL + + println("___ _________________________ ________" + NL + + "__ | / /____ _/__ ___/__ __ \\___ __ \\" + NL + + "__ | / / __ / _____ \\ _ / / /__ /_/ /" + NL + + "__ |/ / __/ / ____/ / / /_/ / _ _, _/" + NL + + "_____/ /___/ /____/ \\____/ /_/ |_|" + NL + NL + "ADMIN CONSOLE" + NL + copyright()) http://git-wip-us.apache.org/repos/asf/ignite/blob/1e8b5501/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala index 1cfbde4..949aa00 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala @@ -19,7 +19,8 @@ package org.apache.ignite.visor.commands.open -import java.util.logging.{ConsoleHandler, Logger} +import java.net.URL +import java.util.logging.{ConsoleHandler, Level, Logger} import org.apache.ignite.IgniteSystemProperties._ import org.apache.ignite.configuration.IgniteConfiguration @@ -28,14 +29,13 @@ import org.apache.ignite.internal.IgniteEx import org.apache.ignite.internal.util.scala.impl import org.apache.ignite.internal.util.spring.IgniteSpringHelper import org.apache.ignite.internal.util.{IgniteUtils => U} +import org.apache.ignite.logger.NullLogger import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi import org.apache.ignite.visor.commands.common.{VisorConsoleCommand, VisorTextTable} import org.apache.ignite.visor.visor._ import org.apache.ignite.visor.{VisorTag, visor} import org.apache.ignite.{IgniteException, IgniteSystemProperties, Ignition} -import java.net.URL - import scala.language.{implicitConversions, reflectiveCalls} /** @@ -134,7 +134,15 @@ class VisorOpenCommand extends VisorConsoleCommand { // Add no-op logger to remove no-appender warning. val log4jTup = - if (classOf[Ignition].getClassLoader.getResource("org/apache/log4j/Appender.class") != null) + if (visor.quiet) { + val springLog = Logger.getLogger("org.springframework") + + if (springLog != null) + springLog.setLevel(Level.WARNING) + + null + } + else if (classOf[Ignition].getClassLoader.getResource("org/apache/log4j/Appender.class") != null) U.addLog4jNoOpLogger() else null @@ -147,7 +155,7 @@ class VisorOpenCommand extends VisorConsoleCommand { spring.loadConfigurations(url, "cacheConfiguration", "fileSystemConfiguration", "lifecycleBeans", "indexingSpi").get1() finally { - if (log4jTup != null) + if (log4jTup != null && !visor.quiet) U.removeLog4jNoOpLogger(log4jTup) } @@ -159,12 +167,16 @@ class VisorOpenCommand extends VisorConsoleCommand { val cfg = cfgs.iterator().next() - if (log4jTup != null) - System.setProperty(IgniteSystemProperties.IGNITE_CONSOLE_APPENDER, "false") - else - Logger.getGlobal.getHandlers.foreach({ - case handler: ConsoleHandler => Logger.getGlobal.removeHandler(handler) - }) + if (visor.quiet) + cfg.setGridLogger(new NullLogger) + else { + if (log4jTup != null) + System.setProperty(IgniteSystemProperties.IGNITE_CONSOLE_APPENDER, "false") + else + Logger.getGlobal.getHandlers.foreach({ + case handler: ConsoleHandler => Logger.getGlobal.removeHandler(handler) + }) + } // Setting up 'Config URL' for properly print in console. System.setProperty(IgniteSystemProperties.IGNITE_CONFIG_URL, url.getPath) http://git-wip-us.apache.org/repos/asf/ignite/blob/1e8b5501/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 28c4301..069e50f 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 @@ -240,6 +240,9 @@ object visor extends VisorTag { var batchMode: Boolean = false + /** Quiet mode to disable node log and information messages output. */ + var quiet: Boolean = false + def reader(reader: ConsoleReader) { assert(reader != null) @@ -1658,20 +1661,22 @@ object visor extends VisorTag { nl() - val t = VisorTextTable() + if (!visor.quiet) { + val t = VisorTextTable() - // Print advise. - println("Some useful commands:") + // Print advise. + println("Some useful commands:") - t += ("Type 'top'", "to see full topology.") - t += ("Type 'node'", "to see node statistics.") - t += ("Type 'cache'", "to see cache statistics.") - t += ("Type 'tasks'", "to see tasks statistics.") - t += ("Type 'config'", "to see node configuration.") + t += ("Type 'top'", "to see full topology.") + t += ("Type 'node'", "to see node statistics.") + t += ("Type 'cache'", "to see cache statistics.") + t += ("Type 'tasks'", "to see tasks statistics.") + t += ("Type 'config'", "to see node configuration.") - t.render() + t.render() - println("\nType 'help' to get help.\n") + println("\nType 'help' to get help.\n") + } status() }
