incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1099075 - in /incubator/deltacloud/trunk/server: ./ lib/deltacloud/ lib/deltacloud/base_driver/ lib/deltacloud/drivers/ec2/ lib/deltacloud/drivers/mock/ lib/deltacloud/drivers/rackspace/ lib/deltacloud/drivers/rimuhosting/ lib/deltacloud/d...
Date Tue, 03 May 2011 14:33:09 GMT
Author: mfojtik
Date: Tue May  3 14:33:08 2011
New Revision: 1099075

URL: http://svn.apache.org/viewvc?rev=1099075&view=rev
Log:
Added DSL for handling exceptions

Added:
    incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/exceptions.rb
    incubator/deltacloud/trunk/server/views/errors/400.html.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/validation_failure.html.haml
    incubator/deltacloud/trunk/server/views/errors/400.xml.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml
    incubator/deltacloud/trunk/server/views/errors/401.html.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/auth_exception.html.haml
    incubator/deltacloud/trunk/server/views/errors/401.xml.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml
    incubator/deltacloud/trunk/server/views/errors/403.html.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/not_allowed.html.haml
    incubator/deltacloud/trunk/server/views/errors/403.xml.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/not_allowed.xml.haml
    incubator/deltacloud/trunk/server/views/errors/404.html.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/not_found.html.haml
    incubator/deltacloud/trunk/server/views/errors/404.xml.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml
    incubator/deltacloud/trunk/server/views/errors/500.xml.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/backend_error.xml.haml
    incubator/deltacloud/trunk/server/views/errors/502.html.haml
    incubator/deltacloud/trunk/server/views/errors/502.xml.haml
      - copied, changed from r1099064, incubator/deltacloud/trunk/server/views/errors/backend_error.xml.haml
Removed:
    incubator/deltacloud/trunk/server/views/errors/auth_exception.html.haml
    incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml
    incubator/deltacloud/trunk/server/views/errors/backend_error.html.haml
    incubator/deltacloud/trunk/server/views/errors/backend_error.xml.haml
    incubator/deltacloud/trunk/server/views/errors/not_allowed.html.haml
    incubator/deltacloud/trunk/server/views/errors/not_allowed.xml.haml
    incubator/deltacloud/trunk/server/views/errors/not_found.html.haml
    incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml
    incubator/deltacloud/trunk/server/views/errors/validation_failure.html.haml
    incubator/deltacloud/trunk/server/views/errors/validation_failure.xml.haml
Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/base_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_client.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/validation.rb
    incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb
    incubator/deltacloud/trunk/server/server.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/base_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/base_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/base_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/base_driver.rb Tue May  3
14:33:08 2011
@@ -14,32 +14,17 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+require 'lib/deltacloud/base_driver/exceptions'
+
 module Deltacloud
 
-  class AuthException < Exception
-  end
+  class BaseDriver
 
-  class BackendError < StandardError
-    attr_reader :code, :cause, :details
-    def initialize(code, cause, message, details)
-      super(message)
-      @code = code
-      @cause = cause
-      @details = details
-    end
-  end
+    include ExceptionHandler
 
-  class BackendFeatureUnsupported < StandardError
-    attr_reader :code, :cause, :details
-    def initialize(code, cause, message, details)
-      super(message)
-      @code = code
-      @cause = cause
-      @details = details
+    def self.exceptions(&block)
+      ExceptionHandler::exceptions(&block)
     end
-  end
-
-  class BaseDriver
     
     def self.define_hardware_profile(name,&block)
       @hardware_profiles ||= []
@@ -233,32 +218,6 @@ module Deltacloud
       { :error => [], :auth => [], :glob => [] }
     end
 
-    def safely(&block)
-      begin
-        block.call
-      rescue => e
-        catched_exceptions_list[:auth].each do |ex|
-          if e.class == ex or e.class.name =~ ex or e.message =~ ex
-            raise Deltacloud::AuthException.new
-          end
-        end
-        catched_exceptions_list[:error].each do |ex|
-          if e.class == ex or e.class.name =~ ex or e.message =~ ex
-            raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace)
if e.class.name =~ ex
-          end
-        end
-        catched_exceptions_list[:glob].each do |ex|
-          if e.class == ex or e.class.name =~ ex or e.message =~ ex
-            raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
-          end
-        end
-        $stderr.puts "# UNCAUGHT EXCEPTION # -> '#{e.class}' - '#{e.message}'"
-        $stderr.puts "# #{e.backtrace.join("\n")}"
-        $stderr.puts "##############"
-        raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
-      end
-    end
-
   end
 
 end

Added: incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/exceptions.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/exceptions.rb?rev=1099075&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/exceptions.rb (added)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/exceptions.rb Tue May  3
14:33:08 2011
@@ -0,0 +1,127 @@
+module Deltacloud
+  module ExceptionHandler
+
+    class DeltacloudException < StandardError
+
+      attr_accessor :code, :name, :message, :backtrace, :request
+
+      def initialize(code, name, message, backtrace, details, request=nil)
+        @code, @name, @message = code, name, message
+        @details = details
+        @backtrace = backtrace
+        @request = request
+        self
+      end
+
+    end
+
+    class AuthenticationFailure < DeltacloudException
+      def initialize(e, details)
+        super(401, e.class.name, e.message, e.backtrace, details)
+      end
+    end
+
+    class ValidationFailure < DeltacloudException
+      def initialize(e, details)
+        super(400, e.class.name, e.message, e.backtrace, details)
+      end
+    end
+
+    class BackendError < DeltacloudException
+      def initialize(e, details)
+        super(500, e.class.name, e.message, e.backtrace, details)
+      end
+    end
+
+    class ProviderError < DeltacloudException
+      def initialize(e, details)
+        super(502, e.class.name, e.message, e.backtrace, details)
+      end
+    end
+
+    class ExceptionDef
+      attr_accessor :status
+      attr_accessor :message
+      attr_reader   :conditions
+      attr_reader   :handler
+
+      def initialize(conditions, &block)
+        @conditions = conditions
+        instance_eval(&block) if block_given?
+      end
+
+      def status(code)
+        self.status = code
+      end
+
+      def message(message)
+        self.message = message
+      end
+
+      def details(details)
+        self.details = details
+      end
+
+      def exception(handler)
+        self.handler = handler
+      end
+
+      # Condition can be class or regexp
+      #
+      def match?(e)
+        @conditions.each do |c|
+          return true if c.class == Class && e.class == c
+          return true if c.class == Regexp && (e.class.name =~ c or e.message =~
c)
+        end
+        return false
+      end
+
+      def handler(e)
+        return @handler if @handler
+        case @status
+          when 401 then Deltacloud::ExceptionHandler::AuthenticationFailure.new(e, @details)
+          when 400 then Deltacloud::ExceptionHandler::ValidationFailure.new(e, @details)
+          when 500 then Deltacloud::ExceptionHandler::BackendError.new(e, @details)
+          when 502 then Deltacloud::ExceptionHandler::ProviderError.new(e, @details)
+        end
+      end
+
+    end
+
+    class Exceptions
+      attr_reader :exception_definitions
+
+      def initialize(&block)
+        @exception_definitions = []
+        instance_eval(&block) if block_given?
+        self
+      end
+
+      def on(*conditions, &block)
+        @exception_definitions << ExceptionDef::new(conditions, &block) if block_given?
+      end
+    end
+
+    def self.exceptions(&block)
+      @definitions = Exceptions.new(&block).exception_definitions if block_given?
+      @definitions 
+    end
+
+    def safely(&block)
+      begin
+        block.call
+      rescue => e
+        Deltacloud::ExceptionHandler::exceptions.each do |exdef|
+          raise exdef.handler(e) if exdef.match?(e)
+        end
+        $stderr.puts "# UNCAUGHT EXCEPTION  ~> '#{e.class}' - "
+        $stderr.puts "# #{e.message}"
+        $stderr.puts "# #{e.backtrace.join("\n")}"
+        $stderr.puts "##############"
+        raise BackendError.new(e)
+      end
+    end
+
+  end
+
+end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb Tue May  3
14:33:08 2011
@@ -772,12 +772,18 @@ module Deltacloud
           end
         end
 
-        def catched_exceptions_list
-          {
-            :auth => [ /AuthFailure/ ],
-            :error => [ /Aws::AwsError/, /Error/ ],
-            :glob => [ /AWS::(\w+)/, /Deltacloud::Runner::(\w+)/ ]
-          }
+        exceptions do
+          on /(AuthFailure|InvalidAccessKeyId)/ do
+            status 401
+          end
+
+          on /Error/ do
+            status 502
+          end
+
+          on /Deltacloud::Runner::(\w+)/ do
+            status 500
+          end
         end
 
       end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb Tue May
 3 14:33:08 2011
@@ -178,7 +178,7 @@ Deltacloud::Drivers::EC2::EC2Driver.clas
 
   def new_client(credentials, opts={})
     if credentials.user != 'mockuser' and credentials.password != 'mockpassword'
-      raise Deltacloud::AuthException.new
+      raise "AuthFailure"
     end
     RightAws::MockEc2.new
   end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb Tue May 
3 14:33:08 2011
@@ -490,7 +490,7 @@ class MockDriver < Deltacloud::BaseDrive
     begin
       check_credentials(credentials)
       return true
-    rescue Deltacloud::AuthException
+    rescue
     end
     return false
   end
@@ -499,16 +499,20 @@ class MockDriver < Deltacloud::BaseDrive
 
   def check_credentials(credentials)
     if ( credentials.user != 'mockuser' ) or ( credentials.password != 'mockpassword' )
-      raise Deltacloud::AuthException.new
+      raise 'AuthFailure'
     end
   end
 
-  def catched_exceptions_list
-    {
-      :auth => [],
-      :error => [ /Deltacloud::BackendError/, /Errno::ENOENT/ ],
-      :glob => [ /Error/ ]
-    }
+  exceptions do
+
+    on /AuthFailure/ do
+      status 401
+    end
+
+    on /Err/ do
+      status 500
+    end
+
   end
 
 end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
(original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
Tue May  3 14:33:08 2011
@@ -391,12 +391,24 @@ private
     end
   end
 
-  def catched_exceptions_list
-    {
-      :auth => [ /Authentication failed/ ],
-      :error => [ /Error/ ],
-      :glob => [ /CloudServers::Exception::(\w+)/, /Deltacloud::Runner::(\w+)/ ]
-    }
+  exceptions do
+
+    on /No offering found/ do
+      status 400 
+    end
+
+    on /Authentication failed/ do
+      status 401
+    end
+
+    on /Error/ do
+      status 500
+    end
+
+    on /CloudServers::Exception::(\w+)/ do
+      status 500
+    end
+
   end
 
   private

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb
(original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb
Tue May  3 14:33:08 2011
@@ -40,6 +40,7 @@ class RimuHostingClient
     if(!@auth.nil?)
       headers["Authorization"] = @auth
     end
+    safely do
     r = @service.send_request(method, @uri.path + resource, data, headers)
          puts r.body
     res = JSON.parse(r.body)
@@ -47,7 +48,7 @@ class RimuHostingClient
 
     if(res['response_type'] == "ERROR" and ( (res['error_info']['error_class'] == "PermissionException")
or
 					     (res['error_info']['error_class'] == "LoginRequired") )) 
-      raise Deltacloud::AuthException.new
+      raise "AuthFailure"
     end
     res
   end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
(original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
Tue May  3 14:33:08 2011
@@ -149,15 +149,12 @@ class RimuHostingDriver < Deltacloud::Ba
     stopped.to( :finish )         .automatically
   end
 
-  def safely(&block)
-    begin
-      block.call
-    rescue Exception => e
-      raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
+  exceptions do
+    on /AuthFailure/ do
+      status 401
     end
   end
 
-
 end
 
     end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_client.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_client.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_client.rb Tue May  3
14:33:08 2011
@@ -180,9 +180,9 @@ class SBCClient
   #
   def backend_error!(resp)
     if resp.is_a?(Net::HTTPUnauthorized)
-      raise Deltacloud::AuthException, resp.message
+      raise "AuthFailure"
     else
-      raise Deltacloud::BackendError.new(resp.code, resp.body, resp.message, '')
+      raise "BackendError"
     end
   end
 

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/sbc/sbc_driver.rb Tue May  3
14:33:08 2011
@@ -118,6 +118,18 @@ class SBCDriver < Deltacloud::BaseDriver
     instance(credentials, instance_id)
   end
 
+  exceptions do
+
+    on /AuthFailure/ do
+      status 401
+    end
+
+    on /BackendError/ do
+      status 502
+    end
+
+  end
+
   #
   # --------------------- Private helpers ---------------------
   #

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/terremark/terremark_driver.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
(original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
Tue May  3 14:33:08 2011
@@ -192,7 +192,7 @@ end
 def valid_credentials?(credentials)
   begin
     new_client(credentials)
-  rescue Deltacloud::AuthException
+  rescue
     return false
   end
   true
@@ -272,20 +272,17 @@ end
       vdc_id = terremark_client.default_vdc_id
     end
     if (vdc_id.nil?)
-       raise DeltaCloud::AuthException.new
+       raise "AuthFailure"
     end
     terremark_client
   end
 
-  def safely(&block)
-    begin
-      block.call
-    rescue Exception => e
-      raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
+  exceptions do
+    on /AuthFailure/ do
+      status 401
     end
   end
 
-
 end
 
     end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb Tue May
 3 14:33:08 2011
@@ -100,16 +100,16 @@ module ApplicationHelper
         format.json { convert_to_json(model, @element) }
       end
     else
-        report_error(404, 'not_found')
+        report_error(404)
     end
   end
 
-  def report_error(status, template)
+  def report_error(code=nil)
     @error = request.env['sinatra.error']
-    response.status = status
+    response.status = code || @error.code
     respond_to do |format|
-      format.xml { haml :"errors/#{template}", :layout => false }
-      format.html { haml :"errors/#{template}", :layout => :error }
+      format.xml { haml :"errors/#{code || @error.code}", :layout => false }
+      format.html { haml :"errors/#{code || @error.code}", :layout => :error }
     end
   end
 
@@ -119,7 +119,7 @@ module ApplicationHelper
     # If original instance doesn't include called action
     # return with 405 error (Method is not Allowed)
     unless driver.instance_actions_for(original_instance.state).include?(name.to_sym)
-      return report_error(405, 'not_allowed')
+      return report_error(405)
     end
 
     @instance = driver.send(:"#{name}_instance", credentials, params["id"])

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/validation.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/validation.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/validation.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/validation.rb Tue May  3 14:33:08 2011
@@ -24,7 +24,7 @@ module Deltacloud::Validation
     end
 
     def name
-      param.name
+      param.name if @param
     end
   end
 

Modified: incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb (original)
+++ incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb Tue May  3 14:33:08 2011
@@ -23,10 +23,20 @@ module Sinatra
 
   module Rabbit
 
-    class DuplicateParamException < Exception; end
-    class DuplicateOperationException < Exception; end
-    class DuplicateCollectionException < Exception; end
-    class UnsupportedCollectionException < Exception; end
+    class DuplicateParamException < Deltacloud::ExceptionHandler::DeltacloudException;
end
+    class DuplicateOperationException < Deltacloud::ExceptionHandler::DeltacloudException;
end
+    class DuplicateCollectionException < Deltacloud::ExceptionHandler::DeltacloudException;
end
+    class UnsupportedCollectionException < Deltacloud::ExceptionHandler::DeltacloudException
+      def initialize
+        @details = "This collection is not supported for this provider."
+        @message = @details
+        # The server understood the request, but is refusing to fulfill it. Authorization
will not help and the request
+        # SHOULD NOT be repeated. If the request method was not HEAD and the server wishes
to make public why the request 
+        # has not been fulfilled, it SHOULD describe the reason for the refusal in the entity.
If the server does not wish
+        # to make this information available to the client, the status code 404 (Not Found)
can be used instead.
+        @code = 403 # 
+      end
+    end
 
     class Operation
       attr_reader :name, :method, :collection
@@ -273,8 +283,7 @@ module Sinatra
 
       def check_supported(driver)
         unless global? || driver.has_collection?(@name)
-          raise UnsupportedCollectionException,
-            "Collection #{@name} not supported by this driver"
+          raise UnsupportedCollectionException
         end
       end
     end

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1099075&r1=1099074&r2=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Tue May  3 14:33:08 2011
@@ -57,24 +57,8 @@ end
 # whatever you want (eg. if you running API behind NAT)
 HOSTNAME=ENV['API_HOST'] ? ENV['API_HOST'] : nil
 
-error Deltacloud::Validation::Failure do
-  report_error(400, "validation_failure")
-end
-
-error Deltacloud::BackendCapability::Failure do
-  report_error(405, "backend_capability_failure")
-end
-
-error Deltacloud::AuthException do
-  report_error(401, "auth_exception")
-end
-
-error Deltacloud::BackendError do
-  report_error(500, "backend_error")
-end
-
-error Sinatra::Rabbit::UnsupportedCollectionException do
-  report_error(404, "not_found")
+error do
+  report_error
 end
 
 Sinatra::Application.register Sinatra::RespondTo
@@ -497,7 +481,7 @@ END
           format.json { convert_to_json(:hardware_profile, @profile) }
         end
       else
-        report_error(404, 'not_found')
+        report_error(404)
       end
     end
   end
@@ -752,7 +736,7 @@ head '/api/buckets/:bucket/:blob' do
         headers["X-Deltacloud-Blobmeta-#{k}"] = v
       end
    else
-    report_error(404, 'not_found')
+    report_error(404)
   end
 end
 
@@ -766,7 +750,7 @@ post '/api/buckets/:bucket/:blob' do
       headers["X-Deltacloud-Blobmeta-#{k}"] = v
     end
   else
-    report_error(404, 'not_found') #FIXME is this the right error code?
+    report_error(404) #FIXME is this the right error code?
   end
 end
 
@@ -780,7 +764,7 @@ get '/api/buckets/:bucket/:blob' do
       format.json { convert_to_json(blobs, @blob) }
       end
   else
-      report_error(404, 'not_found')
+      report_error(404)
   end
 end
 
@@ -793,7 +777,7 @@ get '/api/buckets/:bucket/:blob/content'
     params['content_disposition'] = "attachment; filename=#{@blob.id}"
     BlobStream.call(env, credentials, params)
   else
-    report_error(404, 'not_found')
+    report_error(404)
   end
 end
 

Copied: incubator/deltacloud/trunk/server/views/errors/400.html.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/validation_failure.html.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/400.html.haml?p2=incubator/deltacloud/trunk/server/views/errors/400.html.haml&p1=incubator/deltacloud/trunk/server/views/errors/validation_failure.html.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Copied: incubator/deltacloud/trunk/server/views/errors/400.xml.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/400.xml.haml?p2=incubator/deltacloud/trunk/server/views/errors/400.xml.haml&p1=incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml (original)
+++ incubator/deltacloud/trunk/server/views/errors/400.xml.haml Tue May  3 14:33:08 2011
@@ -1,3 +1,4 @@
 %error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %parameter #{@error.name}
   %message< #{cdata @error.message}
 

Copied: incubator/deltacloud/trunk/server/views/errors/401.html.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/auth_exception.html.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/401.html.haml?p2=incubator/deltacloud/trunk/server/views/errors/401.html.haml&p1=incubator/deltacloud/trunk/server/views/errors/auth_exception.html.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Copied: incubator/deltacloud/trunk/server/views/errors/401.xml.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/401.xml.haml?p2=incubator/deltacloud/trunk/server/views/errors/401.xml.haml&p1=incubator/deltacloud/trunk/server/views/errors/auth_exception.xml.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Copied: incubator/deltacloud/trunk/server/views/errors/403.html.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/not_allowed.html.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/403.html.haml?p2=incubator/deltacloud/trunk/server/views/errors/403.html.haml&p1=incubator/deltacloud/trunk/server/views/errors/not_allowed.html.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Copied: incubator/deltacloud/trunk/server/views/errors/403.xml.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/not_allowed.xml.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/403.xml.haml?p2=incubator/deltacloud/trunk/server/views/errors/403.xml.haml&p1=incubator/deltacloud/trunk/server/views/errors/not_allowed.xml.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Copied: incubator/deltacloud/trunk/server/views/errors/404.html.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/not_found.html.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/404.html.haml?p2=incubator/deltacloud/trunk/server/views/errors/404.html.haml&p1=incubator/deltacloud/trunk/server/views/errors/not_found.html.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Copied: incubator/deltacloud/trunk/server/views/errors/404.xml.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/404.xml.haml?p2=incubator/deltacloud/trunk/server/views/errors/404.xml.haml&p1=incubator/deltacloud/trunk/server/views/errors/not_found.xml.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Copied: incubator/deltacloud/trunk/server/views/errors/500.xml.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/backend_error.xml.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/500.xml.haml?p2=incubator/deltacloud/trunk/server/views/errors/500.xml.haml&p1=incubator/deltacloud/trunk/server/views/errors/backend_error.xml.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)

Added: incubator/deltacloud/trunk/server/views/errors/502.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/502.html.haml?rev=1099075&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/errors/502.html.haml (added)
+++ incubator/deltacloud/trunk/server/views/errors/502.html.haml Tue May  3 14:33:08 2011
@@ -0,0 +1,14 @@
+%h1 Backend Error
+
+%p= @error.message
+
+%dl
+  %di
+    %dt Request URL
+    %dd= request.env['REQUEST_URI']
+  %di
+    %dt Parameters
+    %dd= params.inspect
+  %di
+    %dt Code
+    %dd= @error.code

Copied: incubator/deltacloud/trunk/server/views/errors/502.xml.haml (from r1099064, incubator/deltacloud/trunk/server/views/errors/backend_error.xml.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/errors/502.xml.haml?p2=incubator/deltacloud/trunk/server/views/errors/502.xml.haml&p1=incubator/deltacloud/trunk/server/views/errors/backend_error.xml.haml&r1=1099064&r2=1099075&rev=1099075&view=diff
==============================================================================
    (empty)



Mime
View raw message