cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [04/50] git commit: updated refs/heads/master to 0b83559
Date Wed, 29 Apr 2015 05:43:48 GMT
volume upload: fixed the UI after the change to move params to header.

Signed-off-by: Rajani Karuturi <rajanikaruturi@gmail.com>


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

Branch: refs/heads/master
Commit: da1d8f9dce524db33d61ce8427e288aa753478a2
Parents: dc870b5
Author: ramamurtis <ramamurti.subramanian@citrix.com>
Authored: Fri Feb 20 16:19:54 2015 +0530
Committer: Rajani Karuturi <rajanikaruturi@gmail.com>
Committed: Fri Feb 27 17:40:06 2015 +0530

----------------------------------------------------------------------
 .../debian/config/etc/init.d/cloud-early-config |  10 ++
 systemvm/scripts/config_ssl.sh                  |   9 ++
 ui/scripts/storage.js                           |  27 ++--
 ui/scripts/templates.js                         |  44 ++----
 ui/scripts/ui/dialog.js                         | 157 +++++++++++--------
 5 files changed, 136 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da1d8f9d/systemvm/patches/debian/config/etc/init.d/cloud-early-config
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/etc/init.d/cloud-early-config b/systemvm/patches/debian/config/etc/init.d/cloud-early-config
index 0edd11e..5b98a0c 100755
--- a/systemvm/patches/debian/config/etc/init.d/cloud-early-config
+++ b/systemvm/patches/debian/config/etc/init.d/cloud-early-config
@@ -1159,9 +1159,11 @@ setup_secstorage() {
   log_it "setting up apache2 for post upload of volume/template"
   a2enmod proxy
   a2enmod proxy_http
+  a2enmod headers
 
   SSL_FILE="/etc/apache2/sites-available/default-ssl"
   PATTERN="RewriteRule ^\/upload\/(.*)"
+  CORS_PATTERN="Header set Access-Control-Allow-Origin"
   if [ -f $SSL_FILE ]; then
     if grep -q "$PATTERN" $SSL_FILE ; then
       log_it "rewrite rules already exist in file $SSL_FILE"
@@ -1172,6 +1174,14 @@ setup_secstorage() {
         sed -i -e "s/<\/VirtualHost>/RewriteCond %{REQUEST_METHOD} =POST \n&/"
$SSL_FILE
         sed -i -e "s/<\/VirtualHost>/RewriteRule ^\/upload\/(.*) http:\/\/127.0.0.1:8210\/upload?uuid=\$1
[P,L] \n&/" $SSL_FILE
     fi
+    if grep -q "$CORS_PATTERN" $SSL_FILE ; then
+      log_it "cors rules already exist in file $SSL_FILE"
+    else
+        log_it "adding cors rules to file: $SSL_FILE"
+        sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Origin
\"*\" \n&/" $SSL_FILE
+        sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Methods
\"POST, OPTIONS\" \n&/" $SSL_FILE
+        sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Headers
\"x-requested-with, Content-Type, origin, authorization, accept, client-security-token, x-signature,
x-metadata, x-expires\" \n&/" $SSL_FILE
+    fi
   fi
 
   service apache2 restart

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da1d8f9d/systemvm/scripts/config_ssl.sh
----------------------------------------------------------------------
diff --git a/systemvm/scripts/config_ssl.sh b/systemvm/scripts/config_ssl.sh
index 8022b78..cd8059c 100755
--- a/systemvm/scripts/config_ssl.sh
+++ b/systemvm/scripts/config_ssl.sh
@@ -61,6 +61,7 @@ config_apache2_conf() {
 
   SSL_FILE="/etc/apache2/sites-available/default-ssl"
   PATTERN="RewriteRule ^\/upload\/(.*)"
+  CORS_PATTERN="Header set Access-Control-Allow-Origin"
   if [ -f $SSL_FILE ]; then
     if grep -q "$PATTERN" $SSL_FILE ; then
       echo "rewrite rules already exist in file $SSL_FILE"
@@ -71,6 +72,14 @@ config_apache2_conf() {
         sed -i -e "s/<\/VirtualHost>/RewriteCond %{REQUEST_METHOD} =POST \n&/"
$SSL_FILE
         sed -i -e "s/<\/VirtualHost>/RewriteRule ^\/upload\/(.*) http:\/\/127.0.0.1:8210\/upload?uuid=\$1
[P,L] \n&/" $SSL_FILE
     fi
+    if grep -q "$CORS_PATTERN" $SSL_FILE ; then
+      echo "cors rules already exist in file $SSL_FILE"
+    else
+        echo "adding cors rules to file: $SSL_FILE"
+        sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Origin
\"*\" \n&/" $SSL_FILE
+        sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Methods
\"POST, OPTIONS\" \n&/" $SSL_FILE
+        sed -i -e "s/<\/VirtualHost>/Header always set Access-Control-Allow-Headers
\"x-requested-with, Content-Type, origin, authorization, accept, client-security-token, x-signature,
x-metadata, x-expires\" \n&/" $SSL_FILE
+    fi
   fi
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da1d8f9d/ui/scripts/storage.js
----------------------------------------------------------------------
diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js
index 3ca19b3..68e3ec1 100644
--- a/ui/scripts/storage.js
+++ b/ui/scripts/storage.js
@@ -454,28 +454,25 @@
 
                                                 args.response.success({
                                                     url: uploadparams.postURL,
+                                                    ajaxPost: true,
                                                     data: {
-                                                        signature: uploadparams.signature,
-                                                        expires: uploadparams.expires,
-                                                        metadata: uploadparams.metadata
+                                                        'X-signature': uploadparams.signature,
+                                                        'X-expires': uploadparams.expires,
+                                                        'X-metadata': uploadparams.metadata
                                                     }
                                                 });
-                                                
-                                                cloudStack.dialog.notice({
-                                                    message: "This volume file has been uploaded.
Please check its status at Stroage menu > Volumes > " + args.data.name + " > Status
field."
-                                                });
                                             }
                                         });
                                     },
                                     postUpload: function(args) {
-                                        console.log("postUpload() is hit");
-                                        // Called when upload is done to do 
-                                        // verification checks;
-                                        // i.e., poll the server to verify successful upload
-                                        //
-                                        // success() will close the dialog and call standard
action
-                                        // error() will keep dialog open if user wants to
re-submit
-                                        args.response.success();
+                                        if(args.error) {
+                                            args.response.error(args.errorMsg);
+                                        } else {
+                                            cloudStack.dialog.notice({
+                                                message: "This volume file has been uploaded.
Please check its status at Stroage menu > Volumes > " + args.data.name + " > Status
field."
+                                            });
+                                            args.response.success();
+                                        }
                                     }
                                 },                                
                                 fields: {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da1d8f9d/ui/scripts/templates.js
----------------------------------------------------------------------
diff --git a/ui/scripts/templates.js b/ui/scripts/templates.js
index 4fe0944..c060a0c 100644
--- a/ui/scripts/templates.js
+++ b/ui/scripts/templates.js
@@ -636,48 +636,30 @@
                                             data: data,
                                             async: false,
                                             success: function(json) {                   
                            
-                                                /*                        						
-												{
-												    "postuploadtemplateresponse": {
-												        "getuploadparams": {
-												            "id": "d5bdaf23-dcb9-4eef-9b94-81870490f457",
-												            "postURL": "https://10.223.67.4/upload/d5bdaf23-dcb9-4eef-9b94-81870490f457",
-												            "metadata": "7jCvmzKuMBStM/qEjx9HjSAISd+f3VAUqC9CkYmq92O+SznYov415LUndZ4KuLAtGNY37VeePs8X+0oyaVSj+cjD+KKoBJuynjBJViAQQYKT/amcOdrkloBA4DgNEAn16p32Z2qI4+Ky1ecDAtg1vkYNoz9ReaKbehM3n5MIFPonhnYBEmbVSZkCIbVbJeh+vmYs9Y3SHtcG+0gWiU06YQ4KGl7Wc03wp3wusAlj7+L+fEBha54Rx+C7aS6UPZgm8/+atUUric6xiGMsx603NUElcLWE+gQ7PTimsIr6ySvcmc3D0n6JK6A7bc72sfPrHEbnNPD+5+qXJsBcXPLtEAG2WwduarwZ",
-												            "timeout": "2015-01-20T01:01:02.548Z",
-												            "signature": "NLXv5YsNuUn7NKC+ZP5JtSM26MY="
-												        }
-												    }
-												}
-                                                */
-
-                                                var uploadparams = json.postuploadtemplateresponse.getuploadparams;
//son.postuploadtemplateresponse.getuploadparams is an object, not an array of object.
+                                                var uploadparams = json.postuploadtemplateresponse.getuploadparams;
                                                 var templateId = uploadparams.id;
                                                
                                                 args.response.success({
                                                     url: uploadparams.postURL,
+                                                    ajaxPost: true,
                                                     data: {
-                                                        signature: uploadparams.signature,
-                                                        expires: uploadparams.timeout,
-                                                        metadata: uploadparams.metadata
+                                                        'X-signature': uploadparams.signature,
+                                                        'X-expires': uploadparams.expires,
+                                                        'X-metadata': uploadparams.metadata
                                                     }
                                                 });   
-                                                   
-                                                cloudStack.dialog.notice({ 
-                                                	message: "This template file has been uploaded.
Please check its status at Templates menu > " + args.data.name + " > Zones tab >
click a zone > Status field and Ready field."
-                                                });
-                                                
                                             }
                                         });                                        
                                     },
                                     postUpload: function(args) {
-                                        console.log("postUpload() is hit");
-                                        // Called when upload is done to do 
-                                        // verification checks;
-                                        // i.e., poll the server to verify successful upload
-                                        //
-                                        // success() will close the dialog and call standard
action
-                                        // error() will keep dialog open if user wants to
re-submit
-                                        args.response.success();
+                                        if(args.error) {
+                                            args.response.error(args.errorMsg);
+                                        } else {
+                                            cloudStack.dialog.notice({
+                                                message: "This template file has been uploaded.
Please check its status at Templates menu > " + args.data.name + " > Zones tab >
click a zone > Status field and Ready field."
+                                            });
+                                            args.response.success();
+                                        }
                                     }
                                 },
                                 fields: {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da1d8f9d/ui/scripts/ui/dialog.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js
index 86703d5..38d248d 100644
--- a/ui/scripts/ui/dialog.js
+++ b/ui/scripts/ui/dialog.js
@@ -690,76 +690,103 @@
                         context: args.context,
                         response: {
                             success: function(successArgs) {
-                                //
-                                // Move file field into iframe; keep visible for consistency
-                                //
-                                var $uploadFrame = $('<iframe>');
-                                var $frameForm = $('<form>').attr({
-                                    method: 'POST',
-                                    action: successArgs.url,
-                                    enctype: 'multipart/form-data'
-                                });
                                 var $file = $form.find('input[type=file]');
-                                var $field = $file.closest('.form-item .value');
-                                
-                                // Add additional passed data
-                                $.map(successArgs.data, function(v, k) {
-                                    var $hidden = $('<input>').attr({
-                                        type: 'hidden',
-                                        name: k,
-                                        value: v
+                                var postUploadArgs = {
+                                    $form: $form,
+                                    data: data,
+                                    context: args.context,
+                                    response: {
+                                        success: function() {
+                                            args.after({
+                                                data: data,
+                                                ref: args.ref, // For backwards compatibility;
use context
+                                                context: args.context,
+                                                $form: $form
+                                            });
+
+                                            $('div.overlay').remove();
+                                            $form.find('.loading-overlay').remove();
+                                            $('div.loading-overlay').remove();
+
+                                            $('.tooltip-box').remove();
+                                            $formContainer.remove();
+                                            $(this).dialog('destroy');
+
+                                            $('.hovered-elem').hide();
+                                        },
+                                        error: function(msg) {
+                                            $('div.overlay').remove();
+                                            $form.find('.loading-overlay').remove();
+                                            $('div.loading-overlay').remove();
+
+                                            cloudStack.dialog.error({ message: msg });
+                                        }
+                                    }
+                                };
+                                var postUploadArgsWithStatus = $.extend(true, {}, postUploadArgs);
+
+                                if(successArgs.ajaxPost) {
+                                    var request = new FormData();
+                                    request.append('file', $file.prop("files")[0]);
+                                    $.ajax({
+                                            type: 'POST',
+                                            url: successArgs.url,
+                                            data: request,
+                                            dataType : 'html',
+                                            processData: false,
+                                            contentType: false,
+                                            headers: successArgs.data,
+                                            success: function(r) {
+                                                postUploadArgsWithStatus.error = false;
+                                                args.form.fileUpload.postUpload(postUploadArgsWithStatus);
+                                            },
+                                            error: function(r) {
+                                                postUploadArgsWithStatus.error = true;
+                                                postUploadArgsWithStatus.errorMsg = r.responseText;
+                                                args.form.fileUpload.postUpload(postUploadArgsWithStatus);
+                                            }
+                                        });
+                                } else {
+                                    //
+                                    // Move file field into iframe; keep visible for consistency
+                                    //
+                                    var $uploadFrame = $('<iframe>');
+                                    var $frameForm = $('<form>').attr({
+                                        method: 'POST',
+                                        action: successArgs.url,
+                                        enctype: 'multipart/form-data'
                                     });
+                                    var $field = $file.closest('.form-item .value');
+
+                                    // Add additional passed data
+                                    $.map(successArgs.data, function(v, k) {
+                                        var $hidden = $('<input>').attr({
+                                            type: 'hidden',
+                                            name: k,
+                                            value: v
+                                        });
 
-                                    $hidden.appendTo($frameForm);
-                                });                                
-                                
-                                console.log("The following object is a hidden HTML form that
will submit local file with hidden field signature/expires/metadata:");
-                                console.log($frameForm);                                
-                                
-                                $uploadFrame.css({ width: $field.outerWidth(), height: $field.height()
}).show();
-                                $frameForm.append($file);
-                                $field.append($uploadFrame);
-                                $uploadFrame.contents().find('html body').append($frameForm);
-                                $frameForm.submit(function() {
-                                	console.log("callback() in $frameForm.submit(callback(){})
is triggered");
-                                    $uploadFrame.load(function() {
-                                    	console.log("callback() in $uploadFrame.load(callback(){})
is triggered");
-                                        args.form.fileUpload.postUpload({
-                                            $form: $form,
-                                            formData: data,
-                                            context: args.context,
-                                            response: {
-                                                success: function() {
-                                                    args.after({
-                                                        data: data,
-                                                        ref: args.ref, // For backwards compatibility;
use context
-                                                        context: args.context,
-                                                        $form: $form
-                                                    });
-
-                                                    $('div.overlay').remove();
-                                                    $form.find('.loading-overlay').remove();
-                                                    $('div.loading-overlay').remove();
-                                                    
-                                                    $('.tooltip-box').remove();
-                                                    $formContainer.remove();
-                                                    $(this).dialog('destroy');
-
-                                                    $('.hovered-elem').hide();
-                                                },
-                                                error: function(msg) {
-                                                	$('div.overlay').remove();
-                                                    $form.find('.loading-overlay').remove();
-                                                    $('div.loading-overlay').remove();
-                                                    
-                                                    cloudStack.dialog.error({ message: msg
});
-                                                }
-                                            }
+                                        $hidden.appendTo($frameForm);
+
+                                    });
+
+                                    console.log("The following object is a hidden HTML form
that will submit local file with hidden field signature/expires/metadata:");
+                                    console.log($frameForm);
+
+                                    $uploadFrame.css({ width: $field.outerWidth(), height:
$field.height() }).show();
+                                    $frameForm.append($file);
+                                    $field.append($uploadFrame);
+                                    $uploadFrame.contents().find('html body').append($frameForm);
+                                    $frameForm.submit(function() {
+                                        console.log("callback() in $frameForm.submit(callback(){})
is triggered");
+                                        $uploadFrame.load(function() {
+                                            console.log("callback() in $uploadFrame.load(callback(){})
is triggered");
+                                            args.form.fileUpload.postUpload(postUploadArgs);
                                         });
+                                        return true;
                                     });
-                                    return true;
-                                });
-                                $frameForm.submit();
+                                    $frameForm.submit();
+                                }
                             },
                             error: function(msg) {
                                 cloudStack.dialog.error({ message: msg });


Mime
View raw message