host_component.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 'RESOURCEMANAGER':
  78. return true;
  79. default:
  80. return false;
  81. }
  82. }.property('componentName'),
  83. /**
  84. * Determine if component is slave
  85. * @returns {bool}
  86. */
  87. isSlave: function(){
  88. switch (this.get('componentName')) {
  89. case 'DATANODE':
  90. case 'TASKTRACKER':
  91. case 'HBASE_REGIONSERVER':
  92. case 'GANGLIA_MONITOR':
  93. case 'NODEMANAGER':
  94. case 'ZKFC':
  95. case 'SUPERVISOR':
  96. return true;
  97. default:
  98. return false;
  99. }
  100. }.property('componentName'),
  101. /**
  102. * Only certain components can be deleted.
  103. * They include some from master components,
  104. * some from slave components, and rest from
  105. * client components.
  106. * @returns {bool}
  107. */
  108. isDeletable: function() {
  109. var canDelete = false;
  110. switch (this.get('componentName')) {
  111. case 'DATANODE':
  112. case 'TASKTRACKER':
  113. case 'ZOOKEEPER_SERVER':
  114. case 'HBASE_REGIONSERVER':
  115. case 'GANGLIA_MONITOR':
  116. case 'SUPERVISOR':
  117. case 'NODEMANAGER':
  118. canDelete = true;
  119. break;
  120. default:
  121. }
  122. if (!canDelete) {
  123. canDelete = this.get('isClient');
  124. }
  125. return canDelete;
  126. }.property('componentName', 'isClient'),
  127. /**
  128. * A host-component is decommissioning when it is in HDFS service's list of
  129. * decomNodes.
  130. * @returns {bool}
  131. */
  132. isDecommissioning: function () {
  133. var decommissioning = false;
  134. var hostName = this.get('host.hostName');
  135. var componentName = this.get('componentName');
  136. var hdfsSvc = App.HDFSService.find().objectAt(0);
  137. if (componentName === 'DATANODE' && hdfsSvc) {
  138. var decomNodes = hdfsSvc.get('decommissionDataNodes');
  139. var decomNode = decomNodes != null ? decomNodes.findProperty("hostName", hostName) : null;
  140. decommissioning = decomNode != null;
  141. }
  142. return decommissioning;
  143. }.property('componentName', 'host.hostName', 'App.router.clusterController.isLoaded', 'App.router.updateController.isUpdated'),
  144. /**
  145. * User friendly host component status
  146. * @returns {String}
  147. */
  148. componentTextStatus: function () {
  149. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  150. }.property('workStatus','isDecommissioning')
  151. });
  152. App.HostComponent.FIXTURES = [];
  153. App.HostComponentStatus = {
  154. started: "STARTED",
  155. starting: "STARTING",
  156. stopped: "INSTALLED",
  157. stopping: "STOPPING",
  158. install_failed: "INSTALL_FAILED",
  159. installing: "INSTALLING",
  160. upgrade_failed: "UPGRADE_FAILED",
  161. maintenance: "MAINTENANCE",
  162. unknown: "UNKNOWN",
  163. /**
  164. * Get host component status in "machine" format
  165. * @param {String} value
  166. * @returns {String}
  167. */
  168. getKeyName:function(value){
  169. switch(value){
  170. case this.started:
  171. return 'started';
  172. case this.starting:
  173. return 'starting';
  174. case this.stopped:
  175. return 'installed';
  176. case this.stopping:
  177. return 'stopping';
  178. case this.install_failed:
  179. return 'install_failed';
  180. case this.installing:
  181. return 'installing';
  182. case this.upgrade_failed:
  183. return 'upgrade_failed';
  184. case this.maintenance:
  185. return 'maintenance';
  186. case this.unknown:
  187. return 'unknown';
  188. }
  189. return 'Unknown';
  190. },
  191. /**
  192. * Get user-friendly host component status
  193. * @param {String} value
  194. * @returns {String}
  195. */
  196. getTextStatus: function (value) {
  197. switch (value) {
  198. case this.installing:
  199. return 'Installing...';
  200. case this.install_failed:
  201. return 'Install Failed';
  202. case this.stopped:
  203. return 'Stopped';
  204. case this.started:
  205. return 'Started';
  206. case this.starting:
  207. return 'Starting...';
  208. case this.stopping:
  209. return 'Stopping...';
  210. case this.unknown:
  211. return 'Heartbeat lost...';
  212. case this.upgrade_failed:
  213. return 'Upgrade Failed';
  214. case this.maintenance:
  215. return 'Maintenance';
  216. }
  217. return 'Unknown';
  218. }
  219. };