service.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. displayName: Em.computed.formatRole('serviceName', true),
  23. passiveState: DS.attr('string'),
  24. workStatus: DS.attr('string'),
  25. rand: DS.attr('string'),
  26. toolTipContent: DS.attr('string'),
  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. clientComponents: DS.hasMany('App.ClientComponent'),
  36. slaveComponents: DS.hasMany('App.SlaveComponent'),
  37. masterComponents: DS.hasMany('App.MasterComponent'),
  38. /**
  39. * @type {bool}
  40. */
  41. isInPassive: Em.computed.equal('passiveState', 'ON'),
  42. serviceComponents: function() {
  43. var clientComponents = this.get('clientComponents').mapProperty('componentName');
  44. var slaveComponents = this.get('slaveComponents').mapProperty('componentName');
  45. var masterComponents = this.get('masterComponents').mapProperty('componentName');
  46. return clientComponents.concat(slaveComponents).concat(masterComponents);
  47. }.property('clientComponents.@each', 'slaveComponents.@each','masterComponents.@each'),
  48. // Instead of making healthStatus a computed property that listens on hostComponents.@each.workStatus,
  49. // we are creating a separate observer _updateHealthStatus. This is so that healthStatus is updated
  50. // only once after the run loop. This is because Ember invokes the computed property every time
  51. // a property that it depends on changes. For example, App.statusMapper's map function would invoke
  52. // the computed property too many times and freezes the UI without this hack.
  53. // See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
  54. healthStatus: function(){
  55. switch(this.get('workStatus')){
  56. case 'STARTED':
  57. return 'green';
  58. case 'STARTING':
  59. return 'green-blinking';
  60. case 'INSTALLED':
  61. return 'red';
  62. case 'STOPPING':
  63. return 'red-blinking';
  64. case 'UNKNOWN':
  65. default:
  66. return 'yellow';
  67. }
  68. }.property('workStatus'),
  69. isStopped: Em.computed.equal('workStatus', 'INSTALLED'),
  70. isStarted: Em.computed.equal('workStatus', 'STARTED'),
  71. /**
  72. * Service Tagging by their type.
  73. * @type {String[]}
  74. **/
  75. serviceTypes: function() {
  76. var typeServiceMap = {
  77. GANGLIA: ['MONITORING'],
  78. HDFS: ['HA_MODE'],
  79. YARN: ['HA_MODE'],
  80. RANGER: ['HA_MODE'],
  81. HAWQ: ['HA_MODE']
  82. };
  83. return typeServiceMap[this.get('serviceName')] || [];
  84. }.property('serviceName'),
  85. /**
  86. * For each host-component, if the desired_configs dont match the
  87. * actual_configs, then a restart is required.
  88. */
  89. isRestartRequired: function () {
  90. var rhc = this.get('hostComponents').filterProperty('staleConfigs', true);
  91. var hc = {};
  92. rhc.forEach(function(_rhc) {
  93. var hostName = _rhc.get('hostName');
  94. if (!hc[hostName]) {
  95. hc[hostName] = [];
  96. }
  97. hc[hostName].push(_rhc.get('displayName'));
  98. });
  99. this.set('restartRequiredHostsAndComponents', hc);
  100. return (rhc.length > 0);
  101. }.property('serviceName'),
  102. /**
  103. * Contains a map of which hosts and host_components
  104. * need a restart. This is populated when calculating
  105. * #isRestartRequired()
  106. * Example:
  107. * {
  108. * 'publicHostName1': ['TaskTracker'],
  109. * 'publicHostName2': ['JobTracker', 'TaskTracker']
  110. * }
  111. */
  112. restartRequiredHostsAndComponents: {},
  113. /**
  114. * Based on the information in #restartRequiredHostsAndComponents
  115. */
  116. restartRequiredMessage: function () {
  117. var restartHC = this.get('restartRequiredHostsAndComponents');
  118. var hostCount = 0;
  119. var hcCount = 0;
  120. var hostsMsg = "<ul>";
  121. for(var host in restartHC){
  122. hostCount++;
  123. hostsMsg += "<li>"+host+"</li><ul>";
  124. restartHC[host].forEach(function(c){
  125. hcCount++;
  126. hostsMsg += "<li>"+c+"</li>";
  127. });
  128. hostsMsg += "</ul>";
  129. }
  130. hostsMsg += "</ul>";
  131. return this.t('services.service.config.restartService.TooltipMessage').format(hcCount, hostCount, hostsMsg);
  132. }.property('restartRequiredHostsAndComponents'),
  133. /**
  134. * Does service have Critical Alerts
  135. * @type {boolean}
  136. */
  137. hasCriticalAlerts: false,
  138. /**
  139. * Number of the Critical and Warning alerts for current service
  140. * @type {number}
  141. */
  142. alertsCount: 0
  143. });
  144. /**
  145. * Map of all service states
  146. *
  147. * @type {Object}
  148. */
  149. App.Service.statesMap = {
  150. init: 'INIT',
  151. installing: 'INSTALLING',
  152. install_failed: 'INSTALL_FAILED',
  153. stopped: 'INSTALLED',
  154. starting: 'STARTING',
  155. started: 'STARTED',
  156. stopping: 'STOPPING',
  157. uninstalling: 'UNINSTALLING',
  158. uninstalled: 'UNINSTALLED',
  159. wiping_out: 'WIPING_OUT',
  160. upgrading: 'UPGRADING',
  161. maintenance: 'MAINTENANCE',
  162. unknown: 'UNKNOWN'
  163. };
  164. /**
  165. * @type {String[]}
  166. */
  167. App.Service.inProgressStates = [
  168. App.Service.statesMap.installing,
  169. App.Service.statesMap.starting,
  170. App.Service.statesMap.stopping,
  171. App.Service.statesMap.uninstalling,
  172. App.Service.statesMap.upgrading,
  173. App.Service.statesMap.wiping_out
  174. ];
  175. /**
  176. * @type {String[]}
  177. */
  178. App.Service.allowUninstallStates = [
  179. App.Service.statesMap.init,
  180. App.Service.statesMap.install_failed,
  181. App.Service.statesMap.stopped,
  182. App.Service.statesMap.unknown
  183. ];
  184. App.Service.Health = {
  185. live: "LIVE",
  186. dead: "DEAD-RED",
  187. starting: "STARTING",
  188. stopping: "STOPPING",
  189. unknown: "DEAD-YELLOW",
  190. getKeyName: function (value) {
  191. switch (value) {
  192. case this.live:
  193. return 'live';
  194. case this.dead:
  195. return 'dead';
  196. case this.starting:
  197. return 'starting';
  198. case this.stopping:
  199. return 'stopping';
  200. case this.unknown:
  201. return 'unknown';
  202. }
  203. return 'none';
  204. }
  205. };
  206. /**
  207. * association between service and extended model name
  208. * @type {Object}
  209. */
  210. App.Service.extendedModel = {
  211. 'HDFS': 'HDFSService',
  212. 'HBASE': 'HBaseService',
  213. 'YARN': 'YARNService',
  214. 'MAPREDUCE2': 'MapReduce2Service',
  215. 'STORM': 'StormService',
  216. 'FLUME': 'FlumeService'
  217. };
  218. App.Service.FIXTURES = [];