host_component.js 6.3 KB

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