host_component.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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: function () {
  49. return (this.get('workStatus') == 'STARTED' || this.get('workStatus') == 'STARTING');
  50. }.property('workStatus'),
  51. /**
  52. * Formatted <code>componentName</code>
  53. * @returns {String}
  54. */
  55. displayName: function () {
  56. return App.format.role(this.get('componentName'));
  57. }.property('componentName'),
  58. /**
  59. * Determine if component is master
  60. * @returns {bool}
  61. */
  62. isMaster: function () {
  63. return App.get('components.masters').contains(this.get('componentName'));
  64. }.property('componentName', 'App.components.masters'),
  65. /**
  66. * Determine if component is slave
  67. * @returns {bool}
  68. */
  69. isSlave: function () {
  70. return App.get('components.slaves').contains(this.get('componentName'));
  71. }.property('componentName'),
  72. /**
  73. * Only certain components can be deleted.
  74. * They include some from master components,
  75. * some from slave components, and rest from
  76. * client components.
  77. * @returns {bool}
  78. */
  79. isDeletable: function () {
  80. return App.get('components.deletable').contains(this.get('componentName'));
  81. }.property('componentName'),
  82. /**
  83. * A host-component is decommissioning when it is in HDFS service's list of
  84. * decomNodes.
  85. * @returns {bool}
  86. */
  87. isDecommissioning: function () {
  88. var decommissioning = false;
  89. var hostName = this.get('hostName');
  90. var componentName = this.get('componentName');
  91. var hdfsSvc = App.HDFSService.find().objectAt(0);
  92. if (componentName === 'DATANODE' && hdfsSvc) {
  93. var decomNodes = hdfsSvc.get('decommissionDataNodes');
  94. var decomNode = decomNodes != null ? decomNodes.findProperty("hostName", hostName) : null;
  95. decommissioning = decomNode != null;
  96. }
  97. return decommissioning;
  98. }.property('componentName', 'hostName', 'App.router.clusterController.isLoaded', 'App.router.updateController.isUpdated'),
  99. /**
  100. * User friendly host component status
  101. * @returns {String}
  102. */
  103. isActive: function () {
  104. return (this.get('passiveState') == 'OFF');
  105. }.property('passiveState'),
  106. passiveTooltip: function () {
  107. if (!this.get('isActive')) {
  108. return Em.I18n.t('hosts.component.passive.mode');
  109. }
  110. }.property('isActive'),
  111. statusClass: function () {
  112. return this.get('isActive') ? this.get('workStatus') : 'icon-medkit';
  113. }.property('workStatus', 'isActive'),
  114. statusIconClass: function () {
  115. switch (this.get('statusClass')) {
  116. case 'STARTED':
  117. case 'STARTING':
  118. return App.healthIconClassGreen;
  119. break;
  120. case 'INSTALLED':
  121. case 'STOPPING':
  122. return App.healthIconClassRed;
  123. break;
  124. case 'UNKNOWN':
  125. return App.healthIconClassYellow;
  126. break;
  127. default:
  128. return "";
  129. break;
  130. }
  131. }.property('statusClass'),
  132. componentTextStatus: function () {
  133. return App.HostComponentStatus.getTextStatus(this.get("workStatus"));
  134. }.property('workStatus', 'isDecommissioning')
  135. });
  136. App.HostComponent.FIXTURES = [];
  137. /**
  138. * get particular counter of host-component by name
  139. * @param {string} componentName
  140. * @param {string} type (installedCount|startedCount|totalCount)
  141. * @returns {number}
  142. */
  143. App.HostComponent.getCount = function (componentName, type) {
  144. switch (App.StackServiceComponent.find(componentName).get('componentCategory')) {
  145. case 'MASTER':
  146. return Number(App.MasterComponent.find(componentName).get(type));
  147. case 'SLAVE':
  148. return Number(App.SlaveComponent.find(componentName).get(type));
  149. case 'CLIENT':
  150. return Number(App.ClientComponent.find(componentName).get(type));
  151. default:
  152. return 0;
  153. }
  154. };
  155. App.HostComponentStatus = {
  156. started: "STARTED",
  157. starting: "STARTING",
  158. stopped: "INSTALLED",
  159. stopping: "STOPPING",
  160. install_failed: "INSTALL_FAILED",
  161. installing: "INSTALLING",
  162. upgrade_failed: "UPGRADE_FAILED",
  163. unknown: "UNKNOWN",
  164. disabled: "DISABLED",
  165. init: "INIT",
  166. /**
  167. * Get host component status in "machine" format
  168. * @param {String} value
  169. * @returns {String}
  170. */
  171. getKeyName: function (value) {
  172. switch (value) {
  173. case this.started:
  174. return 'started';
  175. case this.starting:
  176. return 'starting';
  177. case this.stopped:
  178. return 'installed';
  179. case this.stopping:
  180. return 'stopping';
  181. case this.install_failed:
  182. return 'install_failed';
  183. case this.installing:
  184. return 'installing';
  185. case this.upgrade_failed:
  186. return 'upgrade_failed';
  187. case this.disabled:
  188. case this.unknown:
  189. return 'unknown';
  190. }
  191. return 'unknown';
  192. },
  193. /**
  194. * Get user-friendly host component status
  195. * @param {String} value
  196. * @returns {String}
  197. */
  198. getTextStatus: function (value) {
  199. switch (value) {
  200. case this.installing:
  201. return 'Installing...';
  202. case this.install_failed:
  203. return 'Install Failed';
  204. case this.stopped:
  205. return 'Stopped';
  206. case this.started:
  207. return 'Started';
  208. case this.starting:
  209. return 'Starting...';
  210. case this.stopping:
  211. return 'Stopping...';
  212. case this.unknown:
  213. return 'Heartbeat Lost';
  214. case this.upgrade_failed:
  215. return 'Upgrade Failed';
  216. case this.disabled:
  217. return 'Disabled';
  218. case this.init:
  219. return 'Install Pending...';
  220. }
  221. return 'Unknown';
  222. },
  223. /**
  224. * Get list of possible <code>App.HostComponent</code> statuses
  225. * @returns {String[]}
  226. */
  227. getStatusesList: function () {
  228. var ret = [];
  229. for (var st in this) {
  230. if (this.hasOwnProperty(st) && Em.typeOf(this[st]) == 'string') {
  231. ret.push(this[st]);
  232. }
  233. }
  234. return ret;
  235. }
  236. };
  237. App.HostComponentActionMap = {
  238. getMap: function(ctx) {
  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')
  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')
  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')
  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. MASTER_CUSTOM_COMMAND: {
  342. action: 'executeCustomCommand',
  343. cssClass: 'icon-play-circle',
  344. isHidden: false,
  345. disabled: false
  346. }
  347. }
  348. }
  349. };