ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject incubator-ignite git commit: # GG-9945 Review.
Date Mon, 30 Mar 2015 07:41:42 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-639 [created] 58d241c63


# GG-9945 Review.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/58d241c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/58d241c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/58d241c6

Branch: refs/heads/ignite-639
Commit: 58d241c63d2eccf7e66da208804fbd2ce4e6503a
Parents: 8e590f9
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Mon Mar 30 14:41:50 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Mon Mar 30 14:41:50 2015 +0700

----------------------------------------------------------------------
 .../visor/cache/VisorCacheStopTask.java         |  69 ++++++++++
 .../cache/VisorCacheStoreConfiguration.java     |  18 ++-
 .../commands/cache/VisorCacheCommand.scala      |  23 +++-
 .../commands/cache/VisorCacheStopCommand.scala  | 135 +++++++++++++++++++
 4 files changed, 235 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58d241c6/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStopTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStopTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStopTask.java
new file mode 100644
index 0000000..0e848f9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStopTask.java
@@ -0,0 +1,69 @@
+/*
+ * 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.internal.visor.cache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.processors.task.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.internal.visor.*;
+
+/**
+ * Task that stop specified caches on specified node.
+ */
+@GridInternal
+public class VisorCacheStopTask extends VisorOneNodeTask<String, Void> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override protected VisorCacheStopJob job(String arg) {
+        return new VisorCacheStopJob(arg, debug);
+    }
+
+    /**
+     * Job that stop specified caches.
+     */
+    private static class VisorCacheStopJob extends VisorJob<String, Void> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /**
+         * Create job.
+         *
+         * @param cacheName Cache name to clear.
+         * @param debug Debug flag.
+         */
+        private VisorCacheStopJob(String cacheName, boolean debug) {
+            super(cacheName, debug);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected Void run(String cacheName) {
+            IgniteCache cache = ignite.cache(cacheName);
+
+            cache.close();
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(VisorCacheStopJob.class, this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58d241c6/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStoreConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStoreConfiguration.java
index 7284b7d..a4a2235 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStoreConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheStoreConfiguration.java
@@ -22,6 +22,7 @@ import org.apache.ignite.cache.store.*;
 import org.apache.ignite.cache.store.jdbc.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.jetbrains.annotations.*;
 
@@ -67,13 +68,16 @@ public class VisorCacheStoreConfiguration implements Serializable {
     private int flushThreadCnt;
 
     /**
+     * @param ignite Ignite instance.
      * @param ccfg Cache configuration.
      * @return Data transfer object for cache store configuration properties.
      */
     public static VisorCacheStoreConfiguration from(Ignite ignite, CacheConfiguration ccfg)
{
         VisorCacheStoreConfiguration cfg = new VisorCacheStoreConfiguration();
 
-        CacheStore store = ((IgniteKernal)ignite).internalCache(ccfg.getName()).context().store().configuredStore();
+        GridCacheAdapter<Object, Object> c = ((IgniteKernal)ignite).internalCache(ccfg.getName());
+
+        CacheStore store = c != null && c.context().started() ? c.context().store().configuredStore()
: null;
 
         cfg.jdbcStore = store instanceof CacheAbstractJdbcStore;
 
@@ -156,10 +160,10 @@ public class VisorCacheStoreConfiguration implements Serializable {
     }
 
     /**
-     * @param batchSize New maximum batch size for write-behind cache store operations.
+     * @param batchSz New maximum batch size for write-behind cache store operations.
      */
-    public void batchSize(int batchSize) {
-        this.batchSz = batchSize;
+    public void batchSize(int batchSz) {
+        this.batchSz = batchSz;
     }
 
     /**
@@ -184,10 +188,10 @@ public class VisorCacheStoreConfiguration implements Serializable {
     }
 
     /**
-     * @param flushSize New maximum object count in write-behind cache.
+     * @param flushSz New maximum object count in write-behind cache.
      */
-    public void flushSize(int flushSize) {
-        this.flushSz = flushSize;
+    public void flushSize(int flushSz) {
+        this.flushSz = flushSz;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58d241c6/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 eb6e040..f044d53 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
@@ -59,6 +59,8 @@ import scala.util.control.Breaks._
  * +-----------------------------------------------------------------------------------------+
  * | cache -scan    | List all entries in cache with specified name.                    
    |
  * +-----------------------------------------------------------------------------------------+
+ * | cache -stop    | Stop cache with specified name.                                   
    |
+ * +-----------------------------------------------------------------------------------------+
  * }}}
  *
  * ====Specification====
@@ -69,6 +71,7 @@ import scala.util.control.Breaks._
  *     cache -clear {-c=<cache-name>}
  *     cache -scan -c=<cache-name> {-id=<node-id>|id8=<node-id8>} {-p=<page
size>}
  *     cache -swap {-c=<cache-name>} {-id=<node-id>|id8=<node-id8>}
+ *     cache -stop -c=<cache-name>
  * }}}
  *
  * ====Arguments====
@@ -106,6 +109,8 @@ import scala.util.control.Breaks._
  *          Prints list of all entries from cache.
  *     -swap
  *          Swaps backup entries in cache.
+ *     -stop
+ *          Stop cache with specified name.
  *     -p=<page size>
  *         Number of object to fetch from cache at once.
  *         Valid range from 1 to 100.
@@ -142,6 +147,8 @@ import scala.util.control.Breaks._
  *         Swaps entries in cache with name 'cache'.
  *     cache -swap -c=@c0
  *         Swaps entries in cache with name taken from 'c0' memory variable.
+ *     cache -stop -c=cache
+ *         Stops cache with name 'cache'.
  * }}}
  */
 class VisorCacheCommand {
@@ -196,6 +203,9 @@ class VisorCacheCommand {
      * <br>
      * <ex>cache -swap -c=@c0</ex>
      *     Swaps entries in cache with name taken from 'c0' memory variable.
+     * <br>
+     * <ex>cache -stop -c=@c0</ex>
+     *     Stop cache with name taken from 'c0' memory variable.
      *
      * @param args Command arguments.
      */
@@ -237,7 +247,7 @@ class VisorCacheCommand {
                     case cn => cn
                 }
 
-                if (Seq("clear", "swap", "scan").exists(hasArgFlag(_, argLst))) {
+                if (Seq("clear", "swap", "scan", "stop").exists(hasArgFlag(_, argLst))) {
                     if (cacheName.isEmpty)
                         askForCache("Select cache from:", node) match {
                             case Some(name) => argLst = argLst ++ Seq("c" -> name)
@@ -250,6 +260,8 @@ class VisorCacheCommand {
                         VisorCacheSwapCommand().swap(argLst, node)
                     else if (hasArgFlag("scan", argLst))
                         VisorCacheScanCommand().scan(argLst, node)
+                    else if (hasArgFlag("stop", argLst))
+                        VisorCacheStopCommand().scan(argLst, node)
 
                     break()
                 }
@@ -633,7 +645,8 @@ object VisorCacheCommand {
             "cache {-c=<cache-name>} {-id=<node-id>|id8=<node-id8>} {-s=hi|mi|rd|wr}
{-a} {-r}",
             "cache -clear {-c=<cache-name>} {-id=<node-id>|id8=<node-id8>}",
             "cache -scan -c=<cache-name> {-id=<node-id>|id8=<node-id8>}
{-p=<page size>}",
-            "cache -swap {-c=<cache-name>} {-id=<node-id>|id8=<node-id8>}"
+            "cache -swap {-c=<cache-name>} {-id=<node-id>|id8=<node-id8>}",
+            "cache -stop -c=<cache-name>"
     ),
         args = Seq(
             "-id=<node-id>" -> Seq(
@@ -660,6 +673,9 @@ object VisorCacheCommand {
             "-swap" -> Seq(
                 "Swaps backup entries in cache."
             ),
+            "-stop" -> Seq(
+                "Stop cache with specified name"
+            ),
             "-s=hi|mi|rd|wr|cn" -> Seq(
                 "Defines sorting type. Sorted by:",
                 "   hi Hits.",
@@ -715,7 +731,8 @@ object VisorCacheCommand {
             "cache -scan -c=cache -id8=12345678" -> "Prints list entries from cache with
name 'cache' and node '12345678' ID8.",
             "cache -swap" -> "Swaps entries in interactively selected cache.",
             "cache -swap -c=cache" -> "Swaps entries in cache with name 'cache'.",
-            "cache -swap -c=@c0" -> "Swaps entries in cache with name taken from 'c0'
memory variable."
+            "cache -swap -c=@c0" -> "Swaps entries in cache with name taken from 'c0'
memory variable.",
+            "cache -stop -c=@c0" -> "Stop cache with name taken from 'c0' memory variable."
         ),
         ref = VisorConsoleCommand(cmd.cache, cmd.cache)
     )

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/58d241c6/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
new file mode 100644
index 0000000..4c1aa10
--- /dev/null
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheStopCommand.scala
@@ -0,0 +1,135 @@
+/*
+ * 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.cache
+
+import org.apache.ignite.cluster.ClusterNode
+import org.apache.ignite.visor.visor._
+import org.apache.ignite.internal.visor.util.VisorTaskUtils._
+
+import org.apache.ignite.internal.visor.cache.VisorCacheStopTask
+
+/**
+ * ==Overview==
+ * Visor 'stop' command implementation.
+ *
+ * ====Specification====
+ * {{{
+ *     cache -c=<cache name> -stop
+ * }}}
+ *
+ * ====Arguments====
+ * {{{
+ *     <cache-name>
+ *         Name of the cache.
+ * }}}
+ *
+ * ====Examples====
+ * {{{
+ *    cache -c=@c0 -stop
+ *        Stops cache with name taken from 'c0' memory variable.
+ * }}}
+ */
+class VisorCacheStopCommand {
+    /**
+     * Prints error message and advise.
+     *
+     * @param errMsgs Error messages.
+     */
+    private def scold(errMsgs: Any*) {
+        assert(errMsgs != null)
+
+        warn(errMsgs: _*)
+        warn("Type 'help cache' to see how to use this command.")
+    }
+
+    private def error(e: Exception) {
+        var cause: Throwable = e
+
+        while (cause.getCause != null)
+            cause = cause.getCause
+
+        scold(cause.getMessage)
+    }
+
+    /**
+     * ===Command===
+     * Stop cache with specified name.
+     *
+     * ===Examples===
+     * <ex>cache -c=cache -stop</ex>
+     *     Stop cache with name 'cache'.
+     *
+     * @param argLst Command arguments.
+     */
+    def scan(argLst: ArgList, node: Option[ClusterNode]) {
+        val cacheArg = argValue("c", argLst)
+
+        val cacheName = cacheArg match {
+            case None => null // default cache.
+
+            case Some(s) if s.startsWith("@") =>
+                warn("Can't find cache variable with specified name: " + s,
+                    "Type 'cache' to see available cache variables."
+                )
+
+                return
+
+            case Some(name) => name
+        }
+
+        val cachePrj = node match {
+            case Some(n) => ignite.cluster.forNode(n).forCacheNodes(cacheName)
+            case _ => ignite.cluster.forCacheNodes(cacheName)
+        }
+
+        if (cachePrj.nodes().isEmpty) {
+            warn("Can't find nodes with specified cache: " + escapeName(cacheName),
+                "Type 'cache' to see available cache names."
+            )
+
+            return
+        }
+
+        val stopPrj = cachePrj.forRandom()
+
+        val nid = stopPrj.node().id()
+
+        try {
+            ignite.compute(stopPrj)
+                .withName("visor-cstop-task")
+                .withNoFailover()
+                .execute(classOf[VisorCacheStopTask], toTaskArgument(nid, cacheName))
+
+            println("Visor successfully stop cache: " + escapeName(cacheName))
+        }
+        catch {
+            case e: Exception =>
+                error(e)
+        }
+    }
+}
+
+object VisorCacheStopCommand {
+    /** Singleton command. */
+    private val cmd = new VisorCacheStopCommand
+
+    /**
+     * Singleton.
+     */
+    def apply() = cmd
+}


Mime
View raw message