Add config options: - queuesep - identity_queue
Default queuesep and topicsep to the typical stomp values and default identity_queue to false to maintain backwards compat Adjust Util#make_target to support queued targets and subscribe to a per identity queue on the main collective in the runner if configured to do so. Signed-off-by: R.I.Pienaar <[email protected]> --- Local-branch: feature/master/7225 lib/mcollective/config.rb | 12 ++++++++++-- lib/mcollective/runner.rb | 5 +++++ lib/mcollective/util.rb | 10 ++++++---- spec/unit/util_spec.rb | 9 +++++++++ website/changelog.md | 1 + website/reference/basic/configuration.md | 3 ++- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/mcollective/config.rb b/lib/mcollective/config.rb index 8574472..094e376 100644 --- a/lib/mcollective/config.rb +++ b/lib/mcollective/config.rb @@ -8,7 +8,8 @@ module MCollective :securityprovider, :factsource, :registration, :registerinterval, :topicsep, :classesfile, :rpcauditprovider, :rpcaudit, :configdir, :rpcauthprovider, :rpcauthorization, :color, :configfile, :rpchelptemplate, :rpclimitmethod, - :logger_type, :fact_cache_time, :collectives, :main_collective, :ssl_cipher + :logger_type, :fact_cache_time, :collectives, :main_collective, :ssl_cipher, + :queueprefix, :identity_queue def initialize @configured = false @@ -39,8 +40,12 @@ module MCollective @collectives = val.split(",").map {|c| c.strip} when "main_collective" @main_collective = val + when "queueprefix" + @queueprefix = val when "topicprefix" @topicprefix = val + when "identity_queue" + val =~ /^1|y/i ? @identity_queue = true : @identity_queue = false when "logfile" @logfile = val when "keeplogs" @@ -119,13 +124,16 @@ module MCollective @stomp = Hash.new @subscribe = Array.new @pluginconf = Hash.new + @topicprefix = "/topic/" + @queueprefix = "/queue/" + @identity_queue = false + @topicsep = "." @connector = "Stomp" @securityprovider = "Psk" @factsource = "Yaml" @identity = Socket.gethostname @registration = "Agentlist" @registerinterval = 0 - @topicsep = "." @classesfile = "/var/lib/puppet/classes.txt" @rpcaudit = false @rpcauditprovider = "" diff --git a/lib/mcollective/runner.rb b/lib/mcollective/runner.rb index 0d9720f..f80d076 100644 --- a/lib/mcollective/runner.rb +++ b/lib/mcollective/runner.rb @@ -47,6 +47,11 @@ module MCollective controltopics = Util.make_target("mcollective", :command) Util.subscribe(controltopics) + if @config.identity_queue + Log.debug("Subscribing to identity queue") + Util.subscribe(Util.make_target(@config.identity, :command, @config.main_collective, true)) + end + # Start the registration plugin if interval isn't 0 begin PluginManager["registration_plugin"].run(@connection) unless @config.registerinterval == 0 diff --git a/lib/mcollective/util.rb b/lib/mcollective/util.rb index dde8944..0badcba 100644 --- a/lib/mcollective/util.rb +++ b/lib/mcollective/util.rb @@ -156,19 +156,21 @@ module MCollective # # If given a collective name it will return a single target aimed # at just the one collective - def self.make_target(agent, type, collective=nil) + def self.make_target(target, type, collective=nil, queued=false) config = Config.instance raise("Unknown target type #{type}") unless type == :command || type == :reply + queued ? prefix = config.queueprefix : prefix = config.topicprefix + if collective.nil? - config.collectives.map do |c| - ["#{config.topicprefix}#{c}", agent, type].join(config.topicsep) + config.collectives.map do |collective| + ["#{prefix}#{collective}", target, type].join(config.topicsep) end else raise("Unknown collective '#{collective}' known collectives are '#{config.collectives.join ', '}'") unless config.collectives.include?(collective) - ["#{config.topicprefix}#{collective}", agent, type].join(config.topicsep) + ["#{prefix}#{collective}", target, type].join(config.topicsep) end end diff --git a/spec/unit/util_spec.rb b/spec/unit/util_spec.rb index 91e49b2..d6e0324 100644 --- a/spec/unit/util_spec.rb +++ b/spec/unit/util_spec.rb @@ -66,6 +66,15 @@ module MCollective Util.make_target("foo", :command, "one").should == "/topic/one.foo.command" end + + it "should be able to subscribe to a queue" do + c = Config.instance + c.instance_variable_set("@collectives", ["one", "two"]) + c.instance_variable_set("@queueprefix", "/queue/") + c.instance_variable_set("@topicsep", ".") + + Util.make_target("foo", :command, "one", true).should == "/queue/one.foo.command" + end end describe "#subscribe" do diff --git a/website/changelog.md b/website/changelog.md index 5b9c99c..97aa801 100644 --- a/website/changelog.md +++ b/website/changelog.md @@ -11,6 +11,7 @@ title: Changelog |Date|Description|Ticket| |----|-----------|------| +|2011/04/24|Add the ability to subscribe to a queue per identity|7225| |2011/04/23|Encode the target agent and collective in requests|7223| |2011/04/20|Make the SSL Cipher used a config option|7191| |2011/04/20|Add a clear method to the PluginManager that deletes all plugins, improve test isolation|7176| diff --git a/website/reference/basic/configuration.md b/website/reference/basic/configuration.md index 37f7307..2a1b5dc 100644 --- a/website/reference/basic/configuration.md +++ b/website/reference/basic/configuration.md @@ -28,7 +28,8 @@ Configuration is a simple *key = val* style configuration file. |Key|Sample|Description| |---|------|-----------| -|topicprefix|/topic/mcollective|Prefix that gets used for all messages. Post 1.1.3 this should just be /topic/| +|topicprefix|/topic/mcollective|Prefix that gets used for all broadcast messages. Post 1.1.3 this should just be /topic/| +|queueprefix|/queue/mcollective|Prefix that gets used for all point to point messages. Post 1.1.3 this should just be /queue/| |topicnamesep|.|The seperator to use between parts of the topic path| |collectives|mcollective,subcollective|A list of [Subcollectives] to join - 1.1.3 and newer only| |main_collective|mcollective|The main collective to target - 1.1.3 and newer only| -- 1.7.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
