Class MCollective::Aggregate
In: lib/mcollective/aggregate.rb
lib/mcollective/aggregate/result/base.rb
lib/mcollective/aggregate/result/collection_result.rb
lib/mcollective/aggregate/result/numeric_result.rb
lib/mcollective/aggregate/base.rb
lib/mcollective/aggregate/result.rb
Parent: Object

Methods

Classes and Modules

Module MCollective::Aggregate::Result
Class MCollective::Aggregate::Base

Attributes

action  [RW] 
ddl  [RW] 
functions  [RW] 

Public Class methods

[Source]

    # File lib/mcollective/aggregate.rb, line 8
 8:     def initialize(ddl)
 9:       @functions = []
10:       @ddl = ddl
11:       @action = ddl[:action]
12: 
13:       create_functions
14:     end

Public Instance methods

Call all the appropriate functions with the reply data received from RPC::Client

[Source]

    # File lib/mcollective/aggregate.rb, line 35
35:     def call_functions(reply)
36:       @functions.each do |function|
37:         Log.debug("Calling aggregate function #{function} for result")
38:         function.process_result(reply[:data][function.output_name], reply)
39:       end
40:     end

Check if the function param is defined as an output for the action in the ddl

[Source]

    # File lib/mcollective/aggregate.rb, line 30
30:     def contains_output?(output)
31:       raise "'#{@ddl[:action]}' action does not contain output '#{output}'" unless @ddl[:output].keys.include?(output)
32:     end

Creates instances of the Aggregate functions and stores them in the function array. All aggregate call and summarize method calls operate on these function as a batch.

[Source]

    # File lib/mcollective/aggregate.rb, line 18
18:     def create_functions
19:       @ddl[:aggregate].each_with_index do |agg, i|
20:         contains_output?(agg[:args][0])
21: 
22:         output = agg[:args][0]
23:         arguments = agg[:args][1..(agg[:args].size)]
24: 
25:         @functions << load_function(agg[:function]).new(output, arguments, agg[:format], @action)
26:       end
27:     end

Loads function from disk for use

[Source]

    # File lib/mcollective/aggregate.rb, line 52
52:     def load_function(function_name)
53:       function_name = function_name.to_s.capitalize
54: 
55:       PluginManager.loadclass("MCollective::Aggregate::#{function_name}") unless Aggregate.const_defined?(function_name)
56:       Aggregate.const_get(function_name)
57:     rescue Exception
58:       raise "Aggregate function file '#{function_name.downcase}.rb' cannot be loaded"
59:     end

Finalizes the function returning a result object

[Source]

    # File lib/mcollective/aggregate.rb, line 43
43:     def summarize
44:       summary = @functions.map do |function|
45:         function.summarize
46:       end
47: 
48:       summary.sort{|x,y| x.result[:output] <=> y.result[:output]}
49:     end

[Validate]