3 # Simple class to manage compliant requests for MCollective::RPC agents
5 attr_accessor :time, :action, :data, :sender, :agent, :uniqid, :caller, :ddl
7 def initialize(msg, ddl)
9 @action = msg[:body][:action]
10 @data = msg[:body][:data]
11 @sender = msg[:senderid]
12 @agent = msg[:body][:agent]
13 @uniqid = msg[:requestid]
14 @caller = msg[:callerid] || "unknown"
18 # If data is a hash, quick helper to get access to it's include? method
21 return false unless @data.is_a?(Hash)
22 return @data.include?(key)
25 # If no :process_results is specified always respond else respond
26 # based on the supplied property
28 return @data[:process_results] if @data.include?(:process_results)
33 # If data is a hash, gives easy access to its members, else returns nil
35 return nil unless @data.is_a?(Hash)
39 def fetch(key, default)
40 return nil unless @data.is_a?(Hash)
41 return @data.fetch(key, default)
45 return {:agent => @agent,
50 # Validate the request against the DDL
52 @ddl.validate_rpc_request(@action, @data)
56 to_hash.merge!({:sender => @sender,
57 :callerid => @callerid,
58 :uniqid => @uniqid}).to_json