Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Making getNodesInCluster() recursive #3881

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/network/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,13 @@ <h2 id="methods">Methods</h2>
</tr>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','getNodesInCluster', this);">
<td colspan="2"><span parent="getNodesInCluster" class="right-caret" id="method_getNodesInCluster"></span> getNodesInCluster(
<code>String clusterNodeId</code>)
<code>String clusterNodeId, [Boolean recursive]</code>)
</tr>
<tr class="hidden" parent="getNodesInCluster">
<td class="midMethods">Returns: Array</td>
<td>Returns an array of all nodeIds of the nodes that would be released if you open the cluster.
<td>Returns an array of all nodeIds of the nodes that would be released if you open the cluster. If the recursive parameter is false or
undefined and the cluster contains other clusters, this method will return nodeIds of clusters. If the recursive parameter is true
and the cluster contains other clusters, this method will recursively get the nodeIds of the unclustered nodes.
</td>
</tr>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','openCluster', this);">
Expand Down
14 changes: 12 additions & 2 deletions lib/network/modules/Clustering.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,15 +850,25 @@ class ClusterEngine {
/**
*
* @param {Cluster.id} clusterId
* @param {boolean} [recursive=false]
* @returns {Array.<Node.id>}
*/
getNodesInCluster(clusterId) {
getNodesInCluster(clusterId, recursive = false) {
let nodesArray = [];
if (this.isCluster(clusterId) === true) {
let containedNodes = this.body.nodes[clusterId].containedNodes;
for (let nodeId in containedNodes) {
if (containedNodes.hasOwnProperty(nodeId)) {
nodesArray.push(this.body.nodes[nodeId].id)
if (!recursive) {
nodesArray.push(this.body.nodes[nodeId].id);
} else {
let id = this.body.nodes[nodeId].id;
if (this.isCluster(id)) {
nodesArray = nodesArray.concat(this.getNodesInCluster(id, recursive));
} else {
nodesArray.push(id);
}
}
}
}
}
Expand Down