You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/08/21 08:40:26 UTC
[17/50] [abbrv] ignite git commit: IGNITE-5586 Toggle cluster active
state.
IGNITE-5586 Toggle cluster active state.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5283e19f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5283e19f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5283e19f
Branch: refs/heads/ignite-5578
Commit: 5283e19fe21c5b898965ade70cc86e9c64254388
Parents: c5adf46
Author: vsisko <vs...@gridgain.com>
Authored: Thu Aug 17 14:55:08 2017 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Thu Aug 17 14:55:08 2017 +0700
----------------------------------------------------------------------
.../commands/top/VisorTopologyCommand.scala | 111 ++++++++++++-------
.../ignite/visor/VisorRuntimeBaseSpec.scala | 9 +-
.../top/VisorActivationCommandSpec.scala | 67 +++++++++++
.../testsuites/VisorConsoleSelfTestSuite.scala | 3 +-
4 files changed, 146 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5283e19f/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 63b6d2b..b75afc6 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
@@ -48,6 +48,8 @@ import scala.util.control.Breaks._
* ====Specification====
* {{{
* top "{-c1=e1<num> -c2=e2<num> ... -ck=ek<num>} {-h=<host1> ... -h=<hostk>} {-a}"
+ * top -activate
+ * top -deactivate
* }}}
*
* ====Arguments====
@@ -87,6 +89,10 @@ import scala.util.control.Breaks._
* -a
* This defines whether to show a separate table of nodes
* with detail per-node information.
+ * -activate
+ * Activate cluster.
+ * -deactivate
+ * Deactivate cluster.
* }}}
*
* ====Examples====
@@ -99,6 +105,10 @@ import scala.util.control.Breaks._
* Prints topology for provided hosts.
* top
* Prints full topology.
+ * top -activate
+ * Activate cluster.
+ * top -deactivate
+ * Deactivate cluster.
* }}}
*/
class VisorTopologyCommand extends VisorConsoleCommand {
@@ -140,47 +150,53 @@ class VisorTopologyCommand extends VisorConsoleCommand {
else {
val argLst = parseArgs(args)
- val hosts = argLst.filter(_._1 == "h").map((a: Arg) =>
- try
- InetAddress.getByName(a._2).getHostAddress
+ if (hasArgFlag("activate", argLst))
+ ignite.active(true)
+ else if (hasArgFlag("deactivate", argLst))
+ ignite.active(false)
+ else {
+ val hosts = argLst.filter(_._1 == "h").map((a: Arg) =>
+ try
+ InetAddress.getByName(a._2).getHostAddress
+ catch {
+ case e: UnknownHostException => scold("Unknown host: " + a._2).^^
+
+ "" // Never happens.
+ }
+ ).filter(!_.isEmpty).toSet
+
+ val all = hasArgFlag("a", argLst)
+
+ var f: NodeFilter = (ClusterNode) => true
+
+ try {
+ argLst foreach (arg => {
+ val (n, v) = arg
+
+ n match {
+ case "cc" if v != null => f = make(v, f, _.metrics.getTotalCpus)
+ case "cl" if v != null => f = make(v, f, (n: ClusterNode) =>
+ (n.metrics.getCurrentCpuLoad * 100).toLong)
+ case "aj" if v != null => f = make(v, f, _.metrics.getCurrentActiveJobs)
+ case "cj" if v != null => f = make(v, f, _.metrics.getCurrentCancelledJobs)
+ case "tc" if v != null => f = make(v, f, _.metrics.getCurrentThreadCount)
+ case "ut" if v != null => f = make(v, f, _.metrics.getUpTime)
+ case "je" if v != null => f = make(v, f, _.metrics.getCurrentJobExecuteTime)
+ case "jw" if v != null => f = make(v, f, _.metrics.getCurrentJobWaitTime)
+ case "wj" if v != null => f = make(v, f, _.metrics.getCurrentWaitingJobs)
+ case "rj" if v != null => f = make(v, f, _.metrics.getCurrentRejectedJobs)
+ case "hu" if v != null => f = make(v, f, _.metrics.getHeapMemoryUsed)
+ case "hm" if v != null => f = make(v, f, _.metrics.getHeapMemoryMaximum)
+ case _ => ()
+ }
+ })
+
+ show(n => f(n), hosts, all)
+ }
catch {
- case e: UnknownHostException => scold("Unknown host: " + a._2).^^
-
- "" // Never happens.
+ case e: NumberFormatException => scold(e)
+ case e: IgniteException => scold(e)
}
- ).filter(!_.isEmpty).toSet
-
- val all = hasArgFlag("a", argLst)
-
- var f: NodeFilter = (ClusterNode) => true
-
- try {
- argLst foreach (arg => {
- val (n, v) = arg
-
- n match {
- case "cc" if v != null => f = make(v, f, _.metrics.getTotalCpus)
- case "cl" if v != null => f = make(v, f, (n: ClusterNode) =>
- (n.metrics.getCurrentCpuLoad * 100).toLong)
- case "aj" if v != null => f = make(v, f, _.metrics.getCurrentActiveJobs)
- case "cj" if v != null => f = make(v, f, _.metrics.getCurrentCancelledJobs)
- case "tc" if v != null => f = make(v, f, _.metrics.getCurrentThreadCount)
- case "ut" if v != null => f = make(v, f, _.metrics.getUpTime)
- case "je" if v != null => f = make(v, f, _.metrics.getCurrentJobExecuteTime)
- case "jw" if v != null => f = make(v, f, _.metrics.getCurrentJobWaitTime)
- case "wj" if v != null => f = make(v, f, _.metrics.getCurrentWaitingJobs)
- case "rj" if v != null => f = make(v, f, _.metrics.getCurrentRejectedJobs)
- case "hu" if v != null => f = make(v, f, _.metrics.getHeapMemoryUsed)
- case "hm" if v != null => f = make(v, f, _.metrics.getHeapMemoryMaximum)
- case _ => ()
- }
- })
-
- show(n => f(n), hosts, all)
- }
- catch {
- case e: NumberFormatException => scold(e)
- case e: IgniteException => scold(e)
}
}
}
@@ -322,6 +338,7 @@ class VisorTopologyCommand extends VisorConsoleCommand {
val sumT = VisorTextTable()
+ sumT += ("Active", ignite.active)
sumT += ("Total hosts", U.neighborhood(nodes).size)
sumT += ("Total nodes", m.getTotalNodes)
sumT += ("Total CPUs", m.getTotalCpus)
@@ -348,7 +365,9 @@ object VisorTopologyCommand {
name = "top",
shortInfo = "Prints current topology.",
spec = List(
- "top {-c1=e1<num> -c2=e2<num> ... -ck=ek<num>} {-h=<host1> ... -h=<hostk>} {-a}"
+ "top {-c1=e1<num> -c2=e2<num> ... -ck=ek<num>} {-h=<host1> ... -h=<hostk>} {-a}",
+ "top -activate",
+ "top -deactivate"
),
args = List(
"-ck=ek<num>" -> List(
@@ -388,6 +407,12 @@ object VisorTopologyCommand {
"-a" -> List(
"This defines whether to show a separate table of nodes",
"with detail per-node information."
+ ),
+ "-activate" -> List(
+ "Activate cluster."
+ ),
+ "-deactivate" -> List(
+ "Deactivate cluster."
)
),
examples = List(
@@ -398,7 +423,11 @@ object VisorTopologyCommand {
"top -h=10.34.2.122 -h=10.65.3.11" ->
"Prints topology for provided hosts.",
"top" ->
- "Prints full topology."
+ "Prints full topology.",
+ "top -activate" ->
+ "Activate cluster.",
+ "top -deactivate" ->
+ "Deactivate cluster."
),
emptyArgs = cmd.top,
withArgs = cmd.top
http://git-wip-us.apache.org/repos/asf/ignite/blob/5283e19f/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
index 38db760..f5d6e56 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/VisorRuntimeBaseSpec.scala
@@ -20,8 +20,8 @@ package org.apache.ignite.visor
import org.apache.ignite.Ignition
import org.apache.ignite.configuration.IgniteConfiguration
import org.apache.ignite.visor.commands.open.VisorOpenCommand._
-
import org.scalatest._
+import VisorRuntimeBaseSpec._
/**
* Base abstract class for unit tests requiring Visor runtime.
@@ -45,7 +45,7 @@ abstract class VisorRuntimeBaseSpec(private[this] val num: Int) extends FunSpec
}
protected def openVisor() {
- visor.open(config("visor-demo-node"), "n/a")
+ visor.open(config(VISOR_INSTANCE_NAME), "n/a")
}
protected def closeVisorQuiet() {
@@ -75,3 +75,8 @@ abstract class VisorRuntimeBaseSpec(private[this] val num: Int) extends FunSpec
closeVisorQuiet()
}
}
+
+/** Singleton companion object. */
+object VisorRuntimeBaseSpec {
+ val VISOR_INSTANCE_NAME = "visor-demo-node"
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5283e19f/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorActivationCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorActivationCommandSpec.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorActivationCommandSpec.scala
new file mode 100644
index 0000000..fb2a7f4
--- /dev/null
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/top/VisorActivationCommandSpec.scala
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.visor.commands.top
+
+import org.apache.ignite.Ignition
+import org.apache.ignite.configuration.{IgniteConfiguration, MemoryConfiguration, PersistentStoreConfiguration}
+import org.apache.ignite.visor.commands.top.VisorTopologyCommand._
+import org.apache.ignite.visor.{VisorRuntimeBaseSpec, visor}
+import VisorRuntimeBaseSpec._
+
+/**
+ * Unit test for cluster activation commands.
+ */
+class VisorActivationCommandSpec extends VisorRuntimeBaseSpec(2) {
+ override protected def config(name: String): IgniteConfiguration = {
+ val cfg = super.config(name)
+
+ val memCfg = new MemoryConfiguration
+ memCfg.setDefaultMemoryPolicySize(10 * 1024 * 1024)
+
+ cfg.setMemoryConfiguration(memCfg)
+ cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration)
+
+ cfg
+ }
+
+ describe("A 'top' visor command for cluster activation") {
+ it("should activate cluster") {
+ assert(!Ignition.ignite(VISOR_INSTANCE_NAME).active())
+
+ visor.top()
+
+ visor.top("-activate")
+
+ visor.top()
+
+ assert(Ignition.ignite(VISOR_INSTANCE_NAME).active())
+ }
+
+ it("should deactivate cluster") {
+ assert(Ignition.ignite(VISOR_INSTANCE_NAME).active())
+
+ visor.top()
+
+ visor.top("-deactivate")
+
+ visor.top()
+
+ assert(!Ignition.ignite(VISOR_INSTANCE_NAME).active())
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5283e19f/modules/visor-console/src/test/scala/org/apache/ignite/visor/testsuites/VisorConsoleSelfTestSuite.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/testsuites/VisorConsoleSelfTestSuite.scala b/modules/visor-console/src/test/scala/org/apache/ignite/visor/testsuites/VisorConsoleSelfTestSuite.scala
index f23a7c9..5fbc8a0 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/testsuites/VisorConsoleSelfTestSuite.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/testsuites/VisorConsoleSelfTestSuite.scala
@@ -39,7 +39,7 @@ import org.apache.ignite.visor.commands.open.VisorOpenCommandSpec
import org.apache.ignite.visor.commands.ping.VisorPingCommandSpec
import org.apache.ignite.visor.commands.start.VisorStartCommandSpec
import org.apache.ignite.visor.commands.tasks.VisorTasksCommandSpec
-import org.apache.ignite.visor.commands.top.VisorTopologyCommandSpec
+import org.apache.ignite.visor.commands.top.{VisorActivationCommandSpec, VisorTopologyCommandSpec}
import org.junit.runner.RunWith
import org.scalatest.Suites
import org.scalatest.junit.JUnitRunner
@@ -69,6 +69,7 @@ class VisorConsoleSelfTestSuite extends Suites (
new VisorStartCommandSpec,
new VisorTasksCommandSpec,
new VisorTopologyCommandSpec,
+ new VisorActivationCommandSpec,
new VisorArgListSpec
) {
// Mimic GridTestUtils.getNextMulticastGroup behavior because it can't be imported here