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/21 18:46:09 UTC
[6/6] incubator-ignite git commit: #ignite-965:
IgniteCompute.affinityRun nodejs run script on node with key.
#ignite-965: IgniteCompute.affinityRun nodejs run script on node with key.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4a1db957
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4a1db957
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4a1db957
Branch: refs/heads/ignite-965
Commit: 4a1db957c59a8cf25dd443b3f77016db7e1519e7
Parents: eb5cc43
Author: ivasilinets <iv...@gridgain.com>
Authored: Sun Jun 21 19:45:43 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Sun Jun 21 19:45:43 2015 +0300
----------------------------------------------------------------------
.../compute/IgniteComputeCommandHandler.java | 23 +++++++++----
.../rest/request/RestComputeRequest.java | 34 ++++++++++++++++++++
modules/nodejs/src/main/js/compute.js | 8 +++--
.../ignite/internal/NodeJsComputeSelfTest.java | 7 +---
modules/nodejs/src/test/js/test-compute.js | 14 +++++++-
.../http/jetty/GridJettyRestHandler.java | 2 ++
6 files changed, 73 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a1db957/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeCommandHandler.java
index b48e2d4..f3da040 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/compute/IgniteComputeCommandHandler.java
@@ -24,6 +24,8 @@ import org.apache.ignite.internal.processors.rest.handlers.*;
import org.apache.ignite.internal.processors.rest.request.*;
import org.apache.ignite.internal.util.future.*;
import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
import javax.script.*;
import java.util.*;
@@ -57,12 +59,21 @@ public class IgniteComputeCommandHandler extends GridRestCommandHandlerAdapter {
assert SUPPORTED_COMMANDS.contains(req.command());
- try {
- ctx.scripting().runJS(((RestComputeRequest) req).function());
- }
- catch (ScriptException e) {
- throw new IgniteException(e);
- }
+ final RestComputeRequest req0 = (RestComputeRequest) req;
+
+ ctx.grid().compute().affinityRun(req0.cacheName(), req0.key(), new IgniteRunnable() {
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ @Override public void run() {
+ try {
+ ((IgniteKernal)ignite).context().scripting().runJS(req0.function());
+ }
+ catch (ScriptException e) {
+ throw new IgniteException(e);
+ }
+ }
+ });
return new GridFinishedFuture<>(new GridRestResponse("AFFINITY RUN " + req));
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a1db957/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestComputeRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestComputeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestComputeRequest.java
index b046d78..809947e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestComputeRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestComputeRequest.java
@@ -24,6 +24,12 @@ public class RestComputeRequest extends GridRestRequest {
/** Java script function. */
private String func;
+ /** Cache name. */
+ private String cacheName;
+
+ /** Key. */
+ private Object key;
+
/**
* @return Java script function.
*/
@@ -37,4 +43,32 @@ public class RestComputeRequest extends GridRestRequest {
public void function(String func) {
this.func = func;
}
+
+ /**
+ * @return Cache name.
+ */
+ public String cacheName() {
+ return cacheName;
+ }
+
+ /**
+ * @param cacheName Cache name.
+ */
+ public void cacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ /**
+ * @param key Key.
+ */
+ public void key(Object key) {
+ this.key = key;
+ }
+
+ /**
+ * @return Key.
+ */
+ public Object key() {
+ return key;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a1db957/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 d68b6ef..2ab68eb 100644
--- a/modules/nodejs/src/main/js/compute.js
+++ b/modules/nodejs/src/main/js/compute.js
@@ -33,13 +33,17 @@ function Compute(server) {
/**
* @this {Compute}
+ * @param {String} cacheName Cache name.
+ * @param {String} key Key.
* @param {Compute~runnable} runnable Function without parameters
+ * @param {Cache~noValue} callback Callback
*/
-Compute.prototype.affinityRun = function(runnable, callback) {
+Compute.prototype.affinityRun = function(cacheName, key, runnable, callback) {
var f = runnable.toString();
var qs = require('querystring');
f = qs.escape(f);
- this._server.runCommand("affrun", [Server.pair("func", f)], callback);
+ this._server.runCommand("affrun", [Server.pair("cacheName", cacheName),
+ Server.pair("key", key), Server.pair("func", f)], callback);
}
exports.Compute = Compute;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a1db957/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 500e6a2..bd66b1b 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
@@ -28,7 +28,7 @@ public class NodeJsComputeSelfTest extends NodeJsAbstractTest {
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
- startGrid(0);
+ startGrids(2);
}
/** {@inheritDoc} */
@@ -36,11 +36,6 @@ public class NodeJsComputeSelfTest extends NodeJsAbstractTest {
stopAllGrids();
}
- /** {@inheritDoc} */
- @Override protected void beforeTest() throws Exception {
- grid(0).cache(NodeJsAbstractTest.CACHE_NAME).removeAll();
- }
-
/**
* @throws Exception If failed.
*/
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a1db957/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 30ff686..f7eb9b2 100644
--- a/modules/nodejs/src/test/js/test-compute.js
+++ b/modules/nodejs/src/test/js/test-compute.js
@@ -28,13 +28,25 @@ testCompute = function() {
}
function onStart(error, ignite) {
+ var cache = ignite.cache("mycache");
+
+ var params = {"key0" : "val0"}
+
+ for (var i = 0; i < 1000; ++i)
+ params["key" + i] = "val" + i;
+
+ cache.putAll(params, onPut.bind(null, ignite))
+
+}
+
+function onPut(ignite, error) {
var comp = ignite.compute();
var f = function () {
print("Hello world!");
}
- comp.affinityRun(f, onError.bind(null));
+ comp.affinityRun("mycache", "key999", f, onError.bind(null));
}
function onError(error, res) {
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a1db957/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 a9a5b9d..8d3f018 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
@@ -452,6 +452,8 @@ public class GridJettyRestHandler extends AbstractHandler {
RestComputeRequest restReq0 = new RestComputeRequest();
restReq0.function((String)params.get("func"));
+ restReq0.cacheName((String)params.get("cacheName"));
+ restReq0.key(params.get("key"));
restReq = restReq0;
break;