You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jg...@apache.org on 2018/05/16 16:55:34 UTC

[ambari] 01/02: Do not repeatedly add same mpack to registered mpacks list.

This is an automated email from the ASF dual-hosted git repository.

jgolieb pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit 369bf9e26d9b906926b39feedaa98435ab0fe9e5
Author: Jason Golieb <jg...@hortonworks.com>
AuthorDate: Tue May 15 16:23:13 2018 -0700

    Do not repeatedly add same mpack to registered mpacks list.
---
 .../wizard/downloadMpacks_controller.js            | 19 ++++++++++------
 .../test/controllers/wizard/downloadMpacks_test.js | 26 ++++++++++++++++++++--
 2 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/ambari-web/app/controllers/wizard/downloadMpacks_controller.js b/ambari-web/app/controllers/wizard/downloadMpacks_controller.js
index 5eb63d4..72a7bce 100644
--- a/ambari-web/app/controllers/wizard/downloadMpacks_controller.js
+++ b/ambari-web/app/controllers/wizard/downloadMpacks_controller.js
@@ -94,13 +94,18 @@ App.WizardDownloadMpacksController = App.WizardStepController.extend({
   },
 
   loadMpackInfo: function (data) {
-    App.ajax.send({
-      name: 'mpack.get_registered_mpack',
-      sender: this,
-      data: {
-        id: data.resources[0].MpackInfo.id
-      }
-    }).then(mpackInfo => this.get('content.registeredMpacks').push(mpackInfo));
+    const id = data.resources[0].MpackInfo.id;
+    const registeredMpacks = this.get('content.registeredMpacks');
+    
+    if (!registeredMpacks.find(mpack => mpack.MpackInfo.id === id)) {
+      App.ajax.send({
+        name: 'mpack.get_registered_mpack',
+        sender: this,
+        data: {
+          id: id
+        }
+      }).then(mpackInfo => registeredMpacks.push(mpackInfo));
+    }  
   },
 
   retryDownload: function (event) {
diff --git a/ambari-web/test/controllers/wizard/downloadMpacks_test.js b/ambari-web/test/controllers/wizard/downloadMpacks_test.js
index 0fcc9c4..902e7c2 100644
--- a/ambari-web/test/controllers/wizard/downloadMpacks_test.js
+++ b/ambari-web/test/controllers/wizard/downloadMpacks_test.js
@@ -37,6 +37,7 @@ describe('App.WizardConfigureDownloadController', function () {
     ];
 
     controller.set('mpacks', mpacks);
+    controller.set('content', {});
   })
 
   describe('#downloadMpackSuccess', function () {
@@ -107,7 +108,7 @@ describe('App.WizardConfigureDownloadController', function () {
       expect(controller.downloadMpack).to.be.called;
 
       controller.downloadMpack.restore();
-    })
+    });
   });
 
   describe('#showError', function () {
@@ -123,6 +124,27 @@ describe('App.WizardConfigureDownloadController', function () {
       expect(App.ModalPopup.show).to.be.called;
 
       App.ModalPopup.show.restore();
-    })
+    });
+  });
+
+  describe.only('#loadMpackInfo', function () {
+    it('Adds mpackInfo to registered mpacks list only once.', function () {
+      controller.set('content.registeredMpacks', []);
+      var mpackInfo = { MpackInfo: { id: 1 } };
+      var expected = [mpackInfo];
+      
+      App.ajax.send.restore();
+      sinon.stub(App.ajax, 'send').returns({
+        then: function () {
+          controller.get('content.registeredMpacks').push(mpackInfo);
+        }
+      });
+
+      controller.loadMpackInfo({ resources: [mpackInfo] });
+      expect(controller.get('content.registeredMpacks')).to.deep.equal(expected);
+
+      controller.loadMpackInfo({ resources: [mpackInfo] });
+      expect(controller.get('content.registeredMpacks').length).to.equal(1);
+    });
   });
 });
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
jgolieb@apache.org.