Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6196518DEB for ; Wed, 8 Jul 2015 17:32:04 +0000 (UTC) Received: (qmail 48706 invoked by uid 500); 8 Jul 2015 17:32:04 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 48673 invoked by uid 500); 8 Jul 2015 17:32:04 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 48662 invoked by uid 99); 8 Jul 2015 17:32:04 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Jul 2015 17:32:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id CEFD7D3130 for ; Wed, 8 Jul 2015 17:32:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.135 X-Spam-Level: * X-Spam-Status: No, score=1.135 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.666, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id dlGd5Fb0IO17 for ; Wed, 8 Jul 2015 17:31:52 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 0EF6F20F46 for ; Wed, 8 Jul 2015 17:31:52 +0000 (UTC) Received: (qmail 46176 invoked by uid 99); 8 Jul 2015 17:31:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Jul 2015 17:31:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AD364E0974; Wed, 8 Jul 2015 17:31:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ivasilinets@apache.org To: commits@ignite.incubator.apache.org Message-Id: <49678b60d1a841d1b59ed259559f0acb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-ignite git commit: #ignite-964: NodeJs add method ignite.destroyCache() Date: Wed, 8 Jul 2015 17:31:51 +0000 (UTC) Repository: incubator-ignite Updated Branches: refs/heads/ignite-964-1 ae2d0c2ff -> 8733ba258 #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-1 Commit: 8733ba258a004d9ce74665ce90c5c8289014ec0f Parents: ae2d0c2 Author: ivasilinets Authored: Wed Jul 8 20:31:32 2015 +0300 Committer: ivasilinets 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 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 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 { /** 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"));