PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/bigdesk/_site/js/models/cluster/IndicesStatus.js

https://gitlab.com/zouxc/elasticsearch-cn-out-of-box
JavaScript | 97 lines | 60 code | 12 blank | 25 comment | 13 complexity | 4feaae3aadd1ff8e2fd34d2435cd36b2 MD5 | raw file
  1. /*
  2. Copyright 2011-2014 Lukas Vlcek
  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. */
  13. /**
  14. * REST end point: _status
  15. * @see <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-status.html">indices status</a>
  16. */
  17. var IndicesStatusTimestamp = Backbone.Model;
  18. var IndicesStatus = Backbone.Collection.extend({
  19. model: IndicesStatusTimestamp,
  20. url: function() {
  21. return '/_status';
  22. },
  23. parse: function(data) {
  24. // add key
  25. data.id = new Date().getTime();
  26. if (data.indices) {
  27. for (var i in data.indices) {
  28. if (data.indices.hasOwnProperty(i)) {
  29. // drop unused data about index
  30. delete data.indices[i].docs;
  31. delete data.indices[i].flush;
  32. delete data.indices[i].index;
  33. delete data.indices[i].merges;
  34. delete data.indices[i].refresh;
  35. delete data.indices[i].translog;
  36. if (data.indices[i].shards) {
  37. var _shards = data.indices[i].shards;
  38. if (_shards) {
  39. for (var _s in _shards) {
  40. if (_shards.hasOwnProperty(_s)) {
  41. for (var _i in _shards[_s]) {
  42. var _tmp = _shards[_s][_i];
  43. if (_tmp) {
  44. // drop unused data about index shards
  45. delete _tmp.docs;
  46. delete _tmp.flush;
  47. delete _tmp.merges;
  48. delete _tmp.refresh;
  49. // delete _tmp.routing;
  50. delete _tmp.translog;
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. return data;
  61. },
  62. add: function(models, options) {
  63. delete options.silent;
  64. if (options && options.now && options.storeSize) {
  65. var iterator = function(indicesStatusTimestamp) {
  66. return !(indicesStatusTimestamp.id < (options.now - options.storeSize));
  67. };
  68. var rejected = this.reject(iterator);
  69. if (rejected.length > 0) {
  70. this.remove(rejected, options);
  71. }
  72. }
  73. var parentCall = Backbone.Collection.prototype.add.call(this, models, options);
  74. // custom trigger: collection has been updated
  75. this.trigger("indicesStatusUpdated", {});
  76. return parentCall;
  77. },
  78. // make sure models are ordered by time
  79. comparator: function(model) {
  80. return model.id;
  81. }
  82. });