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

AMBARI-12845. Alert Instances overriding issue (onehiporenko)

Oleg Nechiporenko 10 роки тому
батько
коміт
66d0b6e2c1

+ 3 - 3
ambari-web/app/assets/test/tests.js

@@ -275,9 +275,9 @@ var files = ['test/init_model_test',
   'test/models/service/flume_test',
   'test/models/service/hdfs_test',
   'test/models/service/yarn_test',
-  'test/models/alert_config_test',
-  'test/models/alert_definition_test',
-  'test/models/alert_instance_test',
+  'test/models/alerts/alert_config_test',
+  'test/models/alerts/alert_definition_test',
+  'test/models/alerts/alert_instance_test',
   'test/models/authentication_test',
   'test/models/cluster_states_test',
   'test/models/config_group_test',

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

@@ -182,7 +182,7 @@ App.MainAlertInstancesController = Em.Controller.extend({
    * @method getAlertInstancesSuccessCallback
    */
   getAlertInstancesSuccessCallback: function (json) {
-    App.alertInstanceMapper.map(json);
+    App.alertInstanceMapper.mapLocal(json);
     this.set('isLoaded', true);
     this.toggleProperty('reload');
   },
@@ -309,15 +309,6 @@ App.MainAlertInstancesController = Em.Controller.extend({
           this.set('filteredContent', this.get('content'));
         }.observes('content.length'),
 
-        refreshTooltips: function () {
-          this.ensureTooltip();
-        }.observes('contents.[]', 'filteringComplete'),
-
-        ensureTooltip: function () {
-          Em.run.next(this, function () {
-            App.tooltip($(".timeago"));
-          });
-        },
         /**
          * Router transition to alert definition details page
          * @param event
@@ -354,8 +345,6 @@ App.MainAlertInstancesController = Em.Controller.extend({
 
         didInsertElement: function () {
           this.filter();
-          this.addObserver('filteringComplete', this, this.overlayObserver);
-          this.overlayObserver();
           return this._super();
         }
       })

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

@@ -21,7 +21,7 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({
   name: 'mainAlertDefinitionDetailsController',
 
   alerts: function () {
-    return App.AlertInstance.find().toArray()
+    return App.AlertInstanceLocal.find().toArray()
         .filterProperty('definitionId', this.get('content.id'));
   }.property('App.router.mainAlertInstancesController.isLoaded', 'App.router.mainAlertInstancesController.reload'),
 

+ 1 - 1
ambari-web/app/controllers/main/host/host_alerts_controller.js

@@ -30,7 +30,7 @@ App.MainHostAlertsController = Em.ArrayController.extend({
    * @type {App.AlertInstance[]}
    */
   content: function () {
-    return App.AlertInstance.find().toArray().filterProperty('host', this.get('selectedHost'));
+    return App.AlertInstanceLocal.find().toArray().filterProperty('host', this.get('selectedHost'));
   }.property('App.router.mainAlertInstancesController.isLoaded', 'selectedHost'),
 
   /**

+ 12 - 2
ambari-web/app/mappers/alert_instances_mapper.js

@@ -21,6 +21,8 @@ App.alertInstanceMapper = App.QuickDataMapper.create({
 
   model : App.AlertInstance,
 
+  modelLocal: App.AlertInstanceLocal,
+
   config : {
     id: 'Alert.id',
     label: 'Alert.label',
@@ -41,10 +43,17 @@ App.alertInstanceMapper = App.QuickDataMapper.create({
   },
 
   map: function(json) {
+    return this.parse(json, this.get('model'));
+  },
+
+  mapLocal: function(json) {
+    return this.parse(json, this.get('modelLocal'));
+  },
+
+  parse: function(json, model) {
     console.time('App.alertInstanceMapper execution time');
     if (json.items) {
       var alertInstances = [];
-      var model = this.get('model');
       var alertsToDelete = model.find().mapProperty('id');
 
       json.items.forEach(function (item) {
@@ -57,8 +66,9 @@ App.alertInstanceMapper = App.QuickDataMapper.create({
         model.find().clear();
       }
 
-      App.store.loadMany(this.get('model'), alertInstances);
+      App.store.loadMany(model, alertInstances);
       console.timeEnd('App.alertInstanceMapper execution time');
     }
   }
+
 });

+ 6 - 5
ambari-web/app/models.js

@@ -42,11 +42,12 @@ require('models/service/mapreduce2');
 require('models/service/hbase');
 require('models/service/flume');
 require('models/service/storm');
-require('models/alert_definition');
-require('models/alert_instance');
-require('models/alert_notification');
-require('models/alert_config');
-require('models/alert_group');
+require('models/alerts/alert_definition');
+require('models/alerts/alert_instance');
+require('models/alerts/alert_instance_local');
+require('models/alerts/alert_notification');
+require('models/alerts/alert_config');
+require('models/alerts/alert_group');
 require('models/user');
 require('models/host');
 require('models/rack');

+ 0 - 0
ambari-web/app/models/alert_config.js → ambari-web/app/models/alerts/alert_config.js


+ 0 - 0
ambari-web/app/models/alert_definition.js → ambari-web/app/models/alerts/alert_definition.js


+ 0 - 0
ambari-web/app/models/alert_group.js → ambari-web/app/models/alerts/alert_group.js


+ 0 - 0
ambari-web/app/models/alert_instance.js → ambari-web/app/models/alerts/alert_instance.js


+ 30 - 0
ambari-web/app/models/alerts/alert_instance_local.js

@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+/**
+ * Just a copy of <code>App.AlertInstance</code>, used to save separately alert instances for host and definition
+ * Sometimes alert instances can't be stored in the one model. Example: user is in the definition details page and open
+ * alerts popup. Different lists of instances should be shown and loaded. Also it's pretty hard to determine, which
+ * models should be removed from store, when user navigates in the popup or just leave the page
+ * @type {DS.Model}
+ */
+App.AlertInstanceLocal = App.AlertInstance.extend({});
+
+App.AlertInstanceLocal.FIXTURES = [];

+ 0 - 0
ambari-web/app/models/alert_notification.js → ambari-web/app/models/alerts/alert_notification.js


+ 1 - 1
ambari-web/app/views/main/alerts/definition_details_view.js

@@ -163,7 +163,7 @@ App.AlertInstanceServiceHostView = Em.View.extend({
    * Define whether show link for transition to service page
    */
   serviceIsLink: function () {
-    return App.Service.find().someProperty('serviceName', this.get('instance.service.serviceName'));
+    return App.get('services.all').contains(this.get('instance.service.serviceName'));
   }.property('instance.service.serviceName'),
 
   /**

+ 11 - 2
ambari-web/app/views/main/host/host_alerts_view.js

@@ -253,10 +253,15 @@ App.MainHostAlertsView = App.TableView.extend({
    * @method tooltipsUpdater
    */
   tooltipsUpdater: function () {
+    Em.run.once(this,this.tooltipsUpdaterOnce);
+  }.observes('pageContent.@each'),
+
+  tooltipsUpdaterOnce: function() {
+    var self = this;
     Em.run.next(this, function () {
-      App.tooltip($(".enable-disable-button, .timeago, .alert-text"));
+      App.tooltip(self.$(".enable-disable-button, .timeago, .alert-text"));
     });
-  }.observes('pageContent.@each'),
+  },
 
   /**
    * Run <code>clearFilter</code> in the each child filterView
@@ -268,6 +273,10 @@ App.MainHostAlertsView = App.TableView.extend({
         childView.clearFilter();
       }
     });
+  },
+
+  willDestroyElement: function() {
+    this.$(".enable-disable-button, .timeago, .alert-text").tooltip('destroy');
   }
 
 });

+ 1 - 1
ambari-web/test/models/alert_config_test.js → ambari-web/test/models/alerts/alert_config_test.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 
-require('models/alert_config');
+require('models/alerts/alert_config');
 
 var model;
 

+ 1 - 1
ambari-web/test/models/alert_definition_test.js → ambari-web/test/models/alerts/alert_definition_test.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 
-require('models/alert_definition');
+require('models/alerts/alert_definition');
 
 var model;
 

+ 1 - 1
ambari-web/test/models/alert_instance_test.js → ambari-web/test/models/alerts/alert_instance_test.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 
-require('models/alert_instance');
+require('models/alerts/alert_instance');
 
 var model;