deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [1/3] git commit: Core: Added XML output for 504 and 502 errors
Date Wed, 29 Feb 2012 15:38:21 GMT
Updated Branches:
  refs/heads/master 37b077811 -> 7ee08d5a7


Core: Added XML output for 504 and 502 errors

The 501, 502 and 504 errors previously has no XML view
associated and thus client cannot report errors correctly.
This patch add these missing HAML templates.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>


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

Branch: refs/heads/master
Commit: 6562a1c9d7233c568d0afa40eee9e05c5d3d243b
Parents: 37b0778
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Fri Feb 10 13:56:00 2012 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Wed Feb 29 16:39:13 2012 +0100

----------------------------------------------------------------------
 server/lib/deltacloud/base_driver/exceptions.rb    |   16 ++++++
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |   32 ++++++++++-
 .../lib/deltacloud/helpers/application_helper.rb   |    2 +-
 server/lib/sinatra/lazy_auth.rb                    |    2 +-
 server/views/errors/501.html.haml                  |   43 +++++++++++++++
 server/views/errors/501.xml.haml                   |   12 ++++
 server/views/errors/502.xml.haml                   |   13 +++--
 server/views/errors/504.html.haml                  |   43 +++++++++++++++
 server/views/errors/504.xml.haml                   |   12 ++++
 9 files changed, 166 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/lib/deltacloud/base_driver/exceptions.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/base_driver/exceptions.rb b/server/lib/deltacloud/base_driver/exceptions.rb
index 0c66659..e30f94c 100644
--- a/server/lib/deltacloud/base_driver/exceptions.rb
+++ b/server/lib/deltacloud/base_driver/exceptions.rb
@@ -72,6 +72,20 @@ module Deltacloud
       end
     end
 
+    class ProviderTimeout < DeltacloudException
+      def initialize(e, message)
+        message ||= e.message
+        super(504, e.class.name, message, e.backtrace)
+      end
+    end
+
+    class NotImplemented < DeltacloudException
+      def initialize(e, message)
+        message ||= e.message
+        super(501, e.class.name, message, e.backtrace)
+      end
+    end
+
     class ObjectNotFound < DeltacloudException
       def initialize(e, message)
         message ||= e.message
@@ -127,7 +141,9 @@ module Deltacloud
           when 405 then Deltacloud::ExceptionHandler::MethodNotAllowed.new(e, @message)
           when 400 then Deltacloud::ExceptionHandler::ValidationFailure.new(e, @message)
           when 500 then Deltacloud::ExceptionHandler::BackendError.new(e, @message)
+          when 501 then Deltacloud::ExceptionHandler::NotImplemented.new(e, @message)
           when 502 then Deltacloud::ExceptionHandler::ProviderError.new(e, @message)
+          when 504 then Deltacloud::ExceptionHandler::ProviderTimeout.new(e, @message)
         end
       end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/lib/deltacloud/drivers/mock/mock_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index caf14bc..765338d 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -100,8 +100,18 @@ module Deltacloud::Drivers::Mock
     end
 
     def realms(credentials, opts=nil)
-      return REALMS if ( opts.nil? )
-      results = REALMS
+      check_credentials( credentials )
+      results = []
+      safely do
+        # This hack is used to test if client capture exceptions correctly
+        # To raise an exception do GET /api/realms/50[0-2]
+        raise "DeltacloudErrorTest" if opts and opts[:id] == "500"
+        raise "NotImplementedTest" if opts and opts[:id] == "501"
+        raise "ProviderErrorTest" if opts and opts[:id] == "502"
+        raise "ProviderTimeoutTest" if opts and opts[:id] == "504"
+        return REALMS if ( opts.nil? )
+        results = REALMS
+      end
       results = filter_on( results, :id, opts )
       results
     end
@@ -521,8 +531,24 @@ module Deltacloud::Drivers::Mock
         message "Could not delete a non existent blob"
       end
 
-      on /Err/ do
+      on /DeltacloudErrorTest/ do
         status 500
+        message "DeltacloudErrorMessage"
+      end
+
+      on /NotImplementedTest/ do
+        status 501
+        message "NotImplementedMessage"
+      end
+
+      on /ProviderErrorTest/ do
+        status 502
+        message "ProviderErrorMessage"
+      end
+
+      on /ProviderTimeoutTest/ do
+        status 504
+        message "ProviderTimeoutMessage"
       end
 
     end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/lib/deltacloud/helpers/application_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb
index b54ec41..623fac8 100644
--- a/server/lib/deltacloud/helpers/application_helper.rb
+++ b/server/lib/deltacloud/helpers/application_helper.rb
@@ -109,7 +109,7 @@ module ApplicationHelper
         format.json { convert_to_json(model, @element) }
       end
     else
-        report_error(404)
+      report_error(404)
     end
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/lib/sinatra/lazy_auth.rb
----------------------------------------------------------------------
diff --git a/server/lib/sinatra/lazy_auth.rb b/server/lib/sinatra/lazy_auth.rb
index ac8f5c7..9556bbc 100644
--- a/server/lib/sinatra/lazy_auth.rb
+++ b/server/lib/sinatra/lazy_auth.rb
@@ -63,7 +63,7 @@ module Sinatra
     def authorize!
       r = "#{driver_symbol}-deltacloud@#{HOSTNAME}"
       response['WWW-Authenticate'] = %(Basic realm="#{r}")
-      throw(:halt, [401, "Not authorized\n"])
+      report_error(401)
     end
 
     # Request the current user's credentials. Actual credentials are only

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/views/errors/501.html.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/501.html.haml b/server/views/errors/501.html.haml
new file mode 100644
index 0000000..19cf090
--- /dev/null
+++ b/server/views/errors/501.html.haml
@@ -0,0 +1,43 @@
+%div{ :'data-role' => :content, :'data-theme' => 'b'}
+  %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' =>
'e'}
+    %li{ :'data-role' => 'list-divider'} Server message
+    %li
+      %h3=[@error.class.name, @error.message].join(' - ')
+    %li{ :'data-role' => 'list-divider'} Original request URI
+    %li
+      %a{ :href => request.env['REQUEST_URI'], :'data-ajax' => 'false'}
+        %span=request.env['REQUEST_URI']
+        %span{ :class => 'ui-li-count'} Retry
+    %li{ :'data-role' => 'list-divider'} Error details
+    %li
+      - if @error.class.method_defined? :details
+        %p= @error.details
+      - else
+        %em No details
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Backtrace
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      %li
+        %pre=@error.backtrace.join("\n")
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Parameters
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      - if params.keys.empty?
+        %li{ :'data-role' => 'list-divider'} No parameters
+      - params.each do |key, value|
+        - next if value.inspect.to_s == '#'
+        %li{ :'data-role' => 'list-divider'}=key
+        %li
+          %span{:style => 'font-weight:normal;'}=value.inspect
+
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Request details
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      - request.env.each do |key, value|
+        - next if value.inspect.to_s == '#'
+        %li{ :'data-role' => 'list-divider'}=key
+        %li
+          %span{:style => 'font-weight:normal;'}=value.inspect

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/views/errors/501.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/501.xml.haml b/server/views/errors/501.xml.haml
new file mode 100644
index 0000000..788fe4b
--- /dev/null
+++ b/server/views/errors/501.xml.haml
@@ -0,0 +1,12 @@
+%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %kind backend_error
+  %backend{ :driver => driver_symbol, :provider => "#{Thread::current[:provider] ||
ENV['API_PROVIDER'] || 'default'}" }
+  - if @error.respond_to?(:details) && @error.details
+    %details< #{cdata @error.details.join("\n")}
+  %message< #{cdata @error.message}
+  - if @error.respond_to? :backtrace
+    %backtrace=cdata @error.backtrace.join("\n")
+  - if params
+    %request
+      - params.each do |k, v|
+        %param{ :name => k}=v

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/views/errors/502.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/502.xml.haml b/server/views/errors/502.xml.haml
index 6e7a7b8..788fe4b 100644
--- a/server/views/errors/502.xml.haml
+++ b/server/views/errors/502.xml.haml
@@ -1,7 +1,12 @@
 %error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
   %kind backend_error
-  %backend{ :driver => driver_symbol }
-    %code= @error.code
-    - if @error.respond_to?(:details) && @error.details
-      %details< #{cdata @error.details.join("\n")}
+  %backend{ :driver => driver_symbol, :provider => "#{Thread::current[:provider] ||
ENV['API_PROVIDER'] || 'default'}" }
+  - if @error.respond_to?(:details) && @error.details
+    %details< #{cdata @error.details.join("\n")}
   %message< #{cdata @error.message}
+  - if @error.respond_to? :backtrace
+    %backtrace=cdata @error.backtrace.join("\n")
+  - if params
+    %request
+      - params.each do |k, v|
+        %param{ :name => k}=v

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/views/errors/504.html.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/504.html.haml b/server/views/errors/504.html.haml
new file mode 100644
index 0000000..19cf090
--- /dev/null
+++ b/server/views/errors/504.html.haml
@@ -0,0 +1,43 @@
+%div{ :'data-role' => :content, :'data-theme' => 'b'}
+  %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' =>
'e'}
+    %li{ :'data-role' => 'list-divider'} Server message
+    %li
+      %h3=[@error.class.name, @error.message].join(' - ')
+    %li{ :'data-role' => 'list-divider'} Original request URI
+    %li
+      %a{ :href => request.env['REQUEST_URI'], :'data-ajax' => 'false'}
+        %span=request.env['REQUEST_URI']
+        %span{ :class => 'ui-li-count'} Retry
+    %li{ :'data-role' => 'list-divider'} Error details
+    %li
+      - if @error.class.method_defined? :details
+        %p= @error.details
+      - else
+        %em No details
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Backtrace
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      %li
+        %pre=@error.backtrace.join("\n")
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Parameters
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      - if params.keys.empty?
+        %li{ :'data-role' => 'list-divider'} No parameters
+      - params.each do |key, value|
+        - next if value.inspect.to_s == '#'
+        %li{ :'data-role' => 'list-divider'}=key
+        %li
+          %span{:style => 'font-weight:normal;'}=value.inspect
+
+
+  %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+    %h3 Request details
+    %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+      - request.env.each do |key, value|
+        - next if value.inspect.to_s == '#'
+        %li{ :'data-role' => 'list-divider'}=key
+        %li
+          %span{:style => 'font-weight:normal;'}=value.inspect

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/6562a1c9/server/views/errors/504.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/504.xml.haml b/server/views/errors/504.xml.haml
new file mode 100644
index 0000000..788fe4b
--- /dev/null
+++ b/server/views/errors/504.xml.haml
@@ -0,0 +1,12 @@
+%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %kind backend_error
+  %backend{ :driver => driver_symbol, :provider => "#{Thread::current[:provider] ||
ENV['API_PROVIDER'] || 'default'}" }
+  - if @error.respond_to?(:details) && @error.details
+    %details< #{cdata @error.details.join("\n")}
+  %message< #{cdata @error.message}
+  - if @error.respond_to? :backtrace
+    %backtrace=cdata @error.backtrace.join("\n")
+  - if params
+    %request
+      - params.each do |k, v|
+        %param{ :name => k}=v


Mime
View raw message