You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2015/07/06 18:48:48 UTC

incubator-ignite git commit: #ignite-964: add examples.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-964-1 c8af45dc9 -> 94ca8f29e


#ignite-964: add examples.


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

Branch: refs/heads/ignite-964-1
Commit: 94ca8f29e9fce92650e209bb7635f33fc1a3f80e
Parents: c8af45d
Author: ivasilinets <iv...@gridgain.com>
Authored: Mon Jul 6 19:48:31 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Mon Jul 6 19:48:31 2015 +0300

----------------------------------------------------------------------
 .../main/js/examples/src/cache-api-example.js   | 85 ++++++++++++++++++++
 .../js/examples/src/cache-put-get-example.js    |  5 +-
 .../js/examples/src/compute-callable-example.js | 50 ++++++++++++
 .../js/examples/src/compute-runnable-example.js | 42 ++++++++++
 .../examples/src/compute-task-split-example.js  | 62 ++++++++++++++
 modules/nodejs/src/main/js/server.js            |  2 -
 6 files changed, 242 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/94ca8f29/modules/nodejs/src/main/js/examples/src/cache-api-example.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/examples/src/cache-api-example.js b/modules/nodejs/src/main/js/examples/src/cache-api-example.js
new file mode 100644
index 0000000..30e0739
--- /dev/null
+++ b/modules/nodejs/src/main/js/examples/src/cache-api-example.js
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var Ignite = require("../../");
+var assert = require("assert");
+
+var Ignition = Ignite.Ignition;
+var Entry = Ignite.Entry;
+
+Ignition.start(['127.0.0.1:9095'], null, onConnect);
+
+function onConnect(err, ignite) {
+    assert(err === null);
+
+    console.log(">>> Cache API example started.");
+
+    var cache = ignite.getOrCreateCache("ApiExampleCache");
+
+    atomicMapOperations(cache);
+}
+
+/**
+ * Demonstrates cache operations similar to {@link ConcurrentMap} API. Note that
+ * cache API is a lot richer than the JDK {@link ConcurrentMap}.
+ */
+atomicMapOperations = function(cache) {
+    console.log(">>> Cache atomic map operation examples.");
+
+    cache.removeAllFromCache(function(err) {
+        assert(err === null);
+
+        cache.getAndPut(1, "1", onGetAndPut.bind(null, cache))
+    });
+}
+
+function onGetAndPut(cache, err, entry) {
+    assert(err == null);
+    assert(entry == null);
+
+    cache.put(2, "2", onPut.bind(null, cache));
+}
+
+function onPut(cache, err) {
+    assert(err === null);
+
+    cache.putIfAbsent(4, "44", onPutIfAbsent.bind(null, cache, true));
+}
+
+function onPutIfAbsent(cache, expRes, err, res) {
+    assert(err === null);
+    assert(res === expRes);
+
+    if (expRes) {
+        cache.putIfAbsent(4, "44", onPutIfAbsent.bind(null, cache, false));
+    }
+    else {
+        cache.replaceValue(4, "55", "44", onReplaceValue.bind(null, cache, true));
+    }
+}
+
+function onReplaceValue(cache, expRes, err, res) {
+    assert(err === null);
+    assert(res === expRes);
+
+    if (expRes) {
+        cache.replaceValue(4, "555", "44", onReplaceValue.bind(null, cache, false));
+    }
+    else {
+        console.log("End of the example.")
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/94ca8f29/modules/nodejs/src/main/js/examples/src/cache-put-get-example.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/examples/src/cache-put-get-example.js b/modules/nodejs/src/main/js/examples/src/cache-put-get-example.js
index d6b65d8..0906e64 100644
--- a/modules/nodejs/src/main/js/examples/src/cache-put-get-example.js
+++ b/modules/nodejs/src/main/js/examples/src/cache-put-get-example.js
@@ -29,12 +29,11 @@ function onConnect(error, ignite) {
         throw new Error(error);
     }
 
-    var cache = ignite.getOrCreateCache("mycache");
+    var cache = ignite.getOrCreateCache("PutGetExampleCache");
 
     putGet(cache);
 
     putAllGetAll(cache);
-
 }
 
 putGet = function(cache) {
@@ -63,6 +62,8 @@ putGet = function(cache) {
 
         if (putCnt < keyCnt - 1) {
             putCnt++;
+
+            return;
         }
 
         console.log(">>> Stored values in cache.");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/94ca8f29/modules/nodejs/src/main/js/examples/src/compute-callable-example.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/examples/src/compute-callable-example.js b/modules/nodejs/src/main/js/examples/src/compute-callable-example.js
new file mode 100644
index 0000000..bd923e6
--- /dev/null
+++ b/modules/nodejs/src/main/js/examples/src/compute-callable-example.js
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var Ignite = require("../../");
+var assert = require("assert");
+
+var Ignition = Ignite.Ignition;
+
+Ignition.start(['127.0.0.1:9095'], null, onConnect);
+
+function onConnect(err, ignite) {
+    assert(err === null);
+
+    console.log(">>> Compute callable example started");
+
+    var f = function (args) {
+        var words = args.split(" ");
+
+        var sum = 0;
+
+        for (var i = 0; i < words.length; ++i) {
+            sum += words[i].length;
+        }
+
+        return sum;
+    }
+
+    var onRunScript = function(err, sum) {
+        assert(err == null);
+
+        console.log(">>> Total number of characters in the phrase is '" + sum + "'.");
+        console.log(">>> Check all nodes for output (this node is also part of the cluster).");
+    }
+
+    ignite.compute().runScript(f, "Hello Ignite Enabled World!", onRunScript);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/94ca8f29/modules/nodejs/src/main/js/examples/src/compute-runnable-example.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/examples/src/compute-runnable-example.js b/modules/nodejs/src/main/js/examples/src/compute-runnable-example.js
new file mode 100644
index 0000000..191d750
--- /dev/null
+++ b/modules/nodejs/src/main/js/examples/src/compute-runnable-example.js
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var Ignite = require("../../");
+var assert = require("assert");
+
+var Ignition = Ignite.Ignition;
+
+Ignition.start(['127.0.0.1:9095'], null, onConnect);
+
+function onConnect(err, ignite) {
+    assert(err === null);
+
+    console.log(">>> Compute runnable example started.");
+
+    var f = function (args) {
+        print(">>> Printing '" + args + "' on this node from ignite job.");
+    }
+
+    var onRunScript = function(err, res) {
+        assert(err == null, err);
+
+        console.log(">>> Finished printing words using runnable execution.");
+        console.log(">>> Check all nodes for output (this node is also part of the cluster).");
+    }
+
+    ignite.compute().runScript(f, "Hello Ignite Enabled World!", onRunScript);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/94ca8f29/modules/nodejs/src/main/js/examples/src/compute-task-split-example.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/examples/src/compute-task-split-example.js b/modules/nodejs/src/main/js/examples/src/compute-task-split-example.js
new file mode 100644
index 0000000..a5b0102
--- /dev/null
+++ b/modules/nodejs/src/main/js/examples/src/compute-task-split-example.js
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var Ignite = require("../../");
+var assert = require("assert");
+
+var Ignition = Ignite.Ignition;
+
+Ignition.start(['127.0.0.1:9095'], null, onConnect);
+
+function onConnect(err, ignite) {
+    assert(err === null);
+
+    console.log(">>> Compute task split example started.");
+
+    var map = function(nodes, args) {
+        var words = args.split(" ");
+
+        for (var i = 0; i < words.length; i++) {
+            var f = function (word) {
+                print(">>> Printing '" + word + "' on this node from ignite job.");
+
+                return word.length;
+            };
+
+            emit(f, words[i], nodes[i %  nodes.length]);
+        }
+    }
+
+    var reduce = function(results) {
+        var sum = 0;
+
+        for (var i = 0; i < results.length; ++i) {
+            sum += results[i];
+        }
+
+        return sum;
+    }
+
+    var onMapReduce = function(err, cnt) {
+        assert(err === null, err);
+        
+        console.log(">>> Total number of characters in the phrase is '" + cnt + "'.");
+        console.log(">>> Check all nodes for output (this node is also part of the cluster).");
+    }
+
+    ignite.compute().execute(map, reduce, "Hello Ignite Enabled World!", onMapReduce);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/94ca8f29/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 abe24a7..5d7430a 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -86,8 +86,6 @@ Server.prototype.runCommand = function(cmd, callback) {
         });
 
         response.on('end', function () {
-            console.log("fullResponseString:" + fullResponseString);
-
             if (response.statusCode !== 200) {
                 if (response.statusCode === 401) {
                     callback.call(null, "Authentication failed. Status code 401.");