alert_instances_controller.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.MainAlertInstancesController = Em.Controller.extend({
  20. name: 'mainAlertInstancesController',
  21. isLoaded: false,
  22. /**
  23. * Causes automatic updates of content if set to true
  24. */
  25. isUpdating: false,
  26. updateTimer: null,
  27. updateInterval: App.alertInstancesUpdateInterval,
  28. /**
  29. * "HOST" or "ALERT_DEFINITION"
  30. */
  31. sourceType: null,
  32. sourceName: null,
  33. fetchAlertInstances: function () {
  34. switch (this.get('sourceType')) {
  35. case 'HOST':
  36. App.ajax.send({
  37. name: 'alerts.instances.by_host',
  38. sender: this,
  39. data: {
  40. clusterName: App.router.get('clusterName'),
  41. hostName: this.get('sourceName')
  42. },
  43. success: 'getAlertInstancesSuccessCallback',
  44. error: 'getAlertInstancesErrorCallback'
  45. });
  46. break;
  47. case 'ALERT_DEFINITION':
  48. App.ajax.send({
  49. name: 'alerts.instances.by_definition',
  50. sender: this,
  51. data: {
  52. clusterName: App.router.get('clusterName'),
  53. definitionId: this.get('sourceName')
  54. },
  55. success: 'getAlertInstancesSuccessCallback',
  56. error: 'getAlertInstancesErrorCallback'
  57. });
  58. break;
  59. default:
  60. App.ajax.send({
  61. name: 'alerts.instances',
  62. sender: this,
  63. data: {
  64. clusterName: App.router.get('clusterName')
  65. },
  66. success: 'getAlertInstancesSuccessCallback',
  67. error: 'getAlertInstancesErrorCallback'
  68. });
  69. break;
  70. }
  71. },
  72. loadAlertInstances: function () {
  73. this.set('isLoaded', false);
  74. this.set('sourceType', null);
  75. this.set('sourceName', null);
  76. this.fetchAlertInstances();
  77. },
  78. loadAlertInstancesByHost: function (hostName) {
  79. this.set('isLoaded', false);
  80. this.set('sourceType', 'HOST');
  81. this.set('sourceName', hostName);
  82. this.fetchAlertInstances();
  83. },
  84. loadAlertInstancesByAlertDefinition: function (definitionName) {
  85. this.set('isLoaded', false);
  86. this.set('sourceType', 'ALERT_DEFINITION');
  87. this.set('sourceName', definitionName);
  88. this.fetchAlertInstances();
  89. },
  90. scheduleUpdate: function () {
  91. var self = this;
  92. if (this.get('isUpdating')) {
  93. this.set('updateTimer', setTimeout(function () {
  94. self.fetchAlertInstances();
  95. self.scheduleUpdate();
  96. }, this.get('updateInterval')));
  97. } else {
  98. clearTimeout(this.get('updateTimer'));
  99. }
  100. }.observes('isUpdating'),
  101. getAlertInstancesSuccessCallback: function (json) {
  102. App.alertInstanceMapper.map(json);
  103. this.set('isLoaded', true);
  104. },
  105. getAlertInstancesErrorCallback: function () {
  106. this.set('isLoaded', true);
  107. }
  108. });