host.js 3.0 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. App.Host = DS.Model.extend({
  20. hostName: DS.attr('string'),
  21. cluster: DS.belongsTo('App.Cluster'),
  22. components: DS.hasMany('App.Component'),
  23. cpu: DS.attr('string'),
  24. memory: DS.attr('string'),
  25. diskUsage: DS.attr('string'),
  26. loadAvg: DS.attr('string'),
  27. os: DS.attr('string'),
  28. ip: DS.attr('string'),
  29. healthStatus: DS.attr('string'),
  30. cpuUsage: DS.attr('number'),
  31. memoryUsage: DS.attr('number'),
  32. networkUsage: DS.attr('number'),
  33. ioUsage: DS.attr('number'),
  34. lastHeartBeatTime: DS.attr('number'),
  35. osType: DS.attr("string"),
  36. diskInfo: DS.attr('string'),
  37. /**
  38. * Return true if host not heartbeating last 180 seconds
  39. */
  40. isNotHeartBeating : function(){
  41. return ((new Date()).getTime() - this.get('lastHeartBeatTime')) > 180 * 1000;
  42. }.property('lastHeartBeatTime'),
  43. updateHostStatus: function(){
  44. /**
  45. * Do nothing until load
  46. */
  47. if(!this.get('isLoaded') || !this.get('components').everyProperty('isLoaded', true)){
  48. return;
  49. }
  50. var components = this.get('components');
  51. var status;
  52. var masterComponents = components.filterProperty('isMaster', true);
  53. if(components.everyProperty('workStatus', App.Component.Status.started)){
  54. status = 'LIVE';
  55. } else if(false && this.get('isNotHeartBeating')){ //todo uncomment on real data
  56. status = 'DEAD-YELLOW';
  57. } else if(masterComponents.length > 0 && !masterComponents.everyProperty('workStatus', App.Component.Status.started)){
  58. status = 'DEAD';
  59. } else{
  60. status = 'DEAD-ORANGE';
  61. }
  62. if(status){
  63. this.set('healthStatus', status);
  64. // console.log('set ' + status + ' for ' + this.get('hostName'));
  65. }
  66. }.observes('components.@each.workStatus'),
  67. healthClass: function(){
  68. return 'health-status-' + this.get('healthStatus');
  69. }.property('healthStatus')
  70. });
  71. App.Host.FIXTURES = [/*
  72. {
  73. id: 1,
  74. host_name: 'dev.hortonworks.com',
  75. cluster_id: 1,
  76. components:[1, 2, 3, 4, 5],
  77. cpu: '2x2.5GHz',
  78. memory: '8GB',
  79. disk_usage: '40',
  80. load_avg: '0.2, 1.2, 2.4',
  81. ip: '123.123.123.123',
  82. health_status: 'LIVE',
  83. cpu_usage: 33,
  84. memory_usage: 26,
  85. network_usage: 36,
  86. io_usage: 39,
  87. last_heart_beat_time : 1351536732366
  88. }*/
  89. ];