deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH core] Core: Replaced Rack::Builder with Rack::Cascade in config.ru
Date Tue, 04 Sep 2012 20:08:26 GMT
On 05/09/12 15:28 +0200, mfojtik@redhat.com wrote:

I forgot to add the '/' entrypoint ;-) But this is a good question.
What we should do when client access the '/' ?

Before we used redirect to '/api' but what if the '/api' is not
mounted? (like deltacloud is started using -f cimi ;)

   -- michal

>From: Michal Fojtik <mfojtik@redhat.com>
>
>* The Rack::Cascade works nicely with OpenShift
>
>Signed-off-by: Michal fojtik <mfojtik@redhat.com>
>---
> server/config.ru              |   58 +++++++++--------------------------------
> server/lib/deltacloud_rack.rb |    4 +--
> server/lib/ec2/server.rb      |   10 ++++---
> 3 files changed, 20 insertions(+), 52 deletions(-)
>
>diff --git a/server/config.ru b/server/config.ru
>index b1ce2a8..e6e1c71 100644
>--- a/server/config.ru
>+++ b/server/config.ru
>@@ -14,9 +14,7 @@
> # License for the specific language governing permissions and limitations
> # under the License.
>
>-# The default URL prefix (where to mount Deltacloud API)
>-
>-# The default driver is 'mock'
>+# Default values
> ENV['API_DRIVER'] ||= 'mock'
> ENV['API_FRONTEND'] ||= 'deltacloud'
>
>@@ -26,65 +24,33 @@ Deltacloud::configure do |server|
>   server.root_url '/api'
>   server.version '1.0.2'
>   server.klass 'Deltacloud::API'
>-  server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
>-  server.default_driver ENV['API_DRIVER']
> end
>
> Deltacloud::configure(:cimi) do |server|
>   server.root_url '/cimi'
>   server.version '1.0.2'
>   server.klass 'CIMI::API'
>-  server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
>-  server.default_driver ENV['API_DRIVER']
> end
>
> Deltacloud::configure(:ec2) do |server|
>   server.root_url '/ec2'
>   server.version '2012-04-01'
>   server.klass 'Deltacloud::EC2::API'
>-  server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
>-  server.default_driver ENV['API_DRIVER']
> end
>
>-routes = {}
>-
>-# If user wants to launch multiple frontends withing a single instance of DC API
>-# then require them and prepare the routes for Rack
>-#
>-# NOTE: The '/' will not be generated, since multiple frontends could have
>-#       different root_url's
>+# The API_FRONTEND can list multiple frontends delimited
>+# by ',' (eg. ec2,deltacloud)
> #
>-if ENV['API_FRONTEND'].split(',').size > 1
>-
>-  ENV['API_FRONTEND'].split(',').each do |frontend|
>-    Deltacloud[frontend.to_sym].require!
>-    routes.merge!({
>-      Deltacloud[frontend].root_url => Deltacloud[frontend].klass
>-    })
>-  end
>-
>-else
>-  Deltacloud[ENV['API_FRONTEND'].to_sym].require!
>-  Deltacloud[ENV['API_FRONTEND'].to_sym].default_frontend!
>-  class IndexEntrypoint < Sinatra::Base
>-    get "/" do
>-      redirect Deltacloud.default_frontend.root_url, 301
>+def frontend_modules
>+  if ENV['API_FRONTEND'].split(',').size > 1
>+    ENV['API_FRONTEND'].split(',').map do |frontend|
>+      Deltacloud[frontend].require!
>+      Deltacloud[frontend].klass
>     end
>+  else
>+    Deltacloud[ENV['API_FRONTEND']].require!
>+    [Deltacloud[ENV['API_FRONTEND']].klass]
>   end
>-  routes['/'] = IndexEntrypoint.new
>-  routes[Deltacloud.default_frontend.root_url] = Deltacloud.default_frontend.klass
> end
>
>-
>-run Rack::Builder.new {
>-  use Rack::MatrixParams
>-  use Rack::DriverSelect
>-
>-  routes.merge!({
>-    "/stylesheets" =>  Rack::Directory.new( File.join(File.dirname(__FILE__), "public",
"stylesheets") ),
>-    "/javascripts" =>  Rack::Directory.new( File.join(File.dirname(__FILE__), "public",
"javascripts") )
>-  })
>-
>-  run Rack::URLMap.new(routes)
>-
>-} if respond_to? :run
>+run Rack::Cascade.new(frontend_modules)
>diff --git a/server/lib/deltacloud_rack.rb b/server/lib/deltacloud_rack.rb
>index 7b01524..ff461d7e 100644
>--- a/server/lib/deltacloud_rack.rb
>+++ b/server/lib/deltacloud_rack.rb
>@@ -65,8 +65,8 @@ module Deltacloud
>       @root_url = opts[:root_url]
>       @version = opts[:version]
>       @klass = opts[:klass]
>-      @logger = opts[:logger] || Rack::DeltacloudLogger
>-      @default_driver = opts[:default_driver] || :mock
>+      @logger = opts[:logger] || Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
>+      @default_driver = opts[:default_driver] || ENV['API_DRIVER'] || :mock
>       instance_eval(&block)
>     end
>
>diff --git a/server/lib/ec2/server.rb b/server/lib/ec2/server.rb
>index a6c3089..7a0a8d2 100644
>--- a/server/lib/ec2/server.rb
>+++ b/server/lib/ec2/server.rb
>@@ -36,8 +36,6 @@ module Deltacloud::EC2
>     helpers Deltacloud::EC2::Errors
>
>     enable :xhtml
>-    enable :dump_errors
>-    enable :show_errors
>     disable :show_exceptions
>
>     set :config, Deltacloud[:ec2]
>@@ -46,17 +44,21 @@ module Deltacloud::EC2
>     set :version, config.version
>     set :root, File.join(File.dirname(__FILE__), '..', '..')
>     set :public_folder, root + '/public'
>+    set :views, File.join(File.dirname(__FILE__), 'views')
>
>     error Deltacloud::EC2::QueryParser::InvalidAction do
>       status 400
>-      haml :error, :locals => { :code => 'InvalidAction', :message => 'The requested
action is not valid for this web service' }
>+      haml :error, :locals => {
>+        :code => 'InvalidAction',
>+        :message => 'The requested action is not valid for this web service'
>+      }
>     end
>
>     after do
>       headers 'Server' => 'Apache-Deltacloud-EC2/' + settings.version
>     end
>
>-    get '/' do
>+    get Deltacloud[:ec2].root_url do
>       headers 'Connection' => 'close'
>       unless params['Action']
>         redirect settings.root_url, 301
>-- 
>1.7.10.2
>

Mime
View raw message