alert_instances_controller.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. this.set('isLoaded', false);
  35. switch (this.get('sourceType')) {
  36. case 'HOST':
  37. App.ajax.send({
  38. name: 'alerts.instances.by_host',
  39. sender: this,
  40. data: {
  41. clusterName: App.router.get('clusterName'),
  42. hostName: this.get('sourceName')
  43. },
  44. success: 'getAlertInstancesSuccessCallback',
  45. error: 'getAlertInstancesErrorCallback'
  46. });
  47. break;
  48. case 'ALERT_DEFINITION':
  49. App.ajax.send({
  50. name: 'alerts.instances.by_definition',
  51. sender: this,
  52. data: {
  53. clusterName: App.router.get('clusterName'),
  54. definitionName: this.get('sourceName')
  55. },
  56. success: 'getAlertInstancesSuccessCallback',
  57. error: 'getAlertInstancesErrorCallback'
  58. });
  59. break;
  60. default:
  61. App.ajax.send({
  62. name: 'alerts.instances',
  63. sender: this,
  64. data: {
  65. clusterName: App.router.get('clusterName')
  66. },
  67. success: 'getAlertInstancesSuccessCallback',
  68. error: 'getAlertInstancesErrorCallback'
  69. });
  70. break;
  71. }
  72. },
  73. loadAlertInstances: function () {
  74. this.set('sourceType', null);
  75. this.set('sourceName', null);
  76. this.fetchAlertInstances();
  77. },
  78. loadAlertInstancesByHost: function (hostName) {
  79. this.set('sourceType', 'HOST');
  80. this.set('sourceName', hostName);
  81. this.fetchAlertInstances();
  82. },
  83. loadAlertInstancesByAlertDefinition: function (definitionName) {
  84. this.set('sourceType', 'ALERT_DEFINITION');
  85. this.set('sourceName', definitionName);
  86. this.fetchAlertInstances();
  87. },
  88. scheduleUpdate: function () {
  89. var self = this;
  90. if (this.get('isUpdating')) {
  91. this.set('updateTimer', setTimeout(function () {
  92. self.fetchAlertInstances();
  93. self.scheduleUpdate();
  94. }, this.get('updateInterval')));
  95. } else {
  96. clearTimeout(this.get('updateTimer'));
  97. }
  98. }.observes('isUpdating'),
  99. getAlertInstancesSuccessCallback: function (json) {
  100. App.alertInstanceMapper.map(json);
  101. this.set('isLoaded', true);
  102. },
  103. getAlertInstancesErrorCallback: function () {
  104. this.set('isLoaded', true);
  105. }
  106. });