service.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. if (!App.get('supports.hue')) {
  49. availableServices = availableServices.without('HUE');
  50. }
  51. return this.get('content.content').length == availableServices.length;
  52. }.property('content.content.@each', 'content.content.length'),
  53. /**
  54. * Should "Start All"-button be disabled
  55. * @type {bool}
  56. */
  57. isStartAllDisabled: function () {
  58. if (this.get('isStartStopAllClicked') == true) {
  59. return true;
  60. }
  61. var stoppedServices = this.get('content').filter(function (_service) {
  62. return (_service.get('healthStatus') === 'red' && !App.get('services.clientOnly').contains(_service.get('serviceName')));
  63. });
  64. return (stoppedServices.length === 0); // all green status
  65. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  66. /**
  67. * Should "Stop All"-button be disabled
  68. * @type {bool}
  69. */
  70. isStopAllDisabled: function () {
  71. if (this.get('isStartStopAllClicked') == true) {
  72. return true;
  73. }
  74. var startedServiceLength = this.get('content').filterProperty('healthStatus', 'green').length;
  75. return (startedServiceLength === 0);
  76. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  77. /**
  78. * @type {bool}
  79. */
  80. isStartStopAllClicked: function () {
  81. return (App.router.get('backgroundOperationsController').get('allOperationsCount') !== 0);
  82. }.property('App.router.backgroundOperationsController.allOperationsCount'),
  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. return App.showConfirmationFeedBackPopup(function (query) {
  112. self.allServicesCall(state, query);
  113. });
  114. },
  115. /**
  116. * Do request to server for "start|stop" all services
  117. * @param {string} state "STARTED|INSTALLED"
  118. * @param {object} query
  119. * @method allServicesCall
  120. * @return {$.ajax}
  121. */
  122. allServicesCall: function (state, query) {
  123. var context = (state == 'INSTALLED') ? App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES :
  124. App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES;
  125. return App.ajax.send({
  126. name: 'common.services.update',
  127. sender: this,
  128. data: {
  129. context: context,
  130. ServiceInfo: {
  131. state: state
  132. },
  133. query: query
  134. },
  135. success: 'allServicesCallSuccessCallback',
  136. error: 'allServicesCallErrorCallback'
  137. });
  138. },
  139. /**
  140. * Success-callback for all-services request
  141. * @param {object} data
  142. * @param {object} xhr
  143. * @param {object} params
  144. * @method allServicesCallSuccessCallback
  145. */
  146. allServicesCallSuccessCallback: function (data, xhr, params) {
  147. params.query.set('status', 'SUCCESS');
  148. // load data (if we need to show this background operations popup) from persist
  149. App.router.get('applicationController').dataLoading().done(function (initValue) {
  150. if (initValue) {
  151. App.router.get('backgroundOperationsController').showPopup();
  152. }
  153. });
  154. },
  155. /**
  156. * Error-callback for all-services request
  157. * @param {object} request
  158. * @param {object} ajaxOptions
  159. * @param {string} error
  160. * @param {object} opt
  161. * @param {object} params
  162. * @method allServicesCallErrorCallback
  163. */
  164. allServicesCallErrorCallback: function (request, ajaxOptions, error, opt, params) {
  165. params.query.set('status', 'FAIL');
  166. },
  167. /**
  168. * "Add-service"-click handler
  169. * @method gotoAddService
  170. */
  171. gotoAddService: function () {
  172. if (this.get('isAllServicesInstalled')) {
  173. return;
  174. }
  175. App.router.transitionTo('main.serviceAdd');
  176. }
  177. });