ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [05/39] incubator-ignite git commit: #ignite-964: post put all.
Date Wed, 01 Jul 2015 10:13:41 GMT
#ignite-964: post put all.


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

Branch: refs/heads/ignite-964
Commit: 2c1ecf283773c992a8fdaec62de583abd56a340d
Parents: 02b5387
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Tue Jun 30 00:36:13 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Tue Jun 30 00:36:13 2015 +0300

----------------------------------------------------------------------
 .../processors/rest/GridRestCommand.java        |  3 ++
 .../handlers/cache/GridCacheCommandHandler.java |  2 ++
 modules/nodejs/src/main/js/cache.js             | 13 ++++++++
 modules/nodejs/src/main/js/server.js            |  9 +++++-
 .../ignite/internal/NodeJsCacheApiSelfTest.java |  7 ++++
 modules/nodejs/src/test/js/test-cache-api.js    |  8 +++++
 .../http/jetty/GridJettyRestHandler.java        | 34 ++++++++++++++++++++
 7 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c1ecf28/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 0afefb6..375a079 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
@@ -45,6 +45,9 @@ public enum GridRestCommand {
     /** Store several values in cache. */
     CACHE_PUT_ALL("putall"),
 
+    /** Store several values in cache. */
+    CACHE_PUT_ALL2("putall2"),
+
     /** Remove value from cache. */
     CACHE_REMOVE("rmv"),
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c1ecf28/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 1f24023..ef0391e 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
@@ -58,6 +58,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         CACHE_PUT,
         CACHE_ADD,
         CACHE_PUT_ALL,
+        CACHE_PUT_ALL2,
         CACHE_REMOVE,
         CACHE_REMOVE_ALL,
         CACHE_REPLACE,
@@ -190,6 +191,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
                     break;
                 }
 
+                case CACHE_PUT_ALL2:
                 case CACHE_PUT_ALL: {
                     Map<Object, Object> map = req0.values();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c1ecf28/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index fc988da..9f72589 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -108,6 +108,19 @@ Cache.prototype.putAll = function(map, callback) {
 }
 
 /**
+ * Put keys to cache
+ *
+ * @this {Cache}
+ * @param {Object.<string, string>} map collection of entries to put in the cache
+ * @param {noValue} callback Called on finish
+ */
+Cache.prototype.postPutAll = function(map, callback) {
+    var params = [this._cacheNameParam];
+
+    this._server.runCommand("putall2", params, callback, JSON.stringify(map));
+}
+
+/**
  * Callback for cache get
  *
  * @callback Cache~onGetAll

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c1ecf28/modules/nodejs/src/main/js/server.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/server.js b/modules/nodejs/src/main/js/server.js
index 81462a4..b3586e3 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -61,7 +61,7 @@ Server.prototype.host = function() {
  * @param params Parameters for command.
  * @param {onGet} Called on finish
  */
-Server.prototype.runCommand = function(cmdName, params, callback) {
+Server.prototype.runCommand = function(cmdName, params, callback, postData) {
     var paramsString = "";
 
     for (var p of params) {
@@ -75,10 +75,14 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
     var options = {
         host: this._host,
         port: this._port,
+        method : postData ? "POST" : "GET",
         path: "/ignite?" + requestQry,
         headers: this._signature()
     };
 
+    if (postData)
+        options.headers['Content-Length'] = postData.length;
+
     function streamCallback(response) {
         var fullResponseString = '';
 
@@ -125,6 +129,9 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
 
     request.on('error', callback);
 
+    if (postData)
+        request.write(postData);
+
     request.end();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c1ecf28/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
index f17ca60..a6c6140 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
@@ -84,4 +84,11 @@ public class NodeJsCacheApiSelfTest extends NodeJsAbstractTest {
     public void testPutAllGetAll() throws Exception {
         runJsScript("testPutAllGetAll");
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPostPutAllGetAll() throws Exception {
+        runJsScript("testPostPutAllGetAll");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c1ecf28/modules/nodejs/src/test/js/test-cache-api.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-cache-api.js b/modules/nodejs/src/test/js/test-cache-api.js
index 335f888..90ccbb6 100644
--- a/modules/nodejs/src/test/js/test-cache-api.js
+++ b/modules/nodejs/src/test/js/test-cache-api.js
@@ -35,6 +35,10 @@ testPutAllGetAll = function() {
     startTest("mycache", {trace: [putAll, getAll], entry: {"key1": "val1", "key2" : "val2"}});
 }
 
+testPostPutAllGetAll = function() {
+    startTest("mycache", {trace: [postPutAll, getAll], entry: {"key1": "val1", "key2" : "val2"}});
+}
+
 testRemoveAll = function() {
     startTest("mycache", {trace: [putAll, getAll, removeAll, getNone], entry: {"key1": "val1",
"key2" : "val2"}});
 }
@@ -93,6 +97,10 @@ function putAll(cache, entries, next) {
     cache.putAll(entries, next);
 }
 
+function postPutAll(cache, entries, next) {
+    cache.postPutAll(entries, next);
+}
+
 function getAll(cache, entries, next) {
     cache.getAll(Object.keys(entries), onGetAll);
     var expected = entries;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2c1ecf28/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 8d88adf..7e650d3 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
@@ -341,6 +341,40 @@ public class GridJettyRestHandler extends AbstractHandler {
                 break;
             }
 
+            case CACHE_PUT_ALL2: {
+                StringBuilder builder = new StringBuilder();
+
+                Scanner reader = null;
+
+                try {
+                    reader = new Scanner(req.getReader());
+                } catch (IOException e) {
+                    throw new IgniteCheckedException(e);
+                }
+
+                while (reader.hasNext())
+                    builder.append(reader.next() + "\n");
+
+                JSONObject o = JSONObject.fromObject(builder.toString());
+
+                GridRestCacheRequest restReq0 = new GridRestCacheRequest();
+
+                String cacheName = (String) params.get("cacheName");
+
+                restReq0.cacheName(F.isEmpty(cacheName) ? null : cacheName);
+
+                Map<Object, Object> map = U.newHashMap(o.keySet().size());
+
+                for (Object k : o.keySet())
+                    map.put(k, o.get(k));
+
+                restReq0.values(map);
+
+                restReq = restReq0;
+
+                break;
+            }
+
             case CACHE_GET:
             case CACHE_GET_ALL:
             case CACHE_PUT:


Mime
View raw message