ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atk...@apache.org
Subject [1/2] ambari git commit: AMBARI-11715 Alert instances page: prevent removing all records from model. (atkach)
Date Fri, 05 Jun 2015 10:31:07 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 46c15e852 -> ed3d49a59


AMBARI-11715 Alert instances page: prevent removing all records from model. (atkach)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d6228723
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d6228723
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d6228723

Branch: refs/heads/trunk
Commit: d62287237b1a15b6b1852e242a46e43a1cfde6b0
Parents: 46c15e8
Author: Andrii Tkach <atkach@hortonworks.com>
Authored: Fri Jun 5 11:59:22 2015 +0300
Committer: Andrii Tkach <atkach@hortonworks.com>
Committed: Fri Jun 5 12:53:14 2015 +0300

----------------------------------------------------------------------
 .../main/alerts/alert_instances_controller.js   |   2 +-
 .../app/mappers/alert_instances_mapper.js       |  58 ++------
 .../test/mappers/alert_instances_mapper_test.js | 143 ++++++-------------
 3 files changed, 56 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d6228723/ambari-web/app/controllers/main/alerts/alert_instances_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/alert_instances_controller.js b/ambari-web/app/controllers/main/alerts/alert_instances_controller.js
index a55298f..391c326 100644
--- a/ambari-web/app/controllers/main/alerts/alert_instances_controller.js
+++ b/ambari-web/app/controllers/main/alerts/alert_instances_controller.js
@@ -169,7 +169,7 @@ App.MainAlertInstancesController = Em.Controller.extend({
    * @method getAlertInstancesSuccessCallback
    */
   getAlertInstancesSuccessCallback: function (json) {
-    App.alertInstanceMapper.map(json, true);
+    App.alertInstanceMapper.map(json);
     this.set('isLoaded', true);
     this.set('reload', !this.get('reload'));
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6228723/ambari-web/app/mappers/alert_instances_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_instances_mapper.js b/ambari-web/app/mappers/alert_instances_mapper.js
index 852ce71..eabc9f8 100644
--- a/ambari-web/app/mappers/alert_instances_mapper.js
+++ b/ambari-web/app/mappers/alert_instances_mapper.js
@@ -40,53 +40,23 @@ App.alertInstanceMapper = App.QuickDataMapper.create({
     text: 'Alert.text'
   },
 
-  map: function(json, skipDelete) {
+  map: function(json) {
     if (json.items) {
-      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);
+      var alertInstances = [];
+      var model = this.get('model');
+      var 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);
-    });
+      if (alertsToDelete.length > 0) {
+        model.find().clear();
+      }
 
-    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;
+      App.store.loadMany(this.get('model'), alertInstances);
+    }
   }
-
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/d6228723/ambari-web/test/mappers/alert_instances_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/alert_instances_mapper_test.js b/ambari-web/test/mappers/alert_instances_mapper_test.js
index 1cdab7f..2432749 100644
--- a/ambari-web/test/mappers/alert_instances_mapper_test.js
+++ b/ambari-web/test/mappers/alert_instances_mapper_test.js
@@ -18,7 +18,6 @@
 var App = require('app');
 
 require('mappers/alert_instances_mapper');
-var testHelpers = require('test/helpers');
 
 describe('App.alertInstanceMapper', function () {
 
@@ -29,123 +28,63 @@ describe('App.alertInstanceMapper', function () {
       {id: 4}
     ],
     json = {
-      "items" : [
+      "items": [
         {
-          "Alert" : {
-            "component_name" : "AMBARI_AGENT",
-            "host_name" : "c6401.ambari.apache.org",
-            "id" : 2,
-            "instance" : null,
-            "label" : "Ambari Agent Disk Usage",
-            "latest_timestamp" : 1415224354954,
-            "maintenance_state" : "OFF",
-            "name" : "ambari_agent_disk_usage",
-            "original_timestamp" : 1414695835400,
-            "scope" : "HOST",
-            "service_name" : "AMBARI",
-            "state" : "OK",
-            "text" : "Capacity Used: [1.26%, 6.6 GB], Capacity Total: [525.3 GB]"
+          "Alert": {
+            "component_name": "AMBARI_AGENT",
+            "host_name": "c6401.ambari.apache.org",
+            "id": 2,
+            "instance": null,
+            "label": "Ambari Agent Disk Usage",
+            "latest_timestamp": 1415224354954,
+            "maintenance_state": "OFF",
+            "name": "ambari_agent_disk_usage",
+            "original_timestamp": 1414695835400,
+            "scope": "HOST",
+            "service_name": "AMBARI",
+            "state": "OK",
+            "text": "Capacity Used: [1.26%, 6.6 GB], Capacity Total: [525.3 GB]"
           }
         },
         {
-          "Alert" : {
-            "component_name" : null,
-            "host_name" : null,
-            "id" : 3,
-            "instance" : null,
-            "label" : "Percent DataNodes Available",
-            "latest_timestamp" : 1415224362617,
-            "maintenance_state" : "OFF",
-            "name" : "datanode_process_percent",
-            "original_timestamp" : 1414695787466,
-            "scope" : "SERVICE",
-            "service_name" : "HDFS",
-            "state" : "CRITICAL",
-            "text" : "affected: [1], total: [1]"
+          "Alert": {
+            "component_name": null,
+            "host_name": null,
+            "id": 3,
+            "instance": null,
+            "label": "Percent DataNodes Available",
+            "latest_timestamp": 1415224362617,
+            "maintenance_state": "OFF",
+            "name": "datanode_process_percent",
+            "original_timestamp": 1414695787466,
+            "scope": "SERVICE",
+            "service_name": "HDFS",
+            "state": "CRITICAL",
+            "text": "affected: [1], total: [1]"
           }
         }
       ]
     };
 
-  beforeEach(function () {
-
-    sinon.stub(App.alertInstanceMapper, 'deleteRecord', Em.K);
-
-    sinon.stub(App.store, 'loadMany', function (type, content) {
-      type.content = content;
-    });
-
-    App.alertInstanceMapper.model = {
-      find: function () {
-        if (arguments.length) {
-          return alertInstances.findProperty('id', arguments[0]);
-        }
-        return alertInstances;
-      }
-    };
-
-  });
-
-  afterEach(function () {
-
-    App.alertInstanceMapper.deleteRecord.restore();
-    App.alertInstanceMapper.model = App.AlertInstance;
-    App.store.loadMany.restore();
-
-  });
-
-  it('should delete models', function () {
-
+  it('load new records', function () {
     App.alertInstanceMapper.map(json);
 
-    expect(App.alertInstanceMapper.deleteRecord.called).to.be.true;
-
+    expect(App.AlertInstance.find().content.length).to.equal(2);
   });
 
-  it('shouldn\'t delete not existing models', function () {
-
-    App.alertInstanceMapper.map(json, true);
-
-    expect(App.alertInstanceMapper.deleteRecord.called).to.be.false;
+  it('delete inexistent record', function () {
+    App.alertInstanceMapper.map({
+      items: [
+        json.items[0]
+      ]
+    });
 
+    expect(App.AlertInstance.find().content.length).to.equal(1);
   });
 
-  it('should map alert instances', function () {
-
-    var expected = [
-      {
-        "id": 2,
-        "label": "Ambari Agent Disk Usage",
-        "service_id": "AMBARI",
-        "component_name": "AMBARI_AGENT",
-        "host_id": "c6401.ambari.apache.org",
-        "scope": "HOST",
-        "original_timestamp": 1414695835400,
-        "latest_timestamp": 1415224354954,
-        "maintenance_state": "OFF",
-        "instance": null,
-        "state": "OK",
-        "text": "Capacity Used: [1.26%, 6.6 GB], Capacity Total: [525.3 GB]"
-      },
-      {
-        "id": 3,
-        "label": "Percent DataNodes Available",
-        "service_id": "HDFS",
-        "component_name": null,
-        "host_id": null,
-        "scope": "SERVICE",
-        "original_timestamp": 1414695787466,
-        "latest_timestamp": 1415224362617,
-        "maintenance_state": "OFF",
-        "instance": null,
-        "state": "CRITICAL",
-        "text": "affected: [1], total: [1]"
-      }
-    ];
-
-    App.alertInstanceMapper.map(json);
-    testHelpers.nestedExpect(expected, App.alertInstanceMapper.model.content);
+  it('model should be empty', function () {
+    App.alertInstanceMapper.map({items: []});
 
+    expect(App.AlertInstance.find().content).to.be.empty;
   });
-
 });


Mime
View raw message