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