item.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.MainServiceItemView = Em.View.extend({
  20. templateName: require('templates/main/service/item'),
  21. serviceName: Em.computed.alias('controller.content.serviceName'),
  22. displayName: Em.computed.alias('controller.content.displayName'),
  23. isPassive: Em.computed.equal('controller.content.passiveState', 'ON'),
  24. /**
  25. * Some custom commands need custom logic to be executed
  26. */
  27. mastersExcludedCommands: {
  28. 'NAMENODE': ['DECOMMISSION', 'REBALANCEHDFS'],
  29. 'RESOURCEMANAGER': ['DECOMMISSION', 'REFRESHQUEUES'],
  30. 'HBASE_MASTER': ['DECOMMISSION'],
  31. 'KNOX_GATEWAY': ['STARTDEMOLDAP','STOPDEMOLDAP'],
  32. 'HAWQMASTER': ['IMMEDIATE_STOP_CLUSTER']
  33. },
  34. addActionMap: function() {
  35. return [
  36. {
  37. cssClass: 'icon-plus',
  38. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.hbase.masterServer')),
  39. service: 'HBASE',
  40. component: 'HBASE_MASTER'
  41. },
  42. {
  43. cssClass: 'icon-plus',
  44. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.hive.metastore')),
  45. service: 'HIVE',
  46. component: 'HIVE_METASTORE',
  47. isHidden: !App.get('isHadoop22Stack')
  48. },
  49. {
  50. cssClass: 'icon-plus',
  51. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.hive.server2')),
  52. service: 'HIVE',
  53. component: 'HIVE_SERVER',
  54. isHidden: !App.get('isHadoop22Stack')
  55. },
  56. {
  57. cssClass: 'icon-plus',
  58. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.zookeeper.server')),
  59. service: 'ZOOKEEPER',
  60. component: 'ZOOKEEPER_SERVER'
  61. },
  62. {
  63. cssClass: 'icon-plus',
  64. 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.flume.agentLabel')),
  65. service: 'FLUME',
  66. component: 'FLUME_HANDLER'
  67. },
  68. {
  69. cssClass: 'icon-plus',
  70. 'label': '{0} {1}'.format(Em.I18n.t('add'), App.format.role('RANGER_KMS_SERVER')),
  71. service: 'RANGER_KMS',
  72. component: 'RANGER_KMS_SERVER'
  73. },
  74. {
  75. cssClass: 'icon-plus',
  76. 'label': '{0} {1}'.format(Em.I18n.t('add'), App.format.role('NIMBUS')),
  77. service: 'STORM',
  78. component: 'NIMBUS'
  79. }
  80. ]
  81. },
  82. /**
  83. * Create option for MOVE_COMPONENT or ROLLING_RESTART task.
  84. *
  85. * @param {Object} option - one of the options that return by <code>App.HostComponentActionMap.getMap()</code>
  86. * @param {Object} fields - option fields to add/rewrite
  87. * @return {Object}
  88. */
  89. createOption: function(option, fields) {
  90. return $.extend(true, {}, option, fields);
  91. },
  92. maintenance: [],
  93. isMaintenanceSet: false,
  94. observeMaintenance: function() {
  95. if (!this.get('isMaintenanceSet') && this.get('controller.isServicesInfoLoaded')) {
  96. this.observeMaintenanceOnce();
  97. }
  98. Em.run.once(this, 'clearIsMaintenanceSet');
  99. },
  100. observeMaintenanceOnce: function() {
  101. var self = this;
  102. var options = [];
  103. var service = this.get('controller.content');
  104. var allMasters = service.get('hostComponents').filterProperty('isMaster').mapProperty('componentName').uniq();
  105. var allSlaves = service.get('slaveComponents').rejectProperty('totalCount', 0).mapProperty('componentName');
  106. var actionMap = App.HostComponentActionMap.getMap(this);
  107. var serviceCheckSupported = App.get('services.supportsServiceCheck').contains(service.get('serviceName'));
  108. var hasConfigTab = this.get('hasConfigTab');
  109. var excludedCommands = this.get('mastersExcludedCommands');
  110. if (this.get('controller.isClientsOnlyService')) {
  111. if (serviceCheckSupported) {
  112. options.push(actionMap.RUN_SMOKE_TEST);
  113. }
  114. if (hasConfigTab) {
  115. options.push(actionMap.REFRESH_CONFIGS);
  116. }
  117. } else {
  118. if (this.get('serviceName') === 'FLUME') {
  119. options.push(actionMap.REFRESH_CONFIGS);
  120. }
  121. if (this.get('serviceName') === 'YARN') {
  122. options.push(actionMap.REFRESHQUEUES);
  123. }
  124. options.push(actionMap.RESTART_ALL);
  125. allSlaves.concat(allMasters).filter(function (_component) {
  126. return App.get('components.rollinRestartAllowed').contains(_component);
  127. }).forEach(function(_component) {
  128. options.push(self.createOption(actionMap.ROLLING_RESTART, {
  129. context: _component,
  130. label: actionMap.ROLLING_RESTART.label.format(App.format.role(_component))
  131. }));
  132. });
  133. allMasters.filter(function(master) {
  134. return App.get('components.reassignable').contains(master);
  135. }).forEach(function(master) {
  136. options.push(self.createOption(actionMap.MOVE_COMPONENT, {
  137. context: master,
  138. label: actionMap.MOVE_COMPONENT.label.format(App.format.role(master)),
  139. disabled: App.allHostNames.length === App.HostComponent.find().filterProperty('componentName', master).mapProperty('hostName').length
  140. }));
  141. });
  142. if (service.get('serviceTypes').contains('HA_MODE') && App.isAuthorized('SERVICE.ENABLE_HA')) {
  143. switch (service.get('serviceName')) {
  144. case 'HDFS':
  145. options.push(actionMap.TOGGLE_NN_HA);
  146. break;
  147. case 'YARN':
  148. options.push(actionMap.TOGGLE_RM_HA);
  149. break;
  150. case 'RANGER':
  151. options.push(actionMap.TOGGLE_RA_HA);
  152. break;
  153. }
  154. }
  155. if (serviceCheckSupported) {
  156. options.push(actionMap.RUN_SMOKE_TEST);
  157. }
  158. options.push(actionMap.TOGGLE_PASSIVE);
  159. var serviceName = service.get('serviceName');
  160. var nnComponent = App.StackServiceComponent.find().findProperty('componentName','NAMENODE');
  161. var knoxGatewayComponent = App.StackServiceComponent.find().findProperty('componentName','KNOX_GATEWAY');
  162. if (serviceName === 'HDFS' && nnComponent) {
  163. var namenodeCustomCommands = nnComponent.get('customCommands');
  164. if (namenodeCustomCommands && namenodeCustomCommands.contains('REBALANCEHDFS'))
  165. options.push(actionMap.REBALANCEHDFS);
  166. }
  167. if (serviceName === 'KNOX' && knoxGatewayComponent) {
  168. var knoxGatewayCustomCommands = knoxGatewayComponent.get('customCommands');
  169. knoxGatewayCustomCommands.forEach(function(command) {
  170. if (actionMap[command]) {
  171. options.push(actionMap[command]);
  172. }
  173. });
  174. }
  175. var hawqMasterComponent = App.StackServiceComponent.find().findProperty('componentName','HAWQMASTER');
  176. if (serviceName === 'HAWQ' && hawqMasterComponent) {
  177. var hawqMasterCustomCommands = hawqMasterComponent.get('customCommands');
  178. customCommandToStopCluster = 'IMMEDIATE_STOP_CLUSTER';
  179. if (hawqMasterCustomCommands && hawqMasterCustomCommands.contains(customCommandToStopCluster)) {
  180. options.push(self.createOption(actionMap.IMMEDIATE_STOP_CLUSTER, {
  181. label: Em.I18n.t('services.service.actions.run.immediateStopHawqCluster.context'),
  182. context: {
  183. label: Em.I18n.t('services.service.actions.run.immediateStopHawqCluster.context'),
  184. service: hawqMasterComponent.get('serviceName'),
  185. component: hawqMasterComponent.get('componentName'),
  186. command: customCommandToStopCluster
  187. }
  188. })) };
  189. }
  190. self.addActionMap().filterProperty('service', serviceName).forEach(function(item) {
  191. if (App.get('components.addableToHost').contains(item.component)) {
  192. item.action = 'add' + item.component;
  193. item.disabled = self.get('controller.isAddDisabled-' + item.component);
  194. item.tooltip = self.get('controller.addDisabledTooltip' + item.component);
  195. options.push(item);
  196. }
  197. });
  198. allMasters.forEach(function(master) {
  199. var component = App.StackServiceComponent.find(master);
  200. var commands = component.get('customCommands');
  201. if (!commands.length) {
  202. return false;
  203. }
  204. commands.forEach(function(command) {
  205. if (excludedCommands[master] && excludedCommands[master].contains(command)){
  206. return false;
  207. }
  208. options.push(self.createOption(actionMap.MASTER_CUSTOM_COMMAND, {
  209. label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command, ["_", "-", " "])),
  210. context: {
  211. label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command, ["_", "-", " "])),
  212. service: component.get('serviceName'),
  213. component: component.get('componentName'),
  214. command: command
  215. }
  216. }));
  217. });
  218. });
  219. }
  220. if (hasConfigTab) {
  221. options.push(actionMap.DOWNLOAD_CLIENT_CONFIGS);
  222. }
  223. if (this.get('maintenance.length')) {
  224. this.get('maintenance').forEach(function(option, index) {
  225. if (JSON.stringify(option) != JSON.stringify(options[index])) {
  226. self.get('maintenance').removeAt(index).insertAt(index, options[index]);
  227. }
  228. });
  229. options.forEach(function(opt, index) {
  230. if (JSON.stringify(opt) != JSON.stringify(self.get('maintenance')[index])) {
  231. self.get('maintenance').pushObject(opt);
  232. }
  233. });
  234. } else {
  235. this.set('maintenance', options);
  236. }
  237. this.set('isMaintenanceSet', true);
  238. },
  239. clearIsMaintenanceSet: function () {
  240. this.set('isMaintenanceSet', false);
  241. },
  242. isMaintenanceActive: function() {
  243. return this.get('state') !== 'inDOM' || this.get('maintenance').length !== 0;
  244. }.property('maintenance'),
  245. hasConfigTab: function() {
  246. return App.isAuthorized('CLUSTER.VIEW_CONFIGS') && !App.get('services.noConfigTypes').contains(this.get('controller.content.serviceName'));
  247. }.property('controller.content.serviceName','App.services.noConfigTypes'),
  248. hasHeatmapTab: function() {
  249. return App.get('services.servicesWithHeatmapTab').contains(this.get('controller.content.serviceName'));
  250. }.property('controller.content.serviceName', 'App.services.servicesWithHeatmapTab'),
  251. didInsertElement: function () {
  252. this.get('controller').setStartStopState();
  253. },
  254. maintenanceObsFields: ['isStopDisabled', 'isClientsOnlyService', 'content.isRestartRequired', 'isServicesInfoLoaded'],
  255. willInsertElement: function () {
  256. var self = this;
  257. this.get('maintenanceObsFields').forEach(function (field) {
  258. self.addObserver('controller.' + field, self, 'observeMaintenance');
  259. });
  260. },
  261. willDestroyElement: function() {
  262. var self = this;
  263. this.get('maintenanceObsFields').forEach(function (field) {
  264. self.removeObserver('controller.' + field, self, 'observeMaintenance');
  265. });
  266. },
  267. service:function () {
  268. var svc = this.get('controller.content');
  269. var svcName = svc.get('serviceName');
  270. if (svcName) {
  271. switch (svcName.toLowerCase()) {
  272. case 'hdfs':
  273. svc = App.HDFSService.find().objectAt(0);
  274. break;
  275. case 'yarn':
  276. svc = App.YARNService.find().objectAt(0);
  277. break;
  278. case 'hbase':
  279. svc = App.HBaseService.find().objectAt(0);
  280. break;
  281. case 'flume':
  282. svc = App.FlumeService.find().objectAt(0);
  283. break;
  284. default:
  285. break;
  286. }
  287. }
  288. return svc;
  289. }.property('controller.content.serviceName').volatile()
  290. });