item.js 11 KB

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