host_component.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. statusIconClass: function () {
  165. switch (this.get('statusClass')) {
  166. case 'STARTED':
  167. case 'STARTING':
  168. return App.healthIconClassGreen;
  169. break;
  170. case 'INSTALLED':
  171. case 'STOPPING':
  172. return App.healthIconClassRed;
  173. break;
  174. case 'UNKNOWN':
  175. return App.healthIconClassYellow;
  176. break;
  177. default:
  178. return "";
  179. break;
  180. }
  181. }.property('statusClass'),
  182. componentTextStatus: function () {
  183. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  184. }.property('workStatus','isDecommissioning')
  185. });
  186. App.HostComponent.FIXTURES = [];
  187. App.HostComponentStatus = {
  188. started: "STARTED",
  189. starting: "STARTING",
  190. stopped: "INSTALLED",
  191. stopping: "STOPPING",
  192. install_failed: "INSTALL_FAILED",
  193. installing: "INSTALLING",
  194. upgrade_failed: "UPGRADE_FAILED",
  195. unknown: "UNKNOWN",
  196. disabled: "DISABLED",
  197. init: "INIT",
  198. /**
  199. * Get host component status in "machine" format
  200. * @param {String} value
  201. * @returns {String}
  202. */
  203. getKeyName:function(value){
  204. switch(value){
  205. case this.started:
  206. return 'started';
  207. case this.starting:
  208. return 'starting';
  209. case this.stopped:
  210. return 'installed';
  211. case this.stopping:
  212. return 'stopping';
  213. case this.install_failed:
  214. return 'install_failed';
  215. case this.installing:
  216. return 'installing';
  217. case this.upgrade_failed:
  218. return 'upgrade_failed';
  219. case this.disabled:
  220. case this.unknown:
  221. return 'unknown';
  222. }
  223. return 'unknown';
  224. },
  225. /**
  226. * Get user-friendly host component status
  227. * @param {String} value
  228. * @returns {String}
  229. */
  230. getTextStatus: function (value) {
  231. switch (value) {
  232. case this.installing:
  233. return 'Installing...';
  234. case this.install_failed:
  235. return 'Install Failed';
  236. case this.stopped:
  237. return 'Stopped';
  238. case this.started:
  239. return 'Started';
  240. case this.starting:
  241. return 'Starting...';
  242. case this.stopping:
  243. return 'Stopping...';
  244. case this.unknown:
  245. return 'Heartbeat lost...';
  246. case this.upgrade_failed:
  247. return 'Upgrade Failed';
  248. case this.disabled:
  249. return 'Disabled';
  250. case this.init:
  251. return 'Install Pending...';
  252. }
  253. return 'Unknown';
  254. },
  255. /**
  256. * Get list of possible <code>App.HostComponent</code> statuses
  257. * @returns {String[]}
  258. */
  259. getStatusesList: function() {
  260. var ret = [];
  261. for (var st in this) {
  262. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  263. ret.push(this[st]);
  264. }
  265. }
  266. return ret;
  267. }
  268. };