host_component.js 6.5 KB

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