host_component.js 7.6 KB

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