service.js 5.4 KB

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