service.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. App.MainServiceController = Em.ArrayController.extend({
  20. name: 'mainServiceController',
  21. /**
  22. * @type {Ember.Object[]}
  23. */
  24. content: function () {
  25. if (!App.router.get('clusterController.isLoaded')) {
  26. return [];
  27. }
  28. return App.Service.find();
  29. }.property('App.router.clusterController.isLoaded').volatile(),
  30. /**
  31. * Current cluster
  32. * @type {Ember.Object}
  33. */
  34. cluster: function () {
  35. if (!App.router.get('clusterController.isLoaded')) {
  36. return null;
  37. }
  38. return App.Cluster.find().objectAt(0);
  39. }.property('App.router.clusterController.isLoaded'),
  40. /**
  41. * Check if all services are installed
  42. * true - all installed, false - not all
  43. * @type {bool}
  44. */
  45. isAllServicesInstalled: function () {
  46. if (!this.get('content.content')) return false;
  47. var availableServices = App.StackService.find().mapProperty('serviceName');
  48. return this.get('content.content').length == availableServices.length;
  49. }.property('content.content.@each', 'content.content.length'),
  50. /**
  51. * Should "Start All"-button be disabled
  52. * @type {bool}
  53. */
  54. isStartAllDisabled: function () {
  55. if (this.get('isStartStopAllClicked') == true) {
  56. return true;
  57. }
  58. var stoppedServices = this.get('content').filter(function (_service) {
  59. return (_service.get('healthStatus') === 'red' && !App.get('services.clientOnly').contains(_service.get('serviceName')));
  60. });
  61. return (stoppedServices.length === 0); // all green status
  62. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  63. /**
  64. * Should "Stop All"-button be disabled
  65. * @type {bool}
  66. */
  67. isStopAllDisabled: function () {
  68. if (this.get('isStartStopAllClicked') == true) {
  69. return true;
  70. }
  71. var startedServiceLength = this.get('content').filterProperty('healthStatus', 'green').length;
  72. return (startedServiceLength === 0);
  73. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  74. /**
  75. * @type {bool}
  76. */
  77. isStartStopAllClicked: function () {
  78. return (App.router.get('backgroundOperationsController').get('allOperationsCount') !== 0);
  79. }.property('App.router.backgroundOperationsController.allOperationsCount'),
  80. /**
  81. * Callback for <code>start all service</code> button
  82. * @return {App.ModalPopup|null}
  83. * @method startAllService
  84. */
  85. startAllService: function (event) {
  86. return this.startStopAllService(event, 'STARTED');
  87. },
  88. /**
  89. * Callback for <code>stop all service</code> button
  90. * @return {App.ModalPopup|null}
  91. * @method stopAllService
  92. */
  93. stopAllService: function (event) {
  94. return this.startStopAllService(event, 'INSTALLED');
  95. },
  96. /**
  97. * Common method for "start-all", "stop-all" calls
  98. * @param {object} event
  99. * @param {string} state 'STARTED|INSTALLED'
  100. * @returns {App.ModalPopup|null}
  101. * @method startStopAllService
  102. */
  103. startStopAllService: function(event, state) {
  104. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  105. return null;
  106. }
  107. var self = this;
  108. var bodyMessage = Em.Object.create({
  109. confirmMsg: state == 'INSTALLED' ? Em.I18n.t('services.service.stopAll.confirmMsg') : Em.I18n.t('services.service.startAll.confirmMsg'),
  110. confirmButton: state == 'INSTALLED' ? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('services.service.start.confirmButton')
  111. });
  112. return App.showConfirmationFeedBackPopup(function (query) {
  113. self.allServicesCall(state, query);
  114. }, bodyMessage);
  115. },
  116. /**
  117. * Do request to server for "start|stop" all services
  118. * @param {string} state "STARTED|INSTALLED"
  119. * @param {object} query
  120. * @method allServicesCall
  121. * @return {$.ajax}
  122. */
  123. allServicesCall: function (state, query) {
  124. var context = (state == 'INSTALLED') ? App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES :
  125. App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES;
  126. return App.ajax.send({
  127. name: 'common.services.update',
  128. sender: this,
  129. data: {
  130. context: context,
  131. ServiceInfo: {
  132. state: state
  133. },
  134. query: query
  135. },
  136. success: 'allServicesCallSuccessCallback',
  137. error: 'allServicesCallErrorCallback'
  138. });
  139. },
  140. /**
  141. * Success-callback for all-services request
  142. * @param {object} data
  143. * @param {object} xhr
  144. * @param {object} params
  145. * @method allServicesCallSuccessCallback
  146. */
  147. allServicesCallSuccessCallback: function (data, xhr, params) {
  148. params.query.set('status', 'SUCCESS');
  149. // load data (if we need to show this background operations popup) from persist
  150. App.router.get('applicationController').dataLoading().done(function (initValue) {
  151. if (initValue) {
  152. App.router.get('backgroundOperationsController').showPopup();
  153. }
  154. });
  155. },
  156. /**
  157. * Error-callback for all-services request
  158. * @param {object} request
  159. * @param {object} ajaxOptions
  160. * @param {string} error
  161. * @param {object} opt
  162. * @param {object} params
  163. * @method allServicesCallErrorCallback
  164. */
  165. allServicesCallErrorCallback: function (request, ajaxOptions, error, opt, params) {
  166. params.query.set('status', 'FAIL');
  167. },
  168. /**
  169. * "Add-service"-click handler
  170. * @method gotoAddService
  171. */
  172. gotoAddService: function () {
  173. if (this.get('isAllServicesInstalled')) {
  174. return;
  175. }
  176. App.router.transitionTo('main.serviceAdd');
  177. }
  178. });