deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [2/2] git commit: Fixes for blob streaming support - bugs/nits brought over with modular deltacloud
Date Tue, 12 Jun 2012 14:21:15 GMT
Fixes for blob streaming support - bugs/nits brought over
with modular deltacloud


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

Branch: refs/heads/master
Commit: 138adab3396ea95a41c8320058dd78bbac446b08
Parents: c3ec0da
Author: marios <marios@redhat.com>
Authored: Tue Jun 12 17:19:19 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Tue Jun 12 17:20:04 2012 +0300

----------------------------------------------------------------------
 server/lib/deltacloud/collections/buckets.rb       |   36 ++++++++++++++-
 .../lib/deltacloud/helpers/blob_stream_helper.rb   |    3 +-
 2 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/138adab3/server/lib/deltacloud/collections/buckets.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/buckets.rb b/server/lib/deltacloud/collections/buckets.rb
index 355d4d0..3282535 100644
--- a/server/lib/deltacloud/collections/buckets.rb
+++ b/server/lib/deltacloud/collections/buckets.rb
@@ -48,6 +48,40 @@ module Deltacloud::Collections
       end
     end
 
+    put route_for ("/buckets/:bucket/:blob") do
+      if(env["BLOB_SUCCESS"]) #ie got a 200ok after putting blob
+        content_type = env["CONTENT_TYPE"]
+        content_type ||=  ""
+        @blob = driver.blob(credentials, {:id => params[:blob],
+                                          'bucket' => params[:bucket]})
+        respond_to do |format|
+          format.xml { haml :"blobs/show" }
+          format.html { haml :"blobs/show" }
+          format.json { convert_to_json(:blob, @blob) }
+        end
+      elsif(env["BLOB_FAIL"])
+        report_error(500) #OK?
+      else # small blobs - < 112kb dont hit the streaming monkey patch - use 'normal'
create_blob
+        # also, if running under webrick don't hit the streaming patch (Thin specific)
+        bucket_id = params[:bucket]
+        blob_id = params[:blob]
+        temp_file = Tempfile.new("temp_blob_file")
+        temp_file.write(env['rack.input'].read)
+        temp_file.flush
+        content_type = env['CONTENT_TYPE'] || ""
+        blob_data = {:tempfile => temp_file, :type => content_type}
+        user_meta = BlobHelper::extract_blob_metadata_hash(request.env)
+        @blob = driver.create_blob(credentials, bucket_id, blob_id, blob_data, user_meta)
+        temp_file.delete
+        respond_to do |format|
+          format.xml { haml :"blobs/show" }
+          format.html { haml :"blobs/show" }
+          format.json { convert_to_json(:blob, @blob) }
+        end
+      end
+    end
+
+
     collection :buckets do
 
       standard_show_operation
@@ -201,7 +235,7 @@ module Deltacloud::Collections
           control do
             meta_hash = BlobHelper::extract_blob_metadata_hash(request.env)
             success = driver.update_blob_metadata(credentials, {'bucket'=>params[:id],
:id =>params[:blob_id], 'meta_hash' => meta_hash})
-            if(success)
+           if(success)
               meta_hash.each do |k,v|
                 headers["X-Deltacloud-Blobmeta-#{k}"] = v
               end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/138adab3/server/lib/deltacloud/helpers/blob_stream_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/blob_stream_helper.rb b/server/lib/deltacloud/helpers/blob_stream_helper.rb
index 08cafe2..8567543 100644
--- a/server/lib/deltacloud/helpers/blob_stream_helper.rb
+++ b/server/lib/deltacloud/helpers/blob_stream_helper.rb
@@ -149,7 +149,6 @@ require 'base64'
 class BlobStreamIO
 
   attr_accessor :size, :provider, :sock
-
   def initialize(request)
     @client_request = request
     @size = 0
@@ -159,7 +158,7 @@ class BlobStreamIO
     #deal with blob_metadata: (X-Deltacloud-Blobmeta-name: value)
     user_meta = BlobHelper::extract_blob_metadata_hash(request.env)
     @content_length = request.env['CONTENT_LENGTH']
-    @http, provider_request = driver.blob_stream_connection({:user=>user,
+    @http, provider_request = Deltacloud::API.driver.blob_stream_connection({:user=>user,
        :password=>password, :bucket=>bucket, :blob=>blob, :metadata=> user_meta,
        :content_type=>content_type, :content_length=>@content_length })
     @content_length = @content_length.to_i #for comparison of size in '<< (data)'


Mime
View raw message