summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-05 19:51:47 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-05 19:51:47 -0500
commita7d220b828ec5f277a3a3bfb33f517fe864579d0 (patch)
treea538fd3d621e5eab38a5ee874f64e5e89235bd10 /lib/puppet
parent7086ce17d14274f93ef0c03fba531bdb6710e5f7 (diff)
downloadpuppet-a7d220b828ec5f277a3a3bfb33f517fe864579d0.tar.gz
puppet-a7d220b828ec5f277a3a3bfb33f517fe864579d0.tar.xz
puppet-a7d220b828ec5f277a3a3bfb33f517fe864579d0.zip
Moving the webrick/mongrel "servers" over to HTTPServer module instead of Server. Using Server as the master class for client connections. Server (former RESTServer) will instantiate the appropriate subclass based upon Puppet configurator setting. There are now tests broken in the network section which I can't seem to figure out yet. Not a happy place to be.
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/feature/base.rb2
-rw-r--r--lib/puppet/network/http_server.rb2
-rw-r--r--lib/puppet/network/http_server/mongrel.rb (renamed from lib/puppet/network/server/mongrel.rb)4
-rw-r--r--lib/puppet/network/http_server/webrick.rb (renamed from lib/puppet/network/server/webrick.rb)4
-rw-r--r--lib/puppet/network/rest_server.rb37
-rw-r--r--lib/puppet/network/server.rb66
6 files changed, 71 insertions, 44 deletions
diff --git a/lib/puppet/feature/base.rb b/lib/puppet/feature/base.rb
index 6368d0931..518e9b419 100644
--- a/lib/puppet/feature/base.rb
+++ b/lib/puppet/feature/base.rb
@@ -18,7 +18,7 @@ Puppet.features.add(:libshadow, :libs => ["shadow"])
Puppet.features.add(:root) { require 'puppet/util/suidmanager'; Puppet::Util::SUIDManager.uid == 0 }
# We've got mongrel available
-Puppet.features.add(:mongrel, :libs => %w{rubygems mongrel puppet/network/server/mongrel})
+Puppet.features.add(:mongrel, :libs => %w{rubygems mongrel puppet/network/http_server/mongrel})
# We have lcs diff
Puppet.features.add :diff, :libs => %w{diff/lcs diff/lcs/hunk}
diff --git a/lib/puppet/network/http_server.rb b/lib/puppet/network/http_server.rb
new file mode 100644
index 000000000..1ca01b0a6
--- /dev/null
+++ b/lib/puppet/network/http_server.rb
@@ -0,0 +1,2 @@
+module Puppet::Network::HTTPServer
+end
diff --git a/lib/puppet/network/server/mongrel.rb b/lib/puppet/network/http_server/mongrel.rb
index 8cd7e807b..ba4b048b3 100644
--- a/lib/puppet/network/server/mongrel.rb
+++ b/lib/puppet/network/http_server/mongrel.rb
@@ -31,7 +31,7 @@ require 'rubygems'
require 'mongrel'
require 'xmlrpc/server'
require 'puppet/network/xmlrpc/server'
-require 'puppet/network/server'
+require 'puppet/network/http_server'
require 'puppet/network/client_request'
require 'puppet/daemon'
@@ -49,7 +49,7 @@ require 'resolv'
# handler.xmlrpc_server.add_handler("my.add") { |a, b| a.to_i + b.to_i }
# </pre>
module Puppet::Network
- class Server::Mongrel < ::Mongrel::HttpHandler
+ class HTTPServer::Mongrel < ::Mongrel::HttpHandler
include Puppet::Daemon
attr_reader :xmlrpc_server
diff --git a/lib/puppet/network/server/webrick.rb b/lib/puppet/network/http_server/webrick.rb
index dd9a91c7c..2cf85b7b6 100644
--- a/lib/puppet/network/server/webrick.rb
+++ b/lib/puppet/network/http_server/webrick.rb
@@ -6,7 +6,7 @@ require 'fcntl'
require 'puppet/sslcertificates/support'
require 'puppet/network/xmlrpc/webrick_servlet'
-require 'puppet/network/server'
+require 'puppet/network/http_server'
require 'puppet/network/client'
module Puppet
@@ -14,7 +14,7 @@ module Puppet
module Network
# The old-school, pure ruby webrick server, which is the default serving
# mechanism.
- class Server::WEBrick < WEBrick::HTTPServer
+ class HTTPServer::WEBrick < WEBrick::HTTPServer
include Puppet::Daemon
include Puppet::SSLCertificates::Support
diff --git a/lib/puppet/network/rest_server.rb b/lib/puppet/network/rest_server.rb
deleted file mode 100644
index d1206928c..000000000
--- a/lib/puppet/network/rest_server.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-class Puppet::Network::RESTServer
- attr_reader :server
-
- def initialize(args = {})
- raise(ArgumentError, "requires :server to be specified") unless args[:server]
- @routes = {}
- @listening = false
- @server = args[:server]
- end
-
- def register(*indirections)
- raise ArgumentError, "indirection names are required" if indirections.empty?
- indirections.flatten.each { |i| @routes[i.to_sym] = true }
- end
-
- def unregister(*indirections)
- indirections = @routes.keys if indirections.empty?
- indirections.flatten.each do |i|
- raise(ArgumentError, "indirection [%s] is not known" % i) unless @routes[i.to_sym]
- @routes.delete(i.to_sym)
- end
- end
-
- def listening?
- @listening
- end
-
- def listen
- raise "Cannot listen -- already listening" if listening?
- @listening = true
- end
-
- def unlisten
- raise "Cannot unlisten -- not currently listening" unless listening?
- @listening = false
- end
-end
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb
index 0dee30b10..84a71a6b4 100644
--- a/lib/puppet/network/server.rb
+++ b/lib/puppet/network/server.rb
@@ -1,4 +1,66 @@
-# Just a stub, so we can correctly scope other classes.
-module Puppet::Network::Server # :nodoc:
+class Puppet::Network::Server
+ attr_reader :server_type
+
+ # which HTTP server subclass actually handles web requests of a certain type? (e.g., :rest => RESTServer)
+ def self.server_class_by_name(name)
+ klass = (name.to_s + 'Server').to_sym
+ const_get klass
+ end
+
+ # we will actually return an instance of the Server subclass which handles the HTTP web server, instead of
+ # an instance of this generic Server class. A tiny bit of sleight-of-hand is necessary to make this happen.
+ def self.new(args = {})
+ server_type = Puppet[:servertype] or raise "No servertype configuration found."
+ obj = self.server_class_by_name(server_type).allocate
+ obj.send :initialize, args.merge(:server_type => server_type)
+ obj
+ end
+
+ def initialize(args = {})
+ @routes = {}
+ @listening = false
+ @server_type = args[:server_type]
+ self.register(args[:handlers]) if args[:handlers]
+ end
+
+ def register(*indirections)
+ raise ArgumentError, "indirection names are required" if indirections.empty?
+ indirections.flatten.each { |i| @routes[i.to_sym] = true }
+ end
+
+ def unregister(*indirections)
+ indirections = @routes.keys if indirections.empty?
+ indirections.flatten.each do |i|
+ raise(ArgumentError, "indirection [%s] is not known" % i) unless @routes[i.to_sym]
+ @routes.delete(i.to_sym)
+ end
+ end
+
+ def listening?
+ @listening
+ end
+
+ def listen
+ raise "Cannot listen -- already listening" if listening?
+ start_web_server
+ @listening = true
+ end
+
+ def unlisten
+ raise "Cannot unlisten -- not currently listening" unless listening?
+ stop_web_server
+ @listening = false
+ end
+
+ private
+
+ def start_web_server
+ raise NotImplementedError, "this method needs to be implemented by the actual web server (sub)class"
+ end
+
+ def stop_web_server
+ raise NotImplementedError, "this method needs to be implemented by the actual web server (sub)class"
+ end
end
+