You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2010/12/07 12:40:40 UTC

[PATCH core 1/3] Added warning for unhandled exception. This will show just 'visible' message to developer, that he needs to 'catch' this exception and display it as an XML error to client instead of throwing that exception to system log.

From: Michal Fojtik <mf...@redhat.com>

---
 server/lib/deltacloud/base_driver/base_driver.rb |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
index 4419359..ebd2078 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -256,6 +256,9 @@ module Deltacloud
         catched_exceptions_list[:glob].each do |ex|
           raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if e.class.name =~ ex
         end
+        puts "======= UNHANDLED EXCEPTION ============"
+        puts e.inspect
+        puts "========================================"
         raise e
       end
     end
-- 
1.7.3.2


[PATCH core 2/3] Added safely..do block for Blobs in EC2 driver

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index a7a9dbb..7960865 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -398,8 +398,10 @@ class EC2Driver < Deltacloud::BaseDriver
 #--
   def blob_data(credentials, bucket_id, blob_id, opts)
     s3_client = s3_client(credentials)
-    s3_client.interface.get(bucket_id, blob_id) do |chunk|
-      yield chunk
+    safely do
+      s3_client.interface.get(bucket_id, blob_id) do |chunk|
+        yield chunk
+      end
     end
   end
 
@@ -410,15 +412,17 @@ class EC2Driver < Deltacloud::BaseDriver
     s3_client = s3_client(credentials)
     #data is a construct with the temporary file created by server @.tempfile
     #also file[:type] will give us the content-type
-    res = s3_client.interface.put(bucket_id, blob_id, data[:tempfile], {"Content-Type" => data[:type]})
-    #create a new Blob object and return that
-    Blob.new( { :id => blob_id,
+    safely do
+      res = s3_client.interface.put(bucket_id, blob_id, data[:tempfile], {"Content-Type" => data[:type]})
+      #create a new Blob object and return that
+      Blob.new( { :id => blob_id,
                 :bucket => bucket_id,
                 :content_length => data[:tempfile].length,
                 :content_type => data[:type],
                 :last_modified => ''
               }
             )
+    end
   end
 
 #--
@@ -426,7 +430,9 @@ class EC2Driver < Deltacloud::BaseDriver
 #--  
   def delete_blob(credentials, bucket_id, blob_id, opts=nil)
     s3_client = s3_client(credentials)
-    s3_client.interface.delete(bucket_id, blob_id)
+    safely do
+      s3_client.interface.delete(bucket_id, blob_id)
+    end
   end
 
   def load_balancer(credentials, opts={})
@@ -656,8 +662,8 @@ class EC2Driver < Deltacloud::BaseDriver
   def catched_exceptions_list
     {
       :auth => [ AWS::AuthFailure ],
-      :error => [],
-      :glob => [ /AWS::(\w+)/ ]
+      :error => [ RightAws::AwsError ],
+      :glob => [ /.*AWS::(\w+)/ ]
     }
   end
 
-- 
1.7.3.2


[PATCH core 3/3] Added Content-Disposition header for blob, so client can identify content that server is streaming

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

---
 server/lib/deltacloud/helpers/blob_stream.rb |    6 +++++-
 server/server.rb                             |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/helpers/blob_stream.rb b/server/lib/deltacloud/helpers/blob_stream.rb
index 45fdbef..a99e6c2 100644
--- a/server/lib/deltacloud/helpers/blob_stream.rb
+++ b/server/lib/deltacloud/helpers/blob_stream.rb
@@ -28,7 +28,11 @@ begin
       #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
-      EM.next_tick { env['async.callback'].call [200, {'Content-Type' => "#{params['content_type']}", 'Content-Length' => "#{params['content_length']}"}, body] }
+      EM.next_tick { env['async.callback'].call [200, {
+        'Content-Type' => "#{params['content_type']}",
+        'Content-Disposition' => params["content_disposition"],
+        'Content-Length' => "#{params['content_length']}"}, body] 
+      }
       #call the driver from here. the driver method yields for every chunk of blob it receives. We then
       #use body.call to write that chunk as received.
       driver.blob_data(credentials, params[:bucket], params[:blob], params) {|chunk| body.call ["#{chunk}"]} #close blob_data block
diff --git a/server/server.rb b/server/server.rb
index 076859d..a3e2289 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -516,6 +516,7 @@ get '/api/buckets/:bucket/:blob/content' do
   @blob = driver.blob(credentials, { :id => params[:blob], 'bucket' => params[:bucket]})
   params['content_length'] = @blob.content_length
   params['content_type'] = @blob.content_type
+  params['content_disposition'] = "attachment; filename=#{@blob.id}"
   BlobStream.call(env, credentials, params)
 end
 
-- 
1.7.3.2


Re: [PATCH core 1/3] Added warning for unhandled exception. This will show just 'visible' message to developer, that he needs to 'catch' this exception and display it as an XML error to client instead of throwing that exception to system log.

Posted by Michal Fojtik <mf...@redhat.com>.
On 07/12/10 16:12 +0200, marios@redhat.com wrote:
>ack to all 3,
>
>apply fine and all working ok. Only just noticed the 
>'catched_exception_list' mechanism, this is very nice - didn't 
>realise we could define these per driver (i think so far we only have 
>this for ec2).

Yes, it's here from August ;-) and it's really a nice way howto deal with
various exceptions from backend (it's connected with safely..do) and then
report these exceptions to client.

   -- Michal

>
>marios
>On 07/12/10 13:40, mfojtik@redhat.com wrote:
>>From: Michal Fojtik<mf...@redhat.com>
>>
>>---
>>  server/lib/deltacloud/base_driver/base_driver.rb |    3 +++
>>  1 files changed, 3 insertions(+), 0 deletions(-)
>>
>>diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
>>index 4419359..ebd2078 100644
>>--- a/server/lib/deltacloud/base_driver/base_driver.rb
>>+++ b/server/lib/deltacloud/base_driver/base_driver.rb
>>@@ -256,6 +256,9 @@ module Deltacloud
>>          catched_exceptions_list[:glob].each do |ex|
>>            raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if e.class.name =~ ex
>>          end
>>+        puts "======= UNHANDLED EXCEPTION ============"
>>+        puts e.inspect
>>+        puts "========================================"
>>          raise e
>>        end
>>      end
>

-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

Re: [PATCH core 1/3] Added warning for unhandled exception. This will show just 'visible' message to developer, that he needs to 'catch' this exception and display it as an XML error to client instead of throwing that exception to system log.

Posted by Michal Fojtik <mf...@redhat.com>.
On 07/12/10 16:12 +0200, marios@redhat.com wrote:
>ack to all 3,

Thanks for review!. Pushing to master.

  -- Michal

>
>apply fine and all working ok. Only just noticed the 
>'catched_exception_list' mechanism, this is very nice - didn't 
>realise we could define these per driver (i think so far we only have 
>this for ec2).
>
>marios
>On 07/12/10 13:40, mfojtik@redhat.com wrote:
>>From: Michal Fojtik<mf...@redhat.com>
>>
>>---
>>  server/lib/deltacloud/base_driver/base_driver.rb |    3 +++
>>  1 files changed, 3 insertions(+), 0 deletions(-)
>>
>>diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
>>index 4419359..ebd2078 100644
>>--- a/server/lib/deltacloud/base_driver/base_driver.rb
>>+++ b/server/lib/deltacloud/base_driver/base_driver.rb
>>@@ -256,6 +256,9 @@ module Deltacloud
>>          catched_exceptions_list[:glob].each do |ex|
>>            raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if e.class.name =~ ex
>>          end
>>+        puts "======= UNHANDLED EXCEPTION ============"
>>+        puts e.inspect
>>+        puts "========================================"
>>          raise e
>>        end
>>      end
>

-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

Re: [PATCH core 1/3] Added warning for unhandled exception. This will show just 'visible' message to developer, that he needs to 'catch' this exception and display it as an XML error to client instead of throwing that exception to system log.

Posted by "marios@redhat.com" <ma...@redhat.com>.
ack to all 3,

apply fine and all working ok. Only just noticed the 
'catched_exception_list' mechanism, this is very nice - didn't realise 
we could define these per driver (i think so far we only have this for ec2).

marios
On 07/12/10 13:40, mfojtik@redhat.com wrote:
> From: Michal Fojtik<mf...@redhat.com>
>
> ---
>   server/lib/deltacloud/base_driver/base_driver.rb |    3 +++
>   1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
> index 4419359..ebd2078 100644
> --- a/server/lib/deltacloud/base_driver/base_driver.rb
> +++ b/server/lib/deltacloud/base_driver/base_driver.rb
> @@ -256,6 +256,9 @@ module Deltacloud
>           catched_exceptions_list[:glob].each do |ex|
>             raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if e.class.name =~ ex
>           end
> +        puts "======= UNHANDLED EXCEPTION ============"
> +        puts e.inspect
> +        puts "========================================"
>           raise e
>         end
>       end