host_component.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. hostName: DS.attr('string'),
  28. service: DS.belongsTo('App.Service'),
  29. /**
  30. * Determine if component is client
  31. * @returns {bool}
  32. */
  33. isClient:function () {
  34. if(['PIG', 'SQOOP', 'HCAT', 'MAPREDUCE2_CLIENT'].contains(this.get('componentName'))){
  35. return true;
  36. }
  37. return Boolean(this.get('componentName').match(/_client/gi));
  38. }.property('componentName'),
  39. /**
  40. * Determine if component is running now
  41. * Based on <code>workStatus</code>
  42. * @returns {bool}
  43. */
  44. isRunning: function(){
  45. return (this.get('workStatus') == 'STARTED' || this.get('workStatus') == 'STARTING');
  46. }.property('workStatus'),
  47. /**
  48. * Formatted <code>componentName</code>
  49. * @returns {String}
  50. */
  51. displayName: function () {
  52. return App.format.role(this.get('componentName'));
  53. }.property('componentName'),
  54. /**
  55. * Determine if component is master
  56. * @returns {bool}
  57. */
  58. isMaster: function () {
  59. switch (this.get('componentName')) {
  60. case 'NAMENODE':
  61. case 'SECONDARY_NAMENODE':
  62. case 'SNAMENODE':
  63. case 'JOURNALNODE':
  64. case 'JOBTRACKER':
  65. case 'ZOOKEEPER_SERVER':
  66. case 'HIVE_SERVER':
  67. case 'HIVE_METASTORE':
  68. case 'MYSQL_SERVER':
  69. case 'HBASE_MASTER':
  70. case 'NAGIOS_SERVER':
  71. case 'GANGLIA_SERVER':
  72. case 'OOZIE_SERVER':
  73. case 'WEBHCAT_SERVER':
  74. case 'HUE_SERVER':
  75. case 'HISTORYSERVER':
  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. case 'FLUME_HANDLER':
  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('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', '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. statusIconClass: function () {
  166. switch (this.get('statusClass')) {
  167. case 'STARTED':
  168. case 'STARTING':
  169. return App.healthIconClassGreen;
  170. break;
  171. case 'INSTALLED':
  172. case 'STOPPING':
  173. return App.healthIconClassRed;
  174. break;
  175. case 'UNKNOWN':
  176. return App.healthIconClassYellow;
  177. break;
  178. default:
  179. return "";
  180. break;
  181. }
  182. }.property('statusClass'),
  183. componentTextStatus: function () {
  184. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  185. }.property('workStatus','isDecommissioning')
  186. });
  187. App.HostComponent.FIXTURES = [];
  188. App.HostComponentStatus = {
  189. started: "STARTED",
  190. starting: "STARTING",
  191. stopped: "INSTALLED",
  192. stopping: "STOPPING",
  193. install_failed: "INSTALL_FAILED",
  194. installing: "INSTALLING",
  195. upgrade_failed: "UPGRADE_FAILED",
  196. unknown: "UNKNOWN",
  197. disabled: "DISABLED",
  198. init: "INIT",
  199. /**
  200. * Get host component status in "machine" format
  201. * @param {String} value
  202. * @returns {String}
  203. */
  204. getKeyName:function(value){
  205. switch(value){
  206. case this.started:
  207. return 'started';
  208. case this.starting:
  209. return 'starting';
  210. case this.stopped:
  211. return 'installed';
  212. case this.stopping:
  213. return 'stopping';
  214. case this.install_failed:
  215. return 'install_failed';
  216. case this.installing:
  217. return 'installing';
  218. case this.upgrade_failed:
  219. return 'upgrade_failed';
  220. case this.disabled:
  221. case this.unknown:
  222. return 'unknown';
  223. }
  224. return 'unknown';
  225. },
  226. /**
  227. * Get user-friendly host component status
  228. * @param {String} value
  229. * @returns {String}
  230. */
  231. getTextStatus: function (value) {
  232. switch (value) {
  233. case this.installing:
  234. return 'Installing...';
  235. case this.install_failed:
  236. return 'Install Failed';
  237. case this.stopped:
  238. return 'Stopped';
  239. case this.started:
  240. return 'Started';
  241. case this.starting:
  242. return 'Starting...';
  243. case this.stopping:
  244. return 'Stopping...';
  245. case this.unknown:
  246. return 'Heartbeat Lost';
  247. case this.upgrade_failed:
  248. return 'Upgrade Failed';
  249. case this.disabled:
  250. return 'Disabled';
  251. case this.init:
  252. return 'Install Pending...';
  253. }
  254. return 'Unknown';
  255. },
  256. /**
  257. * Get list of possible <code>App.HostComponent</code> statuses
  258. * @returns {String[]}
  259. */
  260. getStatusesList: function() {
  261. var ret = [];
  262. for (var st in this) {
  263. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  264. ret.push(this[st]);
  265. }
  266. }
  267. return ret;
  268. }
  269. };