Class MCollective::Registration::Base
In: lib/mcollective/registration/base.rb
Parent: Object

This is a base class that other registration plugins can use to handle regular announcements to the mcollective

The configuration file determines how often registration messages gets sent using the registerinterval option, the plugin runs in the background in a thread.

Methods

Public Class methods

Register plugins that inherits base

[Source]

    # File lib/mcollective/registration/base.rb, line 11
11:             def self.inherited(klass)
12:                 PluginManager << {:type => "registration_plugin", :class => klass.to_s}
13:             end

Public Instance methods

[Source]

    # File lib/mcollective/registration/base.rb, line 36
36:             def config
37:                 Config.instance
38:             end

[Source]

    # File lib/mcollective/registration/base.rb, line 40
40:             def identity
41:                 config.identity
42:             end

[Source]

    # File lib/mcollective/registration/base.rb, line 69
69:             def interval
70:                 config.registerinterval
71:             end

[Source]

    # File lib/mcollective/registration/base.rb, line 44
44:             def msg_filter
45:                 {"agent" => "registration"}
46:             end

[Source]

    # File lib/mcollective/registration/base.rb, line 48
48:             def msg_id(target)
49:                 reqid = Digest::MD5.hexdigest("#{config.identity}-#{Time.now.to_f.to_s}-#{target}")
50:             end

[Source]

    # File lib/mcollective/registration/base.rb, line 52
52:             def msg_target
53:                 Util.make_target("registration", :command, target_collective)
54:             end

[Source]

    # File lib/mcollective/registration/base.rb, line 73
73:             def publish(message, connection)
74:                 unless message
75:                     Log.debug("Skipping registration due to nil body")
76:                 else
77:                     target = msg_target
78:                     reqid = msg_id(target)
79: 
80:                     req = PluginManager["security_plugin"].encoderequest(identity, target, message, reqid, msg_filter)
81: 
82:                     Log.debug("Sending registration #{reqid} to #{target}")
83: 
84:                     connection.publish(target, req)
85:                 end
86:             end

Creates a background thread that periodically send a registration notice.

The actual registration notices comes from the ‘body’ method of the registration plugins.

[Source]

    # File lib/mcollective/registration/base.rb, line 19
19:             def run(connection)
20:                 return false if interval == 0
21: 
22:                 Thread.new do
23:                     loop do
24:                         begin
25:                             publish(body, connection)
26: 
27:                             sleep interval
28:                         rescue Exception => e
29:                             Log.error("Sending registration message failed: #{e}")
30:                             sleep interval
31:                         end
32:                     end
33:                 end
34:             end

[Source]

    # File lib/mcollective/registration/base.rb, line 56
56:             def target_collective
57:                 main_collective = config.main_collective
58: 
59:                 collective = config.registration_collective || main_collective
60: 
61:                 unless config.collectives.include?(collective)
62:                     Log.warn("Sending registration to #{main_collective}: #{collective} is not a valid collective")
63:                     collective = main_collective
64:                 end
65: 
66:                 return collective
67:             end

[Validate]