ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [1/3] incubator-ignite git commit: # ignite-843 Added download on summary.
Date Fri, 10 Jul 2015 01:18:56 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 f444f66ed -> a0eaaacb0


# ignite-843 Added download on summary.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/3a1eba2e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/3a1eba2e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/3a1eba2e

Branch: refs/heads/ignite-843
Commit: 3a1eba2e7f0078c4fc08f96697b00cf9f0580bf4
Parents: 77caa75
Author: Andrey <anovikov@gridgain.com>
Authored: Thu Jul 9 18:31:09 2015 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Thu Jul 9 18:31:09 2015 +0700

----------------------------------------------------------------------
 .../nodejs/controllers/summary-controller.js    | 24 ++++++----
 modules/web-control-center/nodejs/package.json  |  2 +-
 .../nodejs/routes/generator/common.js           |  4 +-
 .../nodejs/routes/generator/docker.js           |  2 +-
 .../web-control-center/nodejs/routes/summary.js | 48 ++++++++++++++++++++
 .../nodejs/views/summary.jade                   | 14 ++++--
 6 files changed, 76 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a1eba2e/modules/web-control-center/nodejs/controllers/summary-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/controllers/summary-controller.js b/modules/web-control-center/nodejs/controllers/summary-controller.js
index 9e11f8d..1935739 100644
--- a/modules/web-control-center/nodejs/controllers/summary-controller.js
+++ b/modules/web-control-center/nodejs/controllers/summary-controller.js
@@ -30,7 +30,7 @@ controlCenterModule.controller('summaryController', ['$scope', '$http',
function
 
     $scope.generated = undefined;
 
-    $http.post('/configuration/clusters/list').success(function (data) {
+    $http.post('clusters/list').success(function (data) {
         $scope.clusters = data.clusters;
     });
 
@@ -54,7 +54,7 @@ controlCenterModule.controller('summaryController', ['$scope', '$http',
function
 
         $scope.loading = true;
 
-        $http.post('/configuration/summary/generator', {_id: $scope.selectedItem._id})
+        $http.post('summary/generator', {_id: $scope.selectedItem._id})
             .success(function (data) {
                 $scope.generated = data;
 
@@ -70,17 +70,23 @@ controlCenterModule.controller('summaryController', ['$scope', '$http',
function
     };
 
     $scope.download = function() {
-        var file = document.createElement('a');
+        $http.post('summary/download', {_id: $scope.selectedItem._id, javaClass: $scope.javaClass,
os: $scope.os})
+            .success(function (data) {
+                var file = document.createElement('a');
 
-        file.setAttribute('href', 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(text));
-        file.setAttribute('download', $scope.selectedItem.name + '-configuration.zip');
+                file.setAttribute('href', 'data:application/octet-stream;charset=utf-8,'
+ data);
+                file.setAttribute('download', $scope.selectedItem.name + '-configuration.zip');
 
-        file.style.display = 'none';
+                file.style.display = 'none';
 
-        document.body.appendChild(file);
+                document.body.appendChild(file);
 
-        file.click();
+                file.click();
 
-        document.body.removeChild(file);
+                document.body.removeChild(file);
+            })
+            .error(function (data) {
+                $scope.generateError = "Failed to generate zip: " + data;
+            });
     };
 }]);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a1eba2e/modules/web-control-center/nodejs/package.json
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/package.json b/modules/web-control-center/nodejs/package.json
index 9cb3744..82a3906 100644
--- a/modules/web-control-center/nodejs/package.json
+++ b/modules/web-control-center/nodejs/package.json
@@ -9,7 +9,7 @@
   "author": "Ignite",
   "license": "Apache License, Version 2.0",
   "dependencies": {
-    "adm-zip": "^0.4.7",
+    "archiver": "^0.14.4",
     "body-parser": "~1.12.0",
     "connect-flash": "^0.1.1",
     "connect-mongo": "^0.8.1",

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a1eba2e/modules/web-control-center/nodejs/routes/generator/common.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/routes/generator/common.js b/modules/web-control-center/nodejs/routes/generator/common.js
index 42af90d..716d18b 100644
--- a/modules/web-control-center/nodejs/routes/generator/common.js
+++ b/modules/web-control-center/nodejs/routes/generator/common.js
@@ -261,7 +261,7 @@ exports.toJavaName = function(name) {
  * @returns {string} Generated content.
  */
 exports.generateProperties = function(cluster) {
-    var res = builder();
+    var res = exports.builder();
 
     var datasources = [];
 
@@ -290,5 +290,5 @@ exports.generateProperties = function(cluster) {
     if (datasources.length > 0)
         return '# ' + mainComment() + '\n\n' + res.join();
 
-    return '';
+    return undefined;
 };

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a1eba2e/modules/web-control-center/nodejs/routes/generator/docker.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/routes/generator/docker.js b/modules/web-control-center/nodejs/routes/generator/docker.js
index 9ea917d..93faf8e 100644
--- a/modules/web-control-center/nodejs/routes/generator/docker.js
+++ b/modules/web-control-center/nodejs/routes/generator/docker.js
@@ -20,7 +20,7 @@ exports.generateClusterConfiguration = function(cluster, os) {
         os = 'debian:8';
 
     return "" +
-        "# Start from a Debian image.\n"+
+        "# Start from a OS image.\n"+
         "FROM " + os + "\n"+
         "\n"+
         "# Install tools.\n"+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a1eba2e/modules/web-control-center/nodejs/routes/summary.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/routes/summary.js b/modules/web-control-center/nodejs/routes/summary.js
index 9724708..884c78c 100644
--- a/modules/web-control-center/nodejs/routes/summary.js
+++ b/modules/web-control-center/nodejs/routes/summary.js
@@ -46,4 +46,52 @@ router.post('/generator', function(req, res) {
     });
 });
 
+router.post('/download', function(req, res) {
+    // Get cluster.
+    db.Cluster.findById(req.body._id).populate('caches').exec(function (err, cluster) {
+        if (err)
+            return res.status(500).send(err.message);
+
+        if (!cluster)
+            return res.sendStatus(404);
+
+        var archiver = require('archiver');
+
+        // creating archives
+        var zip = archiver('zip');
+
+        zip.on('error', function(err) {
+            res.status(500).send({error: err.message});
+        });
+
+        //on stream closed we can end the request
+        res.on('close', function() {
+            console.log('Archive wrote %d bytes', archive.pointer());
+
+            return res.status(200).send('OK').end();
+        });
+
+        //set the archive name
+        res.attachment(cluster.name + '-configuration.zip');
+
+        var generatorCommon = require('./generator/common');
+
+        var javaClass = req.body.javaClass;
+
+        // Send the file to the page output.
+        zip.pipe(res);
+
+        var props = generatorCommon.generateProperties(cluster);
+
+        if (props)
+            zip.append(props, {name: "secret.properties"});
+
+        zip.append(generatorXml.generateClusterConfiguration(cluster), {name: cluster.name
+ ".xml"})
+            .append(generatorJava.generateClusterConfiguration(cluster, req.body.javaClass),
+                {name: javaClass ? 'ConfigurationFactory.java' : cluster.name + '.snipplet.java'})
+            .append(generatorDocker.generateClusterConfiguration(cluster, req.body.os), {name:
"Dockerfile"})
+            .finalize();
+    });
+});
+
 module.exports = router;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a1eba2e/modules/web-control-center/nodejs/views/summary.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/summary.jade b/modules/web-control-center/nodejs/views/summary.jade
index 54d8395..c2ac0d3 100644
--- a/modules/web-control-center/nodejs/views/summary.jade
+++ b/modules/web-control-center/nodejs/views/summary.jade
@@ -62,19 +62,23 @@ block content
                         a(href, ng-click='cfgLang = "docker"')
                             img(src='/images/docker.png', width='16px' height='16px')
                             |  Dockerfile
-                .settings-row
+                form.settings-row(method='post' action='summary/download')
+                    input(type="hidden" name="_id" value="{{selectedItem._id}}")
+                    input(type="hidden" name="javaClass" value="{{javaClass}}")
+                    input(type="hidden" name="os" value="{{os}}")
+
                     #xmlResult(ng-show="cfgLang == 'xml'")
-                        button.btn.btn-primary.pull-right(style='margin-right: 0px;margin-top:
-45px' ng-click='download(xmlData, selectedItem.name + ".xml")') Download
+                        button.btn.btn-primary.pull-right(style='margin-right: 0px;margin-top:
-45px' type='submit') Download
                         #xmlResultDiv
                     #javaResult(ng-show="cfgLang == 'java'")
                         .col-sm-1
                             label Generate:
                         .col-sm-3
-                            button.form-control(ng-model='javaClass' bs-select data-placeholder='{{detail.placeholder}}'
bs-options='item.value as item.label for item in javaClassItems' data-sort='false')
-                        button.btn.btn-primary.pull-right(style='margin-right: 0px;margin-top:
-40px' ng-click='downloadJava()') Download
+                            button.form-control(type='button' ng-model='javaClass' bs-select
data-placeholder='{{detail.placeholder}}' bs-options='item.value as item.label for item in
javaClassItems' data-sort='false')
+                        button.btn.btn-primary.pull-right(style='margin-right: 0px;margin-top:
-40px' type='submit') Download
                         #javaResultDiv
                     #dockerResult(ng-show="cfgLang == 'docker'")
-                        button.btn.btn-primary.pull-right(style='margin-right: 0px;margin-top:
-40px' ng-click='downloadDocker()') Download
+                        button.btn.btn-primary.pull-right(style='margin-right: 0px;margin-top:
-40px' type='submit') Download
                         p
                             a(style='color:#ec1c24' href='https://docs.docker.com/reference/builder'
target="_blank") Docker
                             | &nbsp;file is a text file with instructions to create Docker
image.<br/>


Mime
View raw message