deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [2/6] git commit: Core: Removed Failure exception from validation
Date Tue, 13 Mar 2012 17:28:31 GMT
Core: Removed Failure exception from validation

Previously we had two exceptions defined to handle the 400
errors (like params validation). This patch will remove
the one defined in validation.rb and re-use the one from
exception handling system.

All validation errors (400) should be now treated with
ValidationFailure exception from exceptions.rb.


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

Branch: refs/heads/master
Commit: 2ece8467416fd04746b798b064a558a5cf09e9a5
Parents: 364fdb4
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Tue Mar 13 14:39:57 2012 +0100
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Tue Mar 13 18:29:14 2012 +0100

----------------------------------------------------------------------
 .../drivers/terremark/terremark_driver.rb          |    4 ++-
 server/lib/deltacloud/server.rb                    |    4 ++-
 server/lib/deltacloud/validation.rb                |   23 +++++---------
 3 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2ece8467/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
index c93bfb3..da58364 100644
--- a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
+++ b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
@@ -141,7 +141,9 @@ VAPP_STATE_MAP = { "0" =>  "PENDING", "1" =>  "PENDING", "2" =>
 "STOPPED", "4"
     end
     unless ( (terremark_hwp.include?(:cpu, opts[:hwp_cpu].to_i)) &&
               (terremark_hwp.include?(:memory, opts[:hwp_memory].to_i)) ) then
-       raise Deltacloud::Validation::Failure.new(Deltacloud::Validation::Param.new(["cpu"]),
"Error with cpu and/or memory values. you said cpu->#{opts[:hwp_cpu]} and mem->#{opts[:hwp_memory]}")
+        raise Deltacloud::ExceptionHandler::ValidationFailure.new(
+          StandardError.new("Error with cpu and/or memory values. you said cpu->#{opts[:hwp_cpu]}
and mem->#{opts[:hwp_memory]}")
+        )
     end
     vapp_opts['cpus'] = opts[:hwp_cpu]
     vapp_opts['memory'] =  opts[:hwp_memory]

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2ece8467/server/lib/deltacloud/server.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/server.rb b/server/lib/deltacloud/server.rb
index d47c87f..b845616 100644
--- a/server/lib/deltacloud/server.rb
+++ b/server/lib/deltacloud/server.rb
@@ -1245,7 +1245,9 @@ collection :firewalls do
       params['addresses'] = addresses
       params['groups'] = groups
       if addresses.empty? && groups.empty?
-        raise Deltacloud::Validation::Failure.new(nil, "No sources. Specify at least one
source ip_address or group")
+        raise Deltacloud::ExceptionHandler::ValidationFailure.new(
+          StandardError.new("No sources. Specify at least one source ip_address or group")
+        )
       end
       driver.create_firewall_rule(credentials, params)
       @firewall = driver.firewall(credentials, {:id => params[:id]})

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/2ece8467/server/lib/deltacloud/validation.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/validation.rb b/server/lib/deltacloud/validation.rb
index e14c532..3d29225 100644
--- a/server/lib/deltacloud/validation.rb
+++ b/server/lib/deltacloud/validation.rb
@@ -16,17 +16,6 @@
 
 module Deltacloud::Validation
 
-  class Failure < Deltacloud::ExceptionHandler::DeltacloudException
-    attr_reader :param
-    def initialize(e, message=nil)
-      message ||= e.message
-      super(400, e.class.name, message, [])
-    end
-    def name
-      param.name if @param
-    end
-  end
-
   class Param
     attr_reader :name, :klass, :type, :options, :description
 
@@ -87,21 +76,25 @@ module Deltacloud::Validation
   def validate(current_driver, all_params, values, credentials)
     all_params.each do |key, p|
       if p.required? and not values[p.name]
-        raise Failure.new(p, "Required parameter #{p.name} not found")
+        raise validation_exception "Required parameter #{p.name} not found"
       end
       next unless values[p.name]
       if p.hwp_property?
         profile = current_driver.hardware_profile(credentials, values['hwp_id'])
-        raise Failure.new(p, "Unknown hardware profile selected #{values['hwp_id']}") unless
profile
+        raise validation_exception("Unknown hardware profile selected #{values['hwp_id']}")
unless profile
         unless p.valid_hwp_value?(profile, values[p.name])
-          raise Failure.new(p, "Hardware profile property #{p.name} has invalid value #{values[p.name]}")
+          raise validation_exception("Hardware profile property #{p.name} has invalid value
#{values[p.name]}")
         end
       else
         if not p.options.empty? and p.valid_value?(values[p.name])
-          raise Failure.new(p, "Parameter #{p.name} has value #{values[p.name]} which is
not in #{p.options.join(", ")}")
+          raise validation_exception("Parameter #{p.name} has value #{values[p.name]} which
is not in #{p.options.join(", ")}")
         end
       end
     end
   end
 
+  def validation_exception(message)
+    Deltacloud::ExceptionHandler::ValidationFailure.new(StandardError.new(message))
+  end
+
 end


Mime
View raw message