service.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. * Indicates when service deleting is in progress
  72. * Used to stop update service's data and topology
  73. *
  74. * @type {boolean}
  75. * @default false
  76. */
  77. deleteInProgress: false,
  78. /**
  79. * Service Tagging by their type.
  80. * @type {String[]}
  81. **/
  82. serviceTypes: function() {
  83. var typeServiceMap = {
  84. GANGLIA: ['MONITORING'],
  85. HDFS: ['HA_MODE'],
  86. YARN: ['HA_MODE'],
  87. RANGER: ['HA_MODE'],
  88. HAWQ: ['HA_MODE']
  89. };
  90. return typeServiceMap[this.get('serviceName')] || [];
  91. }.property('serviceName'),
  92. /**
  93. * For each host-component, if the desired_configs dont match the
  94. * actual_configs, then a restart is required.
  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('hostName');
  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'),
  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. * Does service have Critical Alerts
  142. * @type {boolean}
  143. */
  144. hasCriticalAlerts: false,
  145. /**
  146. * Number of the Critical and Warning alerts for current service
  147. * @type {number}
  148. */
  149. alertsCount: 0
  150. });
  151. /**
  152. * Map of all service states
  153. *
  154. * @type {Object}
  155. */
  156. App.Service.statesMap = {
  157. init: 'INIT',
  158. installing: 'INSTALLING',
  159. install_failed: 'INSTALL_FAILED',
  160. stopped: 'INSTALLED',
  161. starting: 'STARTING',
  162. started: 'STARTED',
  163. stopping: 'STOPPING',
  164. uninstalling: 'UNINSTALLING',
  165. uninstalled: 'UNINSTALLED',
  166. wiping_out: 'WIPING_OUT',
  167. upgrading: 'UPGRADING',
  168. maintenance: 'MAINTENANCE',
  169. unknown: 'UNKNOWN'
  170. };
  171. /**
  172. * @type {String[]}
  173. */
  174. App.Service.inProgressStates = [
  175. App.Service.statesMap.installing,
  176. App.Service.statesMap.starting,
  177. App.Service.statesMap.stopping,
  178. App.Service.statesMap.uninstalling,
  179. App.Service.statesMap.upgrading,
  180. App.Service.statesMap.wiping_out
  181. ];
  182. /**
  183. * @type {String[]}
  184. */
  185. App.Service.allowUninstallStates = [
  186. App.Service.statesMap.init,
  187. App.Service.statesMap.install_failed,
  188. App.Service.statesMap.stopped,
  189. App.Service.statesMap.unknown
  190. ];
  191. App.Service.Health = {
  192. live: "LIVE",
  193. dead: "DEAD-RED",
  194. starting: "STARTING",
  195. stopping: "STOPPING",
  196. unknown: "DEAD-YELLOW",
  197. getKeyName: function (value) {
  198. switch (value) {
  199. case this.live:
  200. return 'live';
  201. case this.dead:
  202. return 'dead';
  203. case this.starting:
  204. return 'starting';
  205. case this.stopping:
  206. return 'stopping';
  207. case this.unknown:
  208. return 'unknown';
  209. }
  210. return 'none';
  211. }
  212. };
  213. /**
  214. * association between service and extended model name
  215. * @type {Object}
  216. */
  217. App.Service.extendedModel = {
  218. 'HDFS': 'HDFSService',
  219. 'HBASE': 'HBaseService',
  220. 'YARN': 'YARNService',
  221. 'MAPREDUCE2': 'MapReduce2Service',
  222. 'STORM': 'StormService',
  223. 'FLUME': 'FlumeService'
  224. };
  225. App.Service.FIXTURES = [];