host_component.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. passiveTooltip: Em.computed.ifThenElse('isActive', '', Em.I18n.t('hosts.component.passive.mode')),
  108. statusClass: function () {
  109. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  110. }.property('workStatus', 'isActive'),
  111. statusIconClass: function () {
  112. switch (this.get('statusClass')) {
  113. case 'STARTED':
  114. case 'STARTING':
  115. return App.healthIconClassGreen;
  116. break;
  117. case 'INSTALLED':
  118. case 'STOPPING':
  119. return App.healthIconClassRed;
  120. break;
  121. case 'UNKNOWN':
  122. return App.healthIconClassYellow;
  123. break;
  124. default:
  125. return "";
  126. break;
  127. }
  128. }.property('statusClass'),
  129. componentTextStatus: function () {
  130. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  131. }.property('workStatus', 'isDecommissioning')
  132. });
  133. App.HostComponent.FIXTURES = [];
  134. /**
  135. * get particular counter of host-component by name
  136. * @param {string} componentName
  137. * @param {string} type (installedCount|startedCount|totalCount)
  138. * @returns {number}
  139. */
  140. App.HostComponent.getCount = function (componentName, type) {
  141. switch (App.StackServiceComponent.find(componentName).get('componentCategory')) {
  142. case 'MASTER':
  143. return Number(App.MasterComponent.find(componentName).get(type));
  144. case 'SLAVE':
  145. return Number(App.SlaveComponent.find(componentName).get(type));
  146. case 'CLIENT':
  147. return Number(App.ClientComponent.find(componentName).get(type));
  148. default:
  149. return 0;
  150. }
  151. };
  152. App.HostComponentStatus = {
  153. started: "STARTED",
  154. starting: "STARTING",
  155. stopped: "INSTALLED",
  156. stopping: "STOPPING",
  157. install_failed: "INSTALL_FAILED",
  158. installing: "INSTALLING",
  159. upgrade_failed: "UPGRADE_FAILED",
  160. unknown: "UNKNOWN",
  161. disabled: "DISABLED",
  162. init: "INIT",
  163. /**
  164. * Get host component status in "machine" format
  165. * @param {String} value
  166. * @returns {String}
  167. */
  168. getKeyName: function (value) {
  169. switch (value) {
  170. case this.started:
  171. return 'started';
  172. case this.starting:
  173. return 'starting';
  174. case this.stopped:
  175. return 'installed';
  176. case this.stopping:
  177. return 'stopping';
  178. case this.install_failed:
  179. return 'install_failed';
  180. case this.installing:
  181. return 'installing';
  182. case this.upgrade_failed:
  183. return 'upgrade_failed';
  184. case this.disabled:
  185. case this.unknown:
  186. return 'unknown';
  187. }
  188. return 'unknown';
  189. },
  190. /**
  191. * Get user-friendly host component status
  192. * @param {String} value
  193. * @returns {String}
  194. */
  195. getTextStatus: function (value) {
  196. switch (value) {
  197. case this.installing:
  198. return 'Installing...';
  199. case this.install_failed:
  200. return 'Install Failed';
  201. case this.stopped:
  202. return 'Stopped';
  203. case this.started:
  204. return 'Started';
  205. case this.starting:
  206. return 'Starting...';
  207. case this.stopping:
  208. return 'Stopping...';
  209. case this.unknown:
  210. return 'Heartbeat Lost';
  211. case this.upgrade_failed:
  212. return 'Upgrade Failed';
  213. case this.disabled:
  214. return 'Disabled';
  215. case this.init:
  216. return 'Install Pending...';
  217. }
  218. return 'Unknown';
  219. },
  220. /**
  221. * Get list of possible <code>App.HostComponent</code> statuses
  222. * @returns {String[]}
  223. */
  224. getStatusesList: function () {
  225. var ret = [];
  226. for (var st in this) {
  227. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  228. ret.push(this[st]);
  229. }
  230. }
  231. return ret;
  232. }
  233. };
  234. App.HostComponentActionMap = {
  235. getMap: function(ctx) {
  236. var NN = ctx.get('controller.content.hostComponents').findProperty('componentName', 'NAMENODE');
  237. var RM = ctx.get('controller.content.hostComponents').findProperty('componentName', 'RESOURCEMANAGER');
  238. var RA = ctx.get('controller.content.hostComponents').findProperty('componentName', 'RANGER_ADMIN');
  239. return {
  240. RESTART_ALL: {
  241. action: 'restartAllHostComponents',
  242. context: ctx.get('serviceName'),
  243. label: Em.I18n.t('restart.service.all'),
  244. cssClass: 'icon-repeat',
  245. disabled: false
  246. },
  247. RUN_SMOKE_TEST: {
  248. action: 'runSmokeTest',
  249. label: Em.I18n.t('services.service.actions.run.smoke'),
  250. cssClass: 'icon-thumbs-up-alt',
  251. disabled: ctx.get('controller.isClientsOnlyService') ? false : ctx.get('controller.isStopDisabled')
  252. },
  253. REFRESH_CONFIGS: {
  254. action: 'refreshConfigs',
  255. label: Em.I18n.t('hosts.host.details.refreshConfigs'),
  256. cssClass: 'icon-refresh',
  257. disabled: false
  258. },
  259. REFRESHQUEUES: {
  260. action: 'refreshYarnQueues',
  261. customCommand: 'REFRESHQUEUES',
  262. context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context'),
  263. label: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.menu'),
  264. cssClass: 'icon-refresh',
  265. disabled: false
  266. },
  267. ROLLING_RESTART: {
  268. action: 'rollingRestart',
  269. context: ctx.get('rollingRestartComponent'),
  270. label: Em.I18n.t('rollingrestart.dialog.title'),
  271. cssClass: 'icon-time',
  272. disabled: false
  273. },
  274. TOGGLE_PASSIVE: {
  275. action: 'turnOnOffPassive',
  276. context: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOffFor').format(ctx.get('displayName')) : Em.I18n.t('passiveState.turnOnFor').format(ctx.get('displayName')),
  277. label: ctx.get('isPassive') ? Em.I18n.t('passiveState.turnOff') : Em.I18n.t('passiveState.turnOn'),
  278. cssClass: 'icon-medkit',
  279. disabled: false
  280. },
  281. TOGGLE_NN_HA: {
  282. action: App.get('isHaEnabled') ? 'disableHighAvailability' : 'enableHighAvailability',
  283. label: App.get('isHaEnabled') ? Em.I18n.t('admin.highAvailability.button.disable') : Em.I18n.t('admin.highAvailability.button.enable'),
  284. cssClass: App.get('isHaEnabled') ? 'icon-arrow-down' : 'icon-arrow-up',
  285. isHidden: App.get('isHaEnabled'),
  286. disabled: App.get('isSingleNode') || !NN || NN.get('isNotInstalled')
  287. },
  288. TOGGLE_RM_HA: {
  289. action: 'enableRMHighAvailability',
  290. label: Em.I18n.t('admin.rm_highAvailability.button.enable'),
  291. cssClass: 'icon-arrow-up',
  292. isHidden: App.get('isRMHaEnabled'),
  293. disabled: App.get('isSingleNode') || !RM || RM.get('isNotInstalled')
  294. },
  295. TOGGLE_RA_HA: {
  296. action: 'enableRAHighAvailability',
  297. label: Em.I18n.t('admin.ra_highAvailability.button.enable'),
  298. cssClass: 'icon-arrow-up',
  299. isHidden: App.get('isRAHaEnabled'),
  300. disabled: App.get('isSingleNode') || !RA || RA.get('isNotInstalled')
  301. },
  302. MOVE_COMPONENT: {
  303. action: 'reassignMaster',
  304. context: '',
  305. label: Em.I18n.t('services.service.actions.reassign.master'),
  306. cssClass: 'icon-share-alt'
  307. },
  308. STARTDEMOLDAP: {
  309. action: 'startLdapKnox',
  310. customCommand: 'STARTDEMOLDAP',
  311. context: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  312. label: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  313. cssClass: 'icon-play-sign',
  314. disabled: false
  315. },
  316. STOPDEMOLDAP: {
  317. action: 'stopLdapKnox',
  318. customCommand: 'STOPDEMOLDAP',
  319. context: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  320. label: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  321. cssClass: 'icon-stop',
  322. disabled: false
  323. },
  324. REBALANCEHDFS: {
  325. action: 'rebalanceHdfsNodes',
  326. customCommand: 'REBALANCEHDFS',
  327. context: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  328. label: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes'),
  329. cssClass: 'icon-refresh',
  330. disabled: false
  331. },
  332. DOWNLOAD_CLIENT_CONFIGS: {
  333. action: ctx.get('controller.isSeveralClients') ? '' : 'downloadClientConfigs',
  334. label: Em.I18n.t('services.service.actions.downloadClientConfigs'),
  335. cssClass: 'icon-download-alt',
  336. isHidden: !!ctx.get('controller.content.clientComponents') ? ctx.get('controller.content.clientComponents').rejectProperty('totalCount', 0).length == 0 : false,
  337. disabled: false,
  338. hasSubmenu: ctx.get('controller.isSeveralClients'),
  339. submenuOptions: ctx.get('controller.clientComponents')
  340. },
  341. IMMEDIATE_STOP_CLUSTER: {
  342. action: 'immediateStopHawqCluster',
  343. customCommand: 'IMMEDIATE_STOP_CLUSTER',
  344. context: Em.I18n.t('services.service.actions.run.immediateStopHawqCluster.context'),
  345. label: Em.I18n.t('services.service.actions.run.immediateStopHawqCluster.context'),
  346. cssClass: 'icon-stop',
  347. disabled: false,
  348. },
  349. MASTER_CUSTOM_COMMAND: {
  350. action: 'executeCustomCommand',
  351. cssClass: 'icon-play-circle',
  352. isHidden: false,
  353. disabled: false
  354. }
  355. };
  356. }
  357. };