You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/08/07 13:56:53 UTC
[PATCH 1/2] Fixes for blob streaming GET /bucket/blob/content
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/deltacloud/collections/buckets.rb | 2 +-
server/lib/deltacloud/drivers/mock/mock_driver.rb | 3 +++
.../lib/deltacloud/helpers/blob_stream_helper.rb | 10 ++++------
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/server/lib/deltacloud/collections/buckets.rb b/server/lib/deltacloud/collections/buckets.rb
index b7b3729..bb2a805 100644
--- a/server/lib/deltacloud/collections/buckets.rb
+++ b/server/lib/deltacloud/collections/buckets.rb
@@ -258,7 +258,7 @@ module Deltacloud::Collections
@blob = driver.blob(credentials, { :id => params[:blob_id], 'bucket' => params[:id]})
if @blob
params['content_length'] = @blob.content_length
- params['content_type'] = @blob.content_type
+ params['content_type'] = (@blob.content_type.nil? || @blob.content_type == "")? "application/octet-stream" : @blob.content_type
params['content_disposition'] = "attachment; filename=#{@blob.id}"
BlobStream.call(self, credentials, params)
else
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 4249a95..2f0d7eb 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -388,6 +388,8 @@ module Deltacloud::Drivers::Mock
def blob_data(credentials, bucket_id, blob_id, opts = {})
check_credentials(credentials)
if blob = @client.load(:blobs, blob_id)
+ #give event machine a chance
+ sleep 1
blob[:content].split('').each {|part| yield part}
end
end
@@ -406,6 +408,7 @@ module Deltacloud::Drivers::Mock
:user_metadata => BlobHelper::rename_metadata_headers(blob_meta, ''),
}
if blob_data.kind_of? Hash
+ blob_data[:tempfile].rewind
blob.merge!({
:content_length => blob_data[:tempfile].length,
:content_type => blob_data[:type],
diff --git a/server/lib/deltacloud/helpers/blob_stream_helper.rb b/server/lib/deltacloud/helpers/blob_stream_helper.rb
index 8567543..dc1d230 100644
--- a/server/lib/deltacloud/helpers/blob_stream_helper.rb
+++ b/server/lib/deltacloud/helpers/blob_stream_helper.rb
@@ -25,10 +25,7 @@ begin
AsyncResponse = [-1, {}, []].freeze
def self.call(context, credentials, params)
body = DeferrableBody.new
- #Get the headers out asap. Don't specify a content-type let
- #the client guess and if they can't they SHOULD default to
- #'application/octet-stream' anyway as per:
- #http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1
+ #Get the headers out asap.
EM.next_tick { context.env['async.callback'].call [200, {
'Content-Type' => "#{params['content_type']}",
'Content-Disposition' => params["content_disposition"],
@@ -36,9 +33,9 @@ begin
}
#call the driver from here. the driver method yields for every chunk
#of blob it receives. Then use body.call to write that chunk as received.
- context.driver.blob_data(credentials, params[:id], params[:blob_id], params) {|chunk| body.call ["#{chunk}"]} #close blob_data block
+ context.driver.blob_data(credentials, params[:id], params[:blob_id], params) {|chunk| body.call [chunk]} #close blob_data block
body.succeed
- AsyncResponse # Tell Thin to not close connection & work other requests
+ AsyncResponse.dup # Tell Thin to not close connection & work other requests
end
end
@@ -54,6 +51,7 @@ begin
def each(&blk)
@body_callback = blk
end
+
end
rescue LoadError => e
# EventMachine isn't available, disable blob streaming
--
1.7.6.5
Re: [PATCH 1/2] Fixes for blob streaming GET /bucket/blob/content
Posted by David Lutterkort <lu...@redhat.com>.
On Tue, 2012-08-07 at 14:56 +0300, marios@redhat.com wrote:
> From: marios <ma...@redhat.com>
>
>
> Signed-off-by: marios <ma...@redhat.com>
> ---
> server/lib/deltacloud/collections/buckets.rb | 2 +-
> server/lib/deltacloud/drivers/mock/mock_driver.rb | 3 +++
> .../lib/deltacloud/helpers/blob_stream_helper.rb | 10 ++++------
> 3 files changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/server/lib/deltacloud/collections/buckets.rb b/server/lib/deltacloud/collections/buckets.rb
> index b7b3729..bb2a805 100644
> --- a/server/lib/deltacloud/collections/buckets.rb
> +++ b/server/lib/deltacloud/collections/buckets.rb
> @@ -258,7 +258,7 @@ module Deltacloud::Collections
> @blob = driver.blob(credentials, { :id => params[:blob_id], 'bucket' => params[:id]})
> if @blob
> params['content_length'] = @blob.content_length
> - params['content_type'] = @blob.content_type
> + params['content_type'] = (@blob.content_type.nil? || @blob.content_type == "")? "application/octet-stream" : @blob.content_type
> params['content_disposition'] = "attachment; filename=#{@blob.id}"
> BlobStream.call(self, credentials, params)
> else
> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> index 4249a95..2f0d7eb 100644
> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> @@ -388,6 +388,8 @@ module Deltacloud::Drivers::Mock
> def blob_data(credentials, bucket_id, blob_id, opts = {})
> check_credentials(credentials)
> if blob = @client.load(:blobs, blob_id)
> + #give event machine a chance
> + sleep 1
Why is this necessary ? Is there some event we can wait for instead of
sleeping ?
David
Re: [PATCH 2/2] API TESTS: restores streaming GET content test
Posted by Ronelle Landy <rl...@redhat.com>.
> From: marios@redhat.com
> To: dev@deltacloud.apache.org
> Sent: Tuesday, August 7, 2012 7:56:54 AM
> Subject: [PATCH 2/2] API TESTS: restores streaming GET content test
>
QE ACK on Patch 1/2 and 2/2 ... will restest with smaller number of blobs
> From: marios <ma...@redhat.com>
>
>
> Signed-off-by: marios <ma...@redhat.com>
> ---
> tests/deltacloud/buckets_test.rb | 1 -
> 1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/tests/deltacloud/buckets_test.rb
> b/tests/deltacloud/buckets_test.rb
> index 82e0e19..38fc120 100644
> --- a/tests/deltacloud/buckets_test.rb
> +++ b/tests/deltacloud/buckets_test.rb
> @@ -212,7 +212,6 @@ describe 'Deltacloud API buckets collection' do
> end
>
> it 'should be possible to GET blob data with GET
> /api/buckets/:id/blob/content' do
> -skip("SKIPPING THIS TEST FOR NOW - KNOWN ISSUE WITH GET CONTENT ON
> DELTACLOUD SIDE FIXME")
> res = get("#{BUCKETS}/#{@@my_bucket}/#{@@my_blob}/content")
> res.code.must_equal 200
> res.must_equal "This is the test blob content"
> --
> 1.7.6.5
>
>
[PATCH 2/2] API TESTS: restores streaming GET content test
Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
tests/deltacloud/buckets_test.rb | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/tests/deltacloud/buckets_test.rb b/tests/deltacloud/buckets_test.rb
index 82e0e19..38fc120 100644
--- a/tests/deltacloud/buckets_test.rb
+++ b/tests/deltacloud/buckets_test.rb
@@ -212,7 +212,6 @@ describe 'Deltacloud API buckets collection' do
end
it 'should be possible to GET blob data with GET /api/buckets/:id/blob/content' do
-skip("SKIPPING THIS TEST FOR NOW - KNOWN ISSUE WITH GET CONTENT ON DELTACLOUD SIDE FIXME")
res = get("#{BUCKETS}/#{@@my_bucket}/#{@@my_blob}/content")
res.code.must_equal 200
res.must_equal "This is the test blob content"
--
1.7.6.5