item.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
  77. App.router.get('backgroundOperationsController').showPopup();
  78. }
  79. },
  80. /**
  81. * Confirmation popup for start/stop services
  82. * @param event
  83. * @param serviceHealth - 'STARTED' or 'INSTALLED'
  84. */
  85. startStopPopup: function(event, serviceHealth) {
  86. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  87. return;
  88. }
  89. var self = this;
  90. App.showConfirmationPopup(function() {
  91. self.set('isPending', true);
  92. self.startStopPopupPrimary(serviceHealth);
  93. });
  94. },
  95. startStopPopupPrimary: function (serviceHealth) {
  96. var requestInfo = "";
  97. if (serviceHealth == "STARTED") {
  98. requestInfo = '_PARSE_.START.' + this.get('content.serviceName');
  99. } else {
  100. requestInfo = '_PARSE_.STOP.' + this.get('content.serviceName');
  101. }
  102. App.ajax.send({
  103. 'name': 'service.item.start_stop',
  104. 'sender': this,
  105. 'success': 'ajaxSuccess',
  106. 'data': {
  107. 'requestInfo': requestInfo,
  108. 'serviceName': this.get('content.serviceName').toUpperCase(),
  109. 'state': serviceHealth
  110. }
  111. });
  112. this.set('isStopDisabled', true);
  113. this.set('isStartDisabled', true);
  114. },
  115. /**
  116. * On click callback for <code>start service</code> button
  117. * @param event
  118. */
  119. startService: function (event) {
  120. this.startStopPopup(event, App.HostComponentStatus.started);
  121. },
  122. /**
  123. * On click callback for <code>stop service</code> button
  124. * @param event
  125. */
  126. stopService: function (event) {
  127. this.startStopPopup(event, App.HostComponentStatus.stopped);
  128. },
  129. /**
  130. * On click callback for <code>run rebalancer</code> button
  131. * @param event
  132. */
  133. runRebalancer: function (event) {
  134. var self = this;
  135. App.showConfirmationPopup(function() {
  136. self.content.set('runRebalancer', true);
  137. if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
  138. App.router.get('backgroundOperationsController').showPopup();
  139. }
  140. });
  141. },
  142. /**
  143. * On click callback for <code>run compaction</code> button
  144. * @param event
  145. */
  146. runCompaction: function (event) {
  147. var self = this;
  148. App.showConfirmationPopup(function() {
  149. self.content.set('runCompaction', true);
  150. if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
  151. App.router.get('backgroundOperationsController').showPopup();
  152. }
  153. });
  154. },
  155. /**
  156. * On click callback for <code>run smoke test</code> button
  157. * @param event
  158. */
  159. runSmokeTest: function (event) {
  160. var self = this;
  161. if (this.get('content.serviceName') === 'MAPREDUCE2' && !App.Service.find('YARN').get('isStarted')) {
  162. App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('services.mapreduce2.smokeTest.requirement'));
  163. return;
  164. }
  165. App.showConfirmationPopup(function() {
  166. self.runSmokeTestPrimary();
  167. });
  168. },
  169. runSmokeTestPrimary: function() {
  170. App.ajax.send({
  171. 'name': 'service.item.smoke',
  172. 'sender': this,
  173. 'success':'runSmokeTestSuccessCallBack',
  174. 'data': {
  175. 'serviceName': this.get('content.serviceName'),
  176. 'displayName': this.get('content.displayName'),
  177. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK'
  178. }
  179. });
  180. },
  181. runSmokeTestSuccessCallBack: function(data) {
  182. if (data.Requests.id) {
  183. if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
  184. App.router.get('backgroundOperationsController').showPopup();
  185. }
  186. }
  187. else {
  188. console.warn('error during runSmokeTestSuccessCallBack');
  189. }
  190. },
  191. /**
  192. * On click callback for <code>Reassign <master component></code> button
  193. * @param hostComponent
  194. */
  195. reassignMaster: function (hostComponent) {
  196. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  197. console.log('In Reassign Master', hostComponent);
  198. var reassignMasterController = App.router.get('reassignMasterController');
  199. reassignMasterController.saveComponentToReassign(component);
  200. reassignMasterController.getSecurityStatus();
  201. reassignMasterController.setCurrentStep('1');
  202. App.router.transitionTo('reassign');
  203. },
  204. /**
  205. * On click callback for <code>action</code> dropdown menu
  206. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  207. * @param event
  208. */
  209. doAction: function (event) {
  210. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  211. return;
  212. }
  213. var methodName = event.context.action;
  214. var context = event.context.context;
  215. if (methodName) {
  216. this[methodName](context);
  217. }
  218. },
  219. setStartStopState: function () {
  220. var serviceName = this.get('content.serviceName');
  221. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  222. if (backgroundOperations.length > 0) {
  223. for (var i = 0; i < backgroundOperations.length; i++) {
  224. if (backgroundOperations[i].isRunning &&
  225. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  226. backgroundOperations[i].dependentService === serviceName)) {
  227. this.set('isPending', true);
  228. return;
  229. }
  230. }
  231. this.set('isPending', false);
  232. } else {
  233. this.set('isPending', true);
  234. }
  235. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  236. isServiceRestartable: function() {
  237. return this.get('content.serviceName') !== "FLUME";
  238. }.property('content.serviceName'),
  239. isStartDisabled: function () {
  240. if(this.get('isPending')) return true;
  241. return !(this.get('content.healthStatus') == 'red');
  242. }.property('content.healthStatus','isPending'),
  243. isStopDisabled: function () {
  244. if(this.get('isPending')) return true;
  245. 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)) {
  246. return false;
  247. }
  248. return (this.get('content.healthStatus') != 'green');
  249. }.property('content.healthStatus','isPending'),
  250. isPending:true
  251. });