item.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 service_components = require('data/service_components');
  20. var batchUtils = require('utils/batch_scheduled_requests');
  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. /**
  45. * Common method for ajax (start/stop service) responses
  46. * @param data
  47. * @param ajaxOptions
  48. * @param params
  49. */
  50. startStopPopupSuccessCallback: function (data, ajaxOptions, params) {
  51. if (data && data.Requests) {
  52. params.query.set('status', 'SUCCESS');
  53. var config = this.get('callBackConfig')[(JSON.parse(ajaxOptions.data)).Body.ServiceInfo.state];
  54. var self = this;
  55. console.log('Send request for ' + config.c + ' successfully');
  56. if (App.testMode) {
  57. self.set('content.workStatus', App.Service.Health[config.f]);
  58. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.f]);
  59. setTimeout(function () {
  60. self.set('content.workStatus', App.Service.Health[config.c2]);
  61. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.hs]);
  62. }, App.testModeDelayForActions);
  63. }
  64. else {
  65. App.router.get('clusterController').loadUpdatedStatusDelayed(500);// @todo check working without param 500
  66. }
  67. // load data (if we need to show this background operations popup) from persist
  68. App.router.get('applicationController').dataLoading().done(function (initValue) {
  69. if (initValue) {
  70. App.router.get('backgroundOperationsController').showPopup();
  71. }
  72. });
  73. } else {
  74. params.query.set('status', 'FAIL');
  75. console.log('cannot get request id from ', data);
  76. }
  77. },
  78. startStopPopupErrorCallback: function(request, ajaxOptions, error, opt, params){
  79. params.query.set('status', 'FAIL');
  80. },
  81. /**
  82. * Confirmation popup for start/stop services
  83. * @param event
  84. * @param serviceHealth - 'STARTED' or 'INSTALLED'
  85. */
  86. startStopPopup: function(event, serviceHealth) {
  87. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  88. return;
  89. }
  90. var self = this;
  91. App.showConfirmationFeedBackPopup(function(query) {
  92. self.set('isPending', true);
  93. self.startStopPopupPrimary(serviceHealth, query);
  94. });
  95. },
  96. startStopPopupPrimary: function (serviceHealth, query) {
  97. var requestInfo = "";
  98. if (serviceHealth == "STARTED") {
  99. requestInfo = App.BackgroundOperationsController.CommandContexts.START_SERVICE.format(this.get('content.serviceName'));
  100. } else {
  101. requestInfo = App.BackgroundOperationsController.CommandContexts.STOP_SERVICE.format(this.get('content.serviceName'));
  102. }
  103. App.ajax.send({
  104. 'name': 'service.item.start_stop',
  105. 'sender': this,
  106. 'success': 'startStopPopupSuccessCallback',
  107. 'error': 'startStopPopupErrorCallback',
  108. 'data': {
  109. 'requestInfo': requestInfo,
  110. 'serviceName': this.get('content.serviceName').toUpperCase(),
  111. 'state': serviceHealth,
  112. 'query': query
  113. }
  114. });
  115. this.set('isStopDisabled', true);
  116. this.set('isStartDisabled', true);
  117. },
  118. /**
  119. * On click callback for <code>start service</code> button
  120. * @param event
  121. */
  122. startService: function (event) {
  123. this.startStopPopup(event, App.HostComponentStatus.started);
  124. },
  125. /**
  126. * On click callback for <code>stop service</code> button
  127. * @param event
  128. */
  129. stopService: function (event) {
  130. this.startStopPopup(event, App.HostComponentStatus.stopped);
  131. },
  132. /**
  133. * On click callback for <code>run rebalancer</code> button
  134. * @param event
  135. */
  136. runRebalancer: function (event) {
  137. var self = this;
  138. App.showConfirmationPopup(function() {
  139. self.content.set('runRebalancer', true);
  140. // load data (if we need to show this background operations popup) from persist
  141. App.router.get('applicationController').dataLoading().done(function (initValue) {
  142. if (initValue) {
  143. App.router.get('backgroundOperationsController').showPopup();
  144. }
  145. });
  146. });
  147. },
  148. /**
  149. * On click callback for <code>run compaction</code> button
  150. * @param event
  151. */
  152. runCompaction: function (event) {
  153. var self = this;
  154. App.showConfirmationPopup(function() {
  155. self.content.set('runCompaction', true);
  156. // load data (if we need to show this background operations popup) from persist
  157. App.router.get('applicationController').dataLoading().done(function (initValue) {
  158. if (initValue) {
  159. App.router.get('backgroundOperationsController').showPopup();
  160. }
  161. });
  162. });
  163. },
  164. /**
  165. * On click callback for <code>run smoke test</code> button
  166. * @param event
  167. */
  168. runSmokeTest: function (event) {
  169. var self = this;
  170. if (this.get('content.serviceName') === 'MAPREDUCE2' && !App.Service.find('YARN').get('isStarted')) {
  171. App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('services.mapreduce2.smokeTest.requirement'));
  172. return;
  173. }
  174. App.showConfirmationFeedBackPopup(function(query) {
  175. self.runSmokeTestPrimary(query);
  176. });
  177. },
  178. restartAllHostComponents : function(serviceName) {
  179. App.showConfirmationFeedBackPopup(function(query) {
  180. batchUtils.restartAllServiceHostComponents(serviceName, false, query);
  181. });
  182. },
  183. turnOnOffPassive: function(label) {
  184. var self = this;
  185. var state = this.get('content.passiveState') == 'OFF' ? 'ON' : 'OFF';
  186. var onOff = state === 'ON' ? "On" : "Off";
  187. App.showConfirmationPopup(function() {
  188. self.turnOnOffPassiveRequest(state, label)
  189. },
  190. Em.I18n.t('hosts.passiveMode.popup').format(onOff,self.get('content.displayName'))
  191. );
  192. },
  193. rollingRestart: function(hostComponentName) {
  194. batchUtils.launchHostComponentRollingRestart(hostComponentName, false, this.get('content.passiveState') === "ON");
  195. },
  196. turnOnOffPassiveRequest: function(state,message) {
  197. App.ajax.send({
  198. 'name': 'service.item.passive',
  199. 'sender': this,
  200. 'data': {
  201. 'requestInfo': message,
  202. 'serviceName': this.get('content.serviceName').toUpperCase(),
  203. 'passive_state': state
  204. },
  205. 'success':'updateService'
  206. });
  207. },
  208. updateService: function(data, opt, params) {
  209. var self = this;
  210. App.router.get('clusterController').loadUpdatedStatus(function(){
  211. self.set('content.passiveState', params.passive_state);
  212. batchUtils.infoPassiveState(params.passive_state);
  213. });
  214. },
  215. runSmokeTestPrimary: function(query) {
  216. App.ajax.send({
  217. 'name': 'service.item.smoke',
  218. 'sender': this,
  219. 'success':'runSmokeTestSuccessCallBack',
  220. 'error':'runSmokeTestErrorCallBack',
  221. 'data': {
  222. 'serviceName': this.get('content.serviceName'),
  223. 'displayName': this.get('content.displayName'),
  224. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK',
  225. 'query': query
  226. }
  227. });
  228. },
  229. runSmokeTestSuccessCallBack: function (data, ajaxOptions, params) {
  230. if (data.Requests.id) {
  231. // load data (if we need to show this background operations popup) from persist
  232. App.router.get('applicationController').dataLoading().done(function (initValue) {
  233. if (initValue) {
  234. params.query.set('status', 'SUCCESS');
  235. App.router.get('backgroundOperationsController').showPopup();
  236. }
  237. });
  238. }
  239. else {
  240. params.query.set('status', 'FAIL');
  241. console.warn('error during runSmokeTestSuccessCallBack');
  242. }
  243. },
  244. runSmokeTestErrorCallBack: function (request, ajaxOptions, error, opt, params) {
  245. params.query.set('status', 'FAIL');
  246. },
  247. /**
  248. * On click callback for <code>Reassign <master component></code> button
  249. * @param hostComponent
  250. */
  251. reassignMaster: function (hostComponent) {
  252. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  253. console.log('In Reassign Master', hostComponent);
  254. var reassignMasterController = App.router.get('reassignMasterController');
  255. reassignMasterController.saveComponentToReassign(component);
  256. reassignMasterController.getSecurityStatus();
  257. reassignMasterController.setCurrentStep('1');
  258. App.router.transitionTo('reassign');
  259. },
  260. /**
  261. * On click callback for <code>action</code> dropdown menu
  262. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  263. * @param event
  264. */
  265. doAction: function (event) {
  266. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  267. return;
  268. }
  269. var methodName = event.context.action;
  270. var context = event.context.context;
  271. if (methodName) {
  272. this[methodName](context);
  273. }
  274. },
  275. /**
  276. * Restart clients host components to apply config changes
  277. */
  278. refreshConfigs: function() {
  279. var self = this;
  280. if (this.get('content.isClientsOnly')) {
  281. App.showConfirmationFeedBackPopup(function(query) {
  282. batchUtils.restartHostComponents(self.get('content.hostComponents'), Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')), query);
  283. });
  284. }
  285. },
  286. setStartStopState: function () {
  287. var serviceName = this.get('content.serviceName');
  288. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  289. if (backgroundOperations.length > 0) {
  290. for (var i = 0; i < backgroundOperations.length; i++) {
  291. if (backgroundOperations[i].isRunning &&
  292. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  293. backgroundOperations[i].dependentService === serviceName)) {
  294. this.set('isPending', true);
  295. return;
  296. }
  297. }
  298. this.set('isPending', false);
  299. } else {
  300. this.set('isPending', true);
  301. }
  302. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  303. isServiceRestartable: function() {
  304. return this.get('content.serviceName') !== "FLUME";
  305. }.property('content.serviceName'),
  306. isStartDisabled: function () {
  307. if(this.get('isPending')) return true;
  308. return !(this.get('content.healthStatus') == 'red');
  309. }.property('content.healthStatus','isPending'),
  310. isStopDisabled: function () {
  311. if(this.get('isPending')) return true;
  312. if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  313. return false;
  314. }
  315. return (this.get('content.healthStatus') != 'green');
  316. }.property('content.healthStatus','isPending'),
  317. isPending:true
  318. });