item.js 8.7 KB

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