PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/hq/_site/js/collection/node/NodeListModel.js

https://gitlab.com/zouxc/elasticsearch-cn-out-of-box
JavaScript | 63 lines | 30 code | 6 blank | 27 comment | 2 complexity | 96707d37e616476de5aa68fb723b3258 MD5 | raw file
  1. /*
  2. Copyright 2013 Roy Russo
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. Latest Builds: https://github.com/royrusso/elasticsearch-HQ
  13. */
  14. /**
  15. * Collection of NodeSimple, when we simply need the list of nodes.
  16. *
  17. * Leverages the ClusterState api call, allowing for filtering of information needed or not.
  18. * fetch() will cast all response to NodeSimple
  19. *
  20. * curl -XGET 'http://localhost:9200/_cluster/state?filter_nodes=false, etc...'
  21. */
  22. var NodeListModel = Backbone.Collection.extend({
  23. model:NodeSimple,
  24. masterNode:'',
  25. initialize:function () {
  26. console.log("Inside NodeList");
  27. },
  28. url:function () {
  29. return '/_cluster/state?filter_nodes=false&filter_metadata=true&filter_routing_table=true&filter_blocks=true&filter_indices=true';
  30. },
  31. parse:function (data) {
  32. if (data.master_node) {
  33. console.log('Master Node is: ' + data.master_node);
  34. this.masterNode = data.master_node;
  35. }
  36. // nodes are keyed by their id, so we need to get the key and add it to the value object foreach
  37. var nodes = data.nodes;
  38. nodes[this.masterNode].master = true; // all the others appear as false, by default.
  39. var nodeKeys = _.keys(nodes);
  40. var nodeValues = _.values(nodes);
  41. for (var i = 0; i < nodeKeys.length; i++) {
  42. nodeValues[i].id = nodeKeys[i];
  43. }
  44. // sort by name
  45. nodeValues = _.sortBy(nodeValues, function (node) {
  46. return node.name;
  47. });
  48. nodeValues = _.sortBy(nodeValues, function (node) { // put masternode first in line
  49. return node.master;
  50. });
  51. return nodeValues;
  52. }
  53. });