item.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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. var componentsUtils = require('utils/components');
  21. App.MainServiceItemController = Em.Controller.extend({
  22. name: 'mainServiceItemController',
  23. /**
  24. * Callback functions for start and stop service have few differences
  25. *
  26. * Used with currentCallBack property
  27. */
  28. callBackConfig: {
  29. 'STARTED': {
  30. 'c': 'STARTING',
  31. 'f': 'starting',
  32. 'c2': 'live',
  33. 'hs': 'started',
  34. 's': 'start'
  35. },
  36. 'INSTALLED': {
  37. 'c': 'STOPPING',
  38. 'f': 'stopping',
  39. 'c2': 'dead',
  40. 'hs': 'stopped',
  41. 's': 'stop'
  42. }
  43. },
  44. initHosts: function() {
  45. if (App.get('components.masters').length !== 0) {
  46. var self = this;
  47. var hostNames = App.Host.find().mapProperty('hostName');
  48. this.set('allHosts', hostNames);
  49. ['HBASE_MASTER', 'HIVE_METASTORE', 'ZOOKEEPER_SERVER', 'FLUME_HANDLER'].forEach(function(componentName) {
  50. self.loadHostsWithoutComponent(componentName);
  51. });
  52. }
  53. }.observes('App.components.masters', 'content.hostComponents.length'),
  54. loadHostsWithoutComponent: function (componentName) {
  55. var self = this;
  56. var hostsWithComponent = App.HostComponent.find().filterProperty('componentName', componentName).mapProperty('hostName');
  57. var hostsWithoutComponent = this.get('allHosts').filter(function(hostName) {
  58. return !hostsWithComponent.contains(hostName);
  59. });
  60. self.set('add' + componentName, function() {
  61. self.addComponent(componentName);
  62. });
  63. Em.defineProperty(self, 'addDisabledTooltip-' + componentName, Em.computed('isAddDisabled-' + componentName, 'addDisabledMsg-' + componentName, function() {
  64. if (self.get('isAddDisabled-' + componentName)) {
  65. return self.get('addDisabledMsg-' + componentName);
  66. }
  67. }));
  68. Em.defineProperty(self, 'isAddDisabled-' + componentName, Em.computed('hostsWithoutComponent-' + componentName, function() {
  69. return self.get('hostsWithoutComponent-' + componentName).length === 0 ? 'disabled' : '';
  70. }));
  71. var disabledMsg = Em.I18n.t('services.summary.allHostsAlreadyRunComponent').format(componentName);
  72. self.set('hostsWithoutComponent-' + componentName, hostsWithoutComponent);
  73. self.set('addDisabledMsg-' + componentName, disabledMsg);
  74. },
  75. /**
  76. * flag to control router switch between service summary and configs
  77. * @type {boolean}
  78. */
  79. routeToConfigs: false,
  80. isClientsOnlyService: function() {
  81. return App.get('services.clientOnly').contains(this.get('content.serviceName'));
  82. }.property('content.serviceName'),
  83. isConfigurable: function () {
  84. return !App.get('services.noConfigTypes').contains(this.get('content.serviceName'));
  85. }.property('App.services.noConfigTypes','content.serviceName'),
  86. allHosts: [],
  87. clientComponents: function () {
  88. var clientNames = [];
  89. var clients = App.StackServiceComponent.find().filterProperty('serviceName', this.get('content.serviceName')).filterProperty('isClient');
  90. clients.forEach(function (item) {
  91. clientNames.push({
  92. action: 'downloadClientConfigs',
  93. context: {
  94. name: item.get('componentName'),
  95. label: item.get('displayName')
  96. }
  97. });
  98. });
  99. return clientNames;
  100. }.property('content.serviceName'),
  101. /**
  102. * Common method for ajax (start/stop service) responses
  103. * @param data
  104. * @param ajaxOptions
  105. * @param params
  106. */
  107. startStopPopupSuccessCallback: function (data, ajaxOptions, params) {
  108. if (data && data.Requests) {
  109. params.query.set('status', 'SUCCESS');
  110. var config = this.get('callBackConfig')[(JSON.parse(ajaxOptions.data)).Body.ServiceInfo.state];
  111. var self = this;
  112. console.log('Send request for ' + config.c + ' successfully');
  113. if (App.get('testMode')) {
  114. self.set('content.workStatus', App.Service.Health[config.f]);
  115. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.f]);
  116. setTimeout(function () {
  117. self.set('content.workStatus', App.Service.Health[config.c2]);
  118. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.hs]);
  119. }, App.get('testModeDelayForActions'));
  120. }
  121. // load data (if we need to show this background operations popup) from persist
  122. App.router.get('applicationController').dataLoading().done(function (initValue) {
  123. if (initValue) {
  124. App.router.get('backgroundOperationsController').showPopup();
  125. }
  126. });
  127. } else {
  128. params.query.set('status', 'FAIL');
  129. console.log('cannot get request id from ', data);
  130. }
  131. },
  132. startStopPopupErrorCallback: function(request, ajaxOptions, error, opt, params){
  133. params.query.set('status', 'FAIL');
  134. },
  135. /**
  136. * Confirmation popup for start/stop services
  137. * @param event
  138. * @param serviceHealth - 'STARTED' or 'INSTALLED'
  139. */
  140. startStopPopup: function(event, serviceHealth) {
  141. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  142. return;
  143. }
  144. var self = this;
  145. var serviceDisplayName = this.get('content.displayName');
  146. var isMaintenanceOFF = this.get('content.passiveState') === 'OFF';
  147. var bodyMessage = Em.Object.create({
  148. putInMaintenance: (serviceHealth == 'INSTALLED' && isMaintenanceOFF) || (serviceHealth == 'STARTED' && !isMaintenanceOFF),
  149. turnOnMmMsg: serviceHealth == 'INSTALLED' ? Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName) : Em.I18n.t('passiveState.turnOffFor').format(serviceDisplayName),
  150. confirmMsg: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmMsg').format(serviceDisplayName) : Em.I18n.t('services.service.start.confirmMsg').format(serviceDisplayName),
  151. confirmButton: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('services.service.start.confirmButton'),
  152. additionalWarningMsg: isMaintenanceOFF && serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.warningMsg.turnOnMM').format(serviceDisplayName) : null
  153. });
  154. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  155. self.set('isPending', true);
  156. self.startStopWithMmode(serviceHealth, query, runMmOperation);
  157. }, bodyMessage);
  158. },
  159. startStopWithMmode: function(serviceHealth, query, runMmOperation) {
  160. var self = this;
  161. if (runMmOperation) {
  162. if (serviceHealth == "STARTED") {
  163. this.startStopPopupPrimary(serviceHealth, query).complete(function() {
  164. batchUtils.turnOnOffPassiveRequest("OFF", Em.I18n.t('passiveState.turnOff'), self.get('content.serviceName').toUpperCase());
  165. });
  166. } else {
  167. batchUtils.turnOnOffPassiveRequest("ON", Em.I18n.t('passiveState.turnOn'), this.get('content.serviceName').toUpperCase()).complete(function() {
  168. self.startStopPopupPrimary(serviceHealth, query);
  169. })
  170. }
  171. } else {
  172. this.startStopPopupPrimary(serviceHealth, query);
  173. }
  174. },
  175. startStopPopupPrimary: function (serviceHealth, query) {
  176. var requestInfo = (serviceHealth == "STARTED")
  177. ? App.BackgroundOperationsController.CommandContexts.START_SERVICE.format(this.get('content.serviceName'))
  178. : App.BackgroundOperationsController.CommandContexts.STOP_SERVICE.format(this.get('content.serviceName'));
  179. var data = {
  180. 'context': requestInfo,
  181. 'serviceName': this.get('content.serviceName').toUpperCase(),
  182. 'ServiceInfo': {
  183. 'state': serviceHealth
  184. },
  185. 'query': query
  186. };
  187. return App.ajax.send({
  188. 'name': 'common.service.update',
  189. 'sender': this,
  190. 'success': 'startStopPopupSuccessCallback',
  191. 'error': 'startStopPopupErrorCallback',
  192. 'data': data
  193. });
  194. },
  195. /**
  196. * On click callback for <code>start service</code> button
  197. * @param event
  198. */
  199. startService: function (event) {
  200. this.startStopPopup(event, App.HostComponentStatus.started);
  201. },
  202. /**
  203. * On click callback for <code>stop service</code> button
  204. * @param event
  205. */
  206. stopService: function (event) {
  207. this.startStopPopup(event, App.HostComponentStatus.stopped);
  208. },
  209. /**
  210. * On click callback for <code>run rebalancer</code> button
  211. * @param event
  212. */
  213. runRebalancer: function (event) {
  214. var self = this;
  215. return App.showConfirmationPopup(function() {
  216. self.set("content.runRebalancer", true);
  217. // load data (if we need to show this background operations popup) from persist
  218. App.router.get('applicationController').dataLoading().done(function (initValue) {
  219. if (initValue) {
  220. App.router.get('backgroundOperationsController').showPopup();
  221. }
  222. });
  223. });
  224. },
  225. /**
  226. * On click handler for Yarn Refresh Queues command from items menu
  227. * @param event
  228. */
  229. refreshYarnQueues : function (event) {
  230. var controller = this;
  231. var hosts = App.Service.find('YARN').get('hostComponents').filterProperty('componentName', 'RESOURCEMANAGER').mapProperty('hostName');
  232. return App.showConfirmationPopup(function() {
  233. App.ajax.send({
  234. name : 'service.item.refreshQueueYarnRequest',
  235. sender: controller,
  236. data : {
  237. command : "REFRESHQUEUES",
  238. context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context') ,
  239. hosts : hosts.join(','),
  240. serviceName : "YARN",
  241. componentName : "RESOURCEMANAGER",
  242. forceRefreshConfigTags : "capacity-scheduler"
  243. },
  244. success : 'refreshYarnQueuesSuccessCallback',
  245. error : 'refreshYarnQueuesErrorCallback'
  246. });
  247. });
  248. },
  249. refreshYarnQueuesSuccessCallback : function(data, ajaxOptions, params) {
  250. if (data.Requests.id) {
  251. App.router.get('backgroundOperationsController').showPopup();
  252. } else {
  253. console.warn('Error during refreshYarnQueues');
  254. }
  255. },
  256. refreshYarnQueuesErrorCallback : function(data) {
  257. var error = Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error');
  258. if(data && data.responseText){
  259. try {
  260. var json = $.parseJSON(data.responseText);
  261. error += json.message;
  262. } catch (err) {}
  263. }
  264. App.showAlertPopup(Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'), error);
  265. console.warn('Error during refreshYarnQueues:'+error);
  266. },
  267. startLdapKnox: function(event) {
  268. var context = Em.I18n.t('services.service.actions.run.startLdapKnox.context');
  269. this.startStopLdapKnox('STARTDEMOLDAP',context);
  270. },
  271. stopLdapKnox: function(event) {
  272. var context = Em.I18n.t('services.service.actions.run.stopLdapKnox.context');
  273. this.startStopLdapKnox('STOPDEMOLDAP',context);
  274. },
  275. startStopLdapKnox: function(command,context) {
  276. var controller = this;
  277. var host = App.HostComponent.find().findProperty('componentName', 'KNOX_GATEWAY').get('hostName');
  278. return App.showConfirmationPopup(function() {
  279. App.ajax.send({
  280. name: 'service.item.startStopLdapKnox',
  281. sender: controller,
  282. data: {
  283. command: command,
  284. context: context,
  285. host: host,
  286. serviceName: "KNOX",
  287. componentName: "KNOX_GATEWAY"
  288. },
  289. success: 'startStopLdapKnoxSuccessCallback',
  290. error: 'startStopLdapKnoxErrorCallback'
  291. });
  292. });
  293. },
  294. startStopLdapKnoxSuccessCallback : function(data, ajaxOptions, params) {
  295. if (data.Requests.id) {
  296. App.router.get('backgroundOperationsController').showPopup();
  297. } else {
  298. console.warn('Error during startStopLdapKnox');
  299. }
  300. },
  301. startStopLdapKnoxErrorCallback : function(data) {
  302. var error = Em.I18n.t('services.service.actions.run.startStopLdapKnox.error');
  303. if(data && data.responseText){
  304. try {
  305. var json = $.parseJSON(data.responseText);
  306. error += json.message;
  307. } catch (err) {}
  308. }
  309. App.showAlertPopup(Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'), error);
  310. console.warn('Error during refreshYarnQueues:'+ error);
  311. },
  312. /**
  313. * On click handler for rebalance Hdfs command from items menu
  314. */
  315. rebalanceHdfsNodes: function () {
  316. var controller = this;
  317. App.ModalPopup.show({
  318. classNames: ['fourty-percent-width-modal'],
  319. header: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  320. primary: Em.I18n.t('common.start'),
  321. secondary: Em.I18n.t('common.cancel'),
  322. inputValue: 10,
  323. errorMessage: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptError'),
  324. isInvalid: function () {
  325. var intValue = Number(this.get('inputValue'));
  326. return this.get('inputValue')!=='DEBUG' && (isNaN(intValue) || intValue < 1 || intValue > 100);
  327. }.property('inputValue'),
  328. disablePrimary : function() {
  329. return this.get('isInvalid');
  330. }.property('isInvalid'),
  331. onPrimary: function () {
  332. if (this.get('isInvalid')) {
  333. return;
  334. }
  335. App.ajax.send({
  336. name : 'service.item.rebalanceHdfsNodes',
  337. sender: controller,
  338. data : {
  339. hosts : App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('hostName'),
  340. threshold: this.get('inputValue')
  341. },
  342. success : 'rebalanceHdfsNodesSuccessCallback',
  343. error : 'rebalanceHdfsNodesErrorCallback'
  344. });
  345. this.hide();
  346. },
  347. bodyClass: Ember.View.extend({
  348. templateName: require('templates/common/prompt_popup'),
  349. text: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.prompt'),
  350. didInsertElement: function () {
  351. App.tooltip(this.$(".prompt-input"), {
  352. placement: "bottom",
  353. title: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptTooltip')
  354. });
  355. }
  356. })
  357. });
  358. },
  359. rebalanceHdfsNodesSuccessCallback: function (data) {
  360. if (data.Requests.id) {
  361. App.router.get('backgroundOperationsController').showPopup();
  362. } else {
  363. console.warn('Error during runRebalanceHdfsNodes');
  364. }
  365. },
  366. rebalanceHdfsNodesErrorCallback : function(data) {
  367. var error = Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error');
  368. if(data && data.responseText){
  369. try {
  370. var json = $.parseJSON(data.responseText);
  371. error += json.message;
  372. } catch (err) {
  373. }
  374. }
  375. App.showAlertPopup(Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error'), error);
  376. console.warn('Error during runRebalanceHdfsNodes:'+error);
  377. },
  378. /**
  379. * On click callback for <code>run compaction</code> button
  380. * @param event
  381. */
  382. runCompaction: function (event) {
  383. var self = this;
  384. return App.showConfirmationPopup(function() {
  385. self.set("content.runCompaction", true);
  386. // load data (if we need to show this background operations popup) from persist
  387. App.router.get('applicationController').dataLoading().done(function (initValue) {
  388. if (initValue) {
  389. App.router.get('backgroundOperationsController').showPopup();
  390. }
  391. });
  392. });
  393. },
  394. /**
  395. * On click callback for <code>run smoke test</code> button
  396. * @param event
  397. */
  398. runSmokeTest: function (event) {
  399. var self = this;
  400. if (this.get('content.serviceName') === 'MAPREDUCE2' && !App.Service.find('YARN').get('isStarted')) {
  401. return App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('services.mapreduce2.smokeTest.requirement'));
  402. }
  403. return App.showConfirmationFeedBackPopup(function(query) {
  404. self.runSmokeTestPrimary(query);
  405. });
  406. },
  407. restartAllHostComponents : function(serviceName) {
  408. var serviceDisplayName = this.get('content.displayName');
  409. var bodyMessage = Em.Object.create({
  410. putInMaintenance: this.get('content.passiveState') === 'OFF',
  411. turnOnMmMsg: Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName),
  412. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  413. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  414. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName): null
  415. });
  416. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  417. batchUtils.restartAllServiceHostComponents(serviceName, false, query, runMmOperation);
  418. }, bodyMessage);
  419. },
  420. turnOnOffPassive: function(label) {
  421. var self = this;
  422. var state = this.get('content.passiveState') == 'OFF' ? 'ON' : 'OFF';
  423. var onOff = state === 'ON' ? "On" : "Off";
  424. return App.showConfirmationPopup(function() {
  425. batchUtils.turnOnOffPassiveRequest(state, label, self.get('content.serviceName').toUpperCase(), function(data, opt, params) {
  426. self.set('content.passiveState', params.passive_state);
  427. batchUtils.infoPassiveState(params.passive_state);})
  428. },
  429. Em.I18n.t('hosts.passiveMode.popup').format(onOff,self.get('content.displayName'))
  430. );
  431. },
  432. rollingRestart: function(hostComponentName) {
  433. batchUtils.launchHostComponentRollingRestart(hostComponentName, this.get('content.displayName'), this.get('content.passiveState') === "ON", false, this.get('content.passiveState') === "ON");
  434. },
  435. runSmokeTestPrimary: function(query) {
  436. App.ajax.send({
  437. 'name': 'service.item.smoke',
  438. 'sender': this,
  439. 'success':'runSmokeTestSuccessCallBack',
  440. 'error':'runSmokeTestErrorCallBack',
  441. 'data': {
  442. 'serviceName': this.get('content.serviceName'),
  443. 'displayName': this.get('content.displayName'),
  444. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK',
  445. 'query': query
  446. }
  447. });
  448. },
  449. runSmokeTestSuccessCallBack: function (data, ajaxOptions, params) {
  450. if (data.Requests.id) {
  451. // load data (if we need to show this background operations popup) from persist
  452. App.router.get('applicationController').dataLoading().done(function (initValue) {
  453. params.query.set('status', 'SUCCESS');
  454. if (initValue) {
  455. App.router.get('backgroundOperationsController').showPopup();
  456. }
  457. });
  458. }
  459. else {
  460. params.query.set('status', 'FAIL');
  461. console.warn('error during runSmokeTestSuccessCallBack');
  462. }
  463. },
  464. runSmokeTestErrorCallBack: function (request, ajaxOptions, error, opt, params) {
  465. params.query.set('status', 'FAIL');
  466. },
  467. /**
  468. * On click callback for <code>Reassign <master component></code> button
  469. * @param hostComponent
  470. */
  471. reassignMaster: function (hostComponent) {
  472. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  473. console.log('In Reassign Master', hostComponent);
  474. if (component) {
  475. var reassignMasterController = App.router.get('reassignMasterController');
  476. reassignMasterController.saveComponentToReassign(component);
  477. reassignMasterController.getSecurityStatus();
  478. reassignMasterController.setCurrentStep('1');
  479. App.router.transitionTo('reassign');
  480. }
  481. },
  482. /**
  483. * On click callback for <code>action</code> dropdown menu
  484. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  485. * @param event
  486. */
  487. doAction: function (event) {
  488. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  489. return;
  490. }
  491. var methodName = event.context.action;
  492. var context = event.context.context;
  493. if (methodName) {
  494. this[methodName](context);
  495. }
  496. },
  497. /**
  498. * Restart clients host components to apply config changes
  499. */
  500. refreshConfigs: function () {
  501. var self = this;
  502. if (this.get('isClientsOnlyService') || this.get('content.serviceName') == "FLUME") {
  503. return App.showConfirmationFeedBackPopup(function (query) {
  504. batchUtils.getComponentsFromServer({
  505. services: [self.get('content.serviceName')]
  506. }, function (data) {
  507. var hostComponents = [];
  508. data.items.forEach(function (host) {
  509. host.host_components.forEach(function (hostComponent) {
  510. hostComponents.push(Em.Object.create({
  511. componentName: hostComponent.HostRoles.component_name,
  512. hostName: host.Hosts.host_name
  513. }))
  514. });
  515. });
  516. batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')), "SERVICE", query);
  517. })
  518. });
  519. }
  520. },
  521. /**
  522. * Send command to server to install client on selected host
  523. * @param componentName
  524. */
  525. addComponent: function (componentName) {
  526. var self = this;
  527. var component = App.HostComponent.find().findProperty('componentName', componentName);
  528. var componentDisplayName = component.get('displayName');
  529. self.loadHostsWithoutComponent(componentName);
  530. return App.ModalPopup.show({
  531. primary: function() {
  532. if (this.get('anyHostsWithoutComponent')) {
  533. return Em.I18n.t('hosts.host.addComponent.popup.confirm')
  534. } else {
  535. return undefined;
  536. }
  537. }.property('anyHostsWithoutComponent'),
  538. header: Em.I18n.t('popup.confirmation.commonHeader'),
  539. addComponentMsg: function () {
  540. return Em.I18n.t('hosts.host.addComponent.msg').format(componentDisplayName);
  541. }.property(),
  542. selectHostMsg: function () {
  543. return Em.I18n.t('services.summary.selectHostForComponent').format(this.get('componentDisplayName'))
  544. }.property('componentDisplayName'),
  545. thereIsNoHostsMsg: function () {
  546. return Em.I18n.t('services.summary.allHostsAlreadyRunComponent').format(this.get('componentDisplayName'))
  547. }.property('componentDisplayName'),
  548. hostsWithoutComponent: function() {
  549. return self.get("hostsWithoutComponent-" + this.get('componentName'));
  550. }.property('componentName', 'self.hostsWithoutComponent-' + this.get('componentName')),
  551. anyHostsWithoutComponent: function() {
  552. return this.get('hostsWithoutComponent').length > 0
  553. }.property('hostsWithoutComponent'),
  554. selectedHost: null,
  555. componentName: function() {
  556. return componentName;
  557. }.property(),
  558. componentDisplayName: function() {
  559. return componentDisplayName;
  560. }.property(),
  561. bodyClass: Em.View.extend({
  562. templateName: require('templates/main/service/add_host_popup')
  563. }),
  564. restartNagiosMsg: Em.View.extend({
  565. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.addComponent.note').format(componentDisplayName))
  566. }),
  567. onPrimary: function () {
  568. var selectedHost = this.get('selectedHost');
  569. // Install
  570. componentsUtils.installHostComponent(selectedHost, component);
  571. // Remove host from 'without' collection to immediate recalculate add menu item state
  572. var hostsWithoutComponent = this.get('hostsWithoutComponent');
  573. var index = hostsWithoutComponent.indexOf(this.get('selectedHost'));
  574. if (index > -1) {
  575. hostsWithoutComponent.splice(index, 1);
  576. }
  577. self.set('hostsWithoutComponent-' + this.get('componentName'), hostsWithoutComponent);
  578. this.hide();
  579. }
  580. });
  581. },
  582. /**
  583. * set property isPending (if this property is true - means that service has task in BGO)
  584. * and this makes start/stop button disabled
  585. */
  586. setStartStopState: function () {
  587. var serviceName = this.get('content.serviceName');
  588. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  589. if (backgroundOperations && backgroundOperations.length > 0) {
  590. for (var i = 0; i < backgroundOperations.length; i++) {
  591. if (backgroundOperations[i].isRunning &&
  592. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  593. backgroundOperations[i].dependentService === serviceName)) {
  594. this.set('isPending', true);
  595. return;
  596. }
  597. }
  598. this.set('isPending', false);
  599. } else {
  600. this.set('isPending', true);
  601. }
  602. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  603. isStartDisabled: function () {
  604. if(this.get('isPending')) return true;
  605. return !(this.get('content.healthStatus') == 'red');
  606. }.property('content.healthStatus','isPending'),
  607. isStopDisabled: function () {
  608. if(this.get('isPending')) return true;
  609. if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  610. return false;
  611. }
  612. return (this.get('content.healthStatus') != 'green');
  613. }.property('content.healthStatus','isPending'),
  614. /**
  615. * Determine if service has than one service client components
  616. */
  617. isSeveralClients: function () {
  618. return App.StackServiceComponent.find().filterProperty('serviceName', this.get('content.serviceName')).filterProperty('isClient').length > 1;
  619. }.property('content.serviceName'),
  620. enableHighAvailability: function() {
  621. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  622. ability_controller.enableHighAvailability();
  623. },
  624. disableHighAvailability: function() {
  625. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  626. ability_controller.disableHighAvailability();
  627. },
  628. enableRMHighAvailability: function() {
  629. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  630. ability_controller.enableRMHighAvailability();
  631. },
  632. downloadClientConfigs: function (event) {
  633. var component = this.get('content.hostComponents').findProperty('isClient');
  634. componentsUtils.downloadClientConfigs.call(this, {
  635. serviceName: this.get('content.serviceName'),
  636. componentName: (event && event.name) || component.get('componentName'),
  637. displayName: (event && event.label) || component.get('displayName')
  638. });
  639. },
  640. /**
  641. * On click handler for custom command from items menu
  642. * @param context
  643. */
  644. executeCustomCommand: function(context) {
  645. var controller = this;
  646. return App.showConfirmationPopup(function() {
  647. App.ajax.send({
  648. name : 'service.item.executeCustomCommand',
  649. sender: controller,
  650. data : {
  651. command : context.command,
  652. context : 'Execute ' + context.command,
  653. hosts : App.Service.find(context.service).get('hostComponents').findProperty('componentName', context.component).get('hostName'),
  654. serviceName : context.service,
  655. componentName : context.component,
  656. forceRefreshConfigTags : "capacity-scheduler"
  657. },
  658. success : 'executeCustomCommandSuccessCallback',
  659. error : 'executeCustomCommandErrorCallback'
  660. });
  661. });
  662. },
  663. executeCustomCommandSuccessCallback : function(data, ajaxOptions, params) {
  664. if (data.Requests.id) {
  665. App.router.get('backgroundOperationsController').showPopup();
  666. } else {
  667. console.warn('Error during execution of ' + params.command + ' custom command on' + params.componentName);
  668. }
  669. },
  670. executeCustomCommandErrorCallback : function(data) {
  671. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  672. if(data && data.responseText){
  673. try {
  674. var json = $.parseJSON(data.responseText);
  675. error += json.message;
  676. } catch (err) {}
  677. }
  678. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  679. console.warn('Error during executing custom command');
  680. },
  681. isPending:true
  682. });