Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 6 commits
  • 18 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 07, 2011
Heinrich Lee Yu Remove unused puppets and services
Change-Id: I2739fb6c67d2152e7eae46d6b28a72cd5591b80e
b45ab3b
Commits on Mar 11, 2011
Heinrich Lee Yu Added mongrel2 puppet
Change-Id: If7044d5cafbbdf8491743192c52879ca816a32df
6ed7274
Commits on May 09, 2011
@markjeee markjeee Changed :rack adapter to :rack_legacy. 4af3b41
@markjeee markjeee updated gemspec 83b4037
@markjeee markjeee merged 52bb081
@markjeee markjeee Change rack loader config.ru, to make it consistent with other rack l…
…oader.
16fd7a1
View
12 Manifest
@@ -3,7 +3,6 @@ Manifest
README
Rakefile
lib/palmade/puppet_master.rb
-lib/palmade/puppet_master/asinc_puppet.rb
lib/palmade/puppet_master/config.rb
lib/palmade/puppet_master/configurator.rb
lib/palmade/puppet_master/controller.rb
@@ -11,14 +10,16 @@ lib/palmade/puppet_master/eventd_puppet.rb
lib/palmade/puppet_master/family.rb
lib/palmade/puppet_master/family/standard_puppets.rb
lib/palmade/puppet_master/master.rb
-lib/palmade/puppet_master/proxy_puppet.rb
+lib/palmade/puppet_master/mongrel2_puppet.rb
+lib/palmade/puppet_master/mongrel2_puppet/backend.rb
+lib/palmade/puppet_master/mongrel2_puppet/connection.rb
+lib/palmade/puppet_master/mongrel2_puppet/rails_adapter.rb
+lib/palmade/puppet_master/mongrel2_puppet/request.rb
+lib/palmade/puppet_master/mongrel2_puppet/response.rb
lib/palmade/puppet_master/puppet.rb
lib/palmade/puppet_master/runner.rb
lib/palmade/puppet_master/service.rb
-lib/palmade/puppet_master/service_cache.rb
-lib/palmade/puppet_master/service_queue.rb
lib/palmade/puppet_master/service_redis.rb
-lib/palmade/puppet_master/service_tokyo_cabinet.rb
lib/palmade/puppet_master/socket_helper.rb
lib/palmade/puppet_master/syslogger.rb
lib/palmade/puppet_master/sysloggerio.rb
@@ -28,7 +29,6 @@ lib/palmade/puppet_master/thin_puppet.rb
lib/palmade/puppet_master/thin_websocket_connection.rb
lib/palmade/puppet_master/utils.rb
lib/palmade/puppet_master/worker.rb
-lib/palmade/puppet_master/workling_puppet.rb
puppet_master.gemspec
test/test_helper.rb
test/thin_websocket_test.rb
View
29 lib/palmade/puppet_master.rb
@@ -39,16 +39,11 @@ def self.master=(m); @master = m; end
autoload :ThinConnection, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/thin_connection')
autoload :ThinWebsocketConnection, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/thin_websocket_connection')
- autoload :ProxyPuppet, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/proxy_puppet')
- autoload :AsincPuppet, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/asinc_puppet')
- autoload :WorklingPuppet, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/workling_puppet')
+ autoload :Mongrel2Puppet, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/mongrel2_puppet')
# auxilliary services
autoload :Service, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/service')
- autoload :ServiceCache, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/service_cache')
- autoload :ServiceQueue, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/service_queue')
autoload :ServiceRedis, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/service_redis')
- autoload :ServiceTokyoCabinet, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/service_tokyo_cabinet')
# common set of launchers
autoload :Config, File.join(PUPPET_MASTER_LIB_DIR, 'puppet_master/config')
@@ -103,27 +98,7 @@ def require_redis
require 'redis'
end
end
-
- # THE FOLLOWING SERVICES HASN'T BEEN UPDATED YET, as of 2010-07-03
- def require_memcache
- unless defined?(::MemCache)
- gem 'memcache-client'
- require 'memcache'
- end
- end
-
- def require_beanstalk
- unless defined?(::Beanstalk)
- gem 'beanstalk-client'
- require 'beanstalk-client'
- end
- end
-
- def require_tt
- unless defined?(::TokyoTyrant)
- require 'tokyotyrant'
- end
- end
end
+
end
end
View
152 lib/palmade/puppet_master/asinc_puppet.rb
@@ -1,152 +0,0 @@
-module Palmade::PuppetMaster
- class AsincPuppet < Palmade::PuppetMaster::EventdPuppet
- DEFAULT_OPTIONS = {
- :nap_time => 0.5,
- :app => nil,
- :reloader => nil
- }
-
- def initialize(asinc_classes, options = { }, &block)
- super(DEFAULT_OPTIONS.merge(options), &block)
-
- if @proc_tag.nil?
- @proc_tag = "asinc"
- else
- @proc_tag = "#{proc_tag}.asinc"
- end
-
- @asinc_worker_module = options[:worker_module] || Palmade::Acts::AsincWorker
- @asinc_classes = asinc_classes
- @resolved_asinc_classes = [ ]
-
- @app = @options[:app]
- @reloader = @options[:reloader]
- end
-
- def post_build(m, fam)
- case @app
- when String
- @app = Palmade::Inflector.constantize(@app).new
- end
-
- case @reloader
- when String
- @reloader = Palmade::Inflector.constantize(@reloader).new
- end
- end
-
- def work_loop(worker, ret = nil, &block)
- super(worker) do
- if block_given?
- yield(self, worker)
- elsif !@work_loop.nil?
- @work_loop.call(self, worker)
- end
- EventMachine.next_tick { work_tubes(worker) }
- end
- ret
- end
-
- def after_fork(w)
- super
-
- if @asinc_worker_module.is_a?(String)
- @asinc_worker_module = Palmade::Inflector.constantize(@asinc_worker_module)
- end
-
- if @reloader.nil?
- _resolve_asinc_classes!
- _attach_worker_module!
- _prepare_asinc_classes!
- end
- end
-
- protected
-
- # TODO: Change this to work with asinc!
- def work_tubes(w)
- return unless w.ok?
- w.alive!
-
- total_worked = 0
-
- # if reloader, used, pre-load apps here
- unless @reloader.nil?
- _resolve_asinc_classes!
- _attach_worker_module!
- _prepare_asinc_classes!
- end
-
- # prepare_for dispatch
- _prepare_for_work!
- begin
- # let's do one work at a time
- @resolved_asinc_classes.each do |klass_data|
- worked, expired = klass_data[0].asinc_work(@app, nil, 1)
-
- # should only be working on only one method
- # per class (though, we won't sleep, just do a next_tick) -- see below
- if worked > 0
- total_worked += worked
- break
- end
- end
- ensure
- _cleanup_after_work!
-
- unless @reloader.nil?
- @resolved_asinc_classes.clear
- @reloader.call(self)
- end
- end
-
- if w.ok?
- w.alive!
- if total_worked > 0
- EventMachine.next_tick { work_tubes(w) }
- else
- # let's take a nap
- EventMachine.add_timer(@options[:nap_time]) { work_tubes(w) }
- end
- else
- # do nothing, let's just let it drop
- end
- end
-
- private
-
- def _prepare_for_work!; end
-
- def _cleanup_after_work!; end
-
- def _resolve_asinc_classes!
- (0...@asinc_classes.size).each do |i|
- case @asinc_classes[i]
- when String
- @resolved_asinc_classes[i] = [ Palmade::Inflector.constantize(@asinc_classes[i].to_s) ]
- when Array
- @resolved_asinc_classes[i] = [ Palmade::Inflector.constantize(@asinc_classes[i][0].to_s) ] + @asinc_classes[1..-1]
- when Class
- @resolved_asinc_classes[i] = [ @asinc_classes[i] ]
- else
- raise TypeError, "Expecting either a string or a class, not #{@asinc_classes[i].class.name}"
- end
- end unless @asinc_classes.empty?
- end
-
- def _attach_worker_module!
- (0...@resolved_asinc_classes.size).each do |i|
- unless @resolved_asinc_classes[i][0].included_modules.include?(@asinc_worker_module)
- @resolved_asinc_classes[i][0].send(:include, @asinc_worker_module)
- end
- end unless @resolved_asinc_classes.empty?
- end
-
- def _prepare_asinc_classes!
- (0...@resolved_asinc_classes.size).each do |i|
- klass = @resolved_asinc_classes[i][0]
- klass.send(:asinc_prepare, *@resolved_asinc_classes[i][1..-1]) if klass.respond_to?(:asinc_prepare)
- end unless @resolved_asinc_classes.empty?
- end
- end
-end
View
20 lib/palmade/puppet_master/family/standard_puppets.rb
@@ -10,20 +10,12 @@ def eventd_puppet(k = nil, options = nil, &block)
create_puppet(:eventd, k, options, &block)
end
- def workling_puppet(k = nil, options = nil, &block)
- create_puppet(:workling, k, options, &block)
- end
-
def thin_puppet(k = nil, options = nil, &block)
create_puppet(:thin, k, options, &block)
end
- def proxy_puppet(k = nil, options = nil, &block)
- create_puppet(:proxy, k, options, &block)
- end
-
- def asinc_puppet(k = nil, options = nil, &block)
- create_puppet(:asinc, k, options, &block)
+ def mongrel2_puppet(k = nil, options = nil, &block)
+ create_puppet(:mongrel2, k, options, &block)
end
def create_puppet(type, k = nil, options = nil, &block)
@@ -41,18 +33,14 @@ def create_puppet(type, k = nil, options = nil, &block)
end
case type
- when :asinc
- @puppets[k] = Palmade::PuppetMaster::AsincPuppet.new(options, &block)
when :eventd
@puppets[k] = Palmade::PuppetMaster::EventdPuppet.new(options, &block)
when :loop
@puppets[k] = Palmade::PuppetMaster::Puppet.new(options, &block)
- when :workling
- @puppets[k] = Palmade::PuppetMaster::WorklingPuppet.new(options, &block)
when :thin
@puppets[k] = Palmade::PuppetMaster::ThinPuppet.new(options, &block)
- when :proxy
- @puppets[k] = Palmade::PuppetMaster::ProxyPuppet.new(options, &block)
+ when :mongrel2
+ @puppets[k] = Palmade::PuppetMaster::Mongrel2Puppet.new(options, &block)
else
raise "Unknown puppet type: #{type}"
end
View
9 lib/palmade/puppet_master/master.rb
@@ -95,18 +95,9 @@ def boot_services
def use_service(type, options = { })
case type
- when :cache
- raise "Cache service already exist!" if @services.include?(:cache)
- @services[:cache] = Palmade::PuppetMaster::ServiceCache.new(self, :cache, options)
- when :queue
- raise "Queue service already exist!" if @services.include?(:queue)
- @services[:queue] = Palmade::PuppetMaster::ServiceQueue.new(self, :queue, options)
when :redis
raise "Redis service already exist!" if @services.include?(:redis)
@services[:redis] = Palmade::PuppetMaster::ServiceRedis.new(self, :redis, options)
- when :tokyo_cabinet
- raise "Tokyo Cabinet service already exist!" if @services.include?(:tokyo_cabinet)
- @services[:tokyo_cabinet] = Palmade::PuppetMaster::ServiceTokyoCabinet.new(self, :tokyo_cabinet, options)
else
raise "Unknown service type"
end
View
228 lib/palmade/puppet_master/mongrel2_puppet.rb
@@ -0,0 +1,228 @@
+require 'rack'
+require 'em-zeromq'
+
+begin
+ require 'yajl'
+rescue LoadError
+ begin
+ require 'json'
+ rescue LoadError
+ raise "You need either the yajl-ruby or json gems present in order to parse JSON!"
+ end
+end
+
+MONGREL2_PUPPET_LIBS_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'mongrel2_puppet'))
+
+module Palmade::PuppetMaster
+ class Mongrel2Puppet < Palmade::PuppetMaster::Puppet
+
+ JSON = Object.const_defined?('Yajl') ? ::Yajl::Parser : ::JSON
+ DEFAULT_OPTIONS = Palmade::PuppetMaster::Puppet::DEFAULT_OPTIONS.merge({
+ :idle_time => 15,
+ })
+
+ autoload :RailsAdapter, File.join(MONGREL2_PUPPET_LIBS_PATH, 'rails_adapter')
+ autoload :Backend, File.join(MONGREL2_PUPPET_LIBS_PATH, 'backend')
+ autoload :Connection, File.join(MONGREL2_PUPPET_LIBS_PATH, 'connection')
+ autoload :Request, File.join(MONGREL2_PUPPET_LIBS_PATH, 'request')
+ autoload :Response, File.join(MONGREL2_PUPPET_LIBS_PATH, 'response')
+
+ def initialize(options = { }, &block)
+ super(DEFAULT_OPTIONS.merge(options), &block)
+
+ @adapter = @options[:adapter]
+ @adapter_options = @options[:adapter_options]
+ end
+
+ def work_loop(worker, ret = nil, &block)
+ master_logger.warn "mongrel2 worker #{worker.proc_tag} started: #{$$}"
+
+ [ :INT ].each { |sig| trap(sig) { } } # do nothing
+ [ :QUIT ].each { |sig| trap(sig) { stop_work_loop(worker) } } # graceful shutdown
+ [ :TERM, :KILL ].each { |sig| trap(sig) { exit!(0) } } # instant #shutdown
+
+ @backend = Mongrel2Puppet::Backend.new(rack_application, @adapter_options[:mongrel2])
+
+ EventMachine.run do
+ EventMachine.epoll rescue nil
+ EventMachine.kqueue rescue nil
+
+ @backend.start
+
+ @idle_timer = EventMachine.add_timer(@options[:idle_time]) { idle_time(worker) }
+ end
+ worker.stop!
+
+ master_logger.warn "mongrel2 worker #{worker.proc_tag} stopped: #{$$}"
+
+ ret
+ end
+
+ def stop_work_loop(worker)
+ @backend.stop
+ worker.stop!
+ EventMachine.stop_event_loop if EventMachine.reactor_running?
+ end
+
+ protected
+
+ def rack_application
+ app = load_adapter
+
+ # Revert logger if Rails changes Logger behavior
+ if master_logger.is_a?(Logger)
+ if Logger.private_instance_methods.include?('old_format_message')
+ master_logger.instance_eval do
+ alias format_message old_format_message
+ end
+ end
+ if defined?(Logger::Formatter)
+ master_logger.formatter = Logger::Formatter.new
+ end
+ end
+
+ unless @options[:rack_builder].nil?
+ app = @options[:rack_builder].call(app, self)
+ end
+
+ # If a prefix is required, wrap in Rack URL mapper
+ app = Rack::URLMap.new(@options[:prefix] => app) if @options[:prefix]
+
+ # If a stats URL is specified, wrap in Stats adapter
+ app = Stats::Adapter.new(app, @options[:stats]) if @options[:stats]
+
+ app
+ end
+
+ def idle_time(w)
+ @idle_timer = nil
+ notify_alive!(w)
+ @idle_timer = EventMachine.add_timer(@options[:idle_time]) { idle_time(w) }
+ end
+
+ def notify_alive!(w)
+ w.alive! if w.ok?
+ end
+
+ def load_adapter
+ unless @adapter.nil?
+ ENV['RACK_ENV'] = @adapter_options[:environment] || 'development'
+ Object.const_set('RACK_ENV', @adapter_options[:environment] || 'development')
+
+ if @adapter.is_a?(Module)
+ @adapter
+ elsif @adapter.respond_to?(:call)
+ @adapter.call(self)
+ elsif @adapter.is_a?(Class)
+ @adapter.new(@adapter_options)
+ elsif @adapter == :rack
+ load_rack_adapter
+ elsif @adapter == :sinatra
+ # let's load the sinatra adapter found on config/sinatra.rb
+ load_sinatra_adapter
+ elsif @adapter == :camping
+ # let's load the camping adapter found on config/camping.rb
+ load_camping_adapter
+ else
+ opts = @adapter_options.merge(:prefix => @options[:prefix])
+ RailsAdapter.new(opts.merge(:root => opts[:chdir]))
+ end
+ else
+ raise ArgumentError, "Rack adapter for Mongrel2 is not specified. I'm too lazy to probe what u want to use."
+ end
+ end
+
+ def load_camping_adapter
+ root = @adapter_options[:root] || Dir.pwd
+ camping_boot = File.join(root, "config/camping.rb")
+ if File.exists?(camping_boot)
+
+ Object.const_set('CAMPING_ENV', RACK_ENV)
+ Object.const_set('CAMPING_ROOT', @adapter_options[:root])
+ Object.const_set('CAMPING_PREFIX', @adapter_options[:prefix])
+ Object.const_set('CAMPING_OPTIONS', @adapter_options)
+
+ require(camping_boot)
+
+ if defined?(::Camping)
+ # by now, camping should have been loaded
+ # let's attach the main camping app to thin server
+ unless Camping::Apps.first.nil?
+ Camping::Apps.first
+ else
+ raise ArgumentError, "No camping app defined"
+ end
+ else
+ raise LoadError, "It looks like Camping gem is not loaded properly (::Camping not defined)"
+ end
+ else
+ raise ArgumentError, "Set to load camping adapter, but could not find config/camping.rb"
+ end
+ end
+
+ def load_sinatra_adapter
+ root = @adapter_options[:root] || Dir.pwd
+ sinatra_boot = File.join(root, "config/sinatra.rb")
+ if File.exists?(sinatra_boot)
+
+ Object.const_set('SINATRA_ENV', RACK_ENV)
+ Object.const_set('SINATRA_ROOT', @adapter_options[:root])
+ Object.const_set('SINATRA_PREFIX', @adapter_options[:prefix])
+ Object.const_set('SINATRA_OPTIONS', @adapter_options)
+
+ require(sinatra_boot)
+
+ if defined?(::Sinatra)
+ if Object.const_defined?('SINATRA_APP')
+ Object.const_get('SINATRA_APP')
+ elsif defined?(::Sinatra::Application)
+ Sinatra::Application
+ else
+ raise ArgumentError, "No sinatra app defined"
+ end
+ else
+ raise LoadError, "It looks like Sinatra gem is not loaded properly (::Sinatra not defined)"
+ end
+ else
+ raise ArgumentError, "Set to load sinatra adapter, but could not find config/sinatra.rb"
+ end
+ end
+
+ def load_rack_adapter
+ root = @adapter_options[:root] || Dir.pwd
+
+ if @adapter_options.include?(:rack_boot)
+ rack_boot = @adapter_options[:rack_boot]
+ else
+ rack_boot = File.join(root, "config/rack.rb")
+ unless File.exists?(rack_boot)
+ raise ArgumentError, "Set to load rack adapter, but could not find #{rack_boot}"
+ end
+ end
+
+ Object.const_set('RACK_ROOT', @adapter_options[:root])
+ Object.const_set('RACK_PREFIX', @adapter_options[:prefix])
+ Object.const_set('RACK_OPTIONS', @adapter_options)
+
+ rack_app = nil
+
+ case rack_boot
+ when String
+ require(rack_boot)
+ when Proc
+ rack_app = rack_boot.call
+ else
+ raise ArgumentError, "Unsupported rack_boot option, #{rack_boot.class}"
+ end
+
+ if !rack_app.nil?
+ rack_app
+ elsif Object.const_defined?('RACK_APP')
+ Object.const_get('RACK_APP')
+ else
+ raise ArgumentError, "No rack app defined"
+ end
+ end
+
+ end
+end
View
43 lib/palmade/puppet_master/mongrel2_puppet/backend.rb
@@ -0,0 +1,43 @@
+require 'ffi-rzmq'
+
+module Palmade::PuppetMaster
+ class Mongrel2Puppet::Backend
+
+ CTX = EM::ZeroMQ::Context.new(1)
+
+ def initialize(app, options)
+ @app = app
+ @uuid, @sub, @pub = options['uuid'], options['recv'], options['send']
+ end
+
+ def start
+ starter = proc do
+ connect
+ end
+
+ if EventMachine.reactor_running?
+ starter.call
+ else
+ EventMachine.run(&starter)
+ end
+ end
+
+ def connect
+ # Connect to send responses
+ @resp = CTX.connect(ZMQ::PUB, @pub, :identity => @uuid)
+
+ # Connect to receive requests
+ @reqs = CTX.connect(ZMQ::PULL, @sub, Mongrel2Puppet::Connection.new(@app, @resp))
+ end
+
+ def stop
+ disconnect
+ end
+
+ def disconnect
+ @reqs.unbind if @reqs
+ @resp.unbind if @resp
+ end
+
+ end
+end
View
89 lib/palmade/puppet_master/mongrel2_puppet/connection.rb
@@ -0,0 +1,89 @@
+module Palmade::PuppetMaster
+ class Mongrel2Puppet::Connection
+
+ CONTENT_LENGTH = 'Content-Length'.freeze
+ TRANSFER_ENCODING = 'Transfer-Encoding'.freeze
+ CHUNKED_REGEXP = /\bchunked\b/i.freeze
+
+ AsyncResponse = [-1, {}, []].freeze
+
+ def initialize(app, response_sock)
+ @app = app
+ @response_sock = response_sock
+ end
+
+ def on_readable(socket, messages)
+ msg = messages.inject("") do |str, m|
+ str += m.copy_out_string
+ m.close
+ str
+ end
+
+ @request = msg.nil? ? nil : Mongrel2Puppet::Request.parse(msg)
+ if !@request.nil? && !@request.disconnect?
+ process
+ end
+ end
+
+ def process
+ post_process(pre_process)
+ end
+
+ def pre_process
+ @request.async_callback = method(:post_process)
+
+ response = AsyncResponse
+ catch(:async) do
+ response = @app.call(@request.env)
+ end
+ response
+ end
+
+ def post_process(result)
+ return unless result
+
+ # Status code -1 indicates that we're going to respond later (async).
+ return if result.first == AsyncResponse.first
+
+ # Set the Content-Length header if possible
+ set_content_length(result) if need_content_length?(result)
+
+ status, headers, body = result
+ reply(body, status, headers)
+ end
+
+ def reply(body, status = 200, headers = {})
+ resp = Mongrel2Puppet::Response.new(@response_sock)
+ resp.send_http(@request, body, status, headers)
+ resp.close(@request) if @request.close?
+ end
+
+ protected
+
+ def need_content_length?(result)
+ status, headers, body = result
+ return false if status == -1
+ return false if headers.has_key?(CONTENT_LENGTH)
+ return false if (100..199).include?(status) || status == 204 || status == 304
+ return false if headers.has_key?(TRANSFER_ENCODING) && headers[TRANSFER_ENCODING] =~ CHUNKED_REGEXP
+ return false unless body.kind_of?(String) || body.kind_of?(Array)
+ true
+ end
+
+ def set_content_length(result)
+ headers, body = result[1..2]
+ case body
+ when String
+ # See http://redmine.ruby-lang.org/issues/show/203
+ headers[CONTENT_LENGTH] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
+ when Array
+ bytes = 0
+ body.each do |p|
+ bytes += p.respond_to?(:bytesize) ? p.bytesize : p.size
+ end
+ headers[CONTENT_LENGTH] = bytes.to_s
+ end
+ end
+
+ end
+end
View
178 lib/palmade/puppet_master/mongrel2_puppet/rails_adapter.rb
@@ -0,0 +1,178 @@
+require 'cgi'
+
+# Adapter to run a Rails app with any supported Rack handler.
+# By default it will try to load the Rails application in the
+# current directory in the development environment.
+#
+# Options:
+# root: Root directory of the Rails app
+# environment: Rails environment to run in (development [default], production or test)
+# prefix: Set the relative URL root.
+#
+# Based on http://fuzed.rubyforge.org/ Rails adapter
+module Palmade::PuppetMaster
+ class Mongrel2Puppet::RailsAdapter
+ FILE_METHODS = %w(GET HEAD).freeze
+
+ def initialize(options={})
+ @root = options[:root] || Dir.pwd
+ @env = options[:environment] || 'development'
+ @prefix = options[:prefix]
+
+ load_application
+
+ @rails_app = if rack_based?
+ ActionController::Dispatcher.new
+ else
+ CgiApp.new
+ end
+
+ @file_app = Rack::File.new(::File.join(RAILS_ROOT, "public"))
+ end
+
+ def rack_based?
+ rails_version = ::Rails::VERSION
+ rails_version::MAJOR >= 2 && rails_version::MINOR >= 2 && rails_version::TINY >= 3
+ end
+
+ def load_application
+ ENV['RAILS_ENV'] = @env
+
+ require "#{@root}/config/environment"
+ require 'dispatcher'
+
+ if @prefix
+ if ActionController::Base.respond_to?(:relative_url_root=)
+ ActionController::Base.relative_url_root = @prefix # Rails 2.1.1
+ else
+ ActionController::AbstractRequest.relative_url_root = @prefix
+ end
+ end
+ end
+
+ def file_exist?(path)
+ full_path = ::File.join(@file_app.root, Rack::Utils.unescape(path))
+ ::File.file?(full_path) && ::File.readable_real?(full_path)
+ end
+
+ def call(env)
+ path = env['PATH_INFO'].chomp('/')
+ method = env['REQUEST_METHOD']
+ cached_path = (path.empty? ? 'index' : path) + ActionController::Base.page_cache_extension
+
+ if FILE_METHODS.include?(method)
+ if file_exist?(path) # Serve the file if it's there
+ return @file_app.call(env)
+ elsif file_exist?(cached_path) # Serve the page cache if it's there
+ env['PATH_INFO'] = cached_path
+ return @file_app.call(env)
+ end
+ end
+
+ # No static file, let Rails handle it
+ @rails_app.call(env)
+ end
+
+ protected
+ # For Rails pre Rack (2.3)
+ class CgiApp
+ def call(env)
+ request = Request.new(env)
+ response = Response.new
+ session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS
+ cgi = CGIWrapper.new(request, response)
+
+ Dispatcher.dispatch(cgi, session_options, response)
+
+ response.finish
+ end
+ end
+
+ class CGIWrapper < ::CGI
+ def initialize(request, response, *args)
+ @request = request
+ @response = response
+ @args = *args
+ @input = request.body
+
+ super *args
+ end
+
+ def header(options = "text/html")
+ if options.is_a?(String)
+ @response['Content-Type'] = options unless @response['Content-Type']
+ else
+ @response['Content-Length'] = options.delete('Content-Length').to_s if options['Content-Length']
+
+ @response['Content-Type'] = options.delete('type') || "text/html"
+ @response['Content-Type'] += "; charset=" + options.delete('charset') if options['charset']
+
+ @response['Content-Language'] = options.delete('language') if options['language']
+ @response['Expires'] = options.delete('expires') if options['expires']
+
+ @response.status = options.delete('Status') if options['Status']
+
+ # Convert 'cookie' header to 'Set-Cookie' headers.
+ # Because Set-Cookie header can appear more the once in the response body,
+ # we store it in a line break seperated string that will be translated to
+ # multiple Set-Cookie header by the handler.
+ if cookie = options.delete('cookie')
+ cookies = []
+
+ case cookie
+ when Array then cookie.each { |c| cookies << c.to_s }
+ when Hash then cookie.each { |_, c| cookies << c.to_s }
+ else cookies << cookie.to_s
+ end
+
+ @output_cookies.each { |c| cookies << c.to_s } if @output_cookies
+
+ @response['Set-Cookie'] = [@response['Set-Cookie'], cookies].compact
+ # See http://groups.google.com/group/rack-devel/browse_thread/thread/e8759b91a82c5a10/a8dbd4574fe97d69?#a8dbd4574fe97d69
+ if Thin.ruby_18?
+ @response['Set-Cookie'].flatten!
+ else
+ @response['Set-Cookie'] = @response['Set-Cookie'].join("\n")
+ end
+ end
+
+ options.each { |k,v| @response[k] = v }
+ end
+
+ ""
+ end
+
+ def params
+ @params ||= @request.params
+ end
+
+ def cookies
+ @request.cookies
+ end
+
+ def query_string
+ @request.query_string
+ end
+
+ # Used to wrap the normal args variable used inside CGI.
+ def args
+ @args
+ end
+
+ # Used to wrap the normal env_table variable used inside CGI.
+ def env_table
+ @request.env
+ end
+
+ # Used to wrap the normal stdinput variable used inside CGI.
+ def stdinput
+ @input
+ end
+
+ def stdoutput
+ STDERR.puts "stdoutput should not be used."
+ @response.body
+ end
+ end
+ end
+end
View
81 lib/palmade/puppet_master/mongrel2_puppet/request.rb
@@ -0,0 +1,81 @@
+module Palmade::PuppetMaster
+ class Mongrel2Puppet::Request
+
+ attr_reader :headers, :body, :uuid, :conn_id, :path
+
+ # CGI-like request environment variables
+ attr_reader :env
+
+ class << self
+ def parse(msg)
+ # UUID CONN_ID PATH SIZE:HEADERS,SIZE:BODY,
+ uuid, conn_id, path, rest = msg.split(' ', 4)
+ headers, rest = parse_netstring(rest)
+ body, _ = parse_netstring(rest)
+ headers = Mongrel2Puppet::JSON.parse(headers)
+ new(uuid, conn_id, path, headers, body)
+ end
+
+ def parse_netstring(ns)
+ # SIZE:HEADERS,
+
+ len, rest = ns.split(':', 2)
+ len = len.to_i
+ raise "Netstring did not end in ','" unless rest[len].chr == ','
+ [rest[0, len], rest[(len + 1)..-1]]
+ end
+ end
+
+ def initialize(uuid, conn_id, path, headers, body)
+ @uuid, @conn_id, @path, @headers, @body = uuid, conn_id, path, headers, body
+ @data = headers['METHOD'] == 'JSON' ? Mongrel2Puppet::JSON.parse(body) : {}
+ initialize_env
+ end
+
+ def initialize_env
+ script_name = ENV['RACK_RELATIVE_URL_ROOT'] ||
+ (headers['PATTERN'].split('(', 2).first.gsub(/\/$/, '') if headers['PATTERN'])
+
+ @env = {
+ 'rack.version' => Rack::VERSION,
+ 'rack.url_scheme' => 'http', # Only HTTP for now
+ 'rack.input' => StringIO.new(@body),
+ 'rack.errors' => $stderr,
+ 'rack.multithread' => true,
+ 'rack.multiprocess' => true,
+ 'rack.run_once' => false,
+ 'mongrel2.pattern' => headers['PATTERN'],
+ 'REQUEST_METHOD' => headers['METHOD'],
+ 'SCRIPT_NAME' => script_name,
+ 'PATH_INFO' => (headers['PATH'].gsub(script_name, '') if headers['PATH']),
+ 'QUERY_STRING' => headers['QUERY'] || ''
+ }
+
+ @env['SERVER_NAME'], @env['SERVER_PORT'] = headers['host'].split(':', 2) if headers['host']
+ headers.each do |key, val|
+ unless key =~ /content_(type|length)/i
+ key = "HTTP_#{key.upcase.gsub('-', '_')}"
+ end
+ @env[key] = val
+ end
+ end
+
+ def async_callback=(callback)
+ @env['async.callback'] = callback
+ @env['async.close'] = EventMachine::DefaultDeferrable.new
+ end
+
+ def async_close
+ @async_close ||= @env[ASYNC_CLOSE]
+ end
+
+ def disconnect?
+ headers['METHOD'] == 'JSON' && @data['type'] == 'disconnect'
+ end
+
+ def close?
+ headers['connection'] == 'close' || headers['VERSION'] == 'HTTP/1.0'
+ end
+
+ end
+end
View
85 lib/palmade/puppet_master/mongrel2_puppet/response.rb
@@ -0,0 +1,85 @@
+module Palmade::PuppetMaster
+ class Mongrel2Puppet::Response
+
+ StatusMessage = {
+ 100 => 'Continue',
+ 101 => 'Switching Protocols',
+ 200 => 'OK',
+ 201 => 'Created',
+ 202 => 'Accepted',
+ 203 => 'Non-Authoritative Information',
+ 204 => 'No Content',
+ 205 => 'Reset Content',
+ 206 => 'Partial Content',
+ 300 => 'Multiple Choices',
+ 301 => 'Moved Permanently',
+ 302 => 'Found',
+ 303 => 'See Other',
+ 304 => 'Not Modified',
+ 305 => 'Use Proxy',
+ 307 => 'Temporary Redirect',
+ 400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 402 => 'Payment Required',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 405 => 'Method Not Allowed',
+ 406 => 'Not Acceptable',
+ 407 => 'Proxy Authentication Required',
+ 408 => 'Request Timeout',
+ 409 => 'Conflict',
+ 410 => 'Gone',
+ 411 => 'Length Required',
+ 412 => 'Precondition Failed',
+ 413 => 'Request Entity Too Large',
+ 414 => 'Request-URI Too Large',
+ 415 => 'Unsupported Media Type',
+ 416 => 'Request Range Not Satisfiable',
+ 417 => 'Expectation Failed',
+ 500 => 'Internal Server Error',
+ 501 => 'Not Implemented',
+ 502 => 'Bad Gateway',
+ 503 => 'Service Unavailable',
+ 504 => 'Gateway Timeout',
+ 505 => 'HTTP Version Not Supported'
+ }
+
+ ZMQ_RESP = "%s %d:%s, %s".freeze
+ HTTP_HEADER = "HTTP/1.1 %s %s\r\n%s\r\n\r\n".freeze
+ HTTP_HEADER_KEY_VAL = "%s: %s".freeze
+
+ def initialize(resp)
+ @resp = resp
+ end
+
+ def send_http(req, body, status, headers)
+ send_resp(req.uuid, req.conn_id, build_http_headers(status, headers))
+
+ if body.respond_to?(:each)
+ body.each do |b|
+ send_resp(req.uuid, req.conn_id, b) unless b == ''
+ end
+ else
+ send_resp(req.uuid, req.conn_id, body.to_s)
+ end
+
+ body.close if body.respond_to?(:close)
+ end
+
+ def close(req)
+ send_resp(req.uuid, req.conn_id, '')
+ end
+
+ private
+
+ def send_resp(uuid, conn_id, data)
+ @resp.send_msg(ZMQ_RESP % [uuid, conn_id.size, conn_id, data])
+ end
+
+ def build_http_headers(status, headers)
+ headers = headers.map{ |k, v| HTTP_HEADER_KEY_VAL % [k,v] }.join("\r\n")
+ HTTP_HEADER % [status, StatusMessage[status.to_i], headers]
+ end
+
+ end
+end
View
240 lib/palmade/puppet_master/proxy_puppet.rb
@@ -1,240 +0,0 @@
-module Palmade::PuppetMaster
- class ProxyPuppet < Palmade::PuppetMaster::EventdPuppet
- DEFAULT_OPTIONS = {
- # to, accepts any connections
- # - host:port
- # - /tmp/some.sock
- :to => nil,
- :idle_time => 5
- }
-
- class ClientConnection < EventMachine::Connection
- attr_accessor :puppet
- attr_accessor :blind
-
- def initialize
- @puppet = nil
- @proxy_conn = nil
- end
-
- def post_init
- end
-
- def receive_data(data)
- if @proxy_conn.nil?
- # only supports data for connecting
- to, error = @puppet.infer(data)
- unless to.nil?
- @proxy_conn = create_proxy(to)
- @proxy_conn.send_data(data) #if @blind
- else
- send_data(error)
- close_connection
- end
- else
- @proxy_conn.send_data(data)
- end
- end
-
- # if the other end has closed their connection
- def proxy_target_unbound
- @proxy_conn = nil
- close_connection
- end
-
- def unbind
- unless @proxy_conn.nil?
- @proxy_conn.close_connection_after_writing rescue nil
- @proxy_conn = nil
- end
- @puppet.connection_finished(self)
- end
-
- protected
-
- def create_proxy(to)
- if to[0] == ?/
- host = to
- port = nil
- else
- host, port = to.split(':')
- end
-
- EventMachine.connect(host, port, ProxyConnection, self)
- end
- end
-
- class ProxyConnection < EventMachine::Connection
- def initialize(client)
- @client = client
- end
-
- def post_init
- # let's enable bi-directional flow
- EventMachine.enable_proxy(@client, self)
- EventMachine.enable_proxy(self, @client)
- end
-
- def proxy_target_unbound
- close_connection
- end
-
- def unbind
- @client.close_connection_after_writing rescue nil
- end
- end
-
- def initialize(options = { }, &block)
- super(DEFAULT_OPTIONS.merge(options), &block)
-
- if @proc_tag.nil?
- @proc_tag = "proxy"
- else
- @proc_tag = "proxy.#{@proc_tag}"
- end
-
- @listen_key = nil
- @sockets = nil
- @signatures = nil
- @connections = [ ]
- @stopping = false
-
- @connection_klass = ClientConnection
- end
-
- def after_fork(w)
- super(w)
- master = w.master
-
- # let's set the sockets with the proper settings for
- # attaching as acceptors to EventMachine
- if master.listeners[@listen_key].nil? || master.listeners[@listen_key].empty?
- raise ArgumentError, "No configured #{@listen_key || 'default'} listeners from master"
- else
- @sockets = master.listeners[@listen_key]
- raise ArgumentError, "Nothing to do, no sockets defined in master" if @sockets.nil? || @sockets.empty?
- end
-
- # * FD_CLOEXEC <-- this is done on the worker class (init method)
- # * SO_REUSEADDR <-- TODO: figure out why we need this? couldn't find it in unicorn
- # * Set non-blocking <--
- @sockets.each do |s|
- s.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
- end
- end
-
- def work_loop(worker, ret = nil, &block)
- master_logger.warn "proxy worker #{worker.proc_tag} started: #{$$}"
-
- # trap(:USR1) { } do nothing, it should reload logs
- trap(:QUIT) { stop_work_loop(worker) }
- [ :TERM, :INT ].each { |sig| trap(sig) { stop_work_loop(worker, true) } } # instant shutdown
-
- EventMachine.run do
- EventMachine.epoll rescue nil
- EventMachine.kqueue rescue nil
-
- # do some work
- if block_given?
- yield(self, worker)
- elsif !@work_loop.nil?
- @work_loop.call(self, worker)
- else
- start!
- end
-
- EventMachine.add_timer(@options[:idle_time]) { idle_time(worker) }
- end
- worker.stop!
- stop
-
- master_logger.warn "proxy worker #{worker.proc_tag} stopped: #{$$}"
-
- ret
- end
-
- def stop_work_loop(worker, now = false)
- worker.stop!
-
- if now
- stop!
- else
- stop
- end
- end
-
- # infer data sent by client
- def infer(data)
- to = nil
-
- if @options[:to].nil?
- error = "-ERR Not implemented\r\n"
- else
- if @options[:to].is_a?(Array)
- @round = 0 unless defined?(@round)
-
- to = @options[:to][@round]
- error = nil
-
- if @round == @options[:to].size - 1
- @round = 0
- else
- @round += 1
- end
- else
- to = @options[:to]
- error = nil
- end
- end
-
- [ to, error ]
- end
-
- # Called by a connection when it's unbinded.
- def connection_finished(connection)
- @connections.delete(connection)
- end
-
- protected
-
- def stop
- @stopping = true
- @signatures.each do |s|
- EventMachine.stop_accept(s)
- end unless @signatures.empty? || !EventMachine.reactor_running?
-
- # we just stop right away, since
- # we're a blind proxy, we don't know what's going on
- # in the pipes
- stop!
- end
-
- def stop!
- if EventMachine.reactor_running?
- # we dup here, since the connection_finished hook above
- # might be called every time we call close_connection
- @connections.dup.each { |connection| connection.close_connection } unless @connections.empty?
-
- EventMachine.stop_event_loop
- end
- end
-
- def start!
- @signatures = @sockets.collect do |s|
- EventMachine.accept(s, @client_connection, &method(:initialize_connection))
- end unless @sockets.nil?
- end
-
- def initialize_connection(connection)
- connection.puppet = self
- @connections << connection
- end
-
- def idle_time(w)
- if w.ok?
- w.alive!
- EventMachine.add_timer(@options[:idle_time]) { idle_time(w) }
- end
- end
- end
-end
View
79 lib/palmade/puppet_master/service_cache.rb
@@ -1,79 +0,0 @@
-module Palmade::PuppetMaster
- class ServiceCache < Palmade::PuppetMaster::Service
- def self.memcached_path; @@memcached_path; end
- def self.memcached_path=(mp); @@memcached_path = mp; end
- self.memcached_path = `which memcached`.strip
-
- DEFAULT_OPTIONS = {
- # if listen_host is nil, then use unix sockets
- # Ruby memcache client don't support this!
- # :listen_host => nil,
- :listen_host => '127.0.0.1'.freeze,
- :listen_port => nil,
- :max_memory => 16,
- :client_options => { },
- :thnum => 2
- }
-
- def initialize(master, service_name = nil, options = { })
- super(master, service_name || :cache, DEFAULT_OPTIONS.merge(options))
-
- @listen_port = @options[:listen_port]
- @listen_host = @options[:listen_host]
- end
-
- def start
- cmd = "#{self.class.memcached_path} -P #{service_pid_file} -U 0 -m #{@options[:max_memory]} -t #{@options[:thnum]}"
- unless @listen_host.nil?
- if @listen_port.nil?
- @listen_port = find_available_port
- end
- @master.reserved_ports.add(@listen_port)
-
- logger.warn "#{@service_name} listen on: #{@listen_host}:#{@listen_port}"
- cmd += " -l #{@listen_host} -p #{@listen_port}"
- else
- @listen_host = service_sock_file
- cmd += " -s #{@listen_host}"
- end
-
- fork_service(cmd)
- end
-
- def reap!(*args)
- if super(*args)
- if @options[:listen_port].nil?
- @master.reserved_ports.delete(@listen_port)
- @listen_port = nil
- end
- end
- end
-
- def client
- if @client.nil? && !@disabled
- Palmade::PuppetMaster.require_memcache
-
- logger.warn "#{@service_name} client connect: #{@listen_host}:#{@listen_port}"
- @client = MemCache.new("#{@listen_host}:#{@listen_port}", @options[:client_options])
- else
- @client
- end
- end
-
- def client_reset
- unless @client.nil?
- @client.close
- @client = nil
- client
- end
- end
-
- def reset
- client.reset unless @client.nil?
- end
-
- def close
- client.close unless @client.nil?
- end
- end
-end
View
70 lib/palmade/puppet_master/service_queue.rb
@@ -1,70 +0,0 @@
-module Palmade::PuppetMaster
- class ServiceQueue < Palmade::PuppetMaster::Service
- def self.beanstalkd_path; @@beanstalkd_path; end
- def self.beanstalkd_path=(bp); @@beanstalkd_path = bp; end
- self.beanstalkd_path = `which beanstalkd`.strip
-
- DEFAULT_OPTIONS = {
- :listen_host => '127.0.0.1',
- :listen_port => nil
- }
-
- def initialize(master, service_name = nil, options = { })
- super(master, service_name || :queue, DEFAULT_OPTIONS.merge(options))
-
- @listen_port = @options[:listen_port]
- @listen_host = @options[:listen_host]
- end
-
- def start
- if @listen_port.nil?
- @listen_port = find_available_port
- end
- @master.reserved_ports.add(@listen_port)
-
- logger.warn "#{@service_name} listen on: #{@listen_host}:#{@listen_port}"
-
- cmd = "#{self.class.beanstalkd_path} -l #{@listen_host} -p #{@listen_port}"
- fork_service(cmd)
- end
-
- def reap!(*args)
- if super(*args)
- if @options[:listen_port].nil?
- @master.reserved_ports.delete(@listen_port)
- @listen_port = nil
- end
- end
- end
-
- def reset
- unless @client.nil?
- client.close
- client.connect
- end
- end
-
- def client_reset
- unless @client.nil?
- @client.close
- @client = nil
- client
- end
- end
-
- def client
- if @client.nil? && !@disabled
- Palmade::PuppetMaster.require_beanstalk
-
- logger.warn "#{@service_name} client connect: #{@listen_host}:#{@listen_port}"
- @client = Beanstalk::Pool.new("#{@listen_host}:#{@listen_port}")
- else
- @client
- end
- end
-
- def close
- client.close unless @client.nil?
- end
- end
-end
View
162 lib/palmade/puppet_master/service_tokyo_cabinet.rb
@@ -1,162 +0,0 @@
-module Palmade::PuppetMaster
- class ServiceTokyoCabinet < Palmade::PuppetMaster::Service
- def self.ttserver_path; @@ttserver_path; end
- def self.ttserver_path=(tp); @@ttserver_path = tp; end
- self.ttserver_path = `which ttserver`.strip
-
- DEFAULT_OPTIONS = {
- :listen_host => nil,
- :listen_port => nil,
- :client_options => { },
- :stealth => true,
-
- :thnum => 2,
-
- :schema => :hash,
-
- :schema_options => {
-# :capsiz => 16 * (1024 * 1024), # 16MB
-# :capnum => 100000
- }
- }
-
- def initialize(master, service_name = nil, options = { })
- super(master, service_name || :tokyo_cabinet, DEFAULT_OPTIONS.merge(options))
-
- @listen_port = @options[:listen_port]
- @listen_host = @options[:listen_host]
-
- @temp_files = { }
- end
-
- def start
- cmd_args = "-thnum #{@options[:thnum]} -le"
- unless @options[:stealth]
- cmd_args += " -pid #{service_pid_file} -log #{service_log_file}"
- end
-
- unless @listen_host.nil? || @listen_host[0] == ?/
- if @listen_port.nil?
- @listen_port = find_available_port
- end
- @master.reserved_ports.add(@listen_port)
-
- logger.warn "#{@service_name} listening on: #{@listen_host}:#{@listen_port}"
- cmd_args += " -host #{@listen_host} -port #{@listen_post}"
- else
- @listen_host = service_sock_file
-
- logger.warn "#{@service_name} listening on: #{@listen_host}"
- cmd_args += " -host #{@listen_host} -port 0"
- end
-
- if @options.include?(:ulog)
- cmd_args += " -ulog #{@options[:ulog]}"
-
- if @options.include?(:ulim)
- cmd_args += " -ulim #{@options[:ulim]}"
- end
-
- if @options.include?(:uas)
- cmd_args += " -uas"
- end
- end
-
- if @options.include?(:server_id)
- cmd_args += " -sid #{@options[:server_id]}"
- end
-
- if @options.include?(:ext)
- cmd_args += " -ext #{@options[:ext]}"
-
- if @options.include?(:extpc)
- cmd_args += " -extpc #{@options[:extpc][0]} #{@options[:extpc][1]}"
- end
- end
-
- if @options.include?(:db)
- dbname = "#{@options[:db]}#{schema_options}"
- else
- case @options[:schema]
- when :hash
- dbname = "*#{schema_options}"
- when :btree
- dbname = "+#{schema_options}"
- else
- raise ArgumentError, "Unknown schema: #{@options[:schema]}"
- end
- end
-
- fork_service(self.class.ttserver_path, *(cmd_args.strip.split(' ').push(dbname)))
- end
-
- def schema_options
- @options[:schema_options].keys.collect do |k|
- "##{k}=#{@options[:schema_options][k]}"
- end.join('')
- end
-
- def reap!(*args)
- if super(*args)
- if @options[:listen_port].nil?
- @master.reserved_ports.delete(@listen_port)
- @listen_port = nil
- end
- end
- end
-
- def client
- if @client.nil? && !@disabled
- Palmade::PuppetMaster.require_tt
-
- @client = ::TokyoTyrant::RDB.new
- if @listen_host[0] == ?/
- logger.warn "#{@service_name} client connect: #{@listen_host}"
- @client.open(@listen_host)
- else
- logger.warn "#{@service_name} client connect: #{@listen_host}:#{@listen_port}"
- @client.open(@listen_host, @listen_port)
- end
- else
- check_if_alive!
- end
-
- @client
- end
-
- def client_reset
- close unless @client.nil?
- @client = nil
- client
- end
-
- def reset
- unless @client.nil?
- close
- reopen
- end
- end
-
- def close
- unless @client.nil?
- @client.close
- end
- end
-
- def reopen
- if @listen_host[0] == ?/
- @client.open(@listen_host)
- else
- @client.open(@listen_host, @listen_port)
- end
- end
-
- protected
-
- def check_if_alive!
- unless @client.nil?
- reset if @client.stat.nil?
- end
- end
- end
-end
View
4 lib/palmade/puppet_master/thin_puppet.rb
@@ -255,7 +255,7 @@ def load_adapter
@adapter.call(self)
elsif @adapter.is_a?(Class)
@adapter.new(@adapter_options)
- elsif @adapter == :rack
+ elsif @adapter == :rack_legacy
load_rack_adapter
elsif @adapter == :sinatra
# let's load the sinatra adapter found on config/sinatra.rb
@@ -334,7 +334,7 @@ def load_rack_adapter
if @adapter_options.include?(:rack_boot)
rack_boot = @adapter_options[:rack_boot]
else
- rack_boot = File.join(root, "config/rack.rb")
+ rack_boot = File.join(root, "config.ru")
unless File.exists?(rack_boot)
raise ArgumentError, "Set to load rack adapter, but could not find #{rack_boot}"
end
View
119 lib/palmade/puppet_master/workling_puppet.rb
@@ -1,119 +0,0 @@
-module Palmade::PuppetMaster
- class WorklingPuppet < Palmade::PuppetMaster::EventdPuppet
- DEFAULT_OPTIONS = {
- :worklings => :all,
- :routing => nil,
- :dispatcher => nil,
- :nap_time => 0.5
- }
-
- attr_reader :worklings
-
- def initialize(options = { }, &block)
- super(DEFAULT_OPTIONS.merge(options), &block)
-
- if @proc_tag.nil?
- @proc_tag = "workling"
- else
- @proc_tag = "#{@proc_tag}.workling"
- end
-
- @worklings = @options[:worklings]
- @discovered_classes = nil
- @active_routes = nil
-
- @dispatcher = nil
- @routng = nil
- end
-
- def post_build(m, fam)
- super
-
- # this is on post-build, since if we're running with thin
- # we want thin to load rails adapter first
- if @options[:dispatcher].nil?
- @dispatcher = Workling::Remote.dispatcher
- else
- @dispatcher = @options[:dispatcher]
- end
-
- if @options[:routing].nil?
- @routing = @dispatcher.routing
- else
- @routing = @options[:routing]
- end
- end
-
- def client
- @dispatcher.client
- end
-
- def work_loop(worker, ret = nil, &block)
- super(worker) do
- if block_given?
- yield(self, worker)
- elsif !@work_loop.nil?
- @work_loop.call(self, worker)
- end
-
- EventMachine.next_tick { work_routes(worker) }
- end
- ret
- end
-
- protected
-
- def work_routes(w)
- return unless w.ok?
- w.alive!
-
- active_routes.each do |ar|
- args = client.retrieve(ar)
- unless args.nil?
- run(ar, args)
- end
- end unless active_routes.nil? || active_routes.empty?
-
- if w.ok?
- w.alive!
- EventMachine.add_timer(@options[:nap_time]) { work_routes(w) }
- else
- # do nothing, let's just let it drop
- end
- end
-
- def run(route, args)
- klass = @routing[route]
- method = @routing.method_name(route)
-
- #warn "dispatching: #{klass} #{method}, #{args.inspect}"
- klass.dispatch_to_worker_method(method, *args)
- end
-
- def discovered_classes
- if @discovered_classes.nil?
- if @worklings == :all
- @discovered_classes = Workling::Discovery.discovered.dup
- else
- @discovered_classes = [ ]
- @worklings.each do |cn|
- if Workling::Discovery.discovered.include?(cn)
- @discovered_classes.push(cn)
- end
- end
- end
- @discovered_classes
- else
- @discovered_classes
- end
- end
-
- def active_routes
- if @active_routes.nil?
- @active_routes = discovered_classes.map { |clazz| @routing.queue_names_routing_class(clazz) }.flatten
- else
- @active_routes
- end
- end
- end
-end
View
13 puppet_master.gemspec
@@ -6,21 +6,20 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Palmade"]
- s.date = %q{2010-12-15}
+ s.date = %q{2011-05-09}
s.description = %q{Master of puppets}
s.email = %q{}
- s.extra_rdoc_files = ["README", "lib/palmade/puppet_master.rb", "lib/palmade/puppet_master/asinc_puppet.rb", "lib/palmade/puppet_master/config.rb", "lib/palmade/puppet_master/configurator.rb", "lib/palmade/puppet_master/controller.rb", "lib/palmade/puppet_master/eventd_puppet.rb", "lib/palmade/puppet_master/family.rb", "lib/palmade/puppet_master/family/standard_puppets.rb", "lib/palmade/puppet_master/master.rb", "lib/palmade/puppet_master/proxy_puppet.rb", "lib/palmade/puppet_master/puppet.rb", "lib/palmade/puppet_master/runner.rb", "lib/palmade/puppet_master/service.rb", "lib/palmade/puppet_master/service_cache.rb", "lib/palmade/puppet_master/service_queue.rb", "lib/palmade/puppet_master/service_redis.rb", "lib/palmade/puppet_master/service_tokyo_cabinet.rb", "lib/palmade/puppet_master/socket_helper.rb", "lib/palmade/puppet_master/syslogger.rb", "lib/palmade/puppet_master/sysloggerio.rb", "lib/palmade/puppet_master/thin_backend.rb", "lib/palmade/puppet_master/thin_connection.rb", "lib/palmade/puppet_master/thin_puppet.rb", "lib/palmade/puppet_master/thin_websocket_connection.rb", "lib/palmade/puppet_master/utils.rb", "lib/palmade/puppet_master/worker.rb", "lib/palmade/puppet_master/workling_puppet.rb"]
- s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "lib/palmade/puppet_master.rb", "lib/palmade/puppet_master/asinc_puppet.rb", "lib/palmade/puppet_master/config.rb", "lib/palmade/puppet_master/configurator.rb", "lib/palmade/puppet_master/controller.rb", "lib/palmade/puppet_master/eventd_puppet.rb", "lib/palmade/puppet_master/family.rb", "lib/palmade/puppet_master/family/standard_puppets.rb", "lib/palmade/puppet_master/master.rb", "lib/palmade/puppet_master/proxy_puppet.rb", "lib/palmade/puppet_master/puppet.rb", "lib/palmade/puppet_master/runner.rb", "lib/palmade/puppet_master/service.rb", "lib/palmade/puppet_master/service_cache.rb", "lib/palmade/puppet_master/service_queue.rb", "lib/palmade/puppet_master/service_redis.rb", "lib/palmade/puppet_master/service_tokyo_cabinet.rb", "lib/palmade/puppet_master/socket_helper.rb", "lib/palmade/puppet_master/syslogger.rb", "lib/palmade/puppet_master/sysloggerio.rb", "lib/palmade/puppet_master/thin_backend.rb", "lib/palmade/puppet_master/thin_connection.rb", "lib/palmade/puppet_master/thin_puppet.rb", "lib/palmade/puppet_master/thin_websocket_connection.rb", "lib/palmade/puppet_master/utils.rb", "lib/palmade/puppet_master/worker.rb", "lib/palmade/puppet_master/workling_puppet.rb", "puppet_master.gemspec", "test/test_helper.rb", "test/thin_websocket_test.rb"]
- s.homepage = %q{}
+ s.extra_rdoc_files = ["README", "lib/palmade/puppet_master.rb", "lib/palmade/puppet_master/config.rb", "lib/palmade/puppet_master/configurator.rb", "lib/palmade/puppet_master/controller.rb", "lib/palmade/puppet_master/eventd_puppet.rb", "lib/palmade/puppet_master/family.rb", "lib/palmade/puppet_master/family/standard_puppets.rb", "lib/palmade/puppet_master/master.rb", "lib/palmade/puppet_master/mongrel2_puppet.rb", "lib/palmade/puppet_master/mongrel2_puppet/backend.rb", "lib/palmade/puppet_master/mongrel2_puppet/connection.rb", "lib/palmade/puppet_master/mongrel2_puppet/rails_adapter.rb", "lib/palmade/puppet_master/mongrel2_puppet/request.rb", "lib/palmade/puppet_master/mongrel2_puppet/response.rb", "lib/palmade/puppet_master/puppet.rb", "lib/palmade/puppet_master/runner.rb", "lib/palmade/puppet_master/service.rb", "lib/palmade/puppet_master/service_redis.rb", "lib/palmade/puppet_master/socket_helper.rb", "lib/palmade/puppet_master/syslogger.rb", "lib/palmade/puppet_master/sysloggerio.rb", "lib/palmade/puppet_master/thin_backend.rb", "lib/palmade/puppet_master/thin_connection.rb", "lib/palmade/puppet_master/thin_puppet.rb", "lib/palmade/puppet_master/thin_websocket_connection.rb", "lib/palmade/puppet_master/utils.rb", "lib/palmade/puppet_master/worker.rb"]
+ s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "lib/palmade/puppet_master.rb", "lib/palmade/puppet_master/config.rb", "lib/palmade/puppet_master/configurator.rb", "lib/palmade/puppet_master/controller.rb", "lib/palmade/puppet_master/eventd_puppet.rb", "lib/palmade/puppet_master/family.rb", "lib/palmade/puppet_master/family/standard_puppets.rb", "lib/palmade/puppet_master/master.rb", "lib/palmade/puppet_master/mongrel2_puppet.rb", "lib/palmade/puppet_master/mongrel2_puppet/backend.rb", "lib/palmade/puppet_master/mongrel2_puppet/connection.rb", "lib/palmade/puppet_master/mongrel2_puppet/rails_adapter.rb", "lib/palmade/puppet_master/mongrel2_puppet/request.rb", "lib/palmade/puppet_master/mongrel2_puppet/response.rb", "lib/palmade/puppet_master/puppet.rb", "lib/palmade/puppet_master/runner.rb", "lib/palmade/puppet_master/service.rb", "lib/palmade/puppet_master/service_redis.rb", "lib/palmade/puppet_master/socket_helper.rb", "lib/palmade/puppet_master/syslogger.rb", "lib/palmade/puppet_master/sysloggerio.rb", "lib/palmade/puppet_master/thin_backend.rb", "lib/palmade/puppet_master/thin_connection.rb", "lib/palmade/puppet_master/thin_puppet.rb", "lib/palmade/puppet_master/thin_websocket_connection.rb", "lib/palmade/puppet_master/utils.rb", "lib/palmade/puppet_master/worker.rb", "puppet_master.gemspec", "test/test_helper.rb", "test/thin_websocket_test.rb"]
+ s.homepage = %q{http://Puppet Master.github.com/Puppet Master/puppet_master/}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Puppet_master", "--main", "README"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{Puppet Master}
- s.rubygems_version = %q{1.3.7}
+ s.rubygems_version = %q{1.6.2}
s.summary = %q{Master of puppets}
- s.test_files = ["test/test_helper.rb", "test/thin_websocket_test.rb"]
+ s.test_files = ["test/thin_websocket_test.rb", "test/test_helper.rb"]
if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then

No commit comments for this range

Something went wrong with that request. Please try again.