service.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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: function() {
  23. return App.format.role(this.get('serviceName'));
  24. }.property('serviceName'),
  25. passiveState: DS.attr('string'),
  26. workStatus: DS.attr('string'),
  27. rand: DS.attr('string'),
  28. toolTipContent: DS.attr('string'),
  29. quickLinks: DS.hasMany('App.QuickLinks'), // mapped in app/mappers/service_metrics_mapper.js method - mapQuickLinks
  30. hostComponents: DS.hasMany('App.HostComponent'),
  31. serviceConfigsTemplate: App.config.get('preDefinedServiceConfigs'),
  32. /**
  33. * used by services("OOZIE", "ZOOKEEPER", "HIVE", "MAPREDUCE2", "TEZ", "SQOOP", "PIG","FALCON")
  34. * that have only client components
  35. */
  36. installedClients: DS.attr('number'),
  37. clientComponents: DS.hasMany('App.ClientComponent'),
  38. slaveComponents: DS.hasMany('App.SlaveComponent'),
  39. masterComponents: DS.hasMany('App.MasterComponent'),
  40. /**
  41. * @type {bool}
  42. */
  43. isInPassive: function() {
  44. return this.get('passiveState') === "ON";
  45. }.property('passiveState'),
  46. serviceComponents: function() {
  47. var clientComponents = this.get('clientComponents').mapProperty('componentName');
  48. var slaveComponents = this.get('slaveComponents').mapProperty('componentName');
  49. var masterComponents = this.get('masterComponents').mapProperty('componentName');
  50. return clientComponents.concat(slaveComponents).concat(masterComponents);
  51. }.property('clientComponents.@each', 'slaveComponents.@each','masterComponents.@each'),
  52. // Instead of making healthStatus a computed property that listens on hostComponents.@each.workStatus,
  53. // we are creating a separate observer _updateHealthStatus. This is so that healthStatus is updated
  54. // only once after the run loop. This is because Ember invokes the computed property every time
  55. // a property that it depends on changes. For example, App.statusMapper's map function would invoke
  56. // the computed property too many times and freezes the UI without this hack.
  57. // See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
  58. healthStatus: function(){
  59. switch(this.get('workStatus')){
  60. case 'STARTED':
  61. return 'green';
  62. case 'STARTING':
  63. return 'green-blinking';
  64. case 'INSTALLED':
  65. return 'red';
  66. case 'STOPPING':
  67. return 'red-blinking';
  68. case 'UNKNOWN':
  69. default:
  70. return 'yellow';
  71. }
  72. }.property('workStatus'),
  73. isStopped: function () {
  74. return this.get('workStatus') === 'INSTALLED';
  75. }.property('workStatus'),
  76. isStarted: function () {
  77. return this.get('workStatus') === 'STARTED';
  78. }.property('workStatus'),
  79. /**
  80. * Service Tagging by their type.
  81. * @type {String[]}
  82. **/
  83. serviceTypes: function() {
  84. var typeServiceMap = {
  85. GANGLIA: ['MONITORING'],
  86. HDFS: ['HA_MODE'],
  87. YARN: ['HA_MODE'],
  88. RANGER: ['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. hasCriticalAlerts: function () {
  141. var controller = App.router.get('mainAlertDefinitionsController');
  142. return controller.getCriticalAlertsCountForService(this.get('serviceName')) > 0;
  143. }.property('alertsCount'),
  144. alertsCount: function () {
  145. var controller = App.router.get('mainAlertDefinitionsController');
  146. return controller.getCriticalOrWarningAlertsCountForService(this.get('serviceName'));
  147. }.property('App.router.mainAlertDefinitionsController.content.@each.isCriticalOrWarning')
  148. });
  149. App.Service.Health = {
  150. live: "LIVE",
  151. dead: "DEAD-RED",
  152. starting: "STARTING",
  153. stopping: "STOPPING",
  154. unknown: "DEAD-YELLOW",
  155. getKeyName: function (value) {
  156. switch (value) {
  157. case this.live:
  158. return 'live';
  159. case this.dead:
  160. return 'dead';
  161. case this.starting:
  162. return 'starting';
  163. case this.stopping:
  164. return 'stopping';
  165. case this.unknown:
  166. return 'unknown';
  167. }
  168. return 'none';
  169. }
  170. };
  171. /**
  172. * association between service and extended model name
  173. * @type {Object}
  174. */
  175. App.Service.extendedModel = {
  176. 'HDFS': 'HDFSService',
  177. 'HBASE': 'HBaseService',
  178. 'YARN': 'YARNService',
  179. 'MAPREDUCE2': 'MapReduce2Service',
  180. 'STORM': 'StormService',
  181. 'FLUME': 'FlumeService'
  182. };
  183. App.Service.FIXTURES = [];