service.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. workStatus: DS.attr('string'),
  23. rand: DS.attr('string'),
  24. alerts: DS.hasMany('App.Alert'),
  25. quickLinks: DS.hasMany('App.QuickLinks'),
  26. hostComponents: DS.hasMany('App.HostComponent'),
  27. serviceConfigsTemplate: App.config.get('preDefinedServiceConfigs'),
  28. runningHostComponents: null,
  29. // Instead of making healthStatus a computed property that listens on hostComponents.@each.workStatus,
  30. // we are creating a separate observer _updateHealthStatus. This is so that healthStatus is updated
  31. // only once after the run loop. This is because Ember invokes the computed property every time
  32. // a property that it depends on changes. For example, App.statusMapper's map function would invoke
  33. // the computed property too many times and freezes the UI without this hack.
  34. // See http://stackoverflow.com/questions/12467345/ember-js-collapsing-deferring-expensive-observers-or-computed-properties
  35. healthStatus: '',
  36. isStopped: false,
  37. isStarted: false,
  38. isConfigurable: function () {
  39. var configurableServices = [
  40. "HDFS",
  41. "YARN",
  42. "MAPREDUCE",
  43. "MAPREDUCE2",
  44. "HBASE",
  45. "OOZIE",
  46. "HIVE",
  47. "WEBHCAT",
  48. "ZOOKEEPER",
  49. "PIG",
  50. "SQOOP",
  51. "NAGIOS",
  52. "HUE"
  53. ];
  54. return configurableServices.contains(this.get('serviceName'));
  55. }.property('serviceName'),
  56. displayName: function () {
  57. switch (this.get('serviceName').toLowerCase()) {
  58. case 'hdfs':
  59. return 'HDFS';
  60. case 'yarn':
  61. return 'YARN';
  62. case 'mapreduce':
  63. return 'MapReduce';
  64. case 'mapreduce2':
  65. return 'MapReduce2';
  66. case 'tez':
  67. return 'Tez';
  68. case 'hbase':
  69. return 'HBase';
  70. case 'oozie':
  71. return 'Oozie';
  72. case 'hive':
  73. return 'Hive';
  74. case 'hcatalog':
  75. return 'HCat';
  76. case 'zookeeper':
  77. return 'ZooKeeper';
  78. case 'pig':
  79. return 'Pig';
  80. case 'sqoop':
  81. return 'Sqoop';
  82. case 'webhcat':
  83. return 'WebHCat';
  84. case 'ganglia':
  85. return 'Ganglia';
  86. case 'nagios':
  87. return 'Nagios';
  88. case 'hue':
  89. return 'Hue';
  90. case 'flume':
  91. return 'Flume';
  92. }
  93. return this.get('serviceName');
  94. }.property('serviceName'),
  95. /**
  96. * For each host-component, if the desired_configs dont match the
  97. * actual_configs, then a restart is required. Except for Global site
  98. * properties, which need to be checked with map.
  99. */
  100. isRestartRequired: function () {
  101. var rhc = this.get('hostComponents').filterProperty('staleConfigs', true);
  102. var hc = {};
  103. rhc.forEach(function(_rhc) {
  104. var hostName = _rhc.get('host.publicHostName');
  105. if (!hc[hostName]) {
  106. hc[hostName] = [];
  107. }
  108. hc[hostName].push(_rhc.get('displayName'));
  109. });
  110. this.set('restartRequiredHostsAndComponents', hc);
  111. return (rhc.length>0);
  112. }.property('serviceName', 'hostComponents'),
  113. /**
  114. * Contains a map of which hosts and host_components
  115. * need a restart. This is populated when calculating
  116. * #isRestartRequired()
  117. * Example:
  118. * {
  119. * 'publicHostName1': ['TaskTracker'],
  120. * 'publicHostName2': ['JobTracker', 'TaskTracker']
  121. * }
  122. */
  123. restartRequiredHostsAndComponents: {},
  124. /**
  125. * Based on the information in #restartRequiredHostsAndComponents
  126. */
  127. restartRequiredMessage: function () {
  128. var restartHC = this.get('restartRequiredHostsAndComponents');
  129. var hostCount = 0;
  130. var hcCount = 0;
  131. var hostsMsg = "<ul>";
  132. for(var host in restartHC){
  133. hostCount++;
  134. hostsMsg += "<li>"+host+"</li><ul>";
  135. restartHC[host].forEach(function(c){
  136. hcCount++;
  137. hostsMsg += "<li>"+c+"</li>";
  138. })
  139. hostsMsg += "</ul>";
  140. }
  141. hostsMsg += "</ul>"
  142. return this.t('services.service.config.restartService.TooltipMessage').format(hcCount, hostCount, hostsMsg);
  143. }.property('restartRequiredHostsAndComponents')
  144. });
  145. App.Service.Health = {
  146. live: "LIVE",
  147. dead: "DEAD-RED",
  148. starting: "STARTING",
  149. stopping: "STOPPING",
  150. unknown: "DEAD-YELLOW",
  151. getKeyName: function (value) {
  152. switch (value) {
  153. case this.live:
  154. return 'live';
  155. case this.dead:
  156. return 'dead';
  157. case this.starting:
  158. return 'starting';
  159. case this.stopping:
  160. return 'stopping';
  161. case this.unknown:
  162. return 'unknown';
  163. }
  164. return 'none';
  165. }
  166. };
  167. App.Service.FIXTURES = [];