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/25 14:33:26 UTC
[6/7] incubator-ignite git commit: #ignite-965: add method cluster
for node js ignite.
#ignite-965: add method cluster for node js ignite.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4bf86c97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4bf86c97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4bf86c97
Branch: refs/heads/ignite-965
Commit: 4bf86c97af3196189df01935d91a626ec8f7df68
Parents: a07b61f
Author: ivasilinets <iv...@gridgain.com>
Authored: Thu Jun 25 13:20:41 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Thu Jun 25 13:20:41 2015 +0300
----------------------------------------------------------------------
modules/nodejs/src/main/js/cluster-node.js | 43 ++++++++++++++++++++
modules/nodejs/src/main/js/ignite.js | 35 +++++++++++++++-
.../ignite/internal/NodeJsIgniteSelfTest.java | 7 ++++
modules/nodejs/src/test/js/test-ignite.js | 24 +++++++++++
4 files changed, 108 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf86c97/modules/nodejs/src/main/js/cluster-node.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cluster-node.js b/modules/nodejs/src/main/js/cluster-node.js
new file mode 100644
index 0000000..940f123
--- /dev/null
+++ b/modules/nodejs/src/main/js/cluster-node.js
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+ /**
+ * @constructor
+ * @this{ClusterNode}
+ * @param {string} nodeId Node id
+ * @param {Object.<string,string>} attr Node Attributes
+ */
+function ClusterNode(nodeId, attr) {
+ this._nodeId = nodeId;
+ this._attr = attr;
+}
+
+/**
+ * @returns {string} Node id
+ */
+ClusterNode.prototype.nodeId = function() {
+ return this._nodeId;
+}
+
+/**
+ * @returns {Object.<string,string>} Node Attributes
+ */
+ClusterNode.prototype.attributes = function() {
+ return this._attr;
+}
+
+exports.ClusterNode = ClusterNode
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf86c97/modules/nodejs/src/main/js/ignite.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/ignite.js b/modules/nodejs/src/main/js/ignite.js
index 6ae13e1..d7203e4 100644
--- a/modules/nodejs/src/main/js/ignite.js
+++ b/modules/nodejs/src/main/js/ignite.js
@@ -16,7 +16,9 @@
*/
var Cache = require("./cache").Cache;
-var Compute = require("./compute").Compute
+var Compute = require("./compute").Compute;
+var ClusterNode = require("./cluster-node").ClusterNode;
+var Server = require("./server").Server;
/**
* Create an instance of Ignite
@@ -78,4 +80,35 @@ Ignite.prototype.name = function(callback) {
this._server.runCommand("name", [], callback);
}
+/**
+ * @this {Ignite}
+ * @param {onGet} callback Result in callback contains list of ClusterNodes
+ */
+Ignite.prototype.cluster = function(callback) {
+ function onTop(callback, err, res) {
+ if (err) {
+ callback.call(null, err, null);
+
+ return;
+ }
+
+ if (!res || res.length == 0) {
+ callback.call(null, "Empty topology cluster.", null);
+
+ return;
+ }
+
+ var nodes = [];
+
+ for (var node of res) {
+ nodes.push(new ClusterNode(node.nodeId, node.attributes));
+ }
+
+ callback.call(null, null, nodes);
+ }
+
+ this._server.runCommand("top", [Server.pair("attr", "true"), Server.pair("mtr", "false")],
+ onTop.bind(null, callback));
+}
+
exports.Ignite = Ignite;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf86c97/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
index db4a2b4..293409b 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsIgniteSelfTest.java
@@ -51,4 +51,11 @@ public class NodeJsIgniteSelfTest extends NodeJsAbstractTest {
public void testIgniteName() throws Exception {
runJsScript("testIgniteName");
}
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCluster() throws Exception {
+ runJsScript("testCluster");
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4bf86c97/modules/nodejs/src/test/js/test-ignite.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-ignite.js b/modules/nodejs/src/test/js/test-ignite.js
index bf73664..99c5242 100644
--- a/modules/nodejs/src/test/js/test-ignite.js
+++ b/modules/nodejs/src/test/js/test-ignite.js
@@ -54,4 +54,28 @@ testIgniteName = function() {
}
TestUtils.startIgniteNode(onStart.bind(null));
+}
+
+testCluster = function() {
+ function igniteCluster(err, res) {
+ assert.equal(err, null);
+ assert(res.length > 0);
+
+ assert(res[0].nodeId() !== null)
+
+ var attrs = res[0].attributes();
+
+ assert(attrs !== null);
+ assert(attrs["os.version"] !== null, "Not correct node attributes [attr=" + res[0].attributes() + "]");
+
+ TestUtils.testDone();
+ }
+
+ function onStart(err, ignite) {
+ assert.equal(err, null);
+
+ ignite.cluster(igniteCluster.bind(null));
+ }
+
+ TestUtils.startIgniteNode(onStart.bind(null));
}
\ No newline at end of file