host_component.js 17 KB

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