deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject git commit: DTACLOUD-379 - raise and handle 409 instead of 500
Date Thu, 13 Dec 2012 20:15:39 GMT
Updated Branches:
  refs/heads/master c101ed456 -> bdf502294


DTACLOUD-379 - raise and handle 409 instead of 500

TrackedAt: http://tracker.deltacloud.org/patch/acbe1c2cc32f6497d4d09d51aa46636f1b27b6c4


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

Branch: refs/heads/master
Commit: bdf5022947ea69fb03a8919a21fbbb6c3dd2a1f5
Parents: c101ed4
Author: Joe VLcek <jvlcek@redhat.com>
Authored: Wed Dec 12 16:03:54 2012 -0500
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Thu Dec 13 21:15:05 2012 +0100

----------------------------------------------------------------------
 server/lib/deltacloud/collections/base.rb          |    4 +
 server/lib/deltacloud/drivers/exceptions.rb        |    8 +++
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |    8 ++-
 server/lib/deltacloud/helpers/deltacloud_helper.rb |    1 +
 server/tests/drivers/rhevm/images_test.rb          |    2 +-
 server/views/errors/409.html.haml                  |   47 +++++++++++++++
 server/views/errors/409.xml.haml                   |   11 ++++
 7 files changed, 77 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bdf50229/server/lib/deltacloud/collections/base.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/base.rb b/server/lib/deltacloud/collections/base.rb
index 21a7e98..bc01eff 100644
--- a/server/lib/deltacloud/collections/base.rb
+++ b/server/lib/deltacloud/collections/base.rb
@@ -43,6 +43,10 @@ module Deltacloud::Collections
       report_error
     end
 
+    error Deltacloud::Exceptions::Conflict do
+      report_error
+    end
+
     error Deltacloud::Exceptions::ValidationFailure do
       report_error
     end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bdf50229/server/lib/deltacloud/drivers/exceptions.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/exceptions.rb b/server/lib/deltacloud/drivers/exceptions.rb
index 7bbf510..5663dae 100644
--- a/server/lib/deltacloud/drivers/exceptions.rb
+++ b/server/lib/deltacloud/drivers/exceptions.rb
@@ -58,6 +58,13 @@ module Deltacloud
       end
     end
 
+    class Conflict < DeltacloudException
+      def initialize(e, message=nil)
+        message ||= e.message
+        super(409, e.class.name, message, e.backtrace)
+      end
+    end
+
     class MethodNotAllowed < DeltacloudException
       def initialize(e, message=nil)
         message ||= e.message
@@ -157,6 +164,7 @@ module Deltacloud
           when 406 then UnknownMediaTypeError.new(e, @message)
           when 405 then MethodNotAllowed.new(e, @message)
           when 400 then ValidationFailure.new(e, @message)
+          when 409 then Conflict.new(e, @message)
           when 500 then BackendError.new(e, @message)
           when 501 then NotImplemented.new(e, @message)
           when 502 then ProviderError.new(e, @message)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bdf50229/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 37e6622..7709be4 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -118,9 +118,7 @@ class RhevmDriver < Deltacloud::BaseDriver
   def destroy_image(credentials, image_id)
     client = new_client(credentials)
     safely do
-      unless client.destroy_template(image_id)
-        raise "ERROR: Unable to remove image"
-      end
+      client.destroy_template(image_id)
     end
   end
 
@@ -342,6 +340,10 @@ class RhevmDriver < Deltacloud::BaseDriver
       status 404
     end
 
+    on /(Cannot delete Template. Template is being used)/ do
+      status 409
+    end
+
     on /(RestClient|RHEVM|OVIRT)/ do
       status 500
     end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bdf50229/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index b3db12f..1ae34d7 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -257,6 +257,7 @@ module Deltacloud::Helpers
       when 404; { :message => "Not Found" }
       when 405; { :message => "Method Not Allowed" }
       when 406; { :message => "Not Acceptable" }
+      when 409; { :message => "Resource Conflict" }
       when 500; { :message => "Internal Server Error" }
       when 502; { :message => "Backend Server Error" }
       when 504; { :message => "Gateway Timeout" }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bdf50229/server/tests/drivers/rhevm/images_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/rhevm/images_test.rb b/server/tests/drivers/rhevm/images_test.rb
index d306af9..7241667 100644
--- a/server/tests/drivers/rhevm/images_test.rb
+++ b/server/tests/drivers/rhevm/images_test.rb
@@ -57,7 +57,7 @@ describe 'RhevmDriver Images' do
       image.state.must_equal 'OK'
       Proc.new {
         @driver.destroy_image(image.id)
-      }.must_raise Deltacloud::Exceptions::BackendError, 'Cannot delete Template. Template
is being used by the following VMs: test1.'
+      }.must_raise Deltacloud::Exceptions::Conflict, 'Cannot delete Template. Template is
being used by the following VMs: test1.'
     end
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bdf50229/server/views/errors/409.html.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/409.html.haml b/server/views/errors/409.html.haml
new file mode 100644
index 0000000..fb9daca
--- /dev/null
+++ b/server/views/errors/409.html.haml
@@ -0,0 +1,47 @@
+%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= h [@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= h @error.details
+      - else
+        %em No details
+    %li{ :'data-role' => 'list-divider'} Backtrace
+    %li
+      %em No details
+
+  - if @error.backtrace
+    %div{ 'data-role' => :collapsible, 'data-collapsed' => "true"}
+      %h3 Backtrace
+      %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme'
=> 'e'}
+        %li
+          %pre= h @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;'}= h value.inspect

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bdf50229/server/views/errors/409.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/errors/409.xml.haml b/server/views/errors/409.xml.haml
new file mode 100644
index 0000000..de05bf8
--- /dev/null
+++ b/server/views/errors/409.xml.haml
@@ -0,0 +1,11 @@
+- unless defined?(partial)
+  !!! XML
+%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+  %kind backend_error
+  %backend{ :driver => driver_symbol, :provider => "#{Thread::current[:provider] ||
ENV['API_PROVIDER'] || 'default'}" }
+    %code=response.status
+  %message< #{cdata @error.message}
+  - if params
+    %request
+      - params.each do |k, v|
+        %param{ :name => k}=v


Mime
View raw message