item.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. var batchUtils = require('utils/batch_scheduled_requests');
  20. App.MainServiceItemView = Em.View.extend({
  21. templateName: require('templates/main/service/item'),
  22. serviceName: function() {
  23. return this.get('controller.content.serviceName');
  24. }.property('controller.content.serviceName'),
  25. displayName: function() {
  26. return this.get('controller.content.displayName');
  27. }.property('controller.content.displayName'),
  28. isPassive: function() {
  29. return this.get('controller.content.passiveState') === 'ON';
  30. }.property('controller.content.passiveState'),
  31. /**
  32. * Some custom commands need custom logic to be executed
  33. */
  34. mastersExcludedCommands: {
  35. 'NAMENODE': ['DECOMMISSION', 'REBALANCEHDFS'],
  36. 'RESOURCEMANAGER': ['DECOMMISSION', 'REFRESHQUEUES'],
  37. 'HBASE_MASTER': ['DECOMMISSION']
  38. },
  39. actionMap: function() {
  40. return {
  41. RESTART_ALL: {
  42. action: 'restartAllHostComponents',
  43. context: this.get('serviceName'),
  44. label: Em.I18n.t('restart.service.all'),
  45. cssClass: 'icon-repeat',
  46. disabled: false
  47. },
  48. RUN_SMOKE_TEST: {
  49. action: 'runSmokeTest',
  50. label: Em.I18n.t('services.service.actions.run.smoke'),
  51. cssClass: 'icon-thumbs-up-alt'
  52. },
  53. REFRESH_CONFIGS: {
  54. action: 'refreshConfigs',
  55. label: Em.I18n.t('hosts.host.details.refreshConfigs'),
  56. cssClass: 'icon-refresh',
  57. disabled: !this.get('controller.content.isRestartRequired')
  58. },
  59. REFRESH_YARN_QUEUE: {
  60. action: 'refreshYarnQueues',
  61. label: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.menu'),
  62. cssClass: 'icon-refresh',
  63. disabled: false
  64. },
  65. ROLLING_RESTART: {
  66. action: 'rollingRestart',
  67. context: this.get('rollingRestartComponent'),
  68. label: Em.I18n.t('rollingrestart.dialog.title'),
  69. cssClass: 'icon-time',
  70. disabled: false
  71. },
  72. TOGGLE_PASSIVE: {
  73. action: 'turnOnOffPassive',
  74. context: this.get('isPassive') ? Em.I18n.t('passiveState.turnOffFor').format(this.get('displayName')) : Em.I18n.t('passiveState.turnOnFor').format(this.get('displayName')),
  75. label: this.get('isPassive') ? Em.I18n.t('passiveState.turnOff') : Em.I18n.t('passiveState.turnOn'),
  76. cssClass: 'icon-medkit',
  77. disabled: false
  78. },
  79. TOGGLE_NN_HA: {
  80. action: App.get('isHaEnabled') ? 'disableHighAvailability' : 'enableHighAvailability',
  81. label: App.get('isHaEnabled') ? Em.I18n.t('admin.highAvailability.button.disable') : Em.I18n.t('admin.highAvailability.button.enable'),
  82. cssClass: App.get('isHaEnabled') ? 'icon-arrow-down' : 'icon-arrow-up',
  83. isHidden: (App.get('isHaEnabled') && !App.get('supports.autoRollbackHA'))
  84. },
  85. TOGGLE_RM_HA: {
  86. action: 'enableRMHighAvailability',
  87. label: Em.I18n.t('admin.rm_highAvailability.button.enable'),
  88. cssClass: 'icon-arrow-up',
  89. isHidden: !App.get('supports.resourceManagerHighAvailability') || App.get('isRMHaEnabled')
  90. },
  91. MOVE_COMPONENT: {
  92. action: 'reassignMaster',
  93. context: '',
  94. label: Em.I18n.t('services.service.actions.reassign.master'),
  95. cssClass: 'icon-share-alt',
  96. disabled: false
  97. },
  98. STARTDEMOLDAP: {
  99. action: 'startLdapKnox',
  100. label: Em.I18n.t('services.service.actions.run.startLdapKnox.context'),
  101. cssClass: 'icon-play-sign',
  102. disabled: false
  103. },
  104. STOPDEMOLDAP: {
  105. action: 'stopLdapKnox',
  106. label: Em.I18n.t('services.service.actions.run.stopLdapKnox.context'),
  107. cssClass: 'icon-stop',
  108. disabled: false
  109. },
  110. REBALANCE_HDFS: {
  111. action: 'rebalanceHdfsNodes',
  112. context: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  113. label: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes'),
  114. cssClass: 'icon-refresh',
  115. disabled: false
  116. },
  117. DOWNLOAD_CLIENT_CONFIGS: {
  118. action: this.get('controller.isSeveralClients') ? '' : 'downloadClientConfigs',
  119. label: Em.I18n.t('services.service.actions.downloadClientConfigs'),
  120. cssClass: 'icon-download-alt',
  121. isHidden: !(App.get('supports.downloadClientConfigs') && this.get('controller.content.hostComponents').findProperty('isClient')),
  122. disabled: false,
  123. hasSubmenu: this.get('controller.isSeveralClients'),
  124. submenuOptions: this.get('controller.clientComponents')
  125. },
  126. MASTER_CUSTOM_COMMAND: {
  127. action: 'executeCustomCommand',
  128. cssClass: 'icon-play-circle',
  129. isHidden: false,
  130. disabled: false
  131. }
  132. }
  133. },
  134. addActionMap: function() {
  135. return [
  136. {
  137. cssClass: 'icon-plus',
  138. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.hbase.masterServer')),
  139. service: 'HBASE',
  140. component: 'HBASE_MASTER'
  141. },
  142. {
  143. cssClass: 'icon-plus',
  144. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.zookeeper.server')),
  145. service: 'ZOOKEEPER',
  146. component: 'ZOOKEEPER_SERVER'
  147. },
  148. {
  149. cssClass: 'icon-plus',
  150. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.flume.agentLabel')),
  151. service: 'FLUME',
  152. component: 'FLUME_HANDLER'
  153. }
  154. ]
  155. },
  156. /**
  157. * Create option for MOVE_COMPONENT or ROLLING_RESTART task.
  158. *
  159. * @param {Object} option - one of the options that return by <code>actionMap()</code>
  160. * @param {Object} fields - option fields to add/rewrite
  161. * @return {Object}
  162. */
  163. createOption: function(option, fields) {
  164. return $.extend(true, {}, option, fields);
  165. },
  166. maintenance: function(){
  167. var self = this;
  168. var options = [];
  169. var service = this.get('controller.content');
  170. var allMasters = service.get('hostComponents').filterProperty('isMaster').mapProperty('componentName').uniq();
  171. var allSlaves = service.get('hostComponents').filterProperty('isSlave').mapProperty('componentName').uniq();
  172. var actionMap = this.actionMap();
  173. var serviceCheckSupported = App.get('services.supportsServiceCheck').contains(service.get('serviceName'));
  174. var hasConfigTab = this.get('hasConfigTab');
  175. var excludedCommands = this.get('mastersExcludedCommands');
  176. if (this.get('controller.isClientsOnlyService')) {
  177. if (serviceCheckSupported) {
  178. options.push(actionMap.RUN_SMOKE_TEST);
  179. }
  180. if (hasConfigTab) {
  181. options.push(actionMap.REFRESH_CONFIGS);
  182. }
  183. } else {
  184. if (this.get('serviceName') === 'FLUME') {
  185. options.push(actionMap.REFRESH_CONFIGS);
  186. }
  187. if (this.get('serviceName') === 'YARN') {
  188. options.push(actionMap.REFRESH_YARN_QUEUE);
  189. }
  190. options.push(actionMap.RESTART_ALL);
  191. allSlaves.filter(function (slave) {
  192. return App.get('components.rollinRestartAllowed').contains(slave);
  193. }).forEach(function(slave) {
  194. options.push(self.createOption(actionMap.ROLLING_RESTART, {
  195. context: slave,
  196. label: actionMap.ROLLING_RESTART.label.format(App.format.role(slave))
  197. }));
  198. });
  199. allMasters.filter(function(master) {
  200. return App.get('components.reassignable').contains(master);
  201. }).forEach(function(master) {
  202. options.push(self.createOption(actionMap.MOVE_COMPONENT, {
  203. context: master,
  204. label: actionMap.MOVE_COMPONENT.label.format(App.format.role(master))
  205. }));
  206. });
  207. if (service.get('serviceTypes').contains('HA_MODE')) {
  208. switch (service.get('serviceName')) {
  209. case 'HDFS':
  210. options.push(actionMap.TOGGLE_NN_HA);
  211. break;
  212. case 'YARN':
  213. options.push(actionMap.TOGGLE_RM_HA);
  214. break;
  215. }
  216. }
  217. if (serviceCheckSupported) {
  218. options.push(actionMap.RUN_SMOKE_TEST);
  219. }
  220. options.push(actionMap.TOGGLE_PASSIVE);
  221. var serviceName = service.get('serviceName');
  222. var nnComponent = App.StackServiceComponent.find().findProperty('componentName','NAMENODE');
  223. var knoxGatewayComponent = App.StackServiceComponent.find().findProperty('componentName','KNOX_GATEWAY');
  224. if (serviceName === 'HDFS' && nnComponent) {
  225. var namenodeCustomCommands = nnComponent.get('customCommands');
  226. if (namenodeCustomCommands && namenodeCustomCommands.contains('REBALANCEHDFS'))
  227. options.push(actionMap.REBALANCE_HDFS);
  228. }
  229. if (serviceName === 'KNOX' && knoxGatewayComponent) {
  230. var knoxGatewayCustomCommands = knoxGatewayComponent.get('customCommands');
  231. knoxGatewayCustomCommands.forEach(function(command) {
  232. if (actionMap[command]) {
  233. options.push(actionMap[command]);
  234. }
  235. });
  236. }
  237. self.addActionMap().filterProperty('service', serviceName).forEach(function(item) {
  238. item.action = 'add' + item.component;
  239. item.disabled = self.get('controller.isAddDisabled-' + item.component);
  240. item.tooltip = self.get('controller.addDisabledTooltip' + item.component);
  241. options.push(item);
  242. });
  243. allMasters.forEach(function(master) {
  244. var component = App.StackServiceComponent.find(master);
  245. var commands = component.get('customCommands');
  246. if (!commands.length) {
  247. return false;
  248. }
  249. commands.forEach(function(command) {
  250. if (excludedCommands[master] && excludedCommands[master].contains(command)){
  251. return false;
  252. }
  253. options.push(self.createOption(actionMap.MASTER_CUSTOM_COMMAND, {
  254. label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(command),
  255. context: {
  256. label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(command),
  257. service: component.get('serviceName'),
  258. component: component.get('componentName'),
  259. command: command
  260. }
  261. }));
  262. });
  263. });
  264. }
  265. if (hasConfigTab) {
  266. options.push(actionMap.DOWNLOAD_CLIENT_CONFIGS);
  267. }
  268. return options;
  269. }.property('controller.content', 'controller.isStopDisabled','controller.isClientsOnlyService', 'controller.content.isRestartRequired', 'isPassive'),
  270. isMaintenanceActive: function() {
  271. return this.get('maintenance').length !== 0;
  272. }.property('maintenance'),
  273. hasConfigTab: function() {
  274. return !App.get('services.noConfigTypes').contains(this.get('controller.content.serviceName'));
  275. }.property('controller.content.serviceName','App.services.noConfigTypes'),
  276. didInsertElement: function () {
  277. this.get('controller').setStartStopState();
  278. },
  279. service:function () {
  280. var svc = this.get('controller.content');
  281. var svcName = svc.get('serviceName');
  282. if (svcName) {
  283. switch (svcName.toLowerCase()) {
  284. case 'hdfs':
  285. svc = App.HDFSService.find().objectAt(0);
  286. break;
  287. case 'yarn':
  288. svc = App.YARNService.find().objectAt(0);
  289. break;
  290. case 'mapreduce':
  291. svc = App.MapReduceService.find().objectAt(0);
  292. break;
  293. case 'hbase':
  294. svc = App.HBaseService.find().objectAt(0);
  295. break;
  296. case 'flume':
  297. svc = App.FlumeService.find().objectAt(0);
  298. break;
  299. default:
  300. break;
  301. }
  302. }
  303. return svc;
  304. }.property('controller.content.serviceName').volatile()
  305. });