service.js 6.8 KB

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