summary.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. App.MainServiceInfoSummaryController = Em.Controller.extend({
  19. name: 'mainServiceInfoSummaryController',
  20. selectedFlumeAgent: null,
  21. /**
  22. * Send start command for selected Flume Agent
  23. * @method startFlumeAgent
  24. */
  25. startFlumeAgent: function () {
  26. var selectedFlumeAgent = arguments[0].context;
  27. if (selectedFlumeAgent && selectedFlumeAgent.get('status') === 'NOT_RUNNING') {
  28. var self = this;
  29. App.showConfirmationPopup(function () {
  30. var state = 'STARTED';
  31. var context = Em.I18n.t('services.service.summary.flume.start.context').format(selectedFlumeAgent.get('name'));
  32. self.sendFlumeAgentCommandToServer(state, context, selectedFlumeAgent);
  33. });
  34. }
  35. },
  36. /**
  37. * Send stop command for selected Flume Agent
  38. * @method stopFlumeAgent
  39. */
  40. stopFlumeAgent: function () {
  41. var selectedFlumeAgent = arguments[0].context;
  42. if (selectedFlumeAgent && selectedFlumeAgent.get('status') === 'RUNNING') {
  43. var self = this;
  44. App.showConfirmationPopup(function () {
  45. var state = 'INSTALLED';
  46. var context = Em.I18n.t('services.service.summary.flume.stop.context').format(selectedFlumeAgent.get('name'));
  47. self.sendFlumeAgentCommandToServer(state, context, selectedFlumeAgent);
  48. });
  49. }
  50. },
  51. /**
  52. * Send command for Flume Agent to server
  53. * @param {string} state
  54. * @param {string} context
  55. * @param {Object} agent
  56. * @method sendFlumeAgentCommandToServer
  57. */
  58. sendFlumeAgentCommandToServer: function (state, context, agent) {
  59. App.ajax.send({
  60. name: 'service.flume.agent.command',
  61. sender: this,
  62. data: {
  63. state: state,
  64. context: context,
  65. agentName: agent.get('name'),
  66. host: agent.get('hostName')
  67. },
  68. success: 'commandSuccessCallback'
  69. });
  70. },
  71. /**
  72. * Callback, that shows Background operations popup if request was successful
  73. */
  74. commandSuccessCallback: function () {
  75. console.log('Send request for refresh configs successfully');
  76. // load data (if we need to show this background operations popup) from persist
  77. App.router.get('applicationController').dataLoading().done(function (showPopup) {
  78. if (showPopup) {
  79. App.router.get('backgroundOperationsController').showPopup();
  80. }
  81. });
  82. },
  83. gotoConfigs: function () {
  84. App.router.get('mainServiceItemController').set('routeToConfigs', true);
  85. App.router.transitionTo('main.services.service.configs', this.get('content'));
  86. App.router.get('mainServiceItemController').set('routeToConfigs', false);
  87. },
  88. nagiosUrl: function () {
  89. return App.router.get('clusterController.nagiosUrl');
  90. }.property('App.router.clusterController.nagiosUrl'),
  91. isNagiosInstalled: function () {
  92. return App.router.get('clusterController.isNagiosInstalled');
  93. }.property('App.router.clusterController.isNagiosInstalled'),
  94. showServiceAlertsPopup: function (event) {
  95. var service = event.context;
  96. return App.ModalPopup.show({
  97. header: Em.I18n.t('services.service.summary.alerts.popup.header').format(service.get('displayName')),
  98. autoHeight: false,
  99. bodyClass: Em.View.extend({
  100. templateName: require('templates/main/service/info/service_alert_popup'),
  101. classNames: ['service-alerts'],
  102. controllerBinding: 'App.router.mainAlertDefinitionsController',
  103. didInsertElement: function () {
  104. Em.run.next(this, function () {
  105. App.tooltip($(".timeago"));
  106. });
  107. },
  108. alerts: function () {
  109. var serviceDefinitions = this.get('controller.content').filterProperty('service', service);
  110. // definitions should be sorted in order: critical, warning, all other
  111. var criticalDefinitions = [];
  112. var warningDefinitions = [];
  113. serviceDefinitions.forEach(function (definition) {
  114. if (definition.get('isCritical')) {
  115. criticalDefinitions.push(definition);
  116. serviceDefinitions = serviceDefinitions.without(definition);
  117. } else if (definition.get('isWarning')) {
  118. warningDefinitions.push(definition);
  119. serviceDefinitions = serviceDefinitions.without(definition);
  120. }
  121. });
  122. serviceDefinitions = criticalDefinitions.concat(warningDefinitions, serviceDefinitions);
  123. return serviceDefinitions;
  124. }.property('controller.content'),
  125. gotoAlertDetails: function (event) {
  126. if (event && event.context) {
  127. this.get('parentView').hide();
  128. App.router.transitionTo('main.alerts.alertDetails', event.context);
  129. }
  130. },
  131. closePopup: function () {
  132. this.get('parentView').hide();
  133. }
  134. }),
  135. isHideBodyScroll: false,
  136. primary: Em.I18n.t('common.close'),
  137. secondary: null
  138. });
  139. }
  140. });