host_component.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. App.HostComponent = DS.Model.extend({
  20. workStatus: DS.attr('string'),
  21. passiveState: DS.attr('string'),
  22. componentName: DS.attr('string'),
  23. haStatus: DS.attr('string'),
  24. displayNameAdvanced: DS.attr('string'),
  25. staleConfigs: DS.attr('boolean'),
  26. host: DS.belongsTo('App.Host'),
  27. service: DS.belongsTo('App.Service'),
  28. /**
  29. * Determine if component is client
  30. * @returns {bool}
  31. */
  32. isClient:function () {
  33. if(['PIG', 'SQOOP', 'HCAT', 'MAPREDUCE2_CLIENT'].contains(this.get('componentName'))){
  34. return true;
  35. }
  36. return Boolean(this.get('componentName').match(/_client/gi));
  37. }.property('componentName'),
  38. /**
  39. * Determine if component is running now
  40. * Based on <code>workStatus</code>
  41. * @returns {bool}
  42. */
  43. isRunning: function(){
  44. return (this.get('workStatus') == 'STARTED' || this.get('workStatus') == 'STARTING');
  45. }.property('workStatus'),
  46. /**
  47. * Formatted <code>componentName</code>
  48. * @returns {String}
  49. */
  50. displayName: function () {
  51. return App.format.role(this.get('componentName'));
  52. }.property('componentName'),
  53. /**
  54. * Determine if component is master
  55. * @returns {bool}
  56. */
  57. isMaster: function () {
  58. switch (this.get('componentName')) {
  59. case 'NAMENODE':
  60. case 'SECONDARY_NAMENODE':
  61. case 'SNAMENODE':
  62. case 'JOURNALNODE':
  63. case 'JOBTRACKER':
  64. case 'ZOOKEEPER_SERVER':
  65. case 'HIVE_SERVER':
  66. case 'HIVE_METASTORE':
  67. case 'MYSQL_SERVER':
  68. case 'HBASE_MASTER':
  69. case 'NAGIOS_SERVER':
  70. case 'GANGLIA_SERVER':
  71. case 'OOZIE_SERVER':
  72. case 'WEBHCAT_SERVER':
  73. case 'HUE_SERVER':
  74. case 'HISTORYSERVER':
  75. case 'FLUME_SERVER':
  76. case 'FALCON_SERVER':
  77. case 'NIMBUS':
  78. case 'STORM_UI_SERVER':
  79. case 'LOGVIEWER_SERVER':
  80. case 'DRPC_SERVER':
  81. case 'STORM_REST_API':
  82. case 'RESOURCEMANAGER':
  83. case 'APP_TIMELINE_SERVER':
  84. return true;
  85. default:
  86. return false;
  87. }
  88. }.property('componentName'),
  89. /**
  90. * Determine if component is slave
  91. * @returns {bool}
  92. */
  93. isSlave: function(){
  94. switch (this.get('componentName')) {
  95. case 'DATANODE':
  96. case 'TASKTRACKER':
  97. case 'HBASE_REGIONSERVER':
  98. case 'GANGLIA_MONITOR':
  99. case 'NODEMANAGER':
  100. case 'ZKFC':
  101. case 'SUPERVISOR':
  102. return true;
  103. default:
  104. return false;
  105. }
  106. }.property('componentName'),
  107. /**
  108. * Only certain components can be deleted.
  109. * They include some from master components,
  110. * some from slave components, and rest from
  111. * client components.
  112. * @returns {bool}
  113. */
  114. isDeletable: function() {
  115. var canDelete = false;
  116. switch (this.get('componentName')) {
  117. case 'DATANODE':
  118. case 'TASKTRACKER':
  119. case 'ZOOKEEPER_SERVER':
  120. case 'HBASE_REGIONSERVER':
  121. case 'GANGLIA_MONITOR':
  122. case 'SUPERVISOR':
  123. case 'NODEMANAGER':
  124. canDelete = true;
  125. break;
  126. default:
  127. }
  128. if (!canDelete) {
  129. canDelete = this.get('isClient');
  130. }
  131. return canDelete;
  132. }.property('componentName', 'isClient'),
  133. /**
  134. * A host-component is decommissioning when it is in HDFS service's list of
  135. * decomNodes.
  136. * @returns {bool}
  137. */
  138. isDecommissioning: function () {
  139. var decommissioning = false;
  140. var hostName = this.get('host.hostName');
  141. var componentName = this.get('componentName');
  142. var hdfsSvc = App.HDFSService.find().objectAt(0);
  143. if (componentName === 'DATANODE' && hdfsSvc) {
  144. var decomNodes = hdfsSvc.get('decommissionDataNodes');
  145. var decomNode = decomNodes != null ? decomNodes.findProperty("hostName", hostName) : null;
  146. decommissioning = decomNode != null;
  147. }
  148. return decommissioning;
  149. }.property('componentName', 'host.hostName', 'App.router.clusterController.isLoaded', 'App.router.updateController.isUpdated'),
  150. /**
  151. * User friendly host component status
  152. * @returns {String}
  153. */
  154. isActive: function() {
  155. return (this.get('passiveState') == 'OFF');
  156. }.property('passiveState'),
  157. passiveTooltip: function() {
  158. if (!this.get('isActive')) {
  159. return Em.I18n.t('hosts.component.passive.mode');
  160. }
  161. }.property('isActive'),
  162. statusClass: function() {
  163. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  164. }.property('workStatus','isActive'),
  165. componentTextStatus: function () {
  166. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  167. }.property('workStatus','isDecommissioning')
  168. });
  169. App.HostComponent.FIXTURES = [];
  170. App.HostComponentStatus = {
  171. started: "STARTED",
  172. starting: "STARTING",
  173. stopped: "INSTALLED",
  174. stopping: "STOPPING",
  175. install_failed: "INSTALL_FAILED",
  176. installing: "INSTALLING",
  177. upgrade_failed: "UPGRADE_FAILED",
  178. unknown: "UNKNOWN",
  179. disabled: "DISABLED",
  180. /**
  181. * Get host component status in "machine" format
  182. * @param {String} value
  183. * @returns {String}
  184. */
  185. getKeyName:function(value){
  186. switch(value){
  187. case this.started:
  188. return 'started';
  189. case this.starting:
  190. return 'starting';
  191. case this.stopped:
  192. return 'installed';
  193. case this.stopping:
  194. return 'stopping';
  195. case this.install_failed:
  196. return 'install_failed';
  197. case this.installing:
  198. return 'installing';
  199. case this.upgrade_failed:
  200. return 'upgrade_failed';
  201. case this.disabled:
  202. case this.unknown:
  203. return 'unknown';
  204. }
  205. return 'unknown';
  206. },
  207. /**
  208. * Get user-friendly host component status
  209. * @param {String} value
  210. * @returns {String}
  211. */
  212. getTextStatus: function (value) {
  213. switch (value) {
  214. case this.installing:
  215. return 'Installing...';
  216. case this.install_failed:
  217. return 'Install Failed';
  218. case this.stopped:
  219. return 'Stopped';
  220. case this.started:
  221. return 'Started';
  222. case this.starting:
  223. return 'Starting...';
  224. case this.stopping:
  225. return 'Stopping...';
  226. case this.unknown:
  227. return 'Heartbeat lost...';
  228. case this.upgrade_failed:
  229. return 'Upgrade Failed';
  230. case this.disabled:
  231. return 'Disabled';
  232. }
  233. return 'Unknown';
  234. }
  235. };