host_component.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. displayName: DS.attr('string'),
  24. haStatus: DS.attr('string'),
  25. displayNameAdvanced: DS.attr('string'),
  26. staleConfigs: DS.attr('boolean'),
  27. host: DS.belongsTo('App.Host'),
  28. componentLogs: DS.belongsTo('App.HostComponentLog'),
  29. hostName: DS.attr('string'),
  30. publicHostName: DS.attr('string'),
  31. service: DS.belongsTo('App.Service'),
  32. adminState: DS.attr('string'),
  33. serviceDisplayName: Em.computed.truncate('service.displayName', 14, 11),
  34. getDisplayName: Em.computed.truncate('displayName', 19, 16),
  35. getDisplayNameAdvanced:Em.computed.truncate('displayNameAdvanced', 19, 16),
  36. summaryLabelClassName:function(){
  37. return 'label_for_'+this.get('componentName').toLowerCase();
  38. }.property('componentName'),
  39. summaryValueClassName:function(){
  40. return 'value_for_'+this.get('componentName').toLowerCase();
  41. }.property('componentName'),
  42. /**
  43. * Determine if component is client
  44. * @returns {bool}
  45. */
  46. isClient: function () {
  47. return App.get('components.clients').contains(this.get('componentName'));
  48. }.property('componentName'),
  49. /**
  50. * Determine if component is running now
  51. * Based on <code>workStatus</code>
  52. * @returns {bool}
  53. */
  54. isRunning: Em.computed.existsIn('workStatus', ['STARTED', 'STARTING']),
  55. /**
  56. * Determines if component is not installed
  57. * Based on <code>workStatus</code>
  58. *
  59. * @type {boolean}
  60. */
  61. isNotInstalled: Em.computed.existsIn('workStatus', ['INIT', 'INSTALL_FAILED']),
  62. /**
  63. * Determine if component is master
  64. * @returns {bool}
  65. */
  66. isMaster: function () {
  67. return App.get('components.masters').contains(this.get('componentName'));
  68. }.property('componentName', 'App.components.masters'),
  69. /**
  70. * Determine if component is slave
  71. * @returns {bool}
  72. */
  73. isSlave: function () {
  74. return App.get('components.slaves').contains(this.get('componentName'));
  75. }.property('componentName'),
  76. /**
  77. * Only certain components can be deleted.
  78. * They include some from master components,
  79. * some from slave components, and rest from
  80. * client components.
  81. * @returns {bool}
  82. */
  83. isDeletable: function () {
  84. return App.get('components.deletable').contains(this.get('componentName'));
  85. }.property('componentName'),
  86. /**
  87. * A host-component is decommissioning when it is in HDFS service's list of
  88. * decomNodes.
  89. * @returns {bool}
  90. */
  91. isDecommissioning: function () {
  92. var decommissioning = false;
  93. var hostName = this.get('hostName');
  94. var componentName = this.get('componentName');
  95. var hdfsSvc = App.HDFSService.find().objectAt(0);
  96. if (componentName === 'DATANODE' && hdfsSvc) {
  97. var decomNodes = hdfsSvc.get('decommissionDataNodes');
  98. var decomNode = decomNodes != null ? decomNodes.findProperty("hostName", hostName) : null;
  99. decommissioning = decomNode != null;
  100. }
  101. return decommissioning;
  102. }.property('componentName', 'hostName', 'App.router.clusterController.isLoaded', 'App.router.updateController.isUpdated'),
  103. /**
  104. * User friendly host component status
  105. * @returns {String}
  106. */
  107. isActive: Em.computed.equal('passiveState', 'OFF'),
  108. /**
  109. * Determine if passiveState is implied from host or/and service
  110. * @returns {Boolean}
  111. */
  112. isImpliedState: Em.computed.existsIn('passiveState', ['IMPLIED_FROM_SERVICE_AND_HOST', 'IMPLIED_FROM_HOST', 'IMPLIED_FROM_SERVICE']),
  113. passiveTooltip: Em.computed.ifThenElse('isActive', '', Em.I18n.t('hosts.component.passive.mode')),
  114. /**
  115. * Determine if component is a HDP component
  116. * @returns {bool}
  117. */
  118. isHDPComponent: function () {
  119. return !App.get('components.nonHDP').contains(this.get('componentName'));
  120. }.property('componentName', 'App.components.nonHDP'),
  121. /**
  122. * Does component have Critical Alerts
  123. * @type {boolean}
  124. */
  125. hasCriticalAlerts: false,
  126. /**
  127. * Number of the Critical and Warning alerts for current component
  128. * @type {number}
  129. */
  130. alertsCount: 0,
  131. statusClass: function () {
  132. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  133. }.property('workStatus', 'isActive'),
  134. statusIconClass: Em.computed.getByKey('statusIconClassMap', 'statusClass', ''),
  135. statusIconClassMap: {
  136. STARTED: App.healthIconClassGreen,
  137. STARTING: App.healthIconClassGreen,
  138. INSTALLED: App.healthIconClassRed,
  139. STOPPING: App.healthIconClassRed,
  140. UNKNOWN: App.healthIconClassYellow
  141. },
  142. componentTextStatus: function () {
  143. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  144. }.property('workStatus', 'isDecommissioning')
  145. });
  146. App.HostComponent.FIXTURES = [];
  147. /**
  148. * get particular counter of host-component by name
  149. * @param {string} componentName
  150. * @param {string} type (installedCount|startedCount|totalCount)
  151. * @returns {number}
  152. */
  153. App.HostComponent.getCount = function (componentName, type) {
  154. switch (App.StackServiceComponent.find(componentName).get('componentCategory')) {
  155. case 'MASTER':
  156. return Number(App.MasterComponent.find(componentName).get(type));
  157. case 'SLAVE':
  158. return Number(App.SlaveComponent.find(componentName).get(type));
  159. case 'CLIENT':
  160. return Number(App.ClientComponent.find(componentName).get(type));
  161. default:
  162. return 0;
  163. }
  164. };
  165. App.HostComponentStatus = {
  166. started: "STARTED",
  167. starting: "STARTING",
  168. stopped: "INSTALLED",
  169. stopping: "STOPPING",
  170. install_failed: "INSTALL_FAILED",
  171. installing: "INSTALLING",
  172. upgrade_failed: "UPGRADE_FAILED",
  173. unknown: "UNKNOWN",
  174. disabled: "DISABLED",
  175. init: "INIT",
  176. /**
  177. * Get host component status in "machine" format
  178. * @param {String} value
  179. * @returns {String}
  180. */
  181. getKeyName: function (value) {
  182. switch (value) {
  183. case this.started:
  184. return 'started';
  185. case this.starting:
  186. return 'starting';
  187. case this.stopped:
  188. return 'installed';
  189. case this.stopping:
  190. return 'stopping';
  191. case this.install_failed:
  192. return 'install_failed';
  193. case this.installing:
  194. return 'installing';
  195. case this.upgrade_failed:
  196. return 'upgrade_failed';
  197. case this.disabled:
  198. case this.unknown:
  199. return 'unknown';
  200. }
  201. return 'unknown';
  202. },
  203. /**
  204. * Get user-friendly host component status
  205. * @param {String} value
  206. * @returns {String}
  207. */
  208. getTextStatus: function (value) {
  209. switch (value) {
  210. case this.installing:
  211. return 'Installing...';
  212. case this.install_failed:
  213. return 'Install Failed';
  214. case this.stopped:
  215. return 'Stopped';
  216. case this.started:
  217. return 'Started';
  218. case this.starting:
  219. return 'Starting...';
  220. case this.stopping:
  221. return 'Stopping...';
  222. case this.unknown:
  223. return 'Heartbeat Lost';
  224. case this.upgrade_failed:
  225. return 'Upgrade Failed';
  226. case this.disabled:
  227. return 'Disabled';
  228. case this.init:
  229. return 'Install Pending...';
  230. }
  231. return 'Unknown';
  232. },
  233. /**
  234. * Get list of possible <code>App.HostComponent</code> statuses
  235. * @returns {String[]}
  236. */
  237. getStatusesList: function () {
  238. var ret = [];
  239. for (var st in this) {
  240. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  241. ret.push(this[st]);
  242. }
  243. }
  244. return ret;
  245. }
  246. };
  247. App.HostComponentActionMap = {
  248. getMap: function(ctx) {
  249. var NN = ctx.get('controller.content.hostComponents').findProperty('componentName', 'NAMENODE');
  250. var RM = ctx.get('controller.content.hostComponents').findProperty('componentName', 'RESOURCEMANAGER');
  251. var RA = ctx.get('controller.content.hostComponents').findProperty('componentName', 'RANGER_ADMIN');
  252. var HM = ctx.get('controller.content.hostComponents').findProperty('componentName', 'HAWQMASTER');
  253. var HS = ctx.get('controller.content.hostComponents').findProperty('componentName', 'HAWQSTANDBY');
  254. var HMComponent = App.MasterComponent.find('HAWQMASTER');
  255. var HSComponent = App.MasterComponent.find('HAWQSTANDBY');
  256. return {
  257. RESTART_ALL: {
  258. action: 'restartAllHostComponents',
  259. context: ctx.get('serviceName'),
  260. label: Em.I18n.t('restart.service.all'),
  261. cssClass: 'icon-repeat',
  262. disabled: false
  263. },
  264. RUN_SMOKE_TEST: {
  265. action: 'runSmokeTest',
  266. label: Em.I18n.t('services.service.actions.run.smoke'),
  267. cssClass: 'icon-thumbs-up-alt',
  268. disabled: ctx.get('controller.isSmokeTestDisabled')
  269. },
  270. REFRESH_CONFIGS: {
  271. action: 'refreshConfigs',
  272. label: Em.I18n.t('hosts.host.details.refreshConfigs'),
  273. cssClass: 'icon-refresh',
  274. disabled: false
  275. },
  276. REFRESHQUEUES: {
  277. action: 'refreshYarnQueues',
  278. customCommand: 'REFRESHQUEUES',
  279. context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context'),
  280. label: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.menu'),
  281. cssClass: 'icon-refresh',
  282. disabled: false
  283. },
  284. ROLLING_RESTART: {
  285. action: 'rollingRestart',
  286. context: ctx.get('rollingRestartComponent'),
  287. label: Em.I18n.t('rollingrestart.dialog.title'),
  288. cssClass: 'icon-time',
  289. disabled: false
  290. },
  291. TOGGLE_PASSIVE: {
  292. action: 'turnOnOffPassive',
  293. context: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOffFor').format(ctx.get('displayName')) : Em.I18n.t('passiveState.turnOnFor').format(ctx.get('displayName')),
  294. label: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOff') : Em.I18n.t('passiveState.turnOn'),
  295. cssClass: 'icon-medkit',
  296. disabled: false
  297. },
  298. TOGGLE_NN_HA: {
  299. action: App.get('isHaEnabled') ? 'disableHighAvailability' : 'enableHighAvailability',
  300. label: App.get('isHaEnabled') ? Em.I18n.t('admin.highAvailability.button.disable') : Em.I18n.t('admin.highAvailability.button.enable'),
  301. cssClass: App.get('isHaEnabled') ? 'icon-arrow-down' : 'icon-arrow-up',
  302. isHidden: App.get('isHaEnabled'),
  303. disabled: App.get('isSingleNode') || !NN || NN.get('isNotInstalled')
  304. },
  305. TOGGLE_RM_HA: {
  306. action: 'enableRMHighAvailability',
  307. label: Em.I18n.t('admin.rm_highAvailability.button.enable'),
  308. cssClass: 'icon-arrow-up',
  309. isHidden: App.get('isRMHaEnabled'),
  310. disabled: App.get('isSingleNode') || !RM || RM.get('isNotInstalled')
  311. },
  312. TOGGLE_RA_HA: {
  313. action: 'enableRAHighAvailability',
  314. label: Em.I18n.t('admin.ra_highAvailability.button.enable'),
  315. cssClass: 'icon-arrow-up',
  316. isHidden: App.get('isRAHaEnabled'),
  317. disabled: App.get('isSingleNode') || !RA || RA.get('isNotInstalled')
  318. },
  319. MOVE_COMPONENT: {
  320. action: 'reassignMaster',
  321. context: '',
  322. isHidden: !App.isAuthorized('SERVICE.MOVE'),
  323. label: Em.I18n.t('services.service.actions.reassign.master'),
  324. cssClass: 'icon-share-alt'
  325. },
  326. STARTDEMOLDAP: {
  327. action: 'startLdapKnox',
  328. customCommand: 'STARTDEMOLDAP',
  329. context: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  330. label: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  331. cssClass: 'icon-play-sign',
  332. disabled: false
  333. },
  334. STOPDEMOLDAP: {
  335. action: 'stopLdapKnox',
  336. customCommand: 'STOPDEMOLDAP',
  337. context: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  338. label: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  339. cssClass: 'icon-stop',
  340. disabled: false
  341. },
  342. RESTART_LLAP: {
  343. action: 'restartLLAP',
  344. customCommand: 'RESTART_LLAP',
  345. context: Em.I18n.t('services.service.actions.run.restartLLAP'),
  346. label: Em.I18n.t('services.service.actions.run.restartLLAP') + ' ∞',
  347. cssClass: 'icon-refresh'
  348. },
  349. REBALANCEHDFS: {
  350. action: 'rebalanceHdfsNodes',
  351. customCommand: 'REBALANCEHDFS',
  352. context: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  353. label: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes'),
  354. cssClass: 'icon-refresh',
  355. disabled: false
  356. },
  357. DOWNLOAD_CLIENT_CONFIGS: {
  358. action: ctx.get('controller.isSeveralClients') ? '' : 'downloadClientConfigs',
  359. label: Em.I18n.t('services.service.actions.downloadClientConfigs'),
  360. cssClass: 'icon-download-alt',
  361. isHidden: !!ctx.get('controller.content.clientComponents') ? ctx.get('controller.content.clientComponents').rejectProperty('totalCount', 0).length == 0 : false,
  362. disabled: false,
  363. hasSubmenu: ctx.get('controller.isSeveralClients'),
  364. submenuOptions: ctx.get('controller.clientComponents')
  365. },
  366. DELETE_SERVICE: {
  367. action: 'deleteService',
  368. context: ctx.get('serviceName'),
  369. label: Em.I18n.t('services.service.actions.deleteService'),
  370. cssClass: 'icon-remove'
  371. },
  372. IMMEDIATE_STOP_HAWQ_SERVICE: {
  373. action: 'executeHawqCustomCommand',
  374. customCommand: 'IMMEDIATE_STOP_HAWQ_SERVICE',
  375. context: Em.I18n.t('services.service.actions.run.immediateStopHawqService.context'),
  376. label: Em.I18n.t('services.service.actions.run.immediateStopHawqService.label'),
  377. cssClass: 'icon-stop',
  378. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started
  379. },
  380. IMMEDIATE_STOP_HAWQ_SEGMENT: {
  381. customCommand: 'IMMEDIATE_STOP_HAWQ_SEGMENT',
  382. context: Em.I18n.t('services.service.actions.run.immediateStopHawqSegment.context'),
  383. label: Em.I18n.t('services.service.actions.run.immediateStopHawqSegment.label'),
  384. cssClass: 'icon-stop'
  385. },
  386. RESYNC_HAWQ_STANDBY: {
  387. action: 'executeHawqCustomCommand',
  388. customCommand: 'RESYNC_HAWQ_STANDBY',
  389. context: Em.I18n.t('services.service.actions.run.resyncHawqStandby.context'),
  390. label: Em.I18n.t('services.service.actions.run.resyncHawqStandby.label'),
  391. cssClass: 'icon-refresh',
  392. isHidden : App.get('isSingleNode') || !HS ,
  393. disabled: !((!!HMComponent && HMComponent.get('startedCount') === 1) && (!!HSComponent && HSComponent.get('startedCount') === 1))
  394. },
  395. TOGGLE_ADD_HAWQ_STANDBY: {
  396. action: 'addHawqStandby',
  397. label: Em.I18n.t('admin.addHawqStandby.button.enable'),
  398. cssClass: 'icon-plus',
  399. isHidden: App.get('isSingleNode') || HS,
  400. disabled: false
  401. },
  402. REMOVE_HAWQ_STANDBY: {
  403. action: 'removeHawqStandby',
  404. context: Em.I18n.t('admin.removeHawqStandby.button.enable'),
  405. label: Em.I18n.t('admin.removeHawqStandby.button.enable'),
  406. cssClass: 'icon-minus',
  407. isHidden: App.get('isSingleNode') || !HS,
  408. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started,
  409. hideFromComponentView: true
  410. },
  411. ACTIVATE_HAWQ_STANDBY: {
  412. action: 'activateHawqStandby',
  413. label: Em.I18n.t('admin.activateHawqStandby.button.enable'),
  414. context: Em.I18n.t('admin.activateHawqStandby.button.enable'),
  415. cssClass: 'icon-arrow-up',
  416. isHidden: App.get('isSingleNode') || !HS,
  417. disabled: false,
  418. hideFromComponentView: true
  419. },
  420. HAWQ_CLEAR_CACHE: {
  421. action: 'executeHawqCustomCommand',
  422. customCommand: 'HAWQ_CLEAR_CACHE',
  423. context: Em.I18n.t('services.service.actions.run.clearHawqCache.label'),
  424. label: Em.I18n.t('services.service.actions.run.clearHawqCache.label'),
  425. cssClass: 'icon-refresh',
  426. isHidden : false,
  427. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started
  428. },
  429. RUN_HAWQ_CHECK: {
  430. action: 'executeHawqCustomCommand',
  431. customCommand: 'RUN_HAWQ_CHECK',
  432. context: Em.I18n.t('services.service.actions.run.runHawqCheck.label'),
  433. label: Em.I18n.t('services.service.actions.run.runHawqCheck.label'),
  434. cssClass: 'icon-thumbs-up-alt',
  435. isHidden : false,
  436. disabled: false
  437. },
  438. MASTER_CUSTOM_COMMAND: {
  439. action: 'executeCustomCommand',
  440. cssClass: 'icon-play-circle',
  441. isHidden: false,
  442. disabled: false
  443. }
  444. };
  445. }
  446. };