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:14 UTC

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

#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].");
         }
     }
 }