Переглянути джерело

AMBARI-9866 Alerts display box not refreshing even after alert is Green. (ababiichuk)

aBabiichuk 10 роки тому
батько
коміт
5474d79616

+ 7 - 2
ambari-web/app/controllers/global/update_controller.js

@@ -23,6 +23,9 @@ App.UpdateController = Em.Controller.extend({
   isUpdated: false,
   cluster: null,
   isWorking: false,
+  updateAlertInstances: function() {
+    return this.get('isWorking') && !App.get('router.mainAlertInstancesController.isUpdating');
+  }.property('isWorking', 'App.router.mainAlertInstancesController.isUpdating'),
   timeIntervalId: null,
   clusterName: function () {
     return App.router.get('clusterController.clusterName');
@@ -132,9 +135,11 @@ App.UpdateController = Em.Controller.extend({
       App.updater.run(this, 'updateAlertGroups', 'isWorking', App.alertGroupsUpdateInterval);
       App.updater.run(this, 'updateAlertDefinitions', 'isWorking', App.alertDefinitionsUpdateInterval);
       App.updater.run(this, 'updateAlertDefinitionSummary', 'isWorking', App.alertDefinitionsUpdateInterval);
-      App.updater.run(this, 'updateUnhealthyAlertInstances', 'isWorking', App.alertInstancesUpdateInterval);
+      if (!App.get('router.mainAlertInstancesController.isUpdating')) {
+        App.updater.run(this, 'updateUnhealthyAlertInstances', 'updateAlertInstances', App.alertInstancesUpdateInterval);
+      }
     }
-  }.observes('isWorking'),
+  }.observes('isWorking', 'App.router.mainAlertInstancesController.isUpdating'),
   /**
    * Update service metrics depending on which page is open
    * Make a call only on follow pages:

+ 1 - 1
ambari-web/app/controllers/main/alerts/alert_instances_controller.js

@@ -158,7 +158,7 @@ App.MainAlertInstancesController = Em.Controller.extend({
    * @method getAlertInstancesSuccessCallback
    */
   getAlertInstancesSuccessCallback: function (json) {
-    App.alertInstanceMapper.map(json);
+    App.alertInstanceMapper.map(json, true);
     this.set('isLoaded', true);
     this.set('reload', !this.get('reload'));
   },

+ 45 - 13
ambari-web/app/mappers/alert_instances_mapper.js

@@ -40,21 +40,53 @@ App.alertInstanceMapper = App.QuickDataMapper.create({
     text: 'Alert.text'
   },
 
-  map: function(json) {
+  map: function(json, skipDelete) {
     if (json.items) {
-      var self = this,
-        alertInstances = [],
-        model = this.get('model'),
-        alertsToDelete = model.find().mapProperty('id');
-
-      json.items.forEach(function (item) {
-        var alert = this.parseIt(item, this.get('config'));
-        alertInstances.push(alert);
-        alertsToDelete = alertsToDelete.without(alert.id);
-      }, this);
-
-      App.store.loadMany(model, alertInstances);
+      var alertInstances = (skipDelete) ? this.mapWithoutDelete(json) : this.mapAndDelete(json);
+
+      App.store.loadMany(this.get('model'), alertInstances);
     }
+  },
+
+  /**
+   * method that used when we not on alert definition state
+   * in this case we need to delete alerts that is not critical and not warning
+   * @param json
+   * @returns {Array}
+   */
+  mapAndDelete: function(json) {
+    var self = this,
+      alertInstances = [],
+      model = this.get('model'),
+      alertsToDelete = model.find().mapProperty('id');
+
+    json.items.forEach(function (item) {
+      var alert = this.parseIt(item, this.get('config'));
+      alertInstances.push(alert);
+      alertsToDelete = alertsToDelete.without(alert.id);
+    }, this);
+
+
+    alertsToDelete.forEach(function(alertId) {
+      var item = model.find(alertId);
+      self.deleteRecord(item);
+    });
+
+    return alertInstances;
+  },
+
+  /**
+   * this method is used on alert definition page
+   * @param json
+   * @returns {Array}
+   */
+  mapWithoutDelete: function(json) {
+    var alertInstances = [];
+    json.items.forEach(function (item) {
+      var alert = this.parseIt(item, this.get('config'));
+      alertInstances.push(alert);
+    }, this);
+    return alertInstances;
   }
 
 });

+ 10 - 2
ambari-web/test/mappers/alert_instances_mapper_test.js

@@ -94,10 +94,18 @@ describe('App.alertInstanceMapper', function () {
 
   });
 
-  it('shouldn\'t delete not existing models', function () {
+  it('should delete models', function () {
 
     App.alertInstanceMapper.map(json);
 
+    expect(App.alertInstanceMapper.deleteRecord.called).to.be.true;
+
+  });
+
+  it('shouldn\'t delete not existing models', function () {
+
+    App.alertInstanceMapper.map(json, true);
+
     expect(App.alertInstanceMapper.deleteRecord.called).to.be.false;
 
   });
@@ -140,4 +148,4 @@ describe('App.alertInstanceMapper', function () {
 
   });
 
-});
+});