item.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. 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. * Success ajax response processing
  45. * @param data
  46. * @param ajaxOptions
  47. */
  48. ajaxSuccess: function(data, ajaxOptions) {
  49. if(data && data.Requests) {
  50. this.ajaxCallBack(data.Requests.id, (JSON.parse(ajaxOptions.data)).Body.ServiceInfo.state);
  51. }
  52. else {
  53. console.log('cannot get request id from ', data);
  54. }
  55. },
  56. /**
  57. * Common method for ajax (start/stop service) responses
  58. * @param requestId
  59. * @param serviceHealth
  60. */
  61. ajaxCallBack: function(requestId, serviceHealth) {
  62. var config = this.get('callBackConfig')[serviceHealth];
  63. var self = this;
  64. console.log('Send request for ' + config.c + ' successfully');
  65. if (App.testMode) {
  66. self.set('content.workStatus', App.Service.Health[config.f]);
  67. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.f]);
  68. setTimeout(function () {
  69. self.set('content.workStatus', App.Service.Health[config.c2]);
  70. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.hs]);
  71. }, App.testModeDelayForActions);
  72. }
  73. else {
  74. App.router.get('clusterController').loadUpdatedStatusDelayed(500);// @todo check working without param 500
  75. }
  76. // load data (if we need to show this background operations popup) from persist
  77. App.router.get('applicationController').dataLoading().done(function (initValue) {
  78. if (initValue) {
  79. App.router.get('backgroundOperationsController').showPopup();
  80. }
  81. });
  82. },
  83. /**
  84. * Confirmation popup for start/stop services
  85. * @param event
  86. * @param serviceHealth - 'STARTED' or 'INSTALLED'
  87. */
  88. startStopPopup: function(event, serviceHealth) {
  89. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  90. return;
  91. }
  92. var self = this;
  93. App.showConfirmationPopup(function() {
  94. self.set('isPending', true);
  95. self.startStopPopupPrimary(serviceHealth);
  96. });
  97. },
  98. startStopPopupPrimary: function (serviceHealth) {
  99. var requestInfo = "";
  100. if (serviceHealth == "STARTED") {
  101. requestInfo = '_PARSE_.START.' + this.get('content.serviceName');
  102. } else {
  103. requestInfo = '_PARSE_.STOP.' + this.get('content.serviceName');
  104. }
  105. App.ajax.send({
  106. 'name': 'service.item.start_stop',
  107. 'sender': this,
  108. 'success': 'ajaxSuccess',
  109. 'data': {
  110. 'requestInfo': requestInfo,
  111. 'serviceName': this.get('content.serviceName').toUpperCase(),
  112. 'state': serviceHealth
  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.showConfirmationPopup(function() {
  175. self.runSmokeTestPrimary();
  176. });
  177. },
  178. runSmokeTestPrimary: function() {
  179. App.ajax.send({
  180. 'name': 'service.item.smoke',
  181. 'sender': this,
  182. 'success':'runSmokeTestSuccessCallBack',
  183. 'data': {
  184. 'serviceName': this.get('content.serviceName'),
  185. 'displayName': this.get('content.displayName'),
  186. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK'
  187. }
  188. });
  189. },
  190. runSmokeTestSuccessCallBack: function(data) {
  191. if (data.Requests.id) {
  192. // load data (if we need to show this background operations popup) from persist
  193. App.router.get('applicationController').dataLoading().done(function (initValue) {
  194. if (initValue) {
  195. App.router.get('backgroundOperationsController').showPopup();
  196. }
  197. });
  198. }
  199. else {
  200. console.warn('error during runSmokeTestSuccessCallBack');
  201. }
  202. },
  203. /**
  204. * On click callback for <code>Reassign <master component></code> button
  205. * @param hostComponent
  206. */
  207. reassignMaster: function (hostComponent) {
  208. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  209. console.log('In Reassign Master', hostComponent);
  210. var reassignMasterController = App.router.get('reassignMasterController');
  211. reassignMasterController.saveComponentToReassign(component);
  212. reassignMasterController.getSecurityStatus();
  213. reassignMasterController.setCurrentStep('1');
  214. App.router.transitionTo('reassign');
  215. },
  216. manageConfigurationGroups: function () {
  217. var serviceName = this.get('content.serviceName');
  218. var displayName = this.get('content.displayName');
  219. App.ModalPopup.show({
  220. header: Em.I18n.t('services.service.config_groups_popup.header').format(displayName),
  221. bodyClass: App.MainServiceManageConfigGroupView.extend({
  222. serviceName: serviceName,
  223. controllerBinding: 'App.router.manageConfigGroupsController'
  224. }),
  225. classNames: ['sixty-percent-width-modal', 'manage-configuration-group-popup'],
  226. primary: Em.I18n.t('common.save'),
  227. onPrimary: function() {
  228. // Save modified config-groups
  229. var modifiedConfigGroups = this.get('subViewController.hostsModifiedConfigGroups');
  230. console.log("manageConfigurationGroups(): Saving modified config-groups: ", modifiedConfigGroups);
  231. var self = this;
  232. var errors = [];
  233. var putCount = modifiedConfigGroups.length;
  234. var finishFunction = function(error) {
  235. if (error != null) {
  236. errors.push(error);
  237. }
  238. if (--putCount <= 0) {
  239. // Done with all the PUTs
  240. if (errors.length > 0) {
  241. console.log(errors);
  242. self.get('subViewController').set('errorMessage',
  243. errors.join(". "));
  244. } else {
  245. self.hide();
  246. }
  247. }
  248. };
  249. this.updateConfigGroupOnServicePage();
  250. modifiedConfigGroups.forEach(function(cg) {
  251. App.config.updateConfigurationGroup(cg, finishFunction, finishFunction);
  252. });
  253. },
  254. onSecondary: function () {
  255. this.updateConfigGroupOnServicePage();
  256. this.hide();
  257. },
  258. onClose: function () {
  259. this.updateConfigGroupOnServicePage();
  260. this.hide();
  261. },
  262. subViewController: function(){
  263. return App.router.get('manageConfigGroupsController');
  264. }.property('App.router.manageConfigGroupsController'),
  265. updateConfigGroupOnServicePage: function () {
  266. var mainServiceInfoConfigsController = App.get('router.mainServiceInfoConfigsController');
  267. var selectedConfigGroup = mainServiceInfoConfigsController.get('selectedConfigGroup');
  268. //check whether selectedConfigGroup was selected
  269. if (selectedConfigGroup) {
  270. var managedConfigGroups = this.get('subViewController.configGroups');
  271. selectedConfigGroup = managedConfigGroups.findProperty('id', selectedConfigGroup.id);
  272. if (selectedConfigGroup) {
  273. mainServiceInfoConfigsController.set('selectedConfigGroup', selectedConfigGroup);
  274. } else {
  275. mainServiceInfoConfigsController.set('selectedConfigGroup', managedConfigGroups.findProperty('isDefault', true));
  276. }
  277. }
  278. mainServiceInfoConfigsController.set('configGroups', this.get('subViewController.configGroups'));
  279. },
  280. updateButtons: function(){
  281. var modified = this.get('subViewController.isHostsModified');
  282. this.set('enablePrimary', modified);
  283. }.observes('subViewController.isHostsModified'),
  284. secondary : Em.I18n.t('common.cancel'),
  285. didInsertElement: function () {}
  286. });
  287. },
  288. /**
  289. * On click callback for <code>action</code> dropdown menu
  290. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  291. * @param event
  292. */
  293. doAction: function (event) {
  294. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  295. return;
  296. }
  297. var methodName = event.context.action;
  298. var context = event.context.context;
  299. if (methodName) {
  300. this[methodName](context);
  301. }
  302. },
  303. setStartStopState: function () {
  304. var serviceName = this.get('content.serviceName');
  305. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  306. if (backgroundOperations.length > 0) {
  307. for (var i = 0; i < backgroundOperations.length; i++) {
  308. if (backgroundOperations[i].isRunning &&
  309. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  310. backgroundOperations[i].dependentService === serviceName)) {
  311. this.set('isPending', true);
  312. return;
  313. }
  314. }
  315. this.set('isPending', false);
  316. } else {
  317. this.set('isPending', true);
  318. }
  319. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  320. isServiceRestartable: function() {
  321. return this.get('content.serviceName') !== "FLUME";
  322. }.property('content.serviceName'),
  323. isStartDisabled: function () {
  324. if(this.get('isPending')) return true;
  325. return !(this.get('content.healthStatus') == 'red');
  326. }.property('content.healthStatus','isPending'),
  327. isStopDisabled: function () {
  328. if(this.get('isPending')) return true;
  329. if (!App.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  330. return false;
  331. }
  332. return (this.get('content.healthStatus') != 'green');
  333. }.property('content.healthStatus','isPending'),
  334. isPending:true
  335. });