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 2015/06/24 17:26:12 UTC

[1/3] incubator-ignite git commit: #ignite-965: map/reduce task for all nodes.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-965 f981f3a0c -> e1c097fa2


#ignite-965:  map/reduce task for all nodes.


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

Branch: refs/heads/ignite-965
Commit: 39cd83e011ef974ef32e0feda74871493a1482ba
Parents: f981f3a
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jun 24 17:31:19 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jun 24 17:31:19 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/NodeJsComputeSelfTest.java  |  2 +-
 modules/nodejs/src/test/js/test-compute.js      | 31 ++++++++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39cd83e0/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
index 0015025..2ba5e63 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
@@ -91,7 +91,7 @@ public class NodeJsComputeSelfTest extends NodeJsAbstractTest {
         }, 2, "runIgnite");
 
         while (!fut.isDone())
-            runJsScript("testComputeExecute");
+            runJsScript("testComputeAllNodeExecute");
 
         stopGrid(1);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39cd83e0/modules/nodejs/src/test/js/test-compute.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-compute.js b/modules/nodejs/src/test/js/test-compute.js
index d883e18..80f0900 100644
--- a/modules/nodejs/src/test/js/test-compute.js
+++ b/modules/nodejs/src/test/js/test-compute.js
@@ -31,6 +31,10 @@ testComputeErrorExecute = function() {
     TestUtils.startIgniteNode(computeErrorExecute);
 }
 
+testComputeAllNodeExecute = function() {
+    TestUtils.startIgniteNode(computeAllNodeExecute);
+}
+
 function onStart(onPut, error, ignite) {
     var cache = ignite.cache("mycache");
 
@@ -86,8 +90,8 @@ function computeExecute(error, ignite) {
     };
 
     var callback = function(err, res) {
-        assert(err == null, "Get error on compute task. [err=" + err + "].");
-        assert(res === 7, "Result is not correct. [expected=7, value=" + res + "].");
+        assert(err == null, "Get error on compute task [err=" + err + "]");
+        assert.equal(res, 7);
 
         TestUtils.testDone();
     }
@@ -95,6 +99,29 @@ function computeExecute(error, ignite) {
     ignite.compute().execute(map, reduce, "Hi Alice", callback);
 }
 
+function computeAllNodeExecute(error, ignite) {
+    var map = function(nodes, arg) {
+        for (var i = 0; i < nodes.length; i++) {
+            var f = function (node) {
+                println(">>> Printing " + node.id().toString());
+
+                return "";
+            };
+
+            emit(f, nodes[i %  nodes.length], nodes[i %  nodes.length]);
+        }
+    };
+
+    var reduce = function(results) {};
+
+    var callback = function(err, res) {
+        assert(err == null, "Get error on compute task. [err=" + err + "].");
+        TestUtils.testDone();
+    }
+
+    ignite.compute().execute(map, reduce, "", callback);
+}
+
 function computeErrorExecute(error, ignite) {
     var map = function(nodes, arg) {
         var f = [function (args) {}, function(args){throw "Bad function";}];


[3/3] incubator-ignite git commit: #ignite-965: JsFunctionCallable return object instead of GridRestResponse.

Posted by sb...@apache.org.
#ignite-965:  JsFunctionCallable return object instead of GridRestResponse.


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

Branch: refs/heads/ignite-965
Commit: e1c097fa2fa0ef28adcb337cff3fbb435e9dad87
Parents: 62a80c4
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jun 24 18:25:52 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jun 24 18:25:52 2015 +0300

----------------------------------------------------------------------
 .../IgniteScriptingCommandHandler.java          | 51 ++++++++++++--------
 .../scripting/IgniteScriptProcessor.java        |  2 +-
 2 files changed, 31 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1c097fa/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
index f491d07..38e4b9c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
@@ -86,11 +86,16 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
             case RUN_SCRIPT: {
                 assert req instanceof RestRunScriptRequest : "Invalid type of run script request.";
 
-                final RestRunScriptRequest req0 = (RestRunScriptRequest) req;
-
-                GridRestResponse res = ctx.grid().compute().call(new JsFunctionCallable(req0.script()));
-
-                return new GridFinishedFuture<>(res);
+                return ctx.closure().callAsync(new IgniteClosure<String, GridRestResponse>() {
+                    @Override public GridRestResponse apply(String o) {
+                        try {
+                            return new GridRestResponse(ctx.grid().compute().call(new JsFunctionCallable(o)));
+                        }
+                        catch (Exception e) {
+                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+                        }
+                    }
+                }, ((RestRunScriptRequest) req).script(), Collections.singleton(ctx.grid().localNode()));
             }
 
             case EXECUTE_MAP_REDUCE_SCRIPT: {
@@ -99,13 +104,18 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
 
                 assert SUPPORTED_COMMANDS.contains(req.command());
 
-                final RestMapReduceScriptRequest req0 = (RestMapReduceScriptRequest) req;
-
-                GridRestResponse res = ctx.grid().compute().execute(
-                    new JsTask(req0.mapFunction(), req0.argument(), req0.reduceFunction(), ctx, emitRes),
-                    null);
-
-                return new GridFinishedFuture<>(res);
+                return ctx.closure().callAsync(new IgniteClosure<RestMapReduceScriptRequest, GridRestResponse>() {
+                    @Override public GridRestResponse apply(RestMapReduceScriptRequest req0) {
+                        try {
+                            return new GridRestResponse(ctx.grid().compute().execute(
+                                new JsTask(req0.mapFunction(), req0.argument(), req0.reduceFunction(), ctx, emitRes),
+                                null));
+                        }
+                        catch (Exception e) {
+                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+                        }
+                }
+                }, (RestMapReduceScriptRequest)req, Collections.singleton(ctx.grid().localNode()));
             }
         }
 
@@ -115,7 +125,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
     /**
      * JS Compute Task.
      */
-    private static class JsTask extends ComputeTaskAdapter<String, GridRestResponse> {
+    private static class JsTask extends ComputeTaskAdapter<String, Object> {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -171,7 +181,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override public GridRestResponse reduce(List<ComputeJobResult> results) {
+        @Nullable @Override public Object reduce(List<ComputeJobResult> results) {
             try {
                 Object[] data = new Object[results.size()];
 
@@ -184,10 +194,10 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
                     data[i] = results.get(i).getData();
                 }
 
-                return new GridRestResponse(ctx.scripting().invokeFunction(reduceFunc, data));
+                return ctx.scripting().invokeFunction(reduceFunc, data);
             }
             catch (IgniteCheckedException e) {
-                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+                throw U.convertException(e);
             }
         }
     }
@@ -232,7 +242,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
     /**
      * Call java script function.
      */
-    private static class JsFunctionCallable implements IgniteCallable<GridRestResponse> {
+    private static class JsFunctionCallable implements IgniteCallable<Object> {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -251,13 +261,12 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
         }
 
         /** {@inheritDoc} */
-        @Override public GridRestResponse call() {
+        @Override public Object call() {
             try {
-                return new GridRestResponse(((IgniteKernal)ignite).
-                    context().scripting().invokeFunction(func));
+                return ((IgniteKernal)ignite).context().scripting().invokeFunction(func);
             }
             catch (IgniteCheckedException e) {
-                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+                throw U.convertException(e);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1c097fa/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteScriptProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteScriptProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteScriptProcessor.java
index 7eae18d..046b8aa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteScriptProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteScriptProcessor.java
@@ -128,7 +128,7 @@ public class IgniteScriptProcessor extends GridProcessorAdapter {
             throw new IgniteCheckedException("Function evaluation failed [funcName=" + src + "].");
         }
         catch (NoSuchMethodException e) {
-            throw new IgniteCheckedException("Cannot find function [funcName=__internalCall].");
+            throw new IgniteCheckedException("Cannot find function [func=__internalCall].");
         }
     }
 }


[2/3] incubator-ignite git commit: #ignite-965: fix Compute.prototype.runScript.

Posted by sb...@apache.org.
#ignite-965:  fix Compute.prototype.runScript.


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

Branch: refs/heads/ignite-965
Commit: 62a80c41797029de5d4ea6b49410b8f19a9bf127
Parents: 39cd83e
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jun 24 17:43:11 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jun 24 17:43:11 2015 +0300

----------------------------------------------------------------------
 .../handlers/scripting/IgniteScriptingCommandHandler.java    | 4 ++--
 .../processors/rest/request/RestMapReduceScriptRequest.java  | 6 +++---
 modules/nodejs/src/main/js/compute.js                        | 7 ++-----
 modules/nodejs/src/test/js/test-compute.js                   | 8 ++++----
 .../rest/protocols/http/jetty/GridJettyRestHandler.java      | 2 +-
 5 files changed, 12 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/62a80c41/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
index c41315b..f491d07 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
@@ -129,7 +129,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
         private GridKernalContext ctx;
 
         /** Map function argument. */
-        private String arg;
+        private Object arg;
 
         /** Emit results. */
         private IgniteJsEmitResult emitRes;
@@ -140,7 +140,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
          * @param reduceFunc Reduce function.
          * @param ctx Kernal context.
          */
-        public JsTask(String mapFunc, String arg, String reduceFunc, GridKernalContext ctx, IgniteJsEmitResult emitRes) {
+        public JsTask(String mapFunc, Object arg, String reduceFunc, GridKernalContext ctx, IgniteJsEmitResult emitRes) {
             this.mapFunc = mapFunc;
             this.reduceFunc = reduceFunc;
             this.arg = arg;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/62a80c41/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestMapReduceScriptRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestMapReduceScriptRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestMapReduceScriptRequest.java
index c21fcf4..904af74 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestMapReduceScriptRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestMapReduceScriptRequest.java
@@ -25,7 +25,7 @@ public class RestMapReduceScriptRequest extends GridRestRequest {
     private String mapFunc;
 
     /** Function argument. */
-    private String arg;
+    private Object arg;
 
     /** Reduce function. */
     private String reduceFunc;
@@ -61,14 +61,14 @@ public class RestMapReduceScriptRequest extends GridRestRequest {
     /**
      * @param arg Argument.
      */
-    public void argument(String arg) {
+    public void argument(Object arg) {
         this.arg = arg;
     }
 
     /**
      * @return Argument.
      */
-    public String argument() {
+    public Object argument() {
         return arg;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/62a80c41/modules/nodejs/src/main/js/compute.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/compute.js b/modules/nodejs/src/main/js/compute.js
index c7a386e..0f932e7 100644
--- a/modules/nodejs/src/main/js/compute.js
+++ b/modules/nodejs/src/main/js/compute.js
@@ -28,14 +28,11 @@ function Compute(server) {
 
 /**
  * @this {Compute}
- * @param {string} cacheName Cache name
- * @param {string} key Key
  * @param runnable Function without parameters
  * @param {onGet} callback Callback
  */
-Compute.prototype.runScript = function(cacheName, key, runnable, callback) {
-    this._server.runCommand("runscript", [Server.pair("cacheName", cacheName),
-        Server.pair("key", key), Server.pair("func", this._escape(runnable))], callback);
+Compute.prototype.runScript = function(runnable, callback) {
+    this._server.runCommand("runscript", [Server.pair("func", this._escape(runnable))], callback);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/62a80c41/modules/nodejs/src/test/js/test-compute.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-compute.js b/modules/nodejs/src/test/js/test-compute.js
index 80f0900..fec5914 100644
--- a/modules/nodejs/src/test/js/test-compute.js
+++ b/modules/nodejs/src/test/js/test-compute.js
@@ -61,7 +61,7 @@ function computeRunScript(ignite, error) {
         TestUtils.testDone();
     }
 
-    comp.runScript("mycache", "key999", f, onEnd.bind(null));
+    comp.runScript(f, onEnd.bind(null));
 }
 
 function computeExecute(error, ignite) {
@@ -115,7 +115,7 @@ function computeAllNodeExecute(error, ignite) {
     var reduce = function(results) {};
 
     var callback = function(err, res) {
-        assert(err == null, "Get error on compute task. [err=" + err + "].");
+        assert(err == null, "Get error on compute task [err=" + err + "]");
         TestUtils.testDone();
     }
 
@@ -133,8 +133,8 @@ function computeErrorExecute(error, ignite) {
     var callback = function(err, res) {
         assert(err != null, "Do not get error on compute task.");
 
-        assert(err.indexOf("Function evaluation failed") > -1, "Incorrect error."+
-            "[expected=function evaluation failed, value=" + err + "].");
+        assert(err.indexOf("Function evaluation failed") > -1, "Incorrect error "+
+            "[expected=function evaluation failed, value=" + err + "]");
 
         TestUtils.testDone();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/62a80c41/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 faffbf1..b650554 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
@@ -461,7 +461,7 @@ public class GridJettyRestHandler extends AbstractHandler {
                 RestMapReduceScriptRequest restReq0 = new RestMapReduceScriptRequest();
 
                 restReq0.mapFunction((String) params.get("map"));
-                restReq0.argument((String)params.get("arg"));
+                restReq0.argument(params.get("arg"));
                 restReq0.reduceFunction((String) params.get("reduce"));
 
                 restReq = restReq0;