service.js 4.3 KB

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