service.js 7.0 KB

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