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

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

https://gitlab.com/zouxc/elasticsearch-cn-out-of-box
JavaScript | 63 lines | 29 code | 12 blank | 22 comment | 4 complexity | 7d1a26e1f783eb87650bf164b183144c 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: _cluster/state/nodes,routing_table?human=true
  15. * @see <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-state.html">cluster state</a>
  16. */
  17. var ClusterStateTimestamp = Backbone.Model;
  18. var ClusterState = Backbone.Collection.extend({
  19. model: ClusterStateTimestamp,
  20. url: function() {
  21. return '/_cluster/state/nodes,routing_table?human=true';
  22. },
  23. parse: function(data) {
  24. // add key
  25. data.id = new Date().getTime();
  26. return data;
  27. },
  28. add: function(models, options) {
  29. delete options.silent;
  30. if (options && options.now && options.storeSize) {
  31. var iterator = function(clusterStateTimestamp) {
  32. return !(clusterStateTimestamp.id < (options.now - options.storeSize));
  33. };
  34. var rejected = this.reject(iterator);
  35. if (rejected.length > 0) {
  36. this.remove(rejected, options);
  37. }
  38. }
  39. var parentCall = Backbone.Collection.prototype.add.call(this, models, options);
  40. // custom trigger: collection has been updated
  41. this.trigger("clusterStateUpdated", {});
  42. return parentCall;
  43. },
  44. // make sure models are ordered by time
  45. comparator: function(model) {
  46. return model.id;
  47. }
  48. });