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 9939018094 for ; Tue, 23 Jun 2015 17:47:36 +0000 (UTC) Received: (qmail 67464 invoked by uid 500); 23 Jun 2015 17:47:36 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 67431 invoked by uid 500); 23 Jun 2015 17:47:36 -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 67422 invoked by uid 99); 23 Jun 2015 17:47:36 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Jun 2015 17:47:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 17579C12D1 for ; Tue, 23 Jun 2015 17:47:36 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 7MUGG9fZGt44 for ; Tue, 23 Jun 2015 17:47:29 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 95FC9262B0 for ; Tue, 23 Jun 2015 17:47:28 +0000 (UTC) Received: (qmail 67143 invoked by uid 99); 23 Jun 2015 17:47:27 -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; Tue, 23 Jun 2015 17:47:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 62361E02A2; Tue, 23 Jun 2015 17:47:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Tue, 23 Jun 2015 17:47:31 -0000 Message-Id: <27d7e55c286b48c69a0cb59e411dc7d5@git.apache.org> In-Reply-To: <755d1051167d4ce3b6a9d45dc26809d1@git.apache.org> References: <755d1051167d4ce3b6a9d45dc26809d1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/20] incubator-ignite git commit: #ignite-965: codestyle IgniteComputeTaskCommandHandler. #ignite-965: codestyle IgniteComputeTaskCommandHandler. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/57e9845a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/57e9845a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/57e9845a Branch: refs/heads/ignite-965 Commit: 57e9845a56ebba443b83f42c2348f6998e511ba3 Parents: 30ec9f7 Author: ivasilinets Authored: Tue Jun 23 19:40:14 2015 +0300 Committer: ivasilinets Committed: Tue Jun 23 19:40:14 2015 +0300 ---------------------------------------------------------------------- .../IgniteComputeTaskCommandHandler.java | 100 ++++++++++--------- .../scripting/IgniteScriptProcessor.java | 2 +- modules/nodejs/src/main/js/compute.js | 10 -- 3 files changed, 52 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/57e9845a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeTaskCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeTaskCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeTaskCommandHandler.java index 33f4893..33cd45b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeTaskCommandHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeTaskCommandHandler.java @@ -56,29 +56,39 @@ public class IgniteComputeTaskCommandHandler extends GridRestCommandHandlerAdapt @Override public IgniteInternalFuture handleAsync(GridRestRequest req) { assert req != null; - assert req instanceof RestComputeTaskRequest : "Invalid type of compute request."; + assert req instanceof RestComputeTaskRequest : "Invalid type of compute task request."; assert SUPPORTED_COMMANDS.contains(req.command()); final RestComputeTaskRequest req0 = (RestComputeTaskRequest) req; - Object res = ctx.grid().compute().execute(new JsTask(req0.mapFunc(), req0.argument(), req0.reduceFunc(), ctx), null); + Object execRes = ctx.grid().compute().execute( + new JsTask(req0.mapFunc(), req0.argument(), req0.reduceFunc(), ctx), null); - return new GridFinishedFuture<>(new GridRestResponse(res)); + return new GridFinishedFuture<>(new GridRestResponse(execRes)); } + /** + * JS Compute Task. + */ private static class JsTask extends ComputeTaskAdapter { /** Mapping function. */ private String mapFunc; + /** Reduce function. */ private String reduceFunc; - /** Grid kernal context. */ + /** Kernal context. */ private GridKernalContext ctx; + /** Map function argument. */ private String arg; /** + * @param mapFunc Map function. + * @param arg Map function argument. + * @param reduceFunc Reduce function. + * @param ctx Kernal context. */ public JsTask(String mapFunc, String arg, String reduceFunc, GridKernalContext ctx) { this.mapFunc = mapFunc; @@ -91,61 +101,30 @@ public class IgniteComputeTaskCommandHandler extends GridRestCommandHandlerAdapt @Override public Map map(List nodes, String arg) { Map map = new HashMap<>(); - String nodesIds = "["; - - for (ClusterNode node : nodes) - nodesIds += "\"" + node.id().toString() + "\"" + ","; - - nodesIds = nodesIds.substring(0, nodesIds.length() - 1) + "]"; - - String newMap = new String("function () {\n" + - " var res = [];\n" + - " var resCont = function(f, args, nodeId) {\n" + - " res.push([f.toString(), args, nodeId])\n" + - " }\n" + - " var locF = " + mapFunc + "; \n locF(" + - nodesIds + ", " + - "\"" + this.arg + "\"" + - ", resCont.bind(null)" + ");\n" + - " return res;\n" + - "}"); - - List mapRes = (List)ctx.scripting().runJSFunction(newMap); - - for (Object arr : mapRes) { - Object[] nodeTask = ((List)arr).toArray(); - - final String func = (String)nodeTask[0]; - - final List argv = (List) nodeTask[1]; + List jsMapResult = (List)ctx.scripting().runJSFunction(wrapMapperFunction(nodes)); - String nodeIdStr = (String) nodeTask[2]; + for (Object jobMapping : jsMapResult) { + List task = (List)jobMapping; - UUID nodeId = UUID.fromString(nodeIdStr); + final String func = (String)task.get(0); + final List argv = (List)task.get(1); + String nodeId = (String)task.get(2); - ClusterNode node = ctx.grid().cluster().node(nodeId); + ClusterNode node = ctx.grid().cluster().node(UUID.fromString(nodeId)); map.put(new ComputeJobAdapter() { - /** Ignite. */ @IgniteInstanceResource private Ignite ignite; @Override public Object execute() throws IgniteException { - System.out.println("Compute job on node " + ignite.cluster().localNode().id()); - try { - String[] argv1 = new String[argv.size()]; - - for (int i = 0; i < argv1.length; ++i) - argv1[i] = "\"" + argv.get(i).toString() + "\""; - - return ctx.scripting().runJSFunction(func, argv1); - } - catch (Exception e) { - throw new IgniteException(e); - } + String[] argv1 = new String[argv.size()]; + + for (int i = 0; i < argv1.length; ++i) + argv1[i] = "\"" + argv.get(i).toString() + "\""; + + return ctx.scripting().runJSFunction(func, argv1); } }, node); - } return map; @@ -158,7 +137,30 @@ public class IgniteComputeTaskCommandHandler extends GridRestCommandHandlerAdapt for (ComputeJobResult res : results) data.add(res.getData()); - return ctx.scripting().runJSFunction(reduceFunc, new String[]{data.toString()}); + return ctx.scripting().runJSFunction(reduceFunc, data.toString()); + } + + /** + * @param nodes Cluster nodes. + * @return Script running map function. + */ + private String wrapMapperFunction(List nodes) { + List ids = new ArrayList<>(); + + for (ClusterNode node : nodes) + ids.add("\"" + node.id().toString() + "\""); + + String sep = System.getProperty("line.separator"); + + return "function () {" + sep + + " var res = [];" + sep + + " var emitFunc = function(f, args, nodeId) {" + sep + + " res.push([f.toString(), args, nodeId])" + sep + + " }" + sep + + " var f = " + mapFunc + ";" + sep + + " f(" + ids + ", " + "\"" + this.arg + "\"" + ", emitFunc.bind(null)" + ");" + sep + + " return res;" + sep + + " }"; } } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/57e9845a/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 094373c..1a72920 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 @@ -61,7 +61,7 @@ public class IgniteScriptProcessor extends GridProcessorAdapter { * @return Script result. * @throws ScriptException If script failed. */ - public Object runJSFunction(String script, String[] args) throws IgniteException { + public Object runJSFunction(String script, String... args) throws IgniteException { try { return jsEngine.eval(callJsFunction(script, args)); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/57e9845a/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 7f45f5b..e452847 100644 --- a/modules/nodejs/src/main/js/compute.js +++ b/modules/nodejs/src/main/js/compute.js @@ -104,14 +104,4 @@ Compute.prototype.execute = function(map, reduce, arg, callback) { * @returns {string} Result */ -/** - * @this{Compute} - * @param {MapFunction} map Map function - * @param {ReduceFunction} reduce Reduce function - * @param {string} arg Argument - * @param {onGet} callback Callback - */ -Compute.prototype._mapWrapper = function(map) { - -} exports.Compute = Compute