service.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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'),
  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. isStartAllDisabled: function(){
  34. if(this.get('isStartStopAllClicked') == true) {
  35. return true;
  36. }
  37. var stoppedServiceLength = this.get('content').filterProperty('healthStatus','red').length;
  38. return (stoppedServiceLength === 0); // all green status
  39. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  40. isStopAllDisabled: function(){
  41. if(this.get('isStartStopAllClicked') == true) {
  42. return true;
  43. }
  44. var startedService = this.get('content').filterProperty('healthStatus','green');
  45. var flag = true;
  46. startedService.forEach(function(item){
  47. if(!['HCATALOG', 'PIG', 'SQOOP'].contains(item.get('serviceName'))){
  48. flag = false;
  49. }
  50. })
  51. return flag;
  52. }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
  53. isStartStopAllClicked: function(){
  54. return (App.router.get('backgroundOperationsController').get('allOperationsCount') !== 0);
  55. }.property('App.router.backgroundOperationsController.allOperationsCount'),
  56. /**
  57. * callback for <code>start all service</code> button
  58. */
  59. startAllService: function(event){
  60. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  61. return;
  62. }
  63. var self = this;
  64. App.showConfirmationPopup(function() {
  65. self.allServicesCall('startAllService');
  66. });
  67. },
  68. /**
  69. * callback for <code>stop all service</code> button
  70. */
  71. stopAllService: function(event){
  72. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  73. return;
  74. }
  75. var self = this;
  76. App.showConfirmationPopup(function() {
  77. self.allServicesCall('stopAllService');
  78. });
  79. },
  80. allServicesCall: function(state) {
  81. var data;
  82. if(state == 'stopAllService') {
  83. data = '{"RequestInfo": {"context" :"'+ Em.I18n.t('requestInfo.stopAllServices') +'"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  84. }
  85. else {
  86. data = '{"RequestInfo": {"context" :"'+ Em.I18n.t('requestInfo.startAllServices') +'"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
  87. }
  88. App.ajax.send({
  89. name: 'service.start_stop',
  90. sender: this,
  91. data: {
  92. data: data
  93. },
  94. success: 'allServicesCallSuccessCallback',
  95. error: 'allServicesCallErrorCallback'
  96. });
  97. },
  98. allServicesCallSuccessCallback: function(data) {
  99. console.log("TRACE: Start/Stop all service -> In success function for the start/stop all Service call");
  100. console.log("TRACE: Start/Stop all service -> value of the received data is: " + data);
  101. var requestId = data.Requests.id;
  102. console.log('requestId is: ' + requestId);
  103. App.router.get('backgroundOperationsController').showPopup();
  104. },
  105. allServicesCallErrorCallback: function() {
  106. console.log("ERROR");
  107. }
  108. })