host.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var misc = require('utils/misc');
  20. App.Host = DS.Model.extend({
  21. hostName: DS.attr('string'),
  22. cluster: DS.belongsTo('App.Cluster'),
  23. components: DS.hasMany('App.Component'),
  24. hostComponents: DS.hasMany('App.HostComponent'),
  25. cpu: DS.attr('string'),
  26. memory: DS.attr('string'),
  27. diskUsage: DS.attr('string'),
  28. osArch: DS.attr('string'),
  29. ip: DS.attr('string'),
  30. rack: DS.attr('string'),
  31. healthStatus: DS.attr('string'),
  32. cpuUsage: DS.attr('number'),
  33. memoryUsage: DS.attr('number'),
  34. networkUsage: DS.attr('number'),
  35. ioUsage: DS.attr('number'),
  36. lastHeartBeatTime: DS.attr('number'),
  37. osType: DS.attr("string"),
  38. diskInfo: DS.attr('string'),
  39. loadOne:DS.attr('number'),
  40. loadFive:DS.attr('number'),
  41. loadFifteen:DS.attr('number'),
  42. /**
  43. * formatted bytes to appropriate value
  44. */
  45. memoryFormatted: function () {
  46. return misc.formatBandwidth(this.get('memory') * 1000);
  47. }.property('memory'),
  48. /**
  49. * Return true if host not heartbeating last 180 seconds
  50. */
  51. isNotHeartBeating : function(){
  52. return ((new Date()).getTime() - this.get('lastHeartBeatTime')) > 180 * 1000;
  53. }.property('lastHeartBeatTime'),
  54. loadAvg: function() {
  55. if (this.get('loadOne') != null) return this.get('loadOne');
  56. if (this.get('loadFive') != null) return this.get('loadFive');
  57. if (this.get('loadFifteen') != null) return this.get('loadFifteen');
  58. }.property('loadOne', 'loadFive', 'loadFifteen'),
  59. updateHostStatus: function(){
  60. /**
  61. * Do nothing until load
  62. */
  63. if(!this.get('isLoaded')){
  64. return;
  65. }
  66. var components = this.get('components');
  67. var status;
  68. var masterComponents = components.filterProperty('isMaster', true);
  69. if(components.everyProperty('workStatus', App.Component.Status.started)){
  70. status = 'LIVE';
  71. } else if(this.get('isNotHeartBeating')){
  72. status = 'DEAD-YELLOW';
  73. } else if(masterComponents.length > 0 && !masterComponents.everyProperty('workStatus', App.Component.Status.started)){
  74. status = 'DEAD';
  75. } else{
  76. status = 'DEAD-ORANGE';
  77. }
  78. if(status){
  79. this.set('healthStatus', status);
  80. // console.log('set ' + status + ' for ' + this.get('hostName'));
  81. }
  82. }.observes('components.@each.workStatus'),
  83. healthClass: function(){
  84. return 'health-status-' + this.get('healthStatus');
  85. }.property('healthStatus')
  86. });
  87. App.Host.FIXTURES = [];