service.js 6.1 KB

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