host_component.js 17 KB

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