host_component.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. return {
  254. RESTART_ALL: {
  255. action: 'restartAllHostComponents',
  256. context: ctx.get('serviceName'),
  257. label: Em.I18n.t('restart.service.all'),
  258. cssClass: 'icon-repeat',
  259. disabled: false
  260. },
  261. RUN_SMOKE_TEST: {
  262. action: 'runSmokeTest',
  263. label: Em.I18n.t('services.service.actions.run.smoke'),
  264. cssClass: 'icon-thumbs-up-alt',
  265. disabled: ctx.get('controller.isClientsOnlyService') ? false : ctx.get('controller.isStopDisabled')
  266. },
  267. REFRESH_CONFIGS: {
  268. action: 'refreshConfigs',
  269. label: Em.I18n.t('hosts.host.details.refreshConfigs'),
  270. cssClass: 'icon-refresh',
  271. disabled: false
  272. },
  273. REFRESHQUEUES: {
  274. action: 'refreshYarnQueues',
  275. customCommand: 'REFRESHQUEUES',
  276. context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context'),
  277. label: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.menu'),
  278. cssClass: 'icon-refresh',
  279. disabled: false
  280. },
  281. ROLLING_RESTART: {
  282. action: 'rollingRestart',
  283. context: ctx.get('rollingRestartComponent'),
  284. label: Em.I18n.t('rollingrestart.dialog.title'),
  285. cssClass: 'icon-time',
  286. disabled: false
  287. },
  288. TOGGLE_PASSIVE: {
  289. action: 'turnOnOffPassive',
  290. context: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOffFor').format(ctx.get('displayName')) : Em.I18n.t('passiveState.turnOnFor').format(ctx.get('displayName')),
  291. label: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOff') : Em.I18n.t('passiveState.turnOn'),
  292. cssClass: 'icon-medkit',
  293. disabled: false
  294. },
  295. TOGGLE_NN_HA: {
  296. action: App.get('isHaEnabled') ? 'disableHighAvailability' : 'enableHighAvailability',
  297. label: App.get('isHaEnabled') ? Em.I18n.t('admin.highAvailability.button.disable') : Em.I18n.t('admin.highAvailability.button.enable'),
  298. cssClass: App.get('isHaEnabled') ? 'icon-arrow-down' : 'icon-arrow-up',
  299. isHidden: App.get('isHaEnabled'),
  300. disabled: App.get('isSingleNode') || !NN || NN.get('isNotInstalled')
  301. },
  302. TOGGLE_RM_HA: {
  303. action: 'enableRMHighAvailability',
  304. label: Em.I18n.t('admin.rm_highAvailability.button.enable'),
  305. cssClass: 'icon-arrow-up',
  306. isHidden: App.get('isRMHaEnabled'),
  307. disabled: App.get('isSingleNode') || !RM || RM.get('isNotInstalled')
  308. },
  309. TOGGLE_RA_HA: {
  310. action: 'enableRAHighAvailability',
  311. label: Em.I18n.t('admin.ra_highAvailability.button.enable'),
  312. cssClass: 'icon-arrow-up',
  313. isHidden: App.get('isRAHaEnabled'),
  314. disabled: App.get('isSingleNode') || !RA || RA.get('isNotInstalled')
  315. },
  316. MOVE_COMPONENT: {
  317. action: 'reassignMaster',
  318. context: '',
  319. isHidden: !App.isAuthorized('SERVICE.MOVE'),
  320. label: Em.I18n.t('services.service.actions.reassign.master'),
  321. cssClass: 'icon-share-alt'
  322. },
  323. STARTDEMOLDAP: {
  324. action: 'startLdapKnox',
  325. customCommand: 'STARTDEMOLDAP',
  326. context: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  327. label: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  328. cssClass: 'icon-play-sign',
  329. disabled: false
  330. },
  331. STOPDEMOLDAP: {
  332. action: 'stopLdapKnox',
  333. customCommand: 'STOPDEMOLDAP',
  334. context: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  335. label: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  336. cssClass: 'icon-stop',
  337. disabled: false
  338. },
  339. REBALANCEHDFS: {
  340. action: 'rebalanceHdfsNodes',
  341. customCommand: 'REBALANCEHDFS',
  342. context: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  343. label: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes'),
  344. cssClass: 'icon-refresh',
  345. disabled: false
  346. },
  347. DOWNLOAD_CLIENT_CONFIGS: {
  348. action: ctx.get('controller.isSeveralClients') ? '' : 'downloadClientConfigs',
  349. label: Em.I18n.t('services.service.actions.downloadClientConfigs'),
  350. cssClass: 'icon-download-alt',
  351. isHidden: !!ctx.get('controller.content.clientComponents') ? ctx.get('controller.content.clientComponents').rejectProperty('totalCount', 0).length == 0 : false,
  352. disabled: false,
  353. hasSubmenu: ctx.get('controller.isSeveralClients'),
  354. submenuOptions: ctx.get('controller.clientComponents')
  355. },
  356. DELETE_SERVICE: {
  357. action: 'deleteService',
  358. context: ctx.get('serviceName'),
  359. label: Em.I18n.t('common.delete'),
  360. cssClass: 'icon-remove'
  361. },
  362. IMMEDIATE_STOP_HAWQ_SERVICE: {
  363. action: 'executeHawqCustomCommand',
  364. customCommand: 'IMMEDIATE_STOP_HAWQ_SERVICE',
  365. context: Em.I18n.t('services.service.actions.run.immediateStopHawqService.context'),
  366. label: Em.I18n.t('services.service.actions.run.immediateStopHawqService.label'),
  367. cssClass: 'icon-stop',
  368. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started
  369. },
  370. IMMEDIATE_STOP_HAWQ_SEGMENT: {
  371. customCommand: 'IMMEDIATE_STOP_HAWQ_SEGMENT',
  372. context: Em.I18n.t('services.service.actions.run.immediateStopHawqSegment.context'),
  373. label: Em.I18n.t('services.service.actions.run.immediateStopHawqSegment.label'),
  374. cssClass: 'icon-stop'
  375. },
  376. RESYNC_HAWQ_STANDBY: {
  377. action: 'executeHawqCustomCommand',
  378. customCommand: 'RESYNC_HAWQ_STANDBY',
  379. context: Em.I18n.t('services.service.actions.run.resyncHawqStandby.context'),
  380. label: Em.I18n.t('services.service.actions.run.resyncHawqStandby.label'),
  381. cssClass: 'icon-refresh',
  382. isHidden : App.get('isSingleNode') || !HS ,
  383. disabled: !((!!HMComponent && HMComponent.get('startedCount') === 1) && (!!HS && HS.get('workStatus') === App.HostComponentStatus.started))
  384. },
  385. TOGGLE_ADD_HAWQ_STANDBY: {
  386. action: 'addHawqStandby',
  387. label: Em.I18n.t('admin.addHawqStandby.button.enable'),
  388. cssClass: 'icon-plus',
  389. isHidden: App.get('isSingleNode') || HS,
  390. disabled: false
  391. },
  392. REMOVE_HAWQ_STANDBY: {
  393. action: 'removeHawqStandby',
  394. context: Em.I18n.t('admin.removeHawqStandby.button.enable'),
  395. label: Em.I18n.t('admin.removeHawqStandby.button.enable'),
  396. cssClass: 'icon-minus',
  397. isHidden: App.get('isSingleNode') || !HS,
  398. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started,
  399. hideFromComponentView: true
  400. },
  401. ACTIVATE_HAWQ_STANDBY: {
  402. action: 'activateHawqStandby',
  403. label: Em.I18n.t('admin.activateHawqStandby.button.enable'),
  404. context: Em.I18n.t('admin.activateHawqStandby.button.enable'),
  405. cssClass: 'icon-arrow-up',
  406. isHidden: App.get('isSingleNode') || !HS,
  407. disabled: false
  408. },
  409. HAWQ_CLEAR_CACHE: {
  410. action: 'executeHawqCustomCommand',
  411. customCommand: 'HAWQ_CLEAR_CACHE',
  412. context: Em.I18n.t('services.service.actions.run.clearHawqCache.label'),
  413. label: Em.I18n.t('services.service.actions.run.clearHawqCache.label'),
  414. cssClass: 'icon-refresh',
  415. isHidden : false,
  416. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started
  417. },
  418. RUN_HAWQ_CHECK: {
  419. action: 'executeHawqCustomCommand',
  420. customCommand: 'RUN_HAWQ_CHECK',
  421. context: Em.I18n.t('services.service.actions.run.runHawqCheck.label'),
  422. label: Em.I18n.t('services.service.actions.run.runHawqCheck.label'),
  423. cssClass: 'icon-thumbs-up-alt',
  424. isHidden : false,
  425. disabled: false
  426. },
  427. MASTER_CUSTOM_COMMAND: {
  428. action: 'executeCustomCommand',
  429. cssClass: 'icon-play-circle',
  430. isHidden: false,
  431. disabled: false
  432. }
  433. };
  434. }
  435. };