service.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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 misc = require('utils/misc');
  20. App.MainServiceController = Em.ArrayController.extend({
  21. name: 'mainServiceController',
  22. /**
  23. * @type {Ember.Object[]}
  24. */
  25. content: function () {
  26. if (!App.router.get('clusterController.isLoaded')) {
  27. return [];
  28. }
  29. return misc.sortByOrder(App.StackService.find().mapProperty('serviceName'), App.Service.find().toArray());
  30. }.property('App.router.clusterController.isLoaded').volatile(),
  31. /**
  32. * Current cluster
  33. * @type {Ember.Object}
  34. */
  35. cluster: function () {
  36. if (!App.router.get('clusterController.isClusterDataLoaded')) {
  37. return null;
  38. }
  39. return App.Cluster.find().objectAt(0);
  40. }.property('App.router.clusterController.isClusterDataLoaded'),
  41. /**
  42. * Check if all services are installed
  43. * true - all installed, false - not all
  44. * @type {bool}
  45. */
  46. isAllServicesInstalled: function () {
  47. if (!this.get('content')) return false;
  48. var availableServices = App.StackService.find().mapProperty('serviceName');
  49. return this.get('content').length == availableServices.length;
  50. }.property('content.@each', 'content.length'),
  51. /**
  52. * Should "Start All"-button be disabled
  53. * @type {bool}
  54. */
  55. isStartAllDisabled: function () {
  56. if (this.get('isStartStopAllClicked') == true) {
  57. return true;
  58. }
  59. var stoppedServices = this.get('content').filter(function (_service) {
  60. return (_service.get('healthStatus') === 'red' && !App.get('services.clientOnly').contains(_service.get('serviceName')));
  61. });
  62. return (stoppedServices.length === 0); // all green status
  63. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  64. /**
  65. * Should "Stop All"-button be disabled
  66. * @type {bool}
  67. */
  68. isStopAllDisabled: function () {
  69. if (this.get('isStartStopAllClicked') == true) {
  70. return true;
  71. }
  72. return !this.get('content').someProperty('healthStatus', 'green');
  73. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  74. /**
  75. * Should "Refresh All"-button be disabled
  76. * @type {bool}
  77. */
  78. isRestartAllRequiredDisabled: Em.computed.everyBy('content', 'isRestartRequired', false),
  79. /**
  80. * @type {bool}
  81. */
  82. isStartStopAllClicked: Em.computed.notEqual('App.router.backgroundOperationsController.allOperationsCount', 0),
  83. /**
  84. * Callback for <code>start all service</code> button
  85. * @return {App.ModalPopup|null}
  86. * @method startAllService
  87. */
  88. startAllService: function (event) {
  89. return this.startStopAllService(event, 'STARTED');
  90. },
  91. /**
  92. * Callback for <code>stop all service</code> button
  93. * @return {App.ModalPopup|null}
  94. * @method stopAllService
  95. */
  96. stopAllService: function (event) {
  97. return this.startStopAllService(event, 'INSTALLED');
  98. },
  99. /**
  100. * Common method for "start-all", "stop-all" calls
  101. * @param {object} event
  102. * @param {string} state 'STARTED|INSTALLED'
  103. * @returns {App.ModalPopup|null}
  104. * @method startStopAllService
  105. */
  106. startStopAllService: function(event, state) {
  107. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  108. return null;
  109. }
  110. var self = this;
  111. var bodyMessage = Em.Object.create({
  112. confirmMsg: state == 'INSTALLED' ? Em.I18n.t('services.service.stopAll.confirmMsg') : Em.I18n.t('services.service.startAll.confirmMsg'),
  113. confirmButton: state == 'INSTALLED' ? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('services.service.start.confirmButton')
  114. });
  115. if (state == 'INSTALLED' && App.Service.find().filterProperty('serviceName', 'HDFS').someProperty('workStatus', App.HostComponentStatus.started)) {
  116. App.router.get('mainServiceItemController').checkNnLastCheckpointTime(function () {
  117. return App.showConfirmationFeedBackPopup(function (query) {
  118. self.allServicesCall(state, query);
  119. }, bodyMessage);
  120. });
  121. } else {
  122. return App.showConfirmationFeedBackPopup(function (query) {
  123. self.allServicesCall(state, query);
  124. }, bodyMessage);
  125. }
  126. },
  127. /**
  128. * Do request to server for "start|stop" all services
  129. * @param {string} state "STARTED|INSTALLED"
  130. * @param {object} query
  131. * @method allServicesCall
  132. * @return {$.ajax}
  133. */
  134. allServicesCall: function (state, query) {
  135. var context = (state == 'INSTALLED') ? App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES :
  136. App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES;
  137. return App.ajax.send({
  138. name: 'common.services.update',
  139. sender: this,
  140. data: {
  141. context: context,
  142. ServiceInfo: {
  143. state: state
  144. },
  145. query: query
  146. },
  147. success: 'allServicesCallSuccessCallback',
  148. error: 'allServicesCallErrorCallback'
  149. });
  150. },
  151. /**
  152. * Restart all services - stops all services, then starts them back
  153. */
  154. restartAllServices: function () {
  155. this.silentStopAllServices();
  156. },
  157. /**
  158. * Silent stop all services - without user confirmation
  159. * @returns {$.ajax}
  160. */
  161. silentStopAllServices: function () {
  162. return App.ajax.send({
  163. name: 'common.services.update',
  164. sender: this,
  165. data: {
  166. context: App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES,
  167. ServiceInfo: {
  168. state: 'INSTALLED'
  169. }
  170. },
  171. success: 'silentStopSuccess'
  172. });
  173. },
  174. isStopAllServicesFailed: function() {
  175. var workStatuses = App.Service.find().mapProperty('workStatus');
  176. for (var i = 0; i < workStatuses.length; i++) {
  177. if (workStatuses[i] !== 'INSTALLED' && workStatuses[i] !== 'STOPPING') {
  178. return true;
  179. }
  180. }
  181. return false;
  182. },
  183. /**
  184. * Success callback for silent stop
  185. */
  186. silentStopSuccess: function () {
  187. var self = this;
  188. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  189. if (initValue) {
  190. App.router.get('backgroundOperationsController').showPopup();
  191. }
  192. Em.run.later(function () {
  193. self.set('shouldStart', true);
  194. }, App.bgOperationsUpdateInterval);
  195. });
  196. },
  197. /**
  198. * Silent start all services - without user confirmation
  199. */
  200. silentStartAllServices: function () {
  201. if (
  202. !App.router.get('backgroundOperationsController').get('allOperationsCount')
  203. && this.get('shouldStart')
  204. && !this.isStopAllServicesFailed()
  205. ) {
  206. this.set('shouldStart', false);
  207. return App.ajax.send({
  208. name: 'common.services.update',
  209. sender: this,
  210. data: {
  211. context: App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES,
  212. ServiceInfo: {
  213. state: 'STARTED'
  214. }
  215. },
  216. success: 'silentCallSuccessCallback'
  217. });
  218. }
  219. }.observes('shouldStart', 'controllers.backgroundOperationsController.allOperationsCount'),
  220. /**
  221. * Success callback for silent start
  222. */
  223. silentCallSuccessCallback: function () {
  224. // load data (if we need to show this background operations popup) from persist
  225. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  226. if (initValue) {
  227. App.router.get('backgroundOperationsController').showPopup();
  228. }
  229. });
  230. },
  231. /**
  232. * Success-callback for all-services request
  233. * @param {object} data
  234. * @param {object} xhr
  235. * @param {object} params
  236. * @method allServicesCallSuccessCallback
  237. */
  238. allServicesCallSuccessCallback: function (data, xhr, params) {
  239. params.query.set('status', 'SUCCESS');
  240. // load data (if we need to show this background operations popup) from persist
  241. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  242. if (initValue) {
  243. App.router.get('backgroundOperationsController').showPopup();
  244. }
  245. });
  246. },
  247. /**
  248. * Error-callback for all-services request
  249. * @param {object} request
  250. * @param {object} ajaxOptions
  251. * @param {string} error
  252. * @param {object} opt
  253. * @param {object} params
  254. * @method allServicesCallErrorCallback
  255. */
  256. allServicesCallErrorCallback: function (request, ajaxOptions, error, opt, params) {
  257. params.query.set('status', 'FAIL');
  258. },
  259. /**
  260. * "Add-service"-click handler
  261. * @method gotoAddService
  262. */
  263. gotoAddService: function () {
  264. if (this.get('isAllServicesInstalled')) {
  265. return;
  266. }
  267. App.router.get('addServiceController').setDBProperty('onClosePath', 'main.services.index');
  268. App.router.transitionTo('main.serviceAdd');
  269. },
  270. /**
  271. * Show confirmation popup and send request to restart all host components with stale_configs=true
  272. */
  273. restartAllRequired: function () {
  274. var self = this;
  275. if (!this.get('isRestartAllRequiredDisabled')) {
  276. return App.showConfirmationPopup(function () {
  277. self.restartHostComponents();
  278. }, Em.I18n.t('services.service.refreshAll.confirmMsg').format(
  279. App.HostComponent.find().filterProperty('staleConfigs').mapProperty('service.displayName').uniq().join(', ')),
  280. null,
  281. null,
  282. Em.I18n.t('services.service.restartAll.confirmButton')
  283. );
  284. } else {
  285. return null;
  286. }
  287. },
  288. /**
  289. * Send request restart host components from hostComponentsToRestart
  290. * @returns {$.ajax}
  291. */
  292. restartHostComponents: function () {
  293. var batches, hiveInteractive = App.HostComponent.find().findProperty('componentName', 'HIVE_SERVER_INTERACTIVE');
  294. var isYARNQueueRefreshRequired = hiveInteractive && hiveInteractive.get('staleConfigs');
  295. var ajaxData = {
  296. "RequestInfo": {
  297. "command": "RESTART",
  298. "context": "Restart all required services",
  299. "operation_level": "host_component"
  300. },
  301. "Requests/resource_filters": [
  302. {
  303. "hosts_predicate": "HostRoles/stale_configs=true"
  304. }
  305. ]
  306. };
  307. if (isYARNQueueRefreshRequired) {
  308. batches = [
  309. {
  310. "order_id": 1,
  311. "type": "POST",
  312. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  313. "RequestBodyInfo": {
  314. "RequestInfo": {
  315. "context": "Refresh YARN Capacity Scheduler",
  316. "command": "REFRESHQUEUES",
  317. "parameters/forceRefreshConfigTags": "capacity-scheduler"
  318. },
  319. "Requests/resource_filters": [{
  320. "service_name": "YARN",
  321. "component_name": "RESOURCEMANAGER",
  322. "hosts": App.HostComponent.find().findProperty('componentName', 'RESOURCEMANAGER').get('hostName')
  323. }]
  324. }
  325. },
  326. {
  327. "order_id": 2,
  328. "type": "POST",
  329. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  330. "RequestBodyInfo": ajaxData
  331. }
  332. ];
  333. App.ajax.send({
  334. name: 'common.batch.request_schedules',
  335. sender: this,
  336. data: {
  337. intervalTimeSeconds: 1,
  338. tolerateSize: 0,
  339. batches: batches
  340. },
  341. success: 'restartAllRequiredSuccessCallback'
  342. });
  343. } else {
  344. App.ajax.send({
  345. name: 'request.post',
  346. sender: this,
  347. data: ajaxData,
  348. success: 'restartAllRequiredSuccessCallback'
  349. });
  350. }
  351. },
  352. /**
  353. * Success callback for restartAllRequired
  354. */
  355. restartAllRequiredSuccessCallback: function () {
  356. // load data (if we need to show this background operations popup) from persist
  357. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  358. if (initValue) {
  359. App.router.get('backgroundOperationsController').showPopup();
  360. }
  361. });
  362. }
  363. });