service.js 6.3 KB

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