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

atkach pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 80fd0a3  AMBARI-23528 Usability: Generate blueprint should download a 
single Zip file and not 2 files.
80fd0a3 is described below

commit 80fd0a3d18d280c8f8f9a2245676e15b0d103535
Author: Andrii Tkach <atk...@apache.org>
AuthorDate: Tue Apr 10 18:03:01 2018 +0300

    AMBARI-23528 Usability: Generate blueprint should download a single Zip 
file and not 2 files.
---
 .../app/controllers/wizard/step8_controller.js     | 22 +++++++++++++++-------
 ambari-web/app/utils/file_utils.js                 | 18 ++++++++++++++++++
 ambari-web/brunch-config.js                        |  3 ++-
 ambari-web/test/controllers/wizard/step8_test.js   |  6 ++++++
 ambari-web/vendor/scripts/jszip.min.js             | 15 +++++++++++++++
 5 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/ambari-web/app/controllers/wizard/step8_controller.js 
b/ambari-web/app/controllers/wizard/step8_controller.js
index 2d9f4d2..261914d 100644
--- a/ambari-web/app/controllers/wizard/step8_controller.js
+++ b/ambari-web/app/controllers/wizard/step8_controller.js
@@ -1865,7 +1865,6 @@ App.WizardStep8Controller = 
Em.Controller.extend(App.AddSecurityConfigs, App.wiz
 
   generateBlueprint: function () {
     console.log("Prepare blueprint for download...");
-    var blueprint = {};
     var self = this;
     //service configurations
     var totalConf = [];
@@ -2005,15 +2004,13 @@ App.WizardStep8Controller = 
Em.Controller.extend(App.AddSecurityConfigs, App.wiz
       }, this);
     }, this);
 
-    var selectedStack = App.Stack.find().findProperty('isSelected', true);
-    blueprint = {
+    const selectedStack = App.Stack.find().findProperty('isSelected', true);
+    const blueprint = {
         'configurations': totalConf,
         'host_groups': host_groups.filter(function (item) { return 
item.cardinality > 0; }),
         'Blueprints': {'blueprint_name' : App.clusterStatus.clusterName, 
'stack_name':selectedStack.get('stackName'), 
'stack_version':selectedStack.get('stackVersion')}
     };
-    fileUtils.downloadTextFile(JSON.stringify(blueprint), 'json', 
'blueprint.json')
-
-    var cluster_template = {
+    const cluster_template = {
       "blueprint": App.clusterStatus.clusterName,
       "config_recommendation_strategy" : "NEVER_APPLY",
       "provision_action" : "INSTALL_AND_START",
@@ -2021,7 +2018,18 @@ App.WizardStep8Controller = 
Em.Controller.extend(App.AddSecurityConfigs, App.wiz
       "host_groups": cluster_template_host_groups.filter(function (item) { 
return item.hosts.length > 0; }),
       "Clusters": {'cluster_name': App.clusterStatus.clusterName}
     };
-    fileUtils.downloadTextFile(JSON.stringify(cluster_template), 'json', 
'clustertemplate.json')
+    fileUtils.downloadFilesInZip([
+      {
+        data: JSON.stringify(blueprint),
+        type: 'json',
+        name: 'blueprint.json'
+      },
+      {
+        data: JSON.stringify(cluster_template),
+        type: 'json',
+        name: 'clustertemplate.json'
+      }
+    ]);
   },
 
   downloadCSV: function() {
diff --git a/ambari-web/app/utils/file_utils.js 
b/ambari-web/app/utils/file_utils.js
index 34a33b9..367f1c4 100644
--- a/ambari-web/app/utils/file_utils.js
+++ b/ambari-web/app/utils/file_utils.js
@@ -47,6 +47,24 @@ module.exports = {
   },
 
   /**
+   * download multiple files archived in ZIP
+   * @param {object[]} files
+   */
+  downloadFilesInZip: function(files) {
+    const zip = new JSZip();
+    for (const file of files) {
+      const blob = new Blob([file.data], {
+        type: (this.fileTypeMap[file.type] || 'text/' + file.type) + 
';charset=utf-8;'
+      });
+      zip.file(file.name, blob);
+    }
+    zip.generateAsync({type:"blob"})
+      .then(function(content) {
+        saveAs(content, "blueprint.zip");
+      });
+  },
+
+  /**
    * open content of text file in new window
    * @param data {String}
    */
diff --git a/ambari-web/brunch-config.js b/ambari-web/brunch-config.js
index c8bed9c..f0a8802 100644
--- a/ambari-web/brunch-config.js
+++ b/ambari-web/brunch-config.js
@@ -85,7 +85,8 @@ module.exports.config = {
           'vendor/scripts/pluralize.js',
           'vendor/scripts/sockjs.min.js',
           'vendor/scripts/stomp.min.js',
-          'vendor/scripts/theme/bootstrap-ambari.js'
+          'vendor/scripts/theme/bootstrap-ambari.js',
+          'vendor/scripts/theme/jszip.min.js'
         ]
       }
     },
diff --git a/ambari-web/test/controllers/wizard/step8_test.js 
b/ambari-web/test/controllers/wizard/step8_test.js
index 22bcf96..683ab6b 100644
--- a/ambari-web/test/controllers/wizard/step8_test.js
+++ b/ambari-web/test/controllers/wizard/step8_test.js
@@ -22,6 +22,7 @@ require('controllers/main/service/info/configs');
 require('controllers/wizard/step8_controller');
 var installerStep8Controller;
 var testHelpers = require('test/helpers');
+var fileUtils = require('utils/file_utils');
 
 var configs = Em.A([
   Em.Object.create({filename: 'hdfs-site.xml', name: 'p1', value: 'v1'}),
@@ -2390,6 +2391,10 @@ describe('App.WizardStep8Controller', function () {
        sinon.spy(installerStep8Controller, 
'getConfigurationDetailsForConfigType');
        sinon.spy(installerStep8Controller, 'hostInExistingHostGroup');
        sinon.spy(installerStep8Controller, 'hostInChildHostGroup');
+       sinon.stub(fileUtils, 'downloadFilesInZip');
+     });
+     afterEach(function() {
+       fileUtils.downloadFilesInZip.restore();
      });
      it('should call generateBlueprint', function() {
        installerStep8Controller.generateBlueprint();
@@ -2397,6 +2402,7 @@ describe('App.WizardStep8Controller', function () {
        
sinon.assert.callCount(installerStep8Controller.getConfigurationDetailsForConfigType,
 4);
        
sinon.assert.callCount(installerStep8Controller.hostInExistingHostGroup, 4);
        sinon.assert.callCount(installerStep8Controller.hostInChildHostGroup, 
1);
+       expect(fileUtils.downloadFilesInZip.calledOnce).to.be.true;
      });
  });
 });
diff --git a/ambari-web/vendor/scripts/jszip.min.js 
b/ambari-web/vendor/scripts/jszip.min.js
new file mode 100644
index 0000000..b918873
--- /dev/null
+++ b/ambari-web/vendor/scripts/jszip.min.js
@@ -0,0 +1,15 @@
+/*!
+
+JSZip v3.1.5 - A JavaScript class for generating and reading zip files
+<http://stuartk.com/jszip>
+
+(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
+Dual licenced under the MIT license or GPLv3. See 
https://raw.github.com/Stuk/jszip/master/LICENSE.markdown.
+
+JSZip uses the library pako released under the MIT license :
+https://github.com/nodeca/pako/blob/master/LICENSE
+*/
+!function(a){if("object"==typeof exports&&"undefined"!=typeof 
module)module.exports=a();else if("function"==typeof 
define&&define.amd)define([],a);else{var b;b="undefined"!=typeof 
window?window:"undefined"!=typeof global?global:"undefined"!=typeof 
self?self:this,b.JSZip=a()}}(function(){return function a(b,c,d){function 
e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof 
require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new 
Error("Cannot find module '"+g+"'");throw j.cod [...]
+return b}var 
i=a("./support"),j=a("./base64"),k=a("./nodejsUtils"),l=a("core-js/library/fn/set-immediate"),m=a("./external");c.newBlob=function(a,b){c.checkSupport("blob");try{return
 new Blob([a],{type:b})}catch(d){try{var 
e=self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder,f=new
 e;return f.append(a),f.getBlob(b)}catch(d){throw new Error("Bug : can't 
construct the Blob.")}}};var n={stringifyByChunk:function(a,b,c){var 
d=[],e=0,f=a.length;if(f<=c)return Str [...]
+}b.exports=d},{}],65:[function(a,b,c){"use 
strict";b.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],66:[function(a,b,c){"use
 strict";function  [...]
+c=a.heap_max+1;c<V;c++)d=a.heap[c],f=i[2*i[2*d+1]+1]+1,f>o&&(f=o,p++),i[2*d+1]=f,d>j||(a.bl_count[f]++,g=0,d>=n&&(g=m[d-n]),h=i[2*d],a.opt_len+=h*(f+g),l&&(a.static_len+=h*(k[2*d+1]+g)));if(0!==p){do{for(f=o-1;0===a.bl_count[f];)f--;a.bl_count[f]--,a.bl_count[f+1]+=2,a.bl_count[o]--,p-=2}while(p>0);for(f=o;0!==f;f--)for(d=a.bl_count[f];0!==d;)e=a.heap[--c],e>j||(i[2*e+1]!==f&&(a.opt_len+=(f-i[2*e+1])*i[2*e],i[2*e+1]=f),d--)}}function
 n(a,b,c){var d,e,f=new Array(W+1),g=0;for(d=1;d<=W;d++ [...]
\ No newline at end of file

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

Reply via email to