service.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /**
  40. * @type {bool}
  41. */
  42. isInPassive: function() {
  43. return this.get('passiveState') === "ON";
  44. }.property('passiveState'),
  45. // Instead of making healthStatus a computed property that listens on hostComponents.@each.workStatus,
  46. // we are creating a separate observer _updateHealthStatus. This is so that healthStatus is updated
  47. // only once after the run loop. This is because Ember invokes the computed property every time
  48. // a property that it depends on changes. For example, App.statusMapper's map function would invoke
  49. // the computed property too many times and freezes the UI without this hack.
  50. // See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
  51. healthStatus: function(){
  52. switch(this.get('workStatus')){
  53. case 'STARTED':
  54. return 'green';
  55. case 'STARTING':
  56. return 'green-blinking';
  57. case 'INSTALLED':
  58. return 'red';
  59. case 'STOPPING':
  60. return 'red-blinking';
  61. case 'UNKNOWN':
  62. default:
  63. return 'yellow';
  64. }
  65. }.property('workStatus'),
  66. isStopped: function () {
  67. return this.get('workStatus') === 'INSTALLED';
  68. }.property('workStatus'),
  69. isStarted: function () {
  70. return this.get('workStatus') === 'STARTED';
  71. }.property('workStatus'),
  72. /**
  73. * Service Tagging by their type.
  74. * @type {String[]}
  75. **/
  76. serviceTypes: function() {
  77. var typeServiceMap = {
  78. GANGLIA: ['MONITORING'],
  79. NAGIOS: ['MONITORING'],
  80. HDFS: ['HA_MODE'],
  81. YARN: ['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', 'hostComponents.@each.staleConfigs'),
  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. criticalAlertsCount: function () {
  134. var controller = App.router.get('mainAlertDefinitionsController');
  135. return controller.getCriticalAlertsCountForService(this);
  136. }.property('App.router.mainAlertDefinitionsController.content.@each.isCriticalOrWarning')
  137. });
  138. App.Service.Health = {
  139. live: "LIVE",
  140. dead: "DEAD-RED",
  141. starting: "STARTING",
  142. stopping: "STOPPING",
  143. unknown: "DEAD-YELLOW",
  144. getKeyName: function (value) {
  145. switch (value) {
  146. case this.live:
  147. return 'live';
  148. case this.dead:
  149. return 'dead';
  150. case this.starting:
  151. return 'starting';
  152. case this.stopping:
  153. return 'stopping';
  154. case this.unknown:
  155. return 'unknown';
  156. }
  157. return 'none';
  158. }
  159. };
  160. /**
  161. * association between service and extended model name
  162. * @type {Object}
  163. */
  164. App.Service.extendedModel = {
  165. 'HDFS': 'HDFSService',
  166. 'MAPREDUCE': 'MapReduceService',
  167. 'HBASE': 'HBaseService',
  168. 'YARN': 'YARNService',
  169. 'MAPREDUCE2': 'MapReduce2Service',
  170. 'STORM': 'StormService',
  171. 'FLUME': 'FlumeService'
  172. };
  173. App.Service.FIXTURES = [];