host_component.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 'DRPC_SERVER':
  80. case 'STORM_REST_API':
  81. case 'RESOURCEMANAGER':
  82. case 'APP_TIMELINE_SERVER':
  83. return true;
  84. default:
  85. return false;
  86. }
  87. }.property('componentName'),
  88. /**
  89. * Determine if component is slave
  90. * @returns {bool}
  91. */
  92. isSlave: function(){
  93. switch (this.get('componentName')) {
  94. case 'DATANODE':
  95. case 'TASKTRACKER':
  96. case 'HBASE_REGIONSERVER':
  97. case 'GANGLIA_MONITOR':
  98. case 'NODEMANAGER':
  99. case 'ZKFC':
  100. case 'SUPERVISOR':
  101. return true;
  102. default:
  103. return false;
  104. }
  105. }.property('componentName'),
  106. /**
  107. * Only certain components can be deleted.
  108. * They include some from master components,
  109. * some from slave components, and rest from
  110. * client components.
  111. * @returns {bool}
  112. */
  113. isDeletable: function() {
  114. var canDelete = false;
  115. switch (this.get('componentName')) {
  116. case 'DATANODE':
  117. case 'TASKTRACKER':
  118. case 'ZOOKEEPER_SERVER':
  119. case 'HBASE_REGIONSERVER':
  120. case 'GANGLIA_MONITOR':
  121. case 'SUPERVISOR':
  122. case 'NODEMANAGER':
  123. canDelete = true;
  124. break;
  125. default:
  126. }
  127. if (!canDelete) {
  128. canDelete = this.get('isClient');
  129. }
  130. return canDelete;
  131. }.property('componentName', 'isClient'),
  132. /**
  133. * A host-component is decommissioning when it is in HDFS service's list of
  134. * decomNodes.
  135. * @returns {bool}
  136. */
  137. isDecommissioning: function () {
  138. var decommissioning = false;
  139. var hostName = this.get('host.hostName');
  140. var componentName = this.get('componentName');
  141. var hdfsSvc = App.HDFSService.find().objectAt(0);
  142. if (componentName === 'DATANODE' && hdfsSvc) {
  143. var decomNodes = hdfsSvc.get('decommissionDataNodes');
  144. var decomNode = decomNodes != null ? decomNodes.findProperty("hostName", hostName) : null;
  145. decommissioning = decomNode != null;
  146. }
  147. return decommissioning;
  148. }.property('componentName', 'host.hostName', 'App.router.clusterController.isLoaded', 'App.router.updateController.isUpdated'),
  149. /**
  150. * User friendly host component status
  151. * @returns {String}
  152. */
  153. isActive: function() {
  154. return (this.get('passiveState') == 'OFF');
  155. }.property('passiveState'),
  156. passiveTooltip: function() {
  157. if (!this.get('isActive')) {
  158. return Em.I18n.t('hosts.component.passive.mode');
  159. }
  160. }.property('isActive'),
  161. statusClass: function() {
  162. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  163. }.property('workStatus','isActive'),
  164. componentTextStatus: function () {
  165. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  166. }.property('workStatus','isDecommissioning')
  167. });
  168. App.HostComponent.FIXTURES = [];
  169. App.HostComponentStatus = {
  170. started: "STARTED",
  171. starting: "STARTING",
  172. stopped: "INSTALLED",
  173. stopping: "STOPPING",
  174. install_failed: "INSTALL_FAILED",
  175. installing: "INSTALLING",
  176. upgrade_failed: "UPGRADE_FAILED",
  177. unknown: "UNKNOWN",
  178. disabled: "DISABLED",
  179. init: "INIT",
  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. case this.init:
  233. return 'Install Pending...';
  234. }
  235. return 'Unknown';
  236. },
  237. /**
  238. * Get list of possible <code>App.HostComponent</code> statuses
  239. * @returns {String[]}
  240. */
  241. getStatusesList: function() {
  242. var ret = [];
  243. for (var st in this) {
  244. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  245. ret.push(this[st]);
  246. }
  247. }
  248. return ret;
  249. }
  250. };