host_component.js 17 KB

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