service.js 5.5 KB

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