service.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. content: function(){
  22. if(!App.router.get('clusterController.isLoaded')){
  23. return [];
  24. }
  25. return App.Service.find();
  26. }.property('App.router.clusterController.isLoaded').volatile(),
  27. cluster: function () {
  28. if (!App.router.get('clusterController.isLoaded')) {
  29. return null;
  30. }
  31. return App.Cluster.find().objectAt(0);
  32. }.property('App.router.clusterController.isLoaded'),
  33. isAllServicesInstalled: function() {
  34. if (!this.get('content.content')) return false;
  35. var availableServices = App.db.getServices();
  36. if (!availableServices) {
  37. this.loadAvailableServices();
  38. availableServices = App.db.getServices();
  39. }
  40. if (!App.supports.hue) {
  41. availableServices = availableServices.without('HUE');
  42. }
  43. return this.get('content.content').length == availableServices.length;
  44. }.property('content.content.@each', 'content.content.length'),
  45. loadAvailableServices: function() {
  46. App.ajax.send({
  47. name: 'wizard.service_components',
  48. sender: this,
  49. data: {
  50. stackUrl: App.get('stack2VersionURL'),
  51. stackVersion: App.get('currentStackVersionNumber')
  52. },
  53. success: 'loadAvailableServicesSuccessCallback'
  54. });
  55. },
  56. loadAvailableServicesSuccessCallback: function(jsonData) {
  57. var data = [];
  58. var displayOrderConfig = require('data/services');
  59. for (var i = 0; i < displayOrderConfig.length; i++) {
  60. var entry = jsonData.items.findProperty("StackServices.service_name", displayOrderConfig[i].serviceName);
  61. if (entry) {
  62. data.push(entry.StackServices.service_name);
  63. }
  64. }
  65. App.db.setServices(data);
  66. },
  67. isStartAllDisabled: function(){
  68. if(this.get('isStartStopAllClicked') == true) {
  69. return true;
  70. }
  71. var stoppedServiceLength = this.get('content').filterProperty('healthStatus','red').filterProperty('isClientsOnly', false).length;
  72. return (stoppedServiceLength === 0); // all green status
  73. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  74. isStopAllDisabled: function(){
  75. if(this.get('isStartStopAllClicked') == true) {
  76. return true;
  77. }
  78. var startedServiceLength = this.get('content').filterProperty('healthStatus','green').length;
  79. return (startedServiceLength === 0);
  80. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  81. isStartStopAllClicked: function(){
  82. return (App.router.get('backgroundOperationsController').get('allOperationsCount') !== 0);
  83. }.property('App.router.backgroundOperationsController.allOperationsCount'),
  84. /**
  85. * callback for <code>start all service</code> button
  86. */
  87. startAllService: function(event){
  88. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  89. return;
  90. }
  91. var self = this;
  92. App.showConfirmationFeedBackPopup(function(query) {
  93. self.allServicesCall('startAllService', query);
  94. });
  95. },
  96. /**
  97. * callback for <code>stop all service</code> button
  98. */
  99. stopAllService: function(event){
  100. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  101. return;
  102. }
  103. var self = this;
  104. App.showConfirmationFeedBackPopup(function(query) {
  105. self.allServicesCall('stopAllService', query);
  106. });
  107. },
  108. allServicesCall: function(state, query) {
  109. var data;
  110. if (state == 'stopAllService') {
  111. data = '{"RequestInfo": {"context" :"' +
  112. App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES +
  113. '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  114. } else {
  115. data = '{"RequestInfo": {"context" :"' +
  116. App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES +
  117. '"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  118. }
  119. App.ajax.send({
  120. name: 'service.start_stop',
  121. sender: this,
  122. data: {
  123. data: data,
  124. query: query
  125. },
  126. success: 'allServicesCallSuccessCallback',
  127. error: 'allServicesCallErrorCallback'
  128. });
  129. },
  130. allServicesCallSuccessCallback: function(data, xhr, params) {
  131. console.log("TRACE: Start/Stop all service -> In success function for the start/stop all Service call");
  132. console.log("TRACE: Start/Stop all service -> value of the received data is: " + data);
  133. var requestId = data.Requests.id;
  134. params.query.set('status', 'SUCCESS');
  135. console.log('requestId is: ' + requestId);
  136. // load data (if we need to show this background operations popup) from persist
  137. App.router.get('applicationController').dataLoading().done(function (initValue) {
  138. if (initValue) {
  139. App.router.get('backgroundOperationsController').showPopup();
  140. }
  141. });
  142. },
  143. allServicesCallErrorCallback: function(request, ajaxOptions, error, opt, params) {
  144. console.log("ERROR");
  145. params.query.set('status', 'FAIL');
  146. },
  147. gotoAddService: function() {
  148. if (this.get('isAllServicesInstalled')) {
  149. return;
  150. }
  151. App.router.transitionTo('main.serviceAdd');
  152. }
  153. });