host_component.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. adminState: DS.attr('string'),
  30. /**
  31. * Determine if component is client
  32. * @returns {bool}
  33. */
  34. isClient: function () {
  35. return App.get('components.clients').contains(this.get('componentName'));
  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. return App.get('components.masters').contains(this.get('componentName'));
  58. }.property('componentName', 'App.components.masters'),
  59. /**
  60. * Determine if component is slave
  61. * @returns {bool}
  62. */
  63. isSlave: function () {
  64. return App.get('components.slaves').contains(this.get('componentName'));
  65. }.property('componentName'),
  66. /**
  67. * Only certain components can be deleted.
  68. * They include some from master components,
  69. * some from slave components, and rest from
  70. * client components.
  71. * @returns {bool}
  72. */
  73. isDeletable: function () {
  74. return App.get('components.deletable').contains(this.get('componentName'));
  75. }.property('componentName'),
  76. /**
  77. * A host-component is decommissioning when it is in HDFS service's list of
  78. * decomNodes.
  79. * @returns {bool}
  80. */
  81. isDecommissioning: function () {
  82. var decommissioning = false;
  83. var hostName = this.get('hostName');
  84. var componentName = this.get('componentName');
  85. var hdfsSvc = App.HDFSService.find().objectAt(0);
  86. if (componentName === 'DATANODE' && hdfsSvc) {
  87. var decomNodes = hdfsSvc.get('decommissionDataNodes');
  88. var decomNode = decomNodes != null ? decomNodes.findProperty("hostName", hostName) : null;
  89. decommissioning = decomNode != null;
  90. }
  91. return decommissioning;
  92. }.property('componentName', 'hostName', 'App.router.clusterController.isLoaded', 'App.router.updateController.isUpdated'),
  93. /**
  94. * User friendly host component status
  95. * @returns {String}
  96. */
  97. isActive: function () {
  98. return (this.get('passiveState') == 'OFF');
  99. }.property('passiveState'),
  100. passiveTooltip: function () {
  101. if (!this.get('isActive')) {
  102. return Em.I18n.t('hosts.component.passive.mode');
  103. }
  104. }.property('isActive'),
  105. statusClass: function () {
  106. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  107. }.property('workStatus', 'isActive'),
  108. statusIconClass: function () {
  109. switch (this.get('statusClass')) {
  110. case 'STARTED':
  111. case 'STARTING':
  112. return App.healthIconClassGreen;
  113. break;
  114. case 'INSTALLED':
  115. case 'STOPPING':
  116. return App.healthIconClassRed;
  117. break;
  118. case 'UNKNOWN':
  119. return App.healthIconClassYellow;
  120. break;
  121. default:
  122. return "";
  123. break;
  124. }
  125. }.property('statusClass'),
  126. componentTextStatus: function () {
  127. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  128. }.property('workStatus', 'isDecommissioning')
  129. });
  130. App.HostComponent.FIXTURES = [];
  131. App.HostComponentStatus = {
  132. started: "STARTED",
  133. starting: "STARTING",
  134. stopped: "INSTALLED",
  135. stopping: "STOPPING",
  136. install_failed: "INSTALL_FAILED",
  137. installing: "INSTALLING",
  138. upgrade_failed: "UPGRADE_FAILED",
  139. unknown: "UNKNOWN",
  140. disabled: "DISABLED",
  141. init: "INIT",
  142. /**
  143. * Get host component status in "machine" format
  144. * @param {String} value
  145. * @returns {String}
  146. */
  147. getKeyName: function (value) {
  148. switch (value) {
  149. case this.started:
  150. return 'started';
  151. case this.starting:
  152. return 'starting';
  153. case this.stopped:
  154. return 'installed';
  155. case this.stopping:
  156. return 'stopping';
  157. case this.install_failed:
  158. return 'install_failed';
  159. case this.installing:
  160. return 'installing';
  161. case this.upgrade_failed:
  162. return 'upgrade_failed';
  163. case this.disabled:
  164. case this.unknown:
  165. return 'unknown';
  166. }
  167. return 'unknown';
  168. },
  169. /**
  170. * Get user-friendly host component status
  171. * @param {String} value
  172. * @returns {String}
  173. */
  174. getTextStatus: function (value) {
  175. switch (value) {
  176. case this.installing:
  177. return 'Installing...';
  178. case this.install_failed:
  179. return 'Install Failed';
  180. case this.stopped:
  181. return 'Stopped';
  182. case this.started:
  183. return 'Started';
  184. case this.starting:
  185. return 'Starting...';
  186. case this.stopping:
  187. return 'Stopping...';
  188. case this.unknown:
  189. return 'Heartbeat Lost';
  190. case this.upgrade_failed:
  191. return 'Upgrade Failed';
  192. case this.disabled:
  193. return 'Disabled';
  194. case this.init:
  195. return 'Install Pending...';
  196. }
  197. return 'Unknown';
  198. },
  199. /**
  200. * Get list of possible <code>App.HostComponent</code> statuses
  201. * @returns {String[]}
  202. */
  203. getStatusesList: function () {
  204. var ret = [];
  205. for (var st in this) {
  206. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  207. ret.push(this[st]);
  208. }
  209. }
  210. return ret;
  211. }
  212. };
  213. App.HostComponentActionMap = {
  214. getMap: function(ctx) {
  215. return {
  216. RESTART_ALL: {
  217. action: 'restartAllHostComponents',
  218. context: ctx.get('serviceName'),
  219. label: Em.I18n.t('restart.service.all'),
  220. cssClass: 'icon-repeat',
  221. disabled: false
  222. },
  223. RUN_SMOKE_TEST: {
  224. action: 'runSmokeTest',
  225. label: Em.I18n.t('services.service.actions.run.smoke'),
  226. cssClass: 'icon-thumbs-up-alt',
  227. disabled: ctx.get('controller.isStopDisabled')
  228. },
  229. REFRESH_CONFIGS: {
  230. action: 'refreshConfigs',
  231. label: Em.I18n.t('hosts.host.details.refreshConfigs'),
  232. cssClass: 'icon-refresh',
  233. disabled: !ctx.get('controller.content.isRestartRequired')
  234. },
  235. REFRESHQUEUES: {
  236. action: 'refreshYarnQueues',
  237. customCommand: 'REFRESHQUEUES',
  238. context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context'),
  239. label: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.menu'),
  240. cssClass: 'icon-refresh',
  241. disabled: false
  242. },
  243. ROLLING_RESTART: {
  244. action: 'rollingRestart',
  245. context: ctx.get('rollingRestartComponent'),
  246. label: Em.I18n.t('rollingrestart.dialog.title'),
  247. cssClass: 'icon-time',
  248. disabled: false
  249. },
  250. TOGGLE_PASSIVE: {
  251. action: 'turnOnOffPassive',
  252. context: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOffFor').format(ctx.get('displayName')) : Em.I18n.t('passiveState.turnOnFor').format(ctx.get('displayName')),
  253. label: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOff') : Em.I18n.t('passiveState.turnOn'),
  254. cssClass: 'icon-medkit',
  255. disabled: false
  256. },
  257. TOGGLE_NN_HA: {
  258. action: App.get('isHaEnabled') ? 'disableHighAvailability' : 'enableHighAvailability',
  259. label: App.get('isHaEnabled') ? Em.I18n.t('admin.highAvailability.button.disable') : Em.I18n.t('admin.highAvailability.button.enable'),
  260. cssClass: App.get('isHaEnabled') ? 'icon-arrow-down' : 'icon-arrow-up',
  261. isHidden: (App.get('isHaEnabled') || (/^1.3/.test(App.get('currentStackVersionNumber')))),
  262. disabled: App.get('isSingleNode')
  263. },
  264. TOGGLE_RM_HA: {
  265. action: 'enableRMHighAvailability',
  266. label: Em.I18n.t('admin.rm_highAvailability.button.enable'),
  267. cssClass: 'icon-arrow-up',
  268. isHidden: App.get('isRMHaEnabled'),
  269. disabled: App.get('isSingleNode')
  270. },
  271. MOVE_COMPONENT: {
  272. action: 'reassignMaster',
  273. context: '',
  274. label: Em.I18n.t('services.service.actions.reassign.master'),
  275. cssClass: 'icon-share-alt'
  276. },
  277. STARTDEMOLDAP: {
  278. action: 'startLdapKnox',
  279. customCommand: 'STARTDEMOLDAP',
  280. context: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  281. label: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  282. cssClass: 'icon-play-sign',
  283. disabled: false
  284. },
  285. STOPDEMOLDAP: {
  286. action: 'stopLdapKnox',
  287. customCommand: 'STOPDEMOLDAP',
  288. context: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  289. label: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  290. cssClass: 'icon-stop',
  291. disabled: false
  292. },
  293. REBALANCEHDFS: {
  294. action: 'rebalanceHdfsNodes',
  295. customCommand: 'REBALANCEHDFS',
  296. context: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  297. label: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes'),
  298. cssClass: 'icon-refresh',
  299. disabled: false
  300. },
  301. DOWNLOAD_CLIENT_CONFIGS: {
  302. action: ctx.get('controller.isSeveralClients') ? '' : 'downloadClientConfigs',
  303. label: Em.I18n.t('services.service.actions.downloadClientConfigs'),
  304. cssClass: 'icon-download-alt',
  305. isHidden: !!ctx.get('controller.content.clientComponents') ? ctx.get('controller.content.clientComponents').rejectProperty('totalCount', 0).length == 0 : false,
  306. disabled: false,
  307. hasSubmenu: ctx.get('controller.isSeveralClients'),
  308. submenuOptions: ctx.get('controller.clientComponents')
  309. },
  310. MASTER_CUSTOM_COMMAND: {
  311. action: 'executeCustomCommand',
  312. cssClass: 'icon-play-circle',
  313. isHidden: false,
  314. disabled: false
  315. }
  316. }
  317. }
  318. };