host.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. publicHostName: DS.attr('string'),
  23. cluster: DS.belongsTo('App.Cluster'),
  24. components: DS.hasMany('App.Component'),
  25. hostComponents: DS.hasMany('App.HostComponent'),
  26. cpu: DS.attr('string'),
  27. memory: DS.attr('string'),
  28. diskUsage: DS.attr('string'),
  29. osArch: DS.attr('string'),
  30. ip: DS.attr('string'),
  31. rack: DS.attr('string'),
  32. healthStatus: DS.attr('string'),
  33. cpuUsage: DS.attr('number'),
  34. memoryUsage: DS.attr('number'),
  35. networkUsage: DS.attr('number'),
  36. ioUsage: DS.attr('number'),
  37. lastHeartBeatTime: DS.attr('number'),
  38. osType: DS.attr("string"),
  39. diskInfo: DS.attr('string'),
  40. loadOne:DS.attr('number'),
  41. loadFive:DS.attr('number'),
  42. loadFifteen:DS.attr('number'),
  43. /**
  44. * formatted bytes to appropriate value
  45. */
  46. memoryFormatted: function () {
  47. return misc.formatBandwidth(this.get('memory') * 1000);
  48. }.property('memory'),
  49. /**
  50. * Return true if host not heartbeating last 180 seconds
  51. */
  52. isNotHeartBeating : function(){
  53. return ((new Date()).getTime() - this.get('lastHeartBeatTime')) > 180 * 1000;
  54. }.property('lastHeartBeatTime'),
  55. loadAvg: function() {
  56. if (this.get('loadOne') != null) return this.get('loadOne');
  57. if (this.get('loadFive') != null) return this.get('loadFive');
  58. if (this.get('loadFifteen') != null) return this.get('loadFifteen');
  59. }.property('loadOne', 'loadFive', 'loadFifteen'),
  60. updateHostStatus: function(){
  61. /**
  62. * Do nothing until load
  63. */
  64. if(!this.get('isLoaded')){
  65. return;
  66. }
  67. var components = this.get('components');
  68. var status;
  69. var masterComponents = components.filterProperty('isMaster', true);
  70. if(components.everyProperty('workStatus', App.Component.Status.started)){
  71. status = 'LIVE';
  72. } else if(this.get('isNotHeartBeating')){
  73. status = 'DEAD-YELLOW';
  74. } else if(masterComponents.length > 0 && !masterComponents.everyProperty('workStatus', App.Component.Status.started)){
  75. status = 'DEAD';
  76. } else{
  77. status = 'DEAD-ORANGE';
  78. }
  79. if(status){
  80. this.set('healthStatus', status);
  81. // console.log('set ' + status + ' for ' + this.get('hostName'));
  82. }
  83. }.observes('components.@each.workStatus'),
  84. healthClass: function(){
  85. return 'health-status-' + this.get('healthStatus');
  86. }.property('healthStatus')
  87. });
  88. App.Host.FIXTURES = [];