ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [30/50] [abbrv] incubator-ignite git commit: #ignite-964: NodeJs add method ignite.destroyCache()
Date Fri, 10 Jul 2015 08:57:52 GMT
#ignite-964: NodeJs add method ignite.destroyCache()


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

Branch: refs/heads/ignite-964
Commit: 8733ba258a004d9ce74665ce90c5c8289014ec0f
Parents: ae2d0c2
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Wed Jul 8 20:31:32 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Wed Jul 8 20:31:32 2015 +0300

----------------------------------------------------------------------
 .../processors/rest/GridRestCommand.java        |  3 ++
 .../handlers/cache/GridCacheCommandHandler.java | 35 +++++++++++++++++--
 modules/nodejs/src/main/js/ignite.js            | 11 ++++++
 .../ignite/internal/NodeJsIgniteSelfTest.java   |  7 ++++
 modules/nodejs/src/test/js/test-ignite.js       | 36 ++++++++++++++++++++
 .../http/jetty/GridJettyRestHandler.java        |  3 +-
 6 files changed, 91 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733ba25/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
index 987269c..00eb746 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
@@ -132,6 +132,9 @@ public enum GridRestCommand {
     /** Get or create cache. */
     GET_OR_CREATE_CACHE("getorcreatecache"),
 
+    /** Stops dynamically started cache. */
+    DESTROY_CACHE("destroycache"),
+
     /** Run script. */
     RUN_SCRIPT("runscript"),
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733ba25/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
index abc195c..c20360a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
@@ -53,6 +53,7 @@ import static org.apache.ignite.transactions.TransactionIsolation.*;
 public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter {
     /** Supported commands. */
     private static final Collection<GridRestCommand> SUPPORTED_COMMANDS = U.sealList(
+        DESTROY_CACHE,
         GET_OR_CREATE_CACHE,
         CACHE_CONTAINS_KEYS,
         CACHE_CONTAINS_KEY,
@@ -156,6 +157,12 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
             IgniteInternalFuture<GridRestResponse> fut;
 
             switch (cmd) {
+                case DESTROY_CACHE: {
+                    fut = ctx.closure().callLocalSafe(new DestroyCacheCommand(ctx, cacheName));
+
+                    break;
+                }
+
                 case GET_OR_CREATE_CACHE: {
                     fut = ctx.closure().callLocalSafe(new GetOrCreateCacheCallable(ctx, cacheName));
 
@@ -1331,14 +1338,36 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
     }
 
     /**
-     * Map reduce callable.
+     * Destroy cache callable.
+     */
+    private static class DestroyCacheCommand extends GetOrCreateCacheCallable {
+
+        public DestroyCacheCommand(GridKernalContext ctx, String cacheName) {
+            super(ctx, cacheName);
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            try {
+                ctx.grid().destroyCache(cacheName);
+
+                return new GridRestResponse();
+            }
+            catch (Exception e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Get or create cache callable.
      */
     private static class GetOrCreateCacheCallable implements Callable<GridRestResponse>
{
         /** Kernal context. */
-        private GridKernalContext ctx;
+        protected GridKernalContext ctx;
 
         /** Cache name. */
-        private String cacheName;
+        protected String cacheName;
 
         /**
          * @param ctx Kernal context.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733ba25/modules/nodejs/src/main/js/ignite.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/ignite.js b/modules/nodejs/src/main/js/ignite.js
index cbe8552..5dfb15b 100644
--- a/modules/nodejs/src/main/js/ignite.js
+++ b/modules/nodejs/src/main/js/ignite.js
@@ -74,6 +74,17 @@ Ignite.prototype.getOrCreateCache = function(cacheName, callback) {
 }
 
 /**
+ * Stops dynamically started cache
+ *
+ * @this {Ignite}
+ * @param {string} cacheName Cache name to stop
+ * @param {noValue} callback Callback contains only error
+ */
+Ignite.prototype.destroyCache = function(cacheName, callback) {
+    this._server.runCommand(new Command("destroycache").addParam("cacheName", cacheName),
callback);
+}
+
+/**
  * Get an instance of compute
  *
  * @this {Ignite}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733ba25/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
index 293409b..dcb0aa4 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
@@ -58,4 +58,11 @@ public class NodeJsIgniteSelfTest extends NodeJsAbstractTest {
     public void testCluster() throws Exception {
         runJsScript("testCluster");
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDestroyCache() throws Exception {
+        runJsScript("testDestroyCache");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733ba25/modules/nodejs/src/test/js/test-ignite.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-ignite.js b/modules/nodejs/src/test/js/test-ignite.js
index 99c5242..29501d7 100644
--- a/modules/nodejs/src/test/js/test-ignite.js
+++ b/modules/nodejs/src/test/js/test-ignite.js
@@ -78,4 +78,40 @@ testCluster = function() {
     }
 
     TestUtils.startIgniteNode(onStart.bind(null));
+}
+
+testDestroyCache = function() {
+    var cacheName = "NEW_CACHE";
+
+    function onErrorPut(err) {
+        assert(err !== null);
+
+        TestUtils.testDone();
+    }
+
+    function onDestroy(cache, err) {
+        assert(err === null, err);
+
+        cache.put("1", "1", onErrorPut);
+    }
+
+    function onPut(ignite, cache, err) {
+        assert(err === null, err);
+
+        ignite.destroyCache(cacheName, onDestroy.bind(null, cache));
+    }
+
+    function onGetOrCreateCache(ignite, err, cache) {
+        assert(err === null, err);
+
+        cache.put("1", "1", onPut.bind(null, ignite, cache));
+    }
+
+    function onStart(err, ignite) {
+        assert.equal(err, null);
+
+        ignite.getOrCreateCache(cacheName, onGetOrCreateCache.bind(null, ignite));
+    }
+
+    TestUtils.startIgniteNode(onStart.bind(null));
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733ba25/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index 13917f8..d601c17 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -360,7 +360,8 @@ public class GridJettyRestHandler extends AbstractHandler {
         GridRestRequest restReq;
 
         switch (cmd) {
-            case GET_OR_CREATE_CACHE: {
+            case GET_OR_CREATE_CACHE:
+            case DESTROY_CACHE: {
                 GridRestCacheRequest restReq0 = new GridRestCacheRequest();
 
                 restReq0.cacheName((String)params.get("cacheName"));


Mime
View raw message