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

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


The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714-ui 
by this push:
     new d2d1773  [AMBARI-22901] View Log feature for failed mpack downloads 
(#251)
d2d1773 is described below

commit d2d17731729d27f5219e2a0990e9ce3a8657eec5
Author: Jason Golieb <j...@golieb.net>
AuthorDate: Fri Feb 2 14:06:01 2018 -0500

    [AMBARI-22901] View Log feature for failed mpack downloads (#251)
    
    * Implemented "view log" feature for mpack downloads.
    
    * Removed .only
    
    * Fix typo.
---
 .../wizard/downloadMpacks_controller.js            | 43 +++++++++++++++++++---
 ambari-web/app/messages.js                         |  2 +
 ambari-web/app/styles/application.less             |  8 +++-
 ambari-web/app/templates/wizard/downloadMpacks.hbs |  7 ++++
 .../test/controllers/wizard/downloadMpacks_test.js | 43 +++++++++++++++++++++-
 5 files changed, 94 insertions(+), 9 deletions(-)

diff --git a/ambari-web/app/controllers/wizard/downloadMpacks_controller.js 
b/ambari-web/app/controllers/wizard/downloadMpacks_controller.js
index 717357e..08e85c1 100644
--- a/ambari-web/app/controllers/wizard/downloadMpacks_controller.js
+++ b/ambari-web/app/controllers/wizard/downloadMpacks_controller.js
@@ -36,7 +36,8 @@ App.WizardDownloadMpacksController = 
App.WizardStepController.extend({
         url: mpack.downloadUrl,
         inProgress: true,
         failed: false,
-        succeeded: false
+        succeeded: false,
+        failureMessage: null
       }));
     }, this);
   },
@@ -76,15 +77,45 @@ App.WizardDownloadMpacksController = 
App.WizardStepController.extend({
       this.get('mpacks').findProperty('name', params.name).set('succeeded', 
false);
       this.get('mpacks').findProperty('name', params.name).set('failed', true);
       this.get('mpacks').findProperty('name', params.name).set('inProgress', 
false);
+      
+      let failureMessage;
+      switch (request.status) {
+        case 400:
+        case 500:
+          failureMessage = request.statusText;
+          break;  
+        default:
+          failureMessage = 
Em.i18n.t('installer.downloadMpacks.failure.default');
+      }
+      
+      this.get('mpacks').findProperty('name', 
params.name).set('failureMessage', failureMessage);
     }
   },
 
   retryDownload: function (event) {
-    var mpack = event.context;
-    mpack.set('inProgress', true);
-    mpack.set('succeeded', false);
-    mpack.set('failed', false);
-    this.downloadMpack(mpack);
+    const mpack = event.context;
+    
+    if (mpack.get('failed')) {
+      mpack.set('inProgress', true);
+      mpack.set('succeeded', false);
+      mpack.set('failed', false);
+      this.downloadMpack(mpack);
+    }  
+  },
+
+  showError: function (event) {
+    const mpack = event.context;
+    
+    if (mpack.get('failed')) {
+      const error = mpack.get('failureMessage');
+      
+      App.ModalPopup.show({
+        header: `${Em.I18n.t('common.download')} 
${Em.I18n.t('common.failed')}`,
+        primary: Em.I18n.t('common.close'),
+        secondary: false,
+        body: error
+      });
+    }
   },
 
   getRegisteredMpacks: function () {
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index b7f7cfa..1c818e6 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -360,6 +360,7 @@ Em.I18n.translations = {
   'common.version':'Version',
   'common.versions':'Versions',
   'common.view': 'View',
+  'common.viewLog': 'View Log',
   'common.views': 'Views',
   'common.warn.message': '<div class="alert alert-warning">{0}</div>',
   'common.warning': 'Warning',
@@ -663,6 +664,7 @@ Em.I18n.translations = {
   'installer.downloadMpacks.header': 'Download Management Packs',
   'installer.downloadMpacks.body.title': 'Download and validate management 
packs',
   'installer.downloadMpacks.body.description': 'Ambari is downloading the 
management packs and validating their contents.',
+  'installer.downloadMpacks.failure.default': 'Downloading management pack 
failed for unknown reasons.',
   
   'installer.customProductRepos.header': 'Set Product Locations',
   'installer.customProductRepos.body.title': 'Customize product locations',
diff --git a/ambari-web/app/styles/application.less 
b/ambari-web/app/styles/application.less
index 535223c..c5d2243 100644
--- a/ambari-web/app/styles/application.less
+++ b/ambari-web/app/styles/application.less
@@ -2920,11 +2920,15 @@ td .no-data {
 }
 
 [data-toggle="tooltip"] [disabled] {
-    pointer-events: none;
+  pointer-events: none;
 }
 
 .retry-button:after {
-  content: '\f01e';    
+  content: '\f01e';
+}
+
+.viewLog-button:after {
+  content: '\f0f6';
 }
 
 .more-info {
diff --git a/ambari-web/app/templates/wizard/downloadMpacks.hbs 
b/ambari-web/app/templates/wizard/downloadMpacks.hbs
index 0f46c28..3eb8e0d 100644
--- a/ambari-web/app/templates/wizard/downloadMpacks.hbs
+++ b/ambari-web/app/templates/wizard/downloadMpacks.hbs
@@ -60,6 +60,13 @@
                   <button type="button" class="icon-button retry-button" 
disabled="disabled"></button>
                   {{/if}}
                 </span>
+                <span data-toggle="tooltip" data-placement="bottom" 
{{translateAttr title="common.viewLog" }}>
+                  {{#if mpack.failed}}
+                  <button type="button" class="icon-button viewLog-button" 
{{action showError mpack target="controller" }}></button>
+                  {{else}}
+                  <button type="button" class="icon-button viewLog-button" 
disabled="disabled"></button>
+                  {{/if}}
+                </span>
               </td>
             </tr>
           {{/each}}
diff --git a/ambari-web/test/controllers/wizard/downloadMpacks_test.js 
b/ambari-web/test/controllers/wizard/downloadMpacks_test.js
index 953445e..0fcc9c4 100644
--- a/ambari-web/test/controllers/wizard/downloadMpacks_test.js
+++ b/ambari-web/test/controllers/wizard/downloadMpacks_test.js
@@ -67,7 +67,7 @@ describe('App.WizardConfigureDownloadController', function () 
{
       controller.downloadMpackError({ status: 500 }, null, null, null, { name: 
'alpha' });
       var actual = controller.get('mpacks').objectAt(0);
 
-      expect(actual).to.deep.equal(expected);
+      expect(actual).to.deep.include(expected);
     });
 
     it('Sets succeeded to true, failed to false, and inProgress to false on 
409 response', function () {
@@ -84,4 +84,45 @@ describe('App.WizardConfigureDownloadController', function 
() {
       expect(actual).to.deep.equal(expected);
     });
   });
+
+  describe('#retryDownload', function () {
+    it('Retries the download and sets the status flags correctly if the 
download failed.', function () {
+      var expected = Em.Object.create({
+        succeeded: false,
+        failed: false,
+        inProgress: true
+      });
+
+      var actual = Em.Object.create({
+        succeeded: false,
+        failed: true,
+        inProgress: false
+      });
+
+      sinon.stub(controller, 'downloadMpack');
+
+      controller.retryDownload({ context: actual });
+
+      expect(actual).to.deep.equal(expected);
+      expect(controller.downloadMpack).to.be.called;
+
+      controller.downloadMpack.restore();
+    })
+  });
+
+  describe('#showError', function () {
+    it('Displays the error if the download failed.', function () {
+      var mpack = Em.Object.create({
+        failed: true
+      });
+
+      sinon.stub(App.ModalPopup, 'show');
+
+      controller.showError({ context: mpack });
+
+      expect(App.ModalPopup.show).to.be.called;
+
+      App.ModalPopup.show.restore();
+    })
+  });
 });
\ No newline at end of file

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

Reply via email to