item.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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.MainServiceItemController = Em.Controller.extend({
  21. name: 'mainServiceItemController',
  22. /**
  23. * Callback functions for start and stop service have few differences
  24. *
  25. * Used with currentCallBack property
  26. */
  27. callBackConfig: {
  28. 'STARTED': {
  29. 'c': 'STARTING',
  30. 'f': 'starting',
  31. 'c2': 'live',
  32. 'hs': 'started',
  33. 's': 'start'
  34. },
  35. 'INSTALLED': {
  36. 'c': 'STOPPING',
  37. 'f': 'stopping',
  38. 'c2': 'dead',
  39. 'hs': 'stopped',
  40. 's': 'stop'
  41. }
  42. },
  43. /**
  44. * Common method for ajax (start/stop service) responses
  45. * @param data
  46. * @param ajaxOptions
  47. * @param params
  48. */
  49. startStopPopupSuccessCallback: function (data, ajaxOptions, params) {
  50. if (data && data.Requests) {
  51. params.query.set('status', 'SUCCESS');
  52. var config = this.get('callBackConfig')[(JSON.parse(ajaxOptions.data)).Body.ServiceInfo.state];
  53. var self = this;
  54. console.log('Send request for ' + config.c + ' successfully');
  55. if (App.testMode) {
  56. self.set('content.workStatus', App.Service.Health[config.f]);
  57. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.f]);
  58. setTimeout(function () {
  59. self.set('content.workStatus', App.Service.Health[config.c2]);
  60. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.hs]);
  61. }, App.testModeDelayForActions);
  62. }
  63. // load data (if we need to show this background operations popup) from persist
  64. App.router.get('applicationController').dataLoading().done(function (initValue) {
  65. if (initValue) {
  66. App.router.get('backgroundOperationsController').showPopup();
  67. }
  68. });
  69. } else {
  70. params.query.set('status', 'FAIL');
  71. console.log('cannot get request id from ', data);
  72. }
  73. },
  74. startStopPopupErrorCallback: function(request, ajaxOptions, error, opt, params){
  75. params.query.set('status', 'FAIL');
  76. },
  77. /**
  78. * Confirmation popup for start/stop services
  79. * @param event
  80. * @param serviceHealth - 'STARTED' or 'INSTALLED'
  81. */
  82. startStopPopup: function(event, serviceHealth) {
  83. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  84. return;
  85. }
  86. var self = this;
  87. var serviceDisplayName = this.get('content.displayName');
  88. var isMaintenanceOFF = this.get('content.passiveState') === 'OFF';
  89. var bodyMessage = Em.Object.create({
  90. putInMaintenance: (serviceHealth == 'INSTALLED' && isMaintenanceOFF) || (serviceHealth == 'STARTED' && !isMaintenanceOFF),
  91. turnOnMmMsg: serviceHealth == 'INSTALLED' ? Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName) : Em.I18n.t('passiveState.turnOffFor').format(serviceDisplayName),
  92. confirmMsg: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmMsg').format(serviceDisplayName) : Em.I18n.t('question.sure'),
  93. confirmButton: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('ok'),
  94. additionalWarningMsg: isMaintenanceOFF && serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.warningMsg.turnOnMM').format(serviceDisplayName) : null
  95. });
  96. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  97. self.set('isPending', true);
  98. self.startStopPopupPrimary(serviceHealth, query, runMmOperation);
  99. }, bodyMessage);
  100. },
  101. startStopPopupPrimary: function (serviceHealth, query, runMmOperation) {
  102. var requestInfo = "";
  103. var turnOnMM = "ON"
  104. if (serviceHealth == "STARTED") {
  105. turnOnMM = "OFF"
  106. requestInfo = App.BackgroundOperationsController.CommandContexts.START_SERVICE.format(this.get('content.serviceName'));
  107. } else {
  108. requestInfo = App.BackgroundOperationsController.CommandContexts.STOP_SERVICE.format(this.get('content.serviceName'));
  109. }
  110. var data = {
  111. 'context': requestInfo,
  112. 'serviceName': this.get('content.serviceName').toUpperCase(),
  113. 'ServiceInfo': {
  114. 'state': serviceHealth
  115. },
  116. 'query': query
  117. };
  118. if (runMmOperation) {
  119. data.ServiceInfo.maintenance_state = turnOnMM;
  120. }
  121. App.ajax.send({
  122. 'name': 'common.service.update',
  123. 'sender': this,
  124. 'success': 'startStopPopupSuccessCallback',
  125. 'error': 'startStopPopupErrorCallback',
  126. 'data': data
  127. });
  128. this.set('isStopDisabled', true);
  129. this.set('isStartDisabled', true);
  130. },
  131. /**
  132. * On click callback for <code>start service</code> button
  133. * @param event
  134. */
  135. startService: function (event) {
  136. this.startStopPopup(event, App.HostComponentStatus.started);
  137. },
  138. /**
  139. * On click callback for <code>stop service</code> button
  140. * @param event
  141. */
  142. stopService: function (event) {
  143. this.startStopPopup(event, App.HostComponentStatus.stopped);
  144. },
  145. /**
  146. * On click callback for <code>run rebalancer</code> button
  147. * @param event
  148. */
  149. runRebalancer: function (event) {
  150. var self = this;
  151. return App.showConfirmationPopup(function() {
  152. self.set("content.runRebalancer", true);
  153. // load data (if we need to show this background operations popup) from persist
  154. App.router.get('applicationController').dataLoading().done(function (initValue) {
  155. if (initValue) {
  156. App.router.get('backgroundOperationsController').showPopup();
  157. }
  158. });
  159. });
  160. },
  161. /**
  162. * On click callback for <code>run compaction</code> button
  163. * @param event
  164. */
  165. runCompaction: function (event) {
  166. var self = this;
  167. return App.showConfirmationPopup(function() {
  168. self.set("content.runCompaction", true);
  169. // load data (if we need to show this background operations popup) from persist
  170. App.router.get('applicationController').dataLoading().done(function (initValue) {
  171. if (initValue) {
  172. App.router.get('backgroundOperationsController').showPopup();
  173. }
  174. });
  175. });
  176. },
  177. /**
  178. * On click callback for <code>run smoke test</code> button
  179. * @param event
  180. */
  181. runSmokeTest: function (event) {
  182. var self = this;
  183. if (this.get('content.serviceName') === 'MAPREDUCE2' && !App.Service.find('YARN').get('isStarted')) {
  184. return App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('services.mapreduce2.smokeTest.requirement'));
  185. }
  186. return App.showConfirmationFeedBackPopup(function(query) {
  187. self.runSmokeTestPrimary(query);
  188. });
  189. },
  190. restartAllHostComponents : function(serviceName) {
  191. var serviceDisplayName = this.get('content.displayName');
  192. var bodyMessage = Em.Object.create({
  193. putInMaintenance: this.get('content.passiveState') === 'OFF',
  194. turnOnMmMsg: Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName),
  195. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  196. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  197. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName): null
  198. });
  199. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  200. batchUtils.restartAllServiceHostComponents(serviceName, false, query, runMmOperation);
  201. }, bodyMessage);
  202. },
  203. turnOnOffPassive: function(label) {
  204. var self = this;
  205. var state = this.get('content.passiveState') == 'OFF' ? 'ON' : 'OFF';
  206. var onOff = state === 'ON' ? "On" : "Off";
  207. return App.showConfirmationPopup(function() {
  208. batchUtils.turnOnOffPassiveRequest(state, label, self.get('content.serviceName').toUpperCase(), function(data, opt, params) {
  209. self.set('content.passiveState', params.passive_state);
  210. batchUtils.infoPassiveState(params.passive_state);})
  211. },
  212. Em.I18n.t('hosts.passiveMode.popup').format(onOff,self.get('content.displayName'))
  213. );
  214. },
  215. rollingRestart: function(hostComponentName) {
  216. batchUtils.launchHostComponentRollingRestart(hostComponentName, this.get('content.displayName'), this.get('content.passiveState') === "ON", false, this.get('content.passiveState') === "ON");
  217. },
  218. runSmokeTestPrimary: function(query) {
  219. App.ajax.send({
  220. 'name': 'service.item.smoke',
  221. 'sender': this,
  222. 'success':'runSmokeTestSuccessCallBack',
  223. 'error':'runSmokeTestErrorCallBack',
  224. 'data': {
  225. 'serviceName': this.get('content.serviceName'),
  226. 'displayName': this.get('content.displayName'),
  227. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK',
  228. 'query': query
  229. }
  230. });
  231. },
  232. runSmokeTestSuccessCallBack: function (data, ajaxOptions, params) {
  233. if (data.Requests.id) {
  234. // load data (if we need to show this background operations popup) from persist
  235. App.router.get('applicationController').dataLoading().done(function (initValue) {
  236. params.query.set('status', 'SUCCESS');
  237. if (initValue) {
  238. App.router.get('backgroundOperationsController').showPopup();
  239. }
  240. });
  241. }
  242. else {
  243. params.query.set('status', 'FAIL');
  244. console.warn('error during runSmokeTestSuccessCallBack');
  245. }
  246. },
  247. runSmokeTestErrorCallBack: function (request, ajaxOptions, error, opt, params) {
  248. params.query.set('status', 'FAIL');
  249. },
  250. /**
  251. * On click callback for <code>Reassign <master component></code> button
  252. * @param hostComponent
  253. */
  254. reassignMaster: function (hostComponent) {
  255. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  256. console.log('In Reassign Master', hostComponent);
  257. if (component) {
  258. var reassignMasterController = App.router.get('reassignMasterController');
  259. reassignMasterController.saveComponentToReassign(component);
  260. reassignMasterController.getSecurityStatus();
  261. reassignMasterController.setCurrentStep('1');
  262. App.router.transitionTo('reassign');
  263. }
  264. },
  265. /**
  266. * On click callback for <code>action</code> dropdown menu
  267. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  268. * @param event
  269. */
  270. doAction: function (event) {
  271. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  272. return;
  273. }
  274. var methodName = event.context.action;
  275. var context = event.context.context;
  276. if (methodName) {
  277. this[methodName](context);
  278. }
  279. },
  280. /**
  281. * Restart clients host components to apply config changes
  282. */
  283. refreshConfigs: function () {
  284. var self = this;
  285. if (this.get('content.isClientsOnly')) {
  286. return App.showConfirmationFeedBackPopup(function (query) {
  287. batchUtils.getComponentsFromServer({
  288. services: [self.get('content.serviceName')]
  289. }, function (data) {
  290. var hostComponents = [];
  291. data.items.forEach(function (host) {
  292. host.host_components.forEach(function (hostComponent) {
  293. hostComponents.push(Em.Object.create({
  294. componentName: hostComponent.HostRoles.component_name,
  295. hostName: host.Hosts.host_name
  296. }))
  297. });
  298. });
  299. batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')), "SERVICE", query);
  300. })
  301. });
  302. }
  303. },
  304. /**
  305. * set property isPending (if this property is true - means that service has task in BGO)
  306. * and this makes start/stop button disabled
  307. */
  308. setStartStopState: function () {
  309. var serviceName = this.get('content.serviceName');
  310. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  311. if (backgroundOperations.length > 0) {
  312. for (var i = 0; i < backgroundOperations.length; i++) {
  313. if (backgroundOperations[i].isRunning &&
  314. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  315. backgroundOperations[i].dependentService === serviceName)) {
  316. this.set('isPending', true);
  317. return;
  318. }
  319. }
  320. this.set('isPending', false);
  321. } else {
  322. this.set('isPending', true);
  323. }
  324. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  325. isStartDisabled: function () {
  326. if(this.get('isPending')) return true;
  327. return !(this.get('content.healthStatus') == 'red');
  328. }.property('content.healthStatus','isPending'),
  329. isStopDisabled: function () {
  330. if(this.get('isPending')) return true;
  331. if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  332. return false;
  333. }
  334. return (this.get('content.healthStatus') != 'green');
  335. }.property('content.healthStatus','isPending'),
  336. enableHighAvailability: function() {
  337. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  338. ability_controller.setSecurityStatus();
  339. ability_controller.enableHighAvailability();
  340. },
  341. disableHighAvailability: function() {
  342. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  343. ability_controller.setSecurityStatus();
  344. ability_controller.disableHighAvailability();
  345. },
  346. isPending:true
  347. });