service.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. require('utils/config');
  20. App.Service = DS.Model.extend({
  21. serviceName: DS.attr('string'),
  22. workStatus: DS.attr('string'),
  23. rand: DS.attr('string'),
  24. toolTipContent: DS.attr('string'),
  25. alerts: DS.hasMany('App.Alert'),
  26. quickLinks: DS.hasMany('App.QuickLinks'), // mapped in app/mappers/service_metrics_mapper.js method - mapQuickLinks
  27. hostComponents: DS.hasMany('App.HostComponent'),
  28. serviceConfigsTemplate: App.config.get('preDefinedServiceConfigs'),
  29. // Instead of making healthStatus a computed property that listens on hostComponents.@each.workStatus,
  30. // we are creating a separate observer _updateHealthStatus. This is so that healthStatus is updated
  31. // only once after the run loop. This is because Ember invokes the computed property every time
  32. // a property that it depends on changes. For example, App.statusMapper's map function would invoke
  33. // the computed property too many times and freezes the UI without this hack.
  34. // See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
  35. healthStatus: function(){
  36. switch(this.get('workStatus')){
  37. case 'STARTED':
  38. return 'green';
  39. case 'STARTING':
  40. return 'green-blinking';
  41. case 'INSTALLED':
  42. return 'red';
  43. case 'STOPPING':
  44. return 'red-blinking';
  45. case 'UNKNOWN':
  46. default:
  47. return 'yellow';
  48. }
  49. }.property('workStatus'),
  50. isStopped: function () {
  51. return this.get('workStatus') === 'INSTALLED';
  52. }.property('workStatus'),
  53. isStarted: function () {
  54. return this.get('workStatus') === 'STARTED';
  55. }.property('workStatus'),
  56. isConfigurable: function () {
  57. var configurableServices = [
  58. "HDFS",
  59. "YARN",
  60. "MAPREDUCE",
  61. "MAPREDUCE2",
  62. "HBASE",
  63. "OOZIE",
  64. "HIVE",
  65. "WEBHCAT",
  66. "ZOOKEEPER",
  67. "PIG",
  68. "SQOOP",
  69. "NAGIOS",
  70. "GANGLIA",
  71. "HUE"
  72. ];
  73. return configurableServices.contains(this.get('serviceName'));
  74. }.property('serviceName'),
  75. displayName: function () {
  76. return App.Service.DisplayNames[this.get('serviceName')];
  77. }.property('serviceName'),
  78. /**
  79. * For each host-component, if the desired_configs dont match the
  80. * actual_configs, then a restart is required. Except for Global site
  81. * properties, which need to be checked with map.
  82. */
  83. isRestartRequired: function () {
  84. var rhc = this.get('hostComponents').filterProperty('staleConfigs', true);
  85. var hc = {};
  86. rhc.forEach(function(_rhc) {
  87. var hostName = _rhc.get('host.publicHostName');
  88. if (!hc[hostName]) {
  89. hc[hostName] = [];
  90. }
  91. hc[hostName].push(_rhc.get('displayName'));
  92. });
  93. this.set('restartRequiredHostsAndComponents', hc);
  94. return (rhc.length>0);
  95. }.property('serviceName', 'hostComponents.@each.staleConfigs'),
  96. /**
  97. * Contains a map of which hosts and host_components
  98. * need a restart. This is populated when calculating
  99. * #isRestartRequired()
  100. * Example:
  101. * {
  102. * 'publicHostName1': ['TaskTracker'],
  103. * 'publicHostName2': ['JobTracker', 'TaskTracker']
  104. * }
  105. */
  106. restartRequiredHostsAndComponents: {},
  107. /**
  108. * Based on the information in #restartRequiredHostsAndComponents
  109. */
  110. restartRequiredMessage: function () {
  111. var restartHC = this.get('restartRequiredHostsAndComponents');
  112. var hostCount = 0;
  113. var hcCount = 0;
  114. var hostsMsg = "<ul>";
  115. for(var host in restartHC){
  116. hostCount++;
  117. hostsMsg += "<li>"+host+"</li><ul>";
  118. restartHC[host].forEach(function(c){
  119. hcCount++;
  120. hostsMsg += "<li>"+c+"</li>";
  121. })
  122. hostsMsg += "</ul>";
  123. }
  124. hostsMsg += "</ul>"
  125. return this.t('services.service.config.restartService.TooltipMessage').format(hcCount, hostCount, hostsMsg);
  126. }.property('restartRequiredHostsAndComponents')
  127. });
  128. App.Service.Health = {
  129. live: "LIVE",
  130. dead: "DEAD-RED",
  131. starting: "STARTING",
  132. stopping: "STOPPING",
  133. unknown: "DEAD-YELLOW",
  134. getKeyName: function (value) {
  135. switch (value) {
  136. case this.live:
  137. return 'live';
  138. case this.dead:
  139. return 'dead';
  140. case this.starting:
  141. return 'starting';
  142. case this.stopping:
  143. return 'stopping';
  144. case this.unknown:
  145. return 'unknown';
  146. }
  147. return 'none';
  148. }
  149. };
  150. App.Service.DisplayNames = {
  151. 'HDFS': 'HDFS',
  152. 'YARN': 'YARN',
  153. 'MAPREDUCE': 'MapReduce',
  154. 'MAPREDUCE2': 'MapReduce2',
  155. 'TEZ': 'Tez',
  156. 'HBASE': 'HBase',
  157. 'OOZIE': 'Oozie',
  158. 'HIVE': 'Hive',
  159. 'HCATALOG': 'HCat',
  160. 'ZOOKEEPER': 'ZooKeeper',
  161. 'PIG': 'Pig',
  162. 'SQOOP': 'Sqoop',
  163. 'WEBHCAT': 'WebHCat',
  164. 'GANGLIA': 'Ganglia',
  165. 'NAGIOS': 'Nagios',
  166. 'HUE': 'Hue',
  167. 'FLUME': 'Flume',
  168. 'STORM': 'Storm'
  169. };
  170. App.Service.servicesSortOrder = [
  171. 'HDFS',
  172. 'YARN',
  173. 'MAPREDUCE',
  174. 'MAPREDUCE2',
  175. 'TEZ',
  176. 'HBASE',
  177. 'HIVE',
  178. 'HCATALOG',
  179. 'WEBHCAT',
  180. 'FLUME',
  181. 'OOZIE',
  182. 'GANGLIA',
  183. 'NAGIOS',
  184. 'ZOOKEEPER',
  185. 'PIG',
  186. 'SQOOP',
  187. 'HUE',
  188. 'STORM'
  189. ];
  190. App.Service.FIXTURES = [];