host_component.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. haStatus: DS.attr('string'),
  24. displayNameAdvanced: DS.attr('string'),
  25. staleConfigs: DS.attr('boolean'),
  26. host: DS.belongsTo('App.Host'),
  27. hostName: DS.attr('string'),
  28. service: DS.belongsTo('App.Service'),
  29. adminState: DS.attr('string'),
  30. summaryLabelClassName:function(){
  31. return 'label_for_'+this.get('componentName').toLowerCase();
  32. }.property('componentName'),
  33. summaryValueClassName:function(){
  34. return 'value_for_'+this.get('componentName').toLowerCase();
  35. }.property('componentName'),
  36. /**
  37. * Determine if component is client
  38. * @returns {bool}
  39. */
  40. isClient: function () {
  41. return App.get('components.clients').contains(this.get('componentName'));
  42. }.property('componentName'),
  43. /**
  44. * Determine if component is running now
  45. * Based on <code>workStatus</code>
  46. * @returns {bool}
  47. */
  48. isRunning: Em.computed.existsIn('workStatus', ['STARTED', 'STARTING']),
  49. /**
  50. * Determines if component is not installed
  51. * Based on <code>workStatus</code>
  52. *
  53. * @type {boolean}
  54. */
  55. isNotInstalled: Em.computed.existsIn('workStatus', ['INIT', 'INSTALL_FAILED']),
  56. /**
  57. * Formatted <code>componentName</code>
  58. * @returns {String}
  59. */
  60. displayName: Em.computed.formatRole('componentName'),
  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. statusClass: function () {
  121. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  122. }.property('workStatus', 'isActive'),
  123. statusIconClass: function () {
  124. switch (this.get('statusClass')) {
  125. case 'STARTED':
  126. case 'STARTING':
  127. return App.healthIconClassGreen;
  128. break;
  129. case 'INSTALLED':
  130. case 'STOPPING':
  131. return App.healthIconClassRed;
  132. break;
  133. case 'UNKNOWN':
  134. return App.healthIconClassYellow;
  135. break;
  136. default:
  137. return "";
  138. break;
  139. }
  140. }.property('statusClass'),
  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. 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. REBALANCEHDFS: {
  341. action: 'rebalanceHdfsNodes',
  342. customCommand: 'REBALANCEHDFS',
  343. context: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  344. label: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes'),
  345. cssClass: 'icon-refresh',
  346. disabled: false
  347. },
  348. DOWNLOAD_CLIENT_CONFIGS: {
  349. action: ctx.get('controller.isSeveralClients') ? '' : 'downloadClientConfigs',
  350. label: Em.I18n.t('services.service.actions.downloadClientConfigs'),
  351. cssClass: 'icon-download-alt',
  352. isHidden: !!ctx.get('controller.content.clientComponents') ? ctx.get('controller.content.clientComponents').rejectProperty('totalCount', 0).length == 0 : false,
  353. disabled: false,
  354. hasSubmenu: ctx.get('controller.isSeveralClients'),
  355. submenuOptions: ctx.get('controller.clientComponents')
  356. },
  357. DELETE_SERVICE: {
  358. action: 'deleteService',
  359. context: ctx.get('serviceName'),
  360. label: Em.I18n.t('common.delete'),
  361. cssClass: 'icon-remove'
  362. },
  363. IMMEDIATE_STOP_HAWQ_SERVICE: {
  364. action: 'executeHawqCustomCommand',
  365. customCommand: 'IMMEDIATE_STOP_HAWQ_SERVICE',
  366. context: Em.I18n.t('services.service.actions.run.immediateStopHawqService.context'),
  367. label: Em.I18n.t('services.service.actions.run.immediateStopHawqService.label'),
  368. cssClass: 'icon-stop',
  369. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started
  370. },
  371. IMMEDIATE_STOP_HAWQ_SEGMENT: {
  372. customCommand: 'IMMEDIATE_STOP_HAWQ_SEGMENT',
  373. context: Em.I18n.t('services.service.actions.run.immediateStopHawqSegment.context'),
  374. label: Em.I18n.t('services.service.actions.run.immediateStopHawqSegment.label'),
  375. cssClass: 'icon-stop'
  376. },
  377. RESYNC_HAWQ_STANDBY: {
  378. action: 'executeHawqCustomCommand',
  379. customCommand: 'RESYNC_HAWQ_STANDBY',
  380. context: Em.I18n.t('services.service.actions.run.resyncHawqStandby.context'),
  381. label: Em.I18n.t('services.service.actions.run.resyncHawqStandby.label'),
  382. cssClass: 'icon-refresh',
  383. isHidden : App.get('isSingleNode') || !HS ,
  384. disabled: !((!!HMComponent && HMComponent.get('startedCount') === 1) && (!!HS && HS.get('workStatus') === App.HostComponentStatus.started))
  385. },
  386. TOGGLE_ADD_HAWQ_STANDBY: {
  387. action: 'addHawqStandby',
  388. label: Em.I18n.t('admin.addHawqStandby.button.enable'),
  389. cssClass: 'icon-plus',
  390. isHidden: App.get('isSingleNode') || HS,
  391. disabled: false
  392. },
  393. ACTIVATE_HAWQ_STANDBY: {
  394. action: 'activateHawqStandby',
  395. label: Em.I18n.t('admin.activateHawqStandby.button.enable'),
  396. context: Em.I18n.t('admin.activateHawqStandby.button.enable'),
  397. cssClass: 'icon-arrow-up',
  398. isHidden: App.get('isSingleNode') || !HS,
  399. disabled: false
  400. },
  401. HAWQ_CLEAR_CACHE: {
  402. action: 'executeHawqCustomCommand',
  403. customCommand: 'HAWQ_CLEAR_CACHE',
  404. context: Em.I18n.t('services.service.actions.run.clearHawqCache.label'),
  405. label: Em.I18n.t('services.service.actions.run.clearHawqCache.label'),
  406. cssClass: 'icon-refresh',
  407. isHidden : false,
  408. disabled: !HM || HM.get('workStatus') != App.HostComponentStatus.started
  409. },
  410. RUN_HAWQ_CHECK: {
  411. action: 'executeHawqCustomCommand',
  412. customCommand: 'RUN_HAWQ_CHECK',
  413. context: Em.I18n.t('services.service.actions.run.runHawqCheck.label'),
  414. label: Em.I18n.t('services.service.actions.run.runHawqCheck.label'),
  415. cssClass: 'icon-thumbs-up-alt',
  416. isHidden : false,
  417. disabled: false
  418. },
  419. MASTER_CUSTOM_COMMAND: {
  420. action: 'executeCustomCommand',
  421. cssClass: 'icon-play-circle',
  422. isHidden: false,
  423. disabled: false
  424. }
  425. };
  426. }
  427. };