item.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 = '_PARSE_.START.' + this.get('content.serviceName');
  103. } else {
  104. requestInfo = '_PARSE_.STOP.' + 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. rollingRestart: function(hostComponentName) {
  185. batchUtils.launchHostComponentRollingRestart(hostComponentName, false);
  186. },
  187. runSmokeTestPrimary: function() {
  188. App.ajax.send({
  189. 'name': 'service.item.smoke',
  190. 'sender': this,
  191. 'success':'runSmokeTestSuccessCallBack',
  192. 'data': {
  193. 'serviceName': this.get('content.serviceName'),
  194. 'displayName': this.get('content.displayName'),
  195. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK'
  196. }
  197. });
  198. },
  199. runSmokeTestSuccessCallBack: function(data) {
  200. if (data.Requests.id) {
  201. // load data (if we need to show this background operations popup) from persist
  202. App.router.get('applicationController').dataLoading().done(function (initValue) {
  203. if (initValue) {
  204. App.router.get('backgroundOperationsController').showPopup();
  205. }
  206. });
  207. }
  208. else {
  209. console.warn('error during runSmokeTestSuccessCallBack');
  210. }
  211. },
  212. /**
  213. * On click callback for <code>Reassign <master component></code> button
  214. * @param hostComponent
  215. */
  216. reassignMaster: function (hostComponent) {
  217. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  218. console.log('In Reassign Master', hostComponent);
  219. var reassignMasterController = App.router.get('reassignMasterController');
  220. reassignMasterController.saveComponentToReassign(component);
  221. reassignMasterController.getSecurityStatus();
  222. reassignMasterController.setCurrentStep('1');
  223. App.router.transitionTo('reassign');
  224. },
  225. /**
  226. * On click callback for <code>action</code> dropdown menu
  227. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  228. * @param event
  229. */
  230. doAction: function (event) {
  231. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  232. return;
  233. }
  234. var methodName = event.context.action;
  235. var context = event.context.context;
  236. if (methodName) {
  237. this[methodName](context);
  238. }
  239. },
  240. setStartStopState: function () {
  241. var serviceName = this.get('content.serviceName');
  242. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  243. if (backgroundOperations.length > 0) {
  244. for (var i = 0; i < backgroundOperations.length; i++) {
  245. if (backgroundOperations[i].isRunning &&
  246. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  247. backgroundOperations[i].dependentService === serviceName)) {
  248. this.set('isPending', true);
  249. return;
  250. }
  251. }
  252. this.set('isPending', false);
  253. } else {
  254. this.set('isPending', true);
  255. }
  256. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  257. isServiceRestartable: function() {
  258. return this.get('content.serviceName') !== "FLUME";
  259. }.property('content.serviceName'),
  260. isStartDisabled: function () {
  261. if(this.get('isPending')) return true;
  262. return !(this.get('content.healthStatus') == 'red');
  263. }.property('content.healthStatus','isPending'),
  264. isStopDisabled: function () {
  265. if(this.get('isPending')) return true;
  266. if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  267. return false;
  268. }
  269. return (this.get('content.healthStatus') != 'green');
  270. }.property('content.healthStatus','isPending'),
  271. isPending:true
  272. });