1 <?xml version="1.0" encoding="iso-8859-1"?>
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
8 <title>Class: MCollective::RPC::Client</title>
9 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10 <meta http-equiv="Content-Script-Type" content="text/javascript" />
11 <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12 <script type="text/javascript">
15 function popupCode( url ) {
16 window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
19 function toggleCode( id ) {
20 if ( document.getElementById )
21 elem = document.getElementById( id );
22 else if ( document.all )
23 elem = eval( "document.all." + id );
27 elemStyle = elem.style;
29 if ( elemStyle.display != "block" ) {
30 elemStyle.display = "block"
32 elemStyle.display = "none"
38 // Make codeblocks hidden by default
39 document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
49 <div id="classHeader">
50 <table class="header-table">
51 <tr class="top-aligned-row">
52 <td><strong>Class</strong></td>
53 <td class="class-name-in-header">MCollective::RPC::Client</td>
55 <tr class="top-aligned-row">
56 <td><strong>In:</strong></td>
58 <a href="../../../files/lib/mcollective/rpc/client_rb.html">
59 lib/mcollective/rpc/client.rb
65 <tr class="top-aligned-row">
66 <td><strong>Parent:</strong></td>
73 <!-- banner header -->
75 <div id="bodyContent">
79 <div id="contextContent">
81 <div id="description">
83 The main component of the Simple <a href="../RPC.html">RPC</a> client
84 system, this wraps around <a href="../Client.html">MCollective::Client</a>
85 and just brings in a lot of convention and standard approached.
93 <div id="method-list">
94 <h3 class="section-bar">Methods</h3>
96 <div class="name-list">
97 <a href="#M000098">agent_filter</a>
98 <a href="#M000112">aggregate_reply</a>
99 <a href="#M000108">batch_size=</a>
100 <a href="#M000109">batch_sleep_time=</a>
101 <a href="#M000117">call_agent</a>
102 <a href="#M000116">call_agent_batched</a>
103 <a href="#M000096">class_filter</a>
104 <a href="#M000105">collective=</a>
105 <a href="#M000100">compound_filter</a>
106 <a href="#M000091">custom_request</a>
107 <a href="#M000086">disconnect</a>
108 <a href="#M000103">discover</a>
109 <a href="#M000094">discovery_method=</a>
110 <a href="#M000095">discovery_options=</a>
111 <a href="#M000092">discovery_timeout</a>
112 <a href="#M000093">discovery_timeout=</a>
113 <a href="#M000097">fact_filter</a>
114 <a href="#M000114">fire_and_forget_request</a>
115 <a href="#M000087">help</a>
116 <a href="#M000099">identity_filter</a>
117 <a href="#M000115">identity_filter_discovery_optimization</a>
118 <a href="#M000107">limit_method=</a>
119 <a href="#M000106">limit_targets=</a>
120 <a href="#M000111">load_aggregate_functions</a>
121 <a href="#M000090">method_missing</a>
122 <a href="#M000085">new</a>
123 <a href="#M000088">new_request</a>
124 <a href="#M000104">options</a>
125 <a href="#M000110">pick_nodes_from_discovered</a>
126 <a href="#M000119">process_results_with_block</a>
127 <a href="#M000118">process_results_without_block</a>
128 <a href="#M000101">reset</a>
129 <a href="#M000102">reset_filter</a>
130 <a href="#M000113">rpc_result_from_reply</a>
131 <a href="#M000089">validate_request</a>
146 <div id="attribute-list">
147 <h3 class="section-bar">Attributes</h3>
149 <div class="name-list">
151 <tr class="top-aligned-row context-row">
152 <td class="context-item-name">agent</td>
153 <td class="context-item-value"> [R] </td>
154 <td class="context-item-desc"></td>
156 <tr class="top-aligned-row context-row">
157 <td class="context-item-name">batch_mode</td>
158 <td class="context-item-value"> [R] </td>
159 <td class="context-item-desc"></td>
161 <tr class="top-aligned-row context-row">
162 <td class="context-item-name">batch_size</td>
163 <td class="context-item-value"> [R] </td>
164 <td class="context-item-desc"></td>
166 <tr class="top-aligned-row context-row">
167 <td class="context-item-name">batch_sleep_time</td>
168 <td class="context-item-value"> [R] </td>
169 <td class="context-item-desc"></td>
171 <tr class="top-aligned-row context-row">
172 <td class="context-item-name">client</td>
173 <td class="context-item-value"> [R] </td>
174 <td class="context-item-desc"></td>
176 <tr class="top-aligned-row context-row">
177 <td class="context-item-name">config</td>
178 <td class="context-item-value"> [RW] </td>
179 <td class="context-item-desc"></td>
181 <tr class="top-aligned-row context-row">
182 <td class="context-item-name">ddl</td>
183 <td class="context-item-value"> [R] </td>
184 <td class="context-item-desc"></td>
186 <tr class="top-aligned-row context-row">
187 <td class="context-item-name">default_discovery_method</td>
188 <td class="context-item-value"> [R] </td>
189 <td class="context-item-desc"></td>
191 <tr class="top-aligned-row context-row">
192 <td class="context-item-name">discovery_method</td>
193 <td class="context-item-value"> [R] </td>
194 <td class="context-item-desc"></td>
196 <tr class="top-aligned-row context-row">
197 <td class="context-item-name">discovery_options</td>
198 <td class="context-item-value"> [R] </td>
199 <td class="context-item-desc"></td>
201 <tr class="top-aligned-row context-row">
202 <td class="context-item-name">filter</td>
203 <td class="context-item-value"> [RW] </td>
204 <td class="context-item-desc"></td>
206 <tr class="top-aligned-row context-row">
207 <td class="context-item-name">limit_method</td>
208 <td class="context-item-value"> [R] </td>
209 <td class="context-item-desc"></td>
211 <tr class="top-aligned-row context-row">
212 <td class="context-item-name">limit_seed</td>
213 <td class="context-item-value"> [R] </td>
214 <td class="context-item-desc"></td>
216 <tr class="top-aligned-row context-row">
217 <td class="context-item-name">limit_targets</td>
218 <td class="context-item-value"> [R] </td>
219 <td class="context-item-desc"></td>
221 <tr class="top-aligned-row context-row">
222 <td class="context-item-name">output_format</td>
223 <td class="context-item-value"> [R] </td>
224 <td class="context-item-desc"></td>
226 <tr class="top-aligned-row context-row">
227 <td class="context-item-name">progress</td>
228 <td class="context-item-value"> [RW] </td>
229 <td class="context-item-desc"></td>
231 <tr class="top-aligned-row context-row">
232 <td class="context-item-name">reply_to</td>
233 <td class="context-item-value"> [RW] </td>
234 <td class="context-item-desc"></td>
236 <tr class="top-aligned-row context-row">
237 <td class="context-item-name">stats</td>
238 <td class="context-item-value"> [R] </td>
239 <td class="context-item-desc"></td>
241 <tr class="top-aligned-row context-row">
242 <td class="context-item-name">timeout</td>
243 <td class="context-item-value"> [RW] </td>
244 <td class="context-item-desc"></td>
246 <tr class="top-aligned-row context-row">
247 <td class="context-item-name">ttl</td>
248 <td class="context-item-value"> [RW] </td>
249 <td class="context-item-desc"></td>
251 <tr class="top-aligned-row context-row">
252 <td class="context-item-name">verbose</td>
253 <td class="context-item-value"> [RW] </td>
254 <td class="context-item-desc"></td>
262 <!-- if method_list -->
264 <h3 class="section-bar">Public Class methods</h3>
266 <div id="method-M000085" class="method-detail">
267 <a name="M000085"></a>
269 <div class="method-heading">
270 <a href="#M000085" class="method-signature">
271 <span class="method-name">new</span><span class="method-args">(agent, flags = {}) {|parser, opts| ...}</span>
275 <div class="method-description">
277 Creates a stub for a remote agent, you can pass in an <a
278 href="Client.html#M000104">options</a> array in the flags which will then
279 be used else it will just create a default <a
280 href="Client.html#M000104">options</a> array with filtering enabled based
281 on the standard command line use.
284 rpc = RPC::Client.new("rpctest", :configfile => "client.cfg", :options => options)
287 You typically would not call this directly you‘d use <a
288 href="../RPC.html#M000037">MCollective::RPC#rpcclient</a> instead which is
289 a wrapper around this that can be used as a Mixin
291 <p><a class="source-toggle" href="#"
292 onclick="toggleCode('M000085-source');return false;">[Source]</a></p>
293 <div class="method-source-code" id="M000085-source">
295 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 20</span>
296 20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">flags</span> = {})
297 21: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:options</span>)
298 22: <span class="ruby-identifier">initial_options</span> = <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:options</span>]
300 24: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@@initial_options</span>
301 25: <span class="ruby-identifier">initial_options</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-ivar">@@initial_options</span>)
303 27: <span class="ruby-keyword kw">else</span>
304 28: <span class="ruby-identifier">oparser</span> = <span class="ruby-constant">MCollective</span><span class="ruby-operator">::</span><span class="ruby-constant">Optionparser</span>.<span class="ruby-identifier">new</span>({<span class="ruby-identifier">:verbose</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">:progress_bar</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">:mcollective_limit_targets</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">:batch_size</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:batch_sleep_time</span> =<span class="ruby-operator">></span> <span class="ruby-value">1</span>}, <span class="ruby-value str">"filter"</span>)
306 30: <span class="ruby-identifier">initial_options</span> = <span class="ruby-identifier">oparser</span>.<span class="ruby-identifier">parse</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">parser</span>, <span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
307 31: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
308 32: <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">parser</span>, <span class="ruby-identifier">opts</span>)
309 33: <span class="ruby-keyword kw">end</span>
311 35: <span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">add_simplerpc_options</span>(<span class="ruby-identifier">parser</span>, <span class="ruby-identifier">opts</span>)
312 36: <span class="ruby-keyword kw">end</span>
314 38: <span class="ruby-ivar">@@initial_options</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">initial_options</span>)
315 39: <span class="ruby-keyword kw">end</span>
317 41: <span class="ruby-ivar">@initial_options</span> = <span class="ruby-identifier">initial_options</span>
319 43: <span class="ruby-ivar">@config</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:config</span>]
320 44: <span class="ruby-ivar">@client</span> = <span class="ruby-constant">MCollective</span><span class="ruby-operator">::</span><span class="ruby-constant">Client</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@config</span>)
321 45: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">initial_options</span>
323 47: <span class="ruby-ivar">@stats</span> = <span class="ruby-constant">Stats</span>.<span class="ruby-identifier">new</span>
324 48: <span class="ruby-ivar">@agent</span> = <span class="ruby-identifier">agent</span>
325 49: <span class="ruby-ivar">@timeout</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-value">5</span>
326 50: <span class="ruby-ivar">@verbose</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:verbose</span>]
327 51: <span class="ruby-ivar">@filter</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:filter</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">empty_filter</span>
328 52: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-keyword kw">nil</span>
329 53: <span class="ruby-ivar">@progress</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:progress_bar</span>]
330 54: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:mcollective_limit_targets</span>]
331 55: <span class="ruby-ivar">@limit_method</span> = <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">rpclimitmethod</span>
332 56: <span class="ruby-ivar">@limit_seed</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:limit_seed</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>
333 57: <span class="ruby-ivar">@output_format</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:output_format</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">:console</span>
334 58: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">false</span>
335 59: <span class="ruby-ivar">@reply_to</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:reply_to</span>]
336 60: <span class="ruby-ivar">@discovery_method</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:discovery_method</span>]
337 61: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@discovery_method</span>
338 62: <span class="ruby-ivar">@discovery_method</span> = <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">default_discovery_method</span>
339 63: <span class="ruby-ivar">@default_discovery_method</span> = <span class="ruby-keyword kw">true</span>
340 64: <span class="ruby-keyword kw">else</span>
341 65: <span class="ruby-ivar">@default_discovery_method</span> = <span class="ruby-keyword kw">false</span>
342 66: <span class="ruby-keyword kw">end</span>
343 67: <span class="ruby-ivar">@discovery_options</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:discovery_options</span>] <span class="ruby-operator">||</span> []
344 68: <span class="ruby-ivar">@force_display_mode</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:force_display_mode</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">false</span>
346 70: <span class="ruby-ivar">@batch_size</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:batch_size</span>] <span class="ruby-operator">||</span> <span class="ruby-value">0</span>)
347 71: <span class="ruby-ivar">@batch_sleep_time</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:batch_sleep_time</span>] <span class="ruby-operator">||</span> <span class="ruby-value">1</span>)
348 72: <span class="ruby-ivar">@batch_mode</span> = <span class="ruby-ivar">@batch_size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
350 74: <span class="ruby-identifier">agent_filter</span> <span class="ruby-identifier">agent</span>
352 76: <span class="ruby-ivar">@discovery_timeout</span> = <span class="ruby-ivar">@initial_options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">:disctimeout</span>, <span class="ruby-keyword kw">nil</span>)
354 78: <span class="ruby-ivar">@collective</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">collective</span>
355 79: <span class="ruby-ivar">@ttl</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:ttl</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">ttl</span>
356 80: <span class="ruby-ivar">@publish_timeout</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:publish_timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">publish_timeout</span>
357 81: <span class="ruby-ivar">@threaded</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:threaded</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">threaded</span>
359 83: <span class="ruby-comment cmt"># if we can find a DDL for the service override</span>
360 84: <span class="ruby-comment cmt"># the timeout of the client so we always magically</span>
361 85: <span class="ruby-comment cmt"># wait appropriate amounts of time.</span>
362 86: <span class="ruby-comment cmt">#</span>
363 87: <span class="ruby-comment cmt"># We add the discovery timeout to the ddl supplied</span>
364 88: <span class="ruby-comment cmt"># timeout as the discovery timeout tends to be tuned</span>
365 89: <span class="ruby-comment cmt"># for local network conditions and fact source speed</span>
366 90: <span class="ruby-comment cmt"># which would other wise not be accounted for and</span>
367 91: <span class="ruby-comment cmt"># some results might get missed.</span>
368 92: <span class="ruby-comment cmt">#</span>
369 93: <span class="ruby-comment cmt"># We do this only if the timeout is the default 5</span>
370 94: <span class="ruby-comment cmt"># seconds, so that users cli overrides will still</span>
371 95: <span class="ruby-comment cmt"># get applied</span>
372 96: <span class="ruby-comment cmt">#</span>
373 97: <span class="ruby-comment cmt"># DDLs are required, failure to find a DDL is fatal</span>
374 98: <span class="ruby-ivar">@ddl</span> = <span class="ruby-constant">DDL</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">agent</span>)
375 99: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">ddl</span> = <span class="ruby-ivar">@ddl</span>
376 100: <span class="ruby-ivar">@timeout</span> = <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">meta</span>[<span class="ruby-identifier">:timeout</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">discovery_timeout</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@timeout</span> <span class="ruby-operator">==</span> <span class="ruby-value">5</span>
378 102: <span class="ruby-comment cmt"># allows stderr and stdout to be overridden for testing</span>
379 103: <span class="ruby-comment cmt"># but also for web apps that might not want a bunch of stuff</span>
380 104: <span class="ruby-comment cmt"># generated to actual file handles</span>
381 105: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stderr</span>]
382 106: <span class="ruby-ivar">@stderr</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stderr</span>]
383 107: <span class="ruby-keyword kw">else</span>
384 108: <span class="ruby-ivar">@stderr</span> = <span class="ruby-constant">STDERR</span>
385 109: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">sync</span> = <span class="ruby-keyword kw">true</span>
386 110: <span class="ruby-keyword kw">end</span>
388 112: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stdout</span>]
389 113: <span class="ruby-ivar">@stdout</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stdout</span>]
390 114: <span class="ruby-keyword kw">else</span>
391 115: <span class="ruby-ivar">@stdout</span> = <span class="ruby-constant">STDOUT</span>
392 116: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">sync</span> = <span class="ruby-keyword kw">true</span>
393 117: <span class="ruby-keyword kw">end</span>
394 118: <span class="ruby-keyword kw">end</span>
400 <h3 class="section-bar">Public Instance methods</h3>
402 <div id="method-M000098" class="method-detail">
403 <a name="M000098"></a>
405 <div class="method-heading">
406 <a href="#M000098" class="method-signature">
407 <span class="method-name">agent_filter</span><span class="method-args">(agent)</span>
411 <div class="method-description">
413 Sets the agent filter
415 <p><a class="source-toggle" href="#"
416 onclick="toggleCode('M000098-source');return false;">[Source]</a></p>
417 <div class="method-source-code" id="M000098-source">
419 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 422</span>
420 422: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">agent_filter</span>(<span class="ruby-identifier">agent</span>)
421 423: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"agent"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"agent"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">agent</span>]
422 424: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"agent"</span>].<span class="ruby-identifier">compact!</span>
423 425: <span class="ruby-identifier">reset</span>
424 426: <span class="ruby-keyword kw">end</span>
430 <div id="method-M000112" class="method-detail">
431 <a name="M000112"></a>
433 <div class="method-heading">
434 <a href="#M000112" class="method-signature">
435 <span class="method-name">aggregate_reply</span><span class="method-args">(reply, aggregate)</span>
439 <div class="method-description">
440 <p><a class="source-toggle" href="#"
441 onclick="toggleCode('M000112-source');return false;">[Source]</a></p>
442 <div class="method-source-code" id="M000112-source">
444 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 687</span>
445 687: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">aggregate_reply</span>(<span class="ruby-identifier">reply</span>, <span class="ruby-identifier">aggregate</span>)
446 688: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">aggregate</span>
448 690: <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">call_functions</span>(<span class="ruby-identifier">reply</span>)
449 691: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">aggregate</span>
450 692: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
451 693: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">"Failed to calculate aggregate summaries for reply from %s, calculating summaries disabled: %s: %s (%s)"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:senderid</span>], <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">first</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>])
452 694: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
453 695: <span class="ruby-keyword kw">end</span>
459 <div id="method-M000108" class="method-detail">
460 <a name="M000108"></a>
462 <div class="method-heading">
463 <a href="#M000108" class="method-signature">
464 <span class="method-name">batch_size=</span><span class="method-args">(limit)</span>
468 <div class="method-description">
470 Sets the batch size, if the size is set to 0 that will disable batch mode
472 <p><a class="source-toggle" href="#"
473 onclick="toggleCode('M000108-source');return false;">[Source]</a></p>
474 <div class="method-source-code" id="M000108-source">
476 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 608</span>
477 608: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">batch_size=</span>(<span class="ruby-identifier">limit</span>)
478 609: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can only set batch size if direct addressing is supported"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
480 611: <span class="ruby-ivar">@batch_size</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">limit</span>)
481 612: <span class="ruby-ivar">@batch_mode</span> = <span class="ruby-ivar">@batch_size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
482 613: <span class="ruby-keyword kw">end</span>
488 <div id="method-M000109" class="method-detail">
489 <a name="M000109"></a>
491 <div class="method-heading">
492 <a href="#M000109" class="method-signature">
493 <span class="method-name">batch_sleep_time=</span><span class="method-args">(time)</span>
497 <div class="method-description">
498 <p><a class="source-toggle" href="#"
499 onclick="toggleCode('M000109-source');return false;">[Source]</a></p>
500 <div class="method-source-code" id="M000109-source">
502 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 615</span>
503 615: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">batch_sleep_time=</span>(<span class="ruby-identifier">time</span>)
504 616: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can only set batch sleep time if direct addressing is supported"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
506 618: <span class="ruby-ivar">@batch_sleep_time</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">time</span>)
507 619: <span class="ruby-keyword kw">end</span>
513 <div id="method-M000117" class="method-detail">
514 <a name="M000117"></a>
516 <div class="method-heading">
517 <a href="#M000117" class="method-signature">
518 <span class="method-name">call_agent</span><span class="method-args">(action, args, opts, disc=:auto, &block)</span>
522 <div class="method-description">
524 Handles traditional calls to the remote agents with full stats blocks, non
525 blocks and everything else supported.
528 Other methods of calling the nodes can reuse this code by for example
529 specifying custom <a href="Client.html#M000104">options</a> and discovery
532 <p><a class="source-toggle" href="#"
533 onclick="toggleCode('M000117-source');return false;">[Source]</a></p>
534 <div class="method-source-code" id="M000117-source">
536 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 844</span>
537 844: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-identifier">disc</span>=<span class="ruby-identifier">:auto</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
538 845: <span class="ruby-comment cmt"># Handle fire and forget requests and make sure</span>
539 846: <span class="ruby-comment cmt"># the :process_results value is set appropriately</span>
540 847: <span class="ruby-comment cmt">#</span>
541 848: <span class="ruby-comment cmt"># specific reply-to requests should be treated like</span>
542 849: <span class="ruby-comment cmt"># fire and forget since the client will never get</span>
543 850: <span class="ruby-comment cmt"># the responses</span>
544 851: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@reply_to</span>
545 852: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">fire_and_forget_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
546 853: <span class="ruby-keyword kw">else</span>
547 854: <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] = <span class="ruby-keyword kw">true</span>
548 855: <span class="ruby-keyword kw">end</span>
550 857: <span class="ruby-comment cmt"># Do discovery when no specific discovery array is given</span>
551 858: <span class="ruby-comment cmt">#</span>
552 859: <span class="ruby-comment cmt"># If an array is given set the force_direct_request hint that</span>
553 860: <span class="ruby-comment cmt"># will tell the message object to be a direct request one</span>
554 861: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">disc</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:auto</span>
555 862: <span class="ruby-identifier">discovered</span> = <span class="ruby-identifier">discover</span>
556 863: <span class="ruby-keyword kw">else</span>
557 864: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
558 865: <span class="ruby-identifier">discovered</span> = <span class="ruby-identifier">disc</span>
559 866: <span class="ruby-keyword kw">end</span>
561 868: <span class="ruby-identifier">req</span> = <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">args</span>)
563 870: <span class="ruby-identifier">message</span> = <span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-keyword kw">nil</span>, {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:request</span>, <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>, <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:filter</span>], <span class="ruby-identifier">:options</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>})
564 871: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">discovered_hosts</span> = <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">clone</span>
566 873: <span class="ruby-identifier">results</span> = []
567 874: <span class="ruby-identifier">respcount</span> = <span class="ruby-value">0</span>
569 876: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
570 877: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">type</span> = <span class="ruby-identifier">:direct_request</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@force_direct_request</span>
572 879: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">block_given?</span>
573 880: <span class="ruby-identifier">twirl</span> = <span class="ruby-constant">Progress</span>.<span class="ruby-identifier">new</span>
574 881: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">puts</span>
575 882: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>)
576 883: <span class="ruby-keyword kw">end</span>
578 885: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">load_aggregate_functions</span>(<span class="ruby-identifier">action</span>, <span class="ruby-ivar">@ddl</span>)
580 887: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">req</span>(<span class="ruby-identifier">message</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">resp</span><span class="ruby-operator">|</span>
581 888: <span class="ruby-identifier">respcount</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
583 890: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
584 891: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_with_block</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">block</span>, <span class="ruby-identifier">aggregate</span>)
585 892: <span class="ruby-keyword kw">else</span>
586 893: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
588 895: <span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_without_block</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">aggregate</span>)
590 897: <span class="ruby-identifier">results</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">result</span>
591 898: <span class="ruby-keyword kw">end</span>
592 899: <span class="ruby-keyword kw">end</span>
594 901: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_summary</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">summarize</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
595 902: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_failures</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">failed</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
596 903: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">client_stats</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>
597 904: <span class="ruby-keyword kw">else</span>
598 905: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\nNo request sent, we did not discover any nodes."</span>)
599 906: <span class="ruby-keyword kw">end</span>
601 908: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">finish_request</span>
603 910: <span class="ruby-constant">RPC</span>.<span class="ruby-identifier">stats</span>(<span class="ruby-ivar">@stats</span>)
605 912: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\n\n"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
607 914: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
608 915: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">stats</span>
609 916: <span class="ruby-keyword kw">else</span>
610 917: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">results</span>].<span class="ruby-identifier">flatten</span>
611 918: <span class="ruby-keyword kw">end</span>
612 919: <span class="ruby-keyword kw">end</span>
618 <div id="method-M000116" class="method-detail">
619 <a name="M000116"></a>
621 <div class="method-heading">
622 <a href="#M000116" class="method-signature">
623 <span class="method-name">call_agent_batched</span><span class="method-args">(action, args, opts, batch_size, sleep_time, &block)</span>
627 <div class="method-description">
629 Calls an agent in a way very similar to <a
630 href="Client.html#M000117">call_agent</a> but it supports batching the
631 queries to the network.
634 The result sets, stats, block handling etc is all exactly like you would
635 expect from normal <a href="Client.html#M000117">call_agent</a>.
638 This is used by <a href="Client.html#M000090">method_missing</a> and works
639 only with direct addressing mode
641 <p><a class="source-toggle" href="#"
642 onclick="toggleCode('M000116-source');return false;">[Source]</a></p>
643 <div class="method-source-code" id="M000116-source">
645 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 759</span>
646 759: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call_agent_batched</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-identifier">batch_size</span>, <span class="ruby-identifier">sleep_time</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
647 760: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Batched requests requires direct addressing"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
648 761: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Cannot bypass result processing for batched requests"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
650 763: <span class="ruby-identifier">batch_size</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">batch_size</span>)
651 764: <span class="ruby-identifier">sleep_time</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">sleep_time</span>)
653 766: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Calling #{agent}##{action} in batches of #{batch_size} with sleep time of #{sleep_time}"</span>)
655 768: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span>
657 770: <span class="ruby-identifier">discovered</span> = <span class="ruby-identifier">discover</span>
658 771: <span class="ruby-identifier">results</span> = []
659 772: <span class="ruby-identifier">respcount</span> = <span class="ruby-value">0</span>
661 774: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
662 775: <span class="ruby-identifier">req</span> = <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">args</span>)
664 777: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">load_aggregate_functions</span>(<span class="ruby-identifier">action</span>, <span class="ruby-ivar">@ddl</span>)
666 779: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">block_given?</span>
667 780: <span class="ruby-identifier">twirl</span> = <span class="ruby-constant">Progress</span>.<span class="ruby-identifier">new</span>
668 781: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">puts</span>
669 782: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>)
670 783: <span class="ruby-keyword kw">end</span>
672 785: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span> = <span class="ruby-keyword kw">nil</span>
674 787: <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">in_groups_of</span>(<span class="ruby-identifier">batch_size</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hosts</span>, <span class="ruby-identifier">last_batch</span><span class="ruby-operator">|</span>
675 788: <span class="ruby-identifier">message</span> = <span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-keyword kw">nil</span>, {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:direct_request</span>, <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>, <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:filter</span>], <span class="ruby-identifier">:options</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>})
677 790: <span class="ruby-comment cmt"># first time round we let the Message object create a request id</span>
678 791: <span class="ruby-comment cmt"># we then re-use it for future requests to keep auditing sane etc</span>
679 792: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span> = <span class="ruby-identifier">message</span>.<span class="ruby-identifier">create_reqid</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span>
680 793: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">requestid</span> = <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span>
682 795: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">discovered_hosts</span> = <span class="ruby-identifier">hosts</span>.<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">compact</span>
684 797: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">req</span>(<span class="ruby-identifier">message</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">resp</span><span class="ruby-operator">|</span>
685 798: <span class="ruby-identifier">respcount</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
687 800: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
688 801: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_with_block</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">block</span>, <span class="ruby-identifier">aggregate</span>)
689 802: <span class="ruby-keyword kw">else</span>
690 803: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
692 805: <span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_without_block</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">aggregate</span>)
694 807: <span class="ruby-identifier">results</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">result</span>
695 808: <span class="ruby-keyword kw">end</span>
696 809: <span class="ruby-keyword kw">end</span>
698 811: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">noresponsefrom</span>.<span class="ruby-identifier">concat</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:noresponsefrom</span>]
699 812: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">responses</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:responses</span>]
700 813: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">blocktime</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:blocktime</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">sleep_time</span>
701 814: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">totaltime</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:totaltime</span>]
702 815: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">discoverytime</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:discoverytime</span>]
704 817: <span class="ruby-identifier">sleep</span> <span class="ruby-identifier">sleep_time</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">last_batch</span>
705 818: <span class="ruby-keyword kw">end</span>
707 820: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_summary</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">summarize</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
708 821: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_failures</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">failed</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
709 822: <span class="ruby-keyword kw">else</span>
710 823: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\nNo request sent, we did not discover any nodes."</span>)
711 824: <span class="ruby-keyword kw">end</span>
713 826: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">finish_request</span>
715 828: <span class="ruby-constant">RPC</span>.<span class="ruby-identifier">stats</span>(<span class="ruby-ivar">@stats</span>)
717 830: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\n"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
719 832: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
720 833: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">stats</span>
721 834: <span class="ruby-keyword kw">else</span>
722 835: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">results</span>].<span class="ruby-identifier">flatten</span>
723 836: <span class="ruby-keyword kw">end</span>
724 837: <span class="ruby-keyword kw">end</span>
730 <div id="method-M000096" class="method-detail">
731 <a name="M000096"></a>
733 <div class="method-heading">
734 <a href="#M000096" class="method-signature">
735 <span class="method-name">class_filter</span><span class="method-args">(klass)</span>
739 <div class="method-description">
741 Sets the class filter
743 <p><a class="source-toggle" href="#"
744 onclick="toggleCode('M000096-source');return false;">[Source]</a></p>
745 <div class="method-source-code" id="M000096-source">
747 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 398</span>
748 398: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_filter</span>(<span class="ruby-identifier">klass</span>)
749 399: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"cf_class"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"cf_class"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">klass</span>]
750 400: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"cf_class"</span>].<span class="ruby-identifier">compact!</span>
751 401: <span class="ruby-identifier">reset</span>
752 402: <span class="ruby-keyword kw">end</span>
758 <div id="method-M000105" class="method-detail">
759 <a name="M000105"></a>
761 <div class="method-heading">
762 <a href="#M000105" class="method-signature">
763 <span class="method-name">collective=</span><span class="method-args">(c)</span>
767 <div class="method-description">
769 Sets the collective we are communicating with
771 <p><a class="source-toggle" href="#"
772 onclick="toggleCode('M000105-source');return false;">[Source]</a></p>
773 <div class="method-source-code" id="M000105-source">
775 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 573</span>
776 573: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collective=</span>(<span class="ruby-identifier">c</span>)
777 574: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown collective #{c}"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">collectives</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">c</span>)
779 576: <span class="ruby-ivar">@collective</span> = <span class="ruby-identifier">c</span>
780 577: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>
781 578: <span class="ruby-identifier">reset</span>
782 579: <span class="ruby-keyword kw">end</span>
788 <div id="method-M000100" class="method-detail">
789 <a name="M000100"></a>
791 <div class="method-heading">
792 <a href="#M000100" class="method-signature">
793 <span class="method-name">compound_filter</span><span class="method-args">(filter)</span>
797 <div class="method-description">
799 Set a compound filter
801 <p><a class="source-toggle" href="#"
802 onclick="toggleCode('M000100-source');return false;">[Source]</a></p>
803 <div class="method-source-code" id="M000100-source">
805 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 436</span>
806 436: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compound_filter</span>(<span class="ruby-identifier">filter</span>)
807 437: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"compound"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"compound"</span>] <span class="ruby-operator">|</span> [<span class="ruby-constant">Matcher</span>.<span class="ruby-identifier">create_compound_callstack</span>(<span class="ruby-identifier">filter</span>)]
808 438: <span class="ruby-identifier">reset</span>
809 439: <span class="ruby-keyword kw">end</span>
815 <div id="method-M000091" class="method-detail">
816 <a name="M000091"></a>
818 <div class="method-heading">
819 <a href="#M000091" class="method-signature">
820 <span class="method-name">custom_request</span><span class="method-args">(action, args, expected_agents, filter = {}, &block)</span>
824 <div class="method-description">
826 Constructs custom requests with custom filters and discovery data the idea
827 is that this would be used in web applications where you might be using a
828 cached copy of data provided by a registration agent to figure out on your
829 own what nodes will be responding and what your filter would be.
832 This will <a href="Client.html#M000087">help</a> you essentially short
833 circuit the traditional cycle of:
836 mc <a href="Client.html#M000103">discover</a> / call / wait for discovered
840 by doing discovery however you like, contructing a filter and a list of
841 nodes you expect responses from.
844 Other than that it will work exactly like a normal call, blocks will behave
845 the same way, stats will be handled the same way etcetc
848 If you just wanted to contact one machine for example with a client that
849 already has other filter <a href="Client.html#M000104">options</a> setup
853 puppet.custom_request("runonce", {}, ["your.box.com"],
854 {:identity => "your.box.com"})
857 This will do runonce action on just ‘your.box.com’, no
858 discovery will be done and after receiving just one response it will stop
859 waiting for responses
862 If direct_addressing is enabled in the config file you can provide an empty
863 hash as a filter, this will force that request to be a directly addressed
864 request which technically does not need filters. If you try to use this
865 mode with direct addressing disabled an exception will be raise
867 <p><a class="source-toggle" href="#"
868 onclick="toggleCode('M000091-source');return false;">[Source]</a></p>
869 <div class="method-source-code" id="M000091-source">
871 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 296</span>
872 296: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">custom_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">expected_agents</span>, <span class="ruby-identifier">filter</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
873 297: <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
875 299: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">filter</span> <span class="ruby-operator">==</span> {} <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
876 300: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Attempted to do a filterless custom_request without direct_addressing enabled, preventing unexpected call to all nodes"</span>
877 301: <span class="ruby-keyword kw">end</span>
879 303: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">reset</span>
881 305: <span class="ruby-identifier">custom_filter</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">empty_filter</span>
882 306: <span class="ruby-identifier">custom_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">clone</span>
884 308: <span class="ruby-comment cmt"># merge the supplied filter with the standard empty one</span>
885 309: <span class="ruby-comment cmt"># we could just use the merge method but I want to be sure</span>
886 310: <span class="ruby-comment cmt"># we dont merge in stuff that isnt actually valid</span>
887 311: [<span class="ruby-value str">"identity"</span>, <span class="ruby-value str">"fact"</span>, <span class="ruby-value str">"agent"</span>, <span class="ruby-value str">"cf_class"</span>, <span class="ruby-value str">"compound"</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ftype</span><span class="ruby-operator">|</span>
888 312: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">filter</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">ftype</span>)
889 313: <span class="ruby-identifier">custom_filter</span>[<span class="ruby-identifier">ftype</span>] = [<span class="ruby-identifier">filter</span>[<span class="ruby-identifier">ftype</span>], <span class="ruby-identifier">custom_filter</span>[<span class="ruby-identifier">ftype</span>]].<span class="ruby-identifier">flatten</span>
890 314: <span class="ruby-keyword kw">end</span>
891 315: <span class="ruby-keyword kw">end</span>
893 317: <span class="ruby-comment cmt"># ensure that all filters at least restrict the call to the agent we're a proxy for</span>
894 318: <span class="ruby-identifier">custom_filter</span>[<span class="ruby-value str">"agent"</span>] <span class="ruby-operator"><<</span> <span class="ruby-ivar">@agent</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">custom_filter</span>[<span class="ruby-value str">"agent"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-ivar">@agent</span>)
895 319: <span class="ruby-identifier">custom_options</span>[<span class="ruby-identifier">:filter</span>] = <span class="ruby-identifier">custom_filter</span>
897 321: <span class="ruby-comment cmt"># Fake out the stats discovery would have put there</span>
898 322: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">discovered_agents</span>([<span class="ruby-identifier">expected_agents</span>].<span class="ruby-identifier">flatten</span>)
900 324: <span class="ruby-comment cmt"># Handle fire and forget requests</span>
901 325: <span class="ruby-comment cmt">#</span>
902 326: <span class="ruby-comment cmt"># If a specific reply-to was set then from the client perspective this should</span>
903 327: <span class="ruby-comment cmt"># be a fire and forget request too since no response will ever reach us - it</span>
904 328: <span class="ruby-comment cmt"># will go to the reply-to destination</span>
905 329: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@reply_to</span>
906 330: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">fire_and_forget_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">custom_filter</span>)
907 331: <span class="ruby-keyword kw">end</span>
909 333: <span class="ruby-comment cmt"># Now do a call pretty much exactly like in method_missing except with our own</span>
910 334: <span class="ruby-comment cmt"># options and discovery magic</span>
911 335: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
912 336: <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">custom_options</span>, [<span class="ruby-identifier">expected_agents</span>].<span class="ruby-identifier">flatten</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
913 337: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">r</span>)
914 338: <span class="ruby-keyword kw">end</span>
915 339: <span class="ruby-keyword kw">else</span>
916 340: <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">custom_options</span>, [<span class="ruby-identifier">expected_agents</span>].<span class="ruby-identifier">flatten</span>)
917 341: <span class="ruby-keyword kw">end</span>
918 342: <span class="ruby-keyword kw">end</span>
924 <div id="method-M000086" class="method-detail">
925 <a name="M000086"></a>
927 <div class="method-heading">
928 <a href="#M000086" class="method-signature">
929 <span class="method-name">disconnect</span><span class="method-args">()</span>
933 <div class="method-description">
935 Disconnects cleanly from the middleware
937 <p><a class="source-toggle" href="#"
938 onclick="toggleCode('M000086-source');return false;">[Source]</a></p>
939 <div class="method-source-code" id="M000086-source">
941 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 121</span>
942 121: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">disconnect</span>
943 122: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">disconnect</span>
944 123: <span class="ruby-keyword kw">end</span>
950 <div id="method-M000103" class="method-detail">
951 <a name="M000103"></a>
953 <div class="method-heading">
954 <a href="#M000103" class="method-signature">
955 <span class="method-name">discover</span><span class="method-args">(flags={})</span>
959 <div class="method-description">
961 Does discovery based on the filters set, if a discovery was previously done
962 return that else do a <a href="Client.html#M000085">new</a> discovery.
965 Alternatively if identity filters are given and none of them are regular
966 expressions then just use the provided data as discovered data, avoiding
970 <a href="../Discovery.html">Discovery</a> can be forced if
971 direct_addressing is enabled by passing in an array of nodes with :nodes or
972 JSON data like those produced by mcollective <a href="../RPC.html">RPC</a>
973 JSON output using :json
976 Will show a message indicating its doing discovery if running verbose or if
977 the :verbose flag is passed in.
980 Use <a href="Client.html#M000101">reset</a> to force a <a
981 href="Client.html#M000085">new</a> discovery
983 <p><a class="source-toggle" href="#"
984 onclick="toggleCode('M000103-source');return false;">[Source]</a></p>
985 <div class="method-source-code" id="M000103-source">
987 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 468</span>
988 468: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discover</span>(<span class="ruby-identifier">flags</span>={})
989 469: <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
990 470: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown option #{key} passed to discover"</span> <span class="ruby-keyword kw">unless</span> [<span class="ruby-identifier">:verbose</span>, <span class="ruby-identifier">:hosts</span>, <span class="ruby-identifier">:nodes</span>, <span class="ruby-identifier">:json</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">key</span>)
991 471: <span class="ruby-keyword kw">end</span>
993 473: <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:verbose</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">verbose</span> = <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:verbose</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">verbose</span> = <span class="ruby-ivar">@verbose</span>
995 475: <span class="ruby-identifier">verbose</span> = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@output_format</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:console</span>
997 477: <span class="ruby-comment cmt"># flags[:nodes] and flags[:hosts] are the same thing, we should never have</span>
998 478: <span class="ruby-comment cmt"># allowed :hosts as that was inconsistent with the established terminology</span>
999 479: <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>] = <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:hosts</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:hosts</span>)
1001 481: <span class="ruby-identifier">reset</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>]
1003 483: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@discovered_agents</span>
1004 484: <span class="ruby-comment cmt"># if either hosts or JSON is supplied try to figure out discovery data from there</span>
1005 485: <span class="ruby-comment cmt"># if direct_addressing is not enabled this is a critical error as the user might</span>
1006 486: <span class="ruby-comment cmt"># not have supplied filters so raise an exception</span>
1007 487: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>]
1008 488: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can only supply discovery data if direct_addressing is enabled"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
1010 490: <span class="ruby-identifier">hosts</span> = []
1012 492: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>]
1013 493: <span class="ruby-identifier">hosts</span> = <span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">extract_hosts_from_array</span>(<span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>])
1014 494: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>]
1015 495: <span class="ruby-identifier">hosts</span> = <span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">extract_hosts_from_json</span>(<span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>])
1016 496: <span class="ruby-keyword kw">end</span>
1018 498: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Could not find any hosts in discovery data provided"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hosts</span>.<span class="ruby-identifier">empty?</span>
1020 500: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-identifier">hosts</span>
1021 501: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span>
1023 503: <span class="ruby-keyword kw">else</span>
1024 504: <span class="ruby-identifier">identity_filter_discovery_optimization</span>
1025 505: <span class="ruby-keyword kw">end</span>
1026 506: <span class="ruby-keyword kw">end</span>
1028 508: <span class="ruby-comment cmt"># All else fails we do it the hard way using a traditional broadcast</span>
1029 509: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@discovered_agents</span>
1030 510: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_discovery</span> <span class="ruby-identifier">:start</span>
1032 512: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>
1034 514: <span class="ruby-comment cmt"># if compound filters are used the only real option is to use the mc</span>
1035 515: <span class="ruby-comment cmt"># discovery plugin since its the only capable of using data queries etc</span>
1036 516: <span class="ruby-comment cmt"># and we do not want to degrade that experience just to allow compounds</span>
1037 517: <span class="ruby-comment cmt"># on other discovery plugins the UX would be too bad raising complex sets</span>
1038 518: <span class="ruby-comment cmt"># of errors etc.</span>
1039 519: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">force_discovery_method_by_filter</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>])
1041 521: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">verbose</span>
1042 522: <span class="ruby-identifier">actual_timeout</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">discovery_timeout</span>(<span class="ruby-identifier">discovery_timeout</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>])
1044 524: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">actual_timeout</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
1045 525: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"Discovering hosts using the %s method for %d second(s) .... "</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">discovery_method</span>, <span class="ruby-identifier">actual_timeout</span>])
1046 526: <span class="ruby-keyword kw">else</span>
1047 527: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"Discovering hosts using the %s method .... "</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">discovery_method</span>])
1048 528: <span class="ruby-keyword kw">end</span>
1049 529: <span class="ruby-keyword kw">end</span>
1051 531: <span class="ruby-comment cmt"># if the requested limit is a pure number and not a percent</span>
1052 532: <span class="ruby-comment cmt"># and if we're configured to use the first found hosts as the</span>
1053 533: <span class="ruby-comment cmt"># limit method then pass in the limit thus minimizing the amount</span>
1054 534: <span class="ruby-comment cmt"># of work we do in the discover phase and speeding it up significantly</span>
1055 535: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_method</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:first</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@limit_targets</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Fixnum</span>)
1056 536: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discover</span>(<span class="ruby-ivar">@filter</span>, <span class="ruby-identifier">discovery_timeout</span>, <span class="ruby-ivar">@limit_targets</span>)
1057 537: <span class="ruby-keyword kw">else</span>
1058 538: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discover</span>(<span class="ruby-ivar">@filter</span>, <span class="ruby-identifier">discovery_timeout</span>)
1059 539: <span class="ruby-keyword kw">end</span>
1061 541: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-ivar">@discovered_agents</span>.<span class="ruby-identifier">size</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">verbose</span>
1063 543: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">force_direct_mode?</span>
1065 545: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_discovery</span> <span class="ruby-identifier">:end</span>
1066 546: <span class="ruby-keyword kw">end</span>
1068 548: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">discovered_agents</span>(<span class="ruby-ivar">@discovered_agents</span>)
1069 549: <span class="ruby-constant">RPC</span>.<span class="ruby-identifier">discovered</span>(<span class="ruby-ivar">@discovered_agents</span>)
1071 551: <span class="ruby-ivar">@discovered_agents</span>
1072 552: <span class="ruby-keyword kw">end</span>
1078 <div id="method-M000094" class="method-detail">
1079 <a name="M000094"></a>
1081 <div class="method-heading">
1082 <a href="#M000094" class="method-signature">
1083 <span class="method-name">discovery_method=</span><span class="method-args">(method)</span>
1087 <div class="method-description">
1089 Sets the discovery method. If we change the method there are a number of
1093 - set the new method
1094 - if discovery options were provided, re-set those to initially
1095 provided ones else clear them as they might now apply to a
1097 - update the client options so it knows there is a new discovery
1099 - reset discovery data forcing a discover on the next request
1102 The remaining item is the discovery timeout, we leave that as is since that
1103 is the user supplied timeout either via initial <a
1104 href="Client.html#M000104">options</a> or via specifically setting it on
1107 <p><a class="source-toggle" href="#"
1108 onclick="toggleCode('M000094-source');return false;">[Source]</a></p>
1109 <div class="method-source-code" id="M000094-source">
1111 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 377</span>
1112 377: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_method=</span>(<span class="ruby-identifier">method</span>)
1113 378: <span class="ruby-ivar">@default_discovery_method</span> = <span class="ruby-keyword kw">false</span>
1114 379: <span class="ruby-ivar">@discovery_method</span> = <span class="ruby-identifier">method</span>
1116 381: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@initial_options</span>[<span class="ruby-identifier">:discovery_options</span>]
1117 382: <span class="ruby-ivar">@discovery_options</span> = <span class="ruby-ivar">@initial_options</span>[<span class="ruby-identifier">:discovery_options</span>]
1118 383: <span class="ruby-keyword kw">else</span>
1119 384: <span class="ruby-ivar">@discovery_options</span>.<span class="ruby-identifier">clear</span>
1120 385: <span class="ruby-keyword kw">end</span>
1122 387: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>
1124 389: <span class="ruby-identifier">reset</span>
1125 390: <span class="ruby-keyword kw">end</span>
1131 <div id="method-M000095" class="method-detail">
1132 <a name="M000095"></a>
1134 <div class="method-heading">
1135 <a href="#M000095" class="method-signature">
1136 <span class="method-name">discovery_options=</span><span class="method-args">(options)</span>
1140 <div class="method-description">
1141 <p><a class="source-toggle" href="#"
1142 onclick="toggleCode('M000095-source');return false;">[Source]</a></p>
1143 <div class="method-source-code" id="M000095-source">
1145 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 392</span>
1146 392: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_options=</span>(<span class="ruby-identifier">options</span>)
1147 393: <span class="ruby-ivar">@discovery_options</span> = [<span class="ruby-identifier">options</span>].<span class="ruby-identifier">flatten</span>
1148 394: <span class="ruby-identifier">reset</span>
1149 395: <span class="ruby-keyword kw">end</span>
1155 <div id="method-M000092" class="method-detail">
1156 <a name="M000092"></a>
1158 <div class="method-heading">
1159 <a href="#M000092" class="method-signature">
1160 <span class="method-name">discovery_timeout</span><span class="method-args">()</span>
1164 <div class="method-description">
1165 <p><a class="source-toggle" href="#"
1166 onclick="toggleCode('M000092-source');return false;">[Source]</a></p>
1167 <div class="method-source-code" id="M000092-source">
1169 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 344</span>
1170 344: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_timeout</span>
1171 345: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@discovery_timeout</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@discovery_timeout</span>
1172 346: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">ddl</span>.<span class="ruby-identifier">meta</span>[<span class="ruby-identifier">:timeout</span>]
1173 347: <span class="ruby-keyword kw">end</span>
1179 <div id="method-M000093" class="method-detail">
1180 <a name="M000093"></a>
1182 <div class="method-heading">
1183 <a href="#M000093" class="method-signature">
1184 <span class="method-name">discovery_timeout=</span><span class="method-args">(timeout)</span>
1188 <div class="method-description">
1189 <p><a class="source-toggle" href="#"
1190 onclick="toggleCode('M000093-source');return false;">[Source]</a></p>
1191 <div class="method-source-code" id="M000093-source">
1193 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 349</span>
1194 349: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_timeout=</span>(<span class="ruby-identifier">timeout</span>)
1195 350: <span class="ruby-ivar">@discovery_timeout</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">timeout</span>)
1197 352: <span class="ruby-comment cmt"># we calculate the overall timeout from the DDL of the agent and</span>
1198 353: <span class="ruby-comment cmt"># the supplied discovery timeout unless someone specifically</span>
1199 354: <span class="ruby-comment cmt"># specifies a timeout to the constructor</span>
1200 355: <span class="ruby-comment cmt">#</span>
1201 356: <span class="ruby-comment cmt"># But if we also then specifically set a discovery_timeout on the</span>
1202 357: <span class="ruby-comment cmt"># agent that has to override the supplied timeout so we then</span>
1203 358: <span class="ruby-comment cmt"># calculate a correct timeout based on DDL timeout and the</span>
1204 359: <span class="ruby-comment cmt"># supplied discovery timeout</span>
1205 360: <span class="ruby-ivar">@timeout</span> = <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">meta</span>[<span class="ruby-identifier">:timeout</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">discovery_timeout</span>
1206 361: <span class="ruby-keyword kw">end</span>
1212 <div id="method-M000097" class="method-detail">
1213 <a name="M000097"></a>
1215 <div class="method-heading">
1216 <a href="#M000097" class="method-signature">
1217 <span class="method-name">fact_filter</span><span class="method-args">(fact, value=nil, operator="=")</span>
1221 <div class="method-description">
1223 Sets the fact filter
1225 <p><a class="source-toggle" href="#"
1226 onclick="toggleCode('M000097-source');return false;">[Source]</a></p>
1227 <div class="method-source-code" id="M000097-source">
1229 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 405</span>
1230 405: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fact_filter</span>(<span class="ruby-identifier">fact</span>, <span class="ruby-identifier">value</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">operator</span>=<span class="ruby-value str">"="</span>)
1231 406: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fact</span>.<span class="ruby-identifier">nil?</span>
1232 407: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fact</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
1234 409: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
1235 410: <span class="ruby-identifier">parsed</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">parse_fact_string</span>(<span class="ruby-identifier">fact</span>)
1236 411: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">parsed</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">parsed</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
1237 412: <span class="ruby-keyword kw">else</span>
1238 413: <span class="ruby-identifier">parsed</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">parse_fact_string</span>(<span class="ruby-node">"#{fact}#{operator}#{value}"</span>)
1239 414: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">parsed</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">parsed</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
1240 415: <span class="ruby-keyword kw">end</span>
1242 417: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>].<span class="ruby-identifier">compact!</span>
1243 418: <span class="ruby-identifier">reset</span>
1244 419: <span class="ruby-keyword kw">end</span>
1250 <div id="method-M000114" class="method-detail">
1251 <a name="M000114"></a>
1253 <div class="method-heading">
1254 <a href="#M000114" class="method-signature">
1255 <span class="method-name">fire_and_forget_request</span><span class="method-args">(action, args, filter=nil)</span>
1259 <div class="method-description">
1261 for requests that do not care for results just return the request id and
1262 don‘t do any of the response processing.
1265 We send the :process_results flag with to the nodes so they can make
1266 decisions based on that.
1269 Should only be called via <a href="Client.html#M000090">method_missing</a>
1271 <p><a class="source-toggle" href="#"
1272 onclick="toggleCode('M000114-source');return false;">[Source]</a></p>
1273 <div class="method-source-code" id="M000114-source">
1275 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 710</span>
1276 710: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fire_and_forget_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">filter</span>=<span class="ruby-keyword kw">nil</span>)
1277 711: <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
1279 713: <span class="ruby-identifier">identity_filter_discovery_optimization</span>
1281 715: <span class="ruby-identifier">req</span> = <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">args</span>)
1283 717: <span class="ruby-identifier">filter</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">filter</span>
1285 719: <span class="ruby-identifier">message</span> = <span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-keyword kw">nil</span>, {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:request</span>, <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>, <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">filter</span>, <span class="ruby-identifier">:options</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">options</span>})
1286 720: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">reply_to</span> = <span class="ruby-ivar">@reply_to</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@reply_to</span>
1288 722: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@force_direct_request</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">force_direct_mode?</span>
1289 723: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">discovered_hosts</span> = <span class="ruby-identifier">discover</span>.<span class="ruby-identifier">clone</span>
1290 724: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">type</span> = <span class="ruby-identifier">:direct_request</span>
1291 725: <span class="ruby-keyword kw">end</span>
1293 727: <span class="ruby-identifier">client</span>.<span class="ruby-identifier">sendreq</span>(<span class="ruby-identifier">message</span>, <span class="ruby-keyword kw">nil</span>)
1294 728: <span class="ruby-keyword kw">end</span>
1300 <div id="method-M000087" class="method-detail">
1301 <a name="M000087"></a>
1303 <div class="method-heading">
1304 <a href="#M000087" class="method-signature">
1305 <span class="method-name">help</span><span class="method-args">(template)</span>
1309 <div class="method-description">
1311 Returns <a href="Client.html#M000087">help</a> for an agent if a <a
1312 href="../DDL.html">DDL</a> was found
1314 <p><a class="source-toggle" href="#"
1315 onclick="toggleCode('M000087-source');return false;">[Source]</a></p>
1316 <div class="method-source-code" id="M000087-source">
1318 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 126</span>
1319 126: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">help</span>(<span class="ruby-identifier">template</span>)
1320 127: <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">help</span>(<span class="ruby-identifier">template</span>)
1321 128: <span class="ruby-keyword kw">end</span>
1327 <div id="method-M000099" class="method-detail">
1328 <a name="M000099"></a>
1330 <div class="method-heading">
1331 <a href="#M000099" class="method-signature">
1332 <span class="method-name">identity_filter</span><span class="method-args">(identity)</span>
1336 <div class="method-description">
1338 Sets the identity filter
1340 <p><a class="source-toggle" href="#"
1341 onclick="toggleCode('M000099-source');return false;">[Source]</a></p>
1342 <div class="method-source-code" id="M000099-source">
1344 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 429</span>
1345 429: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">identity_filter</span>(<span class="ruby-identifier">identity</span>)
1346 430: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"identity"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"identity"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">identity</span>]
1347 431: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">compact!</span>
1348 432: <span class="ruby-identifier">reset</span>
1349 433: <span class="ruby-keyword kw">end</span>
1355 <div id="method-M000115" class="method-detail">
1356 <a name="M000115"></a>
1358 <div class="method-heading">
1359 <a href="#M000115" class="method-signature">
1360 <span class="method-name">identity_filter_discovery_optimization</span><span class="method-args">()</span>
1364 <div class="method-description">
1366 if an identity filter is supplied and it is all strings no regex we can use
1367 that as discovery data, technically the identity filter is then redundant
1368 if we are in direct addressing mode and we could empty it out but this use
1369 case should only really be for a few -I‘s on the CLI
1372 For safety we leave the filter in place for now, that way we can support
1373 this enhancement also in broadcast mode.
1376 This is only needed for the ‘mc’ discovery method, other
1377 methods might change the concept of identity to mean something else so we
1378 should pass the full identity filter to them
1380 <p><a class="source-toggle" href="#"
1381 onclick="toggleCode('M000115-source');return false;">[Source]</a></p>
1382 <div class="method-source-code" id="M000115-source">
1384 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 741</span>
1385 741: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">identity_filter_discovery_optimization</span>
1386 742: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>][<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@discovery_method</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"mc"</span>
1387 743: <span class="ruby-identifier">regex_filters</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>][<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">match</span>(<span class="ruby-value str">"^\/"</span>)}.<span class="ruby-identifier">size</span>
1389 745: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">regex_filters</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
1390 746: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>][<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">clone</span>
1391 747: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
1392 748: <span class="ruby-keyword kw">end</span>
1393 749: <span class="ruby-keyword kw">end</span>
1394 750: <span class="ruby-keyword kw">end</span>
1400 <div id="method-M000107" class="method-detail">
1401 <a name="M000107"></a>
1403 <div class="method-heading">
1404 <a href="#M000107" class="method-signature">
1405 <span class="method-name">limit_method=</span><span class="method-args">(method)</span>
1409 <div class="method-description">
1411 Sets and sanity check the limit_method variable used to determine how to
1412 limit targets if limit_targets is set
1414 <p><a class="source-toggle" href="#"
1415 onclick="toggleCode('M000107-source');return false;">[Source]</a></p>
1416 <div class="method-source-code" id="M000107-source">
1418 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 599</span>
1419 599: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">limit_method=</span>(<span class="ruby-identifier">method</span>)
1420 600: <span class="ruby-identifier">method</span> = <span class="ruby-identifier">method</span>.<span class="ruby-identifier">to_sym</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">method</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
1422 602: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown limit method #{method} must be :random or :first"</span> <span class="ruby-keyword kw">unless</span> [<span class="ruby-identifier">:random</span>, <span class="ruby-identifier">:first</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">method</span>)
1424 604: <span class="ruby-ivar">@limit_method</span> = <span class="ruby-identifier">method</span>
1425 605: <span class="ruby-keyword kw">end</span>
1431 <div id="method-M000106" class="method-detail">
1432 <a name="M000106"></a>
1434 <div class="method-heading">
1435 <a href="#M000106" class="method-signature">
1436 <span class="method-name">limit_targets=</span><span class="method-args">(limit)</span>
1440 <div class="method-description">
1442 Sets and sanity checks the limit_targets variable used to restrict how many
1443 nodes we‘ll target
1445 <p><a class="source-toggle" href="#"
1446 onclick="toggleCode('M000106-source');return false;">[Source]</a></p>
1447 <div class="method-source-code" id="M000106-source">
1449 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 583</span>
1450 583: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">limit_targets=</span>(<span class="ruby-identifier">limit</span>)
1451 584: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">limit</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
1452 585: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Invalid limit specified: #{limit} valid limits are /^\d+%*$/"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">limit</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\d+%*$/</span>
1454 587: <span class="ruby-keyword kw">begin</span>
1455 588: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">limit</span>)
1456 589: <span class="ruby-keyword kw">rescue</span>
1457 590: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-identifier">limit</span>
1458 591: <span class="ruby-keyword kw">end</span>
1459 592: <span class="ruby-keyword kw">else</span>
1460 593: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">limit</span>)
1461 594: <span class="ruby-keyword kw">end</span>
1462 595: <span class="ruby-keyword kw">end</span>
1468 <div id="method-M000111" class="method-detail">
1469 <a name="M000111"></a>
1471 <div class="method-heading">
1472 <a href="#M000111" class="method-signature">
1473 <span class="method-name">load_aggregate_functions</span><span class="method-args">(action, ddl)</span>
1477 <div class="method-description">
1478 <p><a class="source-toggle" href="#"
1479 onclick="toggleCode('M000111-source');return false;">[Source]</a></p>
1480 <div class="method-source-code" id="M000111-source">
1482 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 676</span>
1483 676: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_aggregate_functions</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">ddl</span>)
1484 677: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">ddl</span>
1485 678: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">ddl</span>.<span class="ruby-identifier">action_interface</span>(<span class="ruby-identifier">action</span>).<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:aggregate</span>)
1487 680: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Aggregate</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ddl</span>.<span class="ruby-identifier">action_interface</span>(<span class="ruby-identifier">action</span>))
1489 682: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
1490 683: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">"Failed to load aggregate functions, calculating summaries disabled: %s: %s (%s)"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">first</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>])
1491 684: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
1492 685: <span class="ruby-keyword kw">end</span>
1498 <div id="method-M000090" class="method-detail">
1499 <a name="M000090"></a>
1501 <div class="method-heading">
1502 <a href="#M000090" class="method-signature">
1503 <span class="method-name">method_missing</span><span class="method-args">(method_name, *args, &block)</span>
1507 <div class="method-description">
1509 Magic handler to invoke remote methods
1512 Once the stub is created using the constructor or the <a
1513 href="../RPC.html#M000037">RPC#rpcclient</a> helper you can call remote
1517 ret = rpc.echo(:msg => "hello world")
1520 This will call the ‘echo’ action of the ‘rpctest’
1521 agent and return the result as an array, the array will be a simplified
1522 result set from the usual full MCollective::Client#req with additional
1523 error codes and error text:
1529 :sender => "remote.box.com",
1530 :statuscode => 0,
1531 :statusmsg => "OK",
1532 :data => "hello world"
1538 If :statuscode is 0 then everything went find, if it‘s 1 then you
1539 supplied the correct arguments etc but the request could not be completed,
1540 you‘ll find a human parsable reason in :statusmsg then.
1543 Codes 2 to 5 maps directly to <a
1544 href="../UnknownRPCAction.html">UnknownRPCAction</a>, <a
1545 href="../MissingRPCData.html">MissingRPCData</a>, <a
1546 href="../InvalidRPCData.html">InvalidRPCData</a> and <a
1547 href="../UnknownRPCError.html">UnknownRPCError</a> see below for a
1548 description of those, in each case :statusmsg would be the reason for
1552 To get access to the full result of the MCollective::Client#req calls you
1553 can pass in a block:
1556 rpc.echo(:msg => "hello world") do |resp|
1561 In this case resp will the result from MCollective::Client#req. Instead of
1562 returning simple text and codes as above you‘ll also need to handle
1563 the following exceptions:
1566 <a href="../UnknownRPCAction.html">UnknownRPCAction</a> - There is no
1567 matching action on the agent <a
1568 href="../MissingRPCData.html">MissingRPCData</a> - You did not supply all
1569 the needed parameters for the action <a
1570 href="../InvalidRPCData.html">InvalidRPCData</a> - The data you did supply
1571 did not pass validation <a
1572 href="../UnknownRPCError.html">UnknownRPCError</a> - Some other error
1573 prevented the agent from running
1576 During calls a progress indicator will be shown of how many results
1577 we‘ve received against how many nodes were discovered, you can
1578 disable this by setting progress to false:
1581 rpc.progress = false
1584 This supports a 2nd mode where it will send the SimpleRPC request and never
1585 handle the responses. It‘s a bit like UDP, it sends the request with
1586 the filter attached and you only get back the requestid, you have no
1587 indication about results.
1590 You can invoke this using:
1593 puts rpc.echo(:process_results => false)
1596 This will output just the request id.
1599 Batched processing is supported:
1602 printrpc rpc.ping(:batch_size => 5)
1605 This will do everything exactly as normal but communicate to only 5 agents
1608 <p><a class="source-toggle" href="#"
1609 onclick="toggleCode('M000090-source');return false;">[Source]</a></p>
1610 <div class="method-source-code" id="M000090-source">
1612 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 231</span>
1613 231: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">method_name</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
1614 232: <span class="ruby-comment cmt"># set args to an empty hash if nothings given</span>
1615 233: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>]
1616 234: <span class="ruby-identifier">args</span> = {} <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
1618 236: <span class="ruby-identifier">action</span> = <span class="ruby-identifier">method_name</span>.<span class="ruby-identifier">to_s</span>
1620 238: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">reset</span>
1622 240: <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
1624 242: <span class="ruby-comment cmt"># if a global batch size is set just use that else set it</span>
1625 243: <span class="ruby-comment cmt"># in the case that it was passed as an argument</span>
1626 244: <span class="ruby-identifier">batch_mode</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:batch_size</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@batch_mode</span>
1627 245: <span class="ruby-identifier">batch_size</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:batch_size</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@batch_size</span>
1628 246: <span class="ruby-identifier">batch_sleep_time</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:batch_sleep_time</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@batch_sleep_time</span>
1630 248: <span class="ruby-comment cmt"># if we were given a batch_size argument thats 0 and batch_mode was</span>
1631 249: <span class="ruby-comment cmt"># determined to be on via global options etc this will allow a batch_size</span>
1632 250: <span class="ruby-comment cmt"># of 0 to disable or batch_mode for this call only</span>
1633 251: <span class="ruby-identifier">batch_mode</span> = (<span class="ruby-identifier">batch_mode</span> <span class="ruby-operator">&&</span> <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">batch_size</span>) <span class="ruby-operator">></span> <span class="ruby-value">0</span>)
1635 253: <span class="ruby-comment cmt"># Handle single target requests by doing discovery and picking</span>
1636 254: <span class="ruby-comment cmt"># a random node. Then do a custom request specifying a filter</span>
1637 255: <span class="ruby-comment cmt"># that will only match the one node.</span>
1638 256: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_targets</span>
1639 257: <span class="ruby-identifier">target_nodes</span> = <span class="ruby-identifier">pick_nodes_from_discovered</span>(<span class="ruby-ivar">@limit_targets</span>)
1640 258: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Picked #{target_nodes.join(',')} as limited target(s)"</span>)
1642 260: <span class="ruby-identifier">custom_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">target_nodes</span>, {<span class="ruby-value str">"identity"</span> =<span class="ruby-operator">></span> <span class="ruby-node">/^(#{target_nodes.join('|')})$/</span>}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
1643 261: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">batch_mode</span>
1644 262: <span class="ruby-identifier">call_agent_batched</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">batch_size</span>, <span class="ruby-identifier">batch_sleep_time</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
1645 263: <span class="ruby-keyword kw">else</span>
1646 264: <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">:auto</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
1647 265: <span class="ruby-keyword kw">end</span>
1648 266: <span class="ruby-keyword kw">end</span>
1654 <div id="method-M000088" class="method-detail">
1655 <a name="M000088"></a>
1657 <div class="method-heading">
1658 <a href="#M000088" class="method-signature">
1659 <span class="method-name">new_request</span><span class="method-args">(action, data)</span>
1663 <div class="method-description">
1665 Creates a suitable request hash for the SimpleRPC agent.
1668 You‘d use this if you ever wanted to take care of sending requests on
1669 your own - perhaps via Client#sendreq if you didn‘t care for
1673 In that case you can just do:
1676 msg = your_rpc.new_request("some_action", :foo => :bar)
1677 filter = your_rpc.filter
1679 your_rpc.client.sendreq(msg, msg[:agent], filter)
1682 This will send a SimpleRPC request to the action some_action with arguments
1683 :foo = :bar, it will return immediately and you will have no indication at
1684 all if the request was receieved or not
1687 Clearly the use of this technique should be limited and done only if your
1688 code requires such a thing
1690 <p><a class="source-toggle" href="#"
1691 onclick="toggleCode('M000088-source');return false;">[Source]</a></p>
1692 <div class="method-source-code" id="M000088-source">
1694 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 149</span>
1695 149: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">data</span>)
1696 150: <span class="ruby-identifier">callerid</span> = <span class="ruby-constant">PluginManager</span>[<span class="ruby-value str">"security_plugin"</span>].<span class="ruby-identifier">callerid</span>
1698 152: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'callerid received from security plugin is not valid'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">PluginManager</span>[<span class="ruby-value str">"security_plugin"</span>].<span class="ruby-identifier">valid_callerid?</span>(<span class="ruby-identifier">callerid</span>)
1700 154: {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>,
1701 155: <span class="ruby-identifier">:action</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">action</span>,
1702 156: <span class="ruby-identifier">:caller</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">callerid</span>,
1703 157: <span class="ruby-identifier">:data</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">data</span>}
1704 158: <span class="ruby-keyword kw">end</span>
1710 <div id="method-M000104" class="method-detail">
1711 <a name="M000104"></a>
1713 <div class="method-heading">
1714 <a href="#M000104" class="method-signature">
1715 <span class="method-name">options</span><span class="method-args">()</span>
1719 <div class="method-description">
1721 Provides a normal <a href="Client.html#M000104">options</a> hash like you
1722 would get from <a href="../Optionparser.html">Optionparser</a>
1724 <p><a class="source-toggle" href="#"
1725 onclick="toggleCode('M000104-source');return false;">[Source]</a></p>
1726 <div class="method-source-code" id="M000104-source">
1728 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 556</span>
1729 556: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options</span>
1730 557: {<span class="ruby-identifier">:disctimeout</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">discovery_timeout</span>,
1731 558: <span class="ruby-identifier">:timeout</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@timeout</span>,
1732 559: <span class="ruby-identifier">:verbose</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@verbose</span>,
1733 560: <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@filter</span>,
1734 561: <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>,
1735 562: <span class="ruby-identifier">:output_format</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@output_format</span>,
1736 563: <span class="ruby-identifier">:ttl</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@ttl</span>,
1737 564: <span class="ruby-identifier">:discovery_method</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@discovery_method</span>,
1738 565: <span class="ruby-identifier">:discovery_options</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@discovery_options</span>,
1739 566: <span class="ruby-identifier">:force_display_mode</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@force_display_mode</span>,
1740 567: <span class="ruby-identifier">:config</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@config</span>,
1741 568: <span class="ruby-identifier">:publish_timeout</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@publish_timeout</span>,
1742 569: <span class="ruby-identifier">:threaded</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@threaded</span>}
1743 570: <span class="ruby-keyword kw">end</span>
1749 <div id="method-M000110" class="method-detail">
1750 <a name="M000110"></a>
1752 <div class="method-heading">
1753 <a href="#M000110" class="method-signature">
1754 <span class="method-name">pick_nodes_from_discovered</span><span class="method-args">(count)</span>
1758 <div class="method-description">
1760 Pick a number of nodes from the discovered nodes
1763 The count should be a string that can be either just a number or a
1767 It will select nodes from the discovered list based on the rpclimitmethod
1768 configuration option which can be either :first or anything else
1771 - :first would be a simple way to do a distance based
1773 - anything else will just pick one at random
1774 - if random chosen, and batch-seed set, then set srand
1775 for the generator, and reset afterwards
1777 <p><a class="source-toggle" href="#"
1778 onclick="toggleCode('M000110-source');return false;">[Source]</a></p>
1779 <div class="method-source-code" id="M000110-source">
1781 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 635</span>
1782 635: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pick_nodes_from_discovered</span>(<span class="ruby-identifier">count</span>)
1783 636: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/%$/</span>
1784 637: <span class="ruby-identifier">pct</span> = <span class="ruby-constant">Integer</span>((<span class="ruby-identifier">discover</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">count</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">100</span>)))
1785 638: <span class="ruby-identifier">pct</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">count</span> = <span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">count</span> = <span class="ruby-identifier">pct</span>
1786 639: <span class="ruby-keyword kw">else</span>
1787 640: <span class="ruby-identifier">count</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">count</span>)
1788 641: <span class="ruby-keyword kw">end</span>
1790 643: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">discover</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">discover</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">count</span>
1792 645: <span class="ruby-identifier">result</span> = []
1794 647: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_method</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:first</span>
1795 648: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">discover</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">count</span>]
1796 649: <span class="ruby-keyword kw">else</span>
1797 650: <span class="ruby-comment cmt"># we delete from the discovered list because we want</span>
1798 651: <span class="ruby-comment cmt"># to be sure there is no chance that the same node will</span>
1799 652: <span class="ruby-comment cmt"># be randomly picked twice. So we have to clone the</span>
1800 653: <span class="ruby-comment cmt"># discovered list else this method will only ever work</span>
1801 654: <span class="ruby-comment cmt"># once per discovery cycle and not actually return the</span>
1802 655: <span class="ruby-comment cmt"># right nodes.</span>
1803 656: <span class="ruby-identifier">haystack</span> = <span class="ruby-identifier">discover</span>.<span class="ruby-identifier">clone</span>
1805 658: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_seed</span>
1806 659: <span class="ruby-identifier">haystack</span>.<span class="ruby-identifier">sort!</span>
1807 660: <span class="ruby-identifier">srand</span>(<span class="ruby-ivar">@limit_seed</span>)
1808 661: <span class="ruby-keyword kw">end</span>
1810 663: <span class="ruby-identifier">count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
1811 664: <span class="ruby-identifier">rnd</span> = <span class="ruby-identifier">rand</span>(<span class="ruby-identifier">haystack</span>.<span class="ruby-identifier">size</span>)
1812 665: <span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">haystack</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">rnd</span>)
1813 666: <span class="ruby-keyword kw">end</span>
1815 668: <span class="ruby-comment cmt"># Reset random number generator to fresh seed</span>
1816 669: <span class="ruby-comment cmt"># As our seed from options is most likely short</span>
1817 670: <span class="ruby-identifier">srand</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_seed</span>
1818 671: <span class="ruby-keyword kw">end</span>
1820 673: [<span class="ruby-identifier">result</span>].<span class="ruby-identifier">flatten</span>
1821 674: <span class="ruby-keyword kw">end</span>
1827 <div id="method-M000119" class="method-detail">
1828 <a name="M000119"></a>
1830 <div class="method-heading">
1831 <a href="#M000119" class="method-signature">
1832 <span class="method-name">process_results_with_block</span><span class="method-args">(action, resp, block, aggregate)</span>
1836 <div class="method-description">
1838 process client requests by calling a block on each result in this mode we
1839 do not do anything fancy with the result objects and we raise exceptions if
1840 there are problems with the data
1842 <p><a class="source-toggle" href="#"
1843 onclick="toggleCode('M000119-source');return false;">[Source]</a></p>
1844 <div class="method-source-code" id="M000119-source">
1846 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 944</span>
1847 944: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_results_with_block</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">block</span>, <span class="ruby-identifier">aggregate</span>)
1848 945: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">node_responded</span>(<span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:senderid</span>])
1850 947: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">rpc_result_from_reply</span>(<span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>)
1851 948: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">aggregate_reply</span>(<span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
1853 950: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
1854 951: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">ok</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
1855 952: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
1856 953: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_block_execution</span> <span class="ruby-identifier">:start</span>
1858 955: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">arity</span>
1859 956: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>
1860 957: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">resp</span>)
1861 958: <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>
1862 959: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">result</span>)
1863 960: <span class="ruby-keyword kw">end</span>
1865 962: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_block_execution</span> <span class="ruby-identifier">:end</span>
1866 963: <span class="ruby-keyword kw">else</span>
1867 964: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span>
1869 966: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>]
1870 967: <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>
1871 968: <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnknownRPCAction</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
1872 969: <span class="ruby-keyword kw">when</span> <span class="ruby-value">3</span>
1873 970: <span class="ruby-identifier">raise</span> <span class="ruby-constant">MissingRPCData</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
1874 971: <span class="ruby-keyword kw">when</span> <span class="ruby-value">4</span>
1875 972: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidRPCData</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
1876 973: <span class="ruby-keyword kw">when</span> <span class="ruby-value">5</span>
1877 974: <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnknownRPCError</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
1878 975: <span class="ruby-keyword kw">end</span>
1879 976: <span class="ruby-keyword kw">end</span>
1881 978: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">aggregate</span>
1882 979: <span class="ruby-keyword kw">end</span>
1888 <div id="method-M000118" class="method-detail">
1889 <a name="M000118"></a>
1891 <div class="method-heading">
1892 <a href="#M000118" class="method-signature">
1893 <span class="method-name">process_results_without_block</span><span class="method-args">(resp, action, aggregate)</span>
1897 <div class="method-description">
1899 Handles result sets that has no block associated, sets fails and ok in the
1900 stats object and return a hash of the response to send to the caller
1902 <p><a class="source-toggle" href="#"
1903 onclick="toggleCode('M000118-source');return false;">[Source]</a></p>
1904 <div class="method-source-code" id="M000118-source">
1906 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 924</span>
1907 924: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_results_without_block</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">aggregate</span>)
1908 925: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">node_responded</span>(<span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:senderid</span>])
1910 927: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">rpc_result_from_reply</span>(<span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>)
1911 928: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">aggregate_reply</span>(<span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
1913 930: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
1914 931: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">ok</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
1915 932: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
1916 933: <span class="ruby-keyword kw">else</span>
1917 934: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span>
1918 935: <span class="ruby-keyword kw">end</span>
1920 937: [<span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span>]
1921 938: <span class="ruby-keyword kw">end</span>
1927 <div id="method-M000101" class="method-detail">
1928 <a name="M000101"></a>
1930 <div class="method-heading">
1931 <a href="#M000101" class="method-signature">
1932 <span class="method-name">reset</span><span class="method-args">()</span>
1936 <div class="method-description">
1938 Resets various internal parts of the class, most importantly it clears out
1939 the cached discovery
1941 <p><a class="source-toggle" href="#"
1942 onclick="toggleCode('M000101-source');return false;">[Source]</a></p>
1943 <div class="method-source-code" id="M000101-source">
1945 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 443</span>
1946 443: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset</span>
1947 444: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-keyword kw">nil</span>
1948 445: <span class="ruby-keyword kw">end</span>
1954 <div id="method-M000102" class="method-detail">
1955 <a name="M000102"></a>
1957 <div class="method-heading">
1958 <a href="#M000102" class="method-signature">
1959 <span class="method-name">reset_filter</span><span class="method-args">()</span>
1963 <div class="method-description">
1965 Reet the filter to an empty one
1967 <p><a class="source-toggle" href="#"
1968 onclick="toggleCode('M000102-source');return false;">[Source]</a></p>
1969 <div class="method-source-code" id="M000102-source">
1971 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 448</span>
1972 448: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_filter</span>
1973 449: <span class="ruby-ivar">@filter</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">empty_filter</span>
1974 450: <span class="ruby-identifier">agent_filter</span> <span class="ruby-ivar">@agent</span>
1975 451: <span class="ruby-keyword kw">end</span>
1981 <div id="method-M000113" class="method-detail">
1982 <a name="M000113"></a>
1984 <div class="method-heading">
1985 <a href="#M000113" class="method-signature">
1986 <span class="method-name">rpc_result_from_reply</span><span class="method-args">(agent, action, reply)</span>
1990 <div class="method-description">
1991 <p><a class="source-toggle" href="#"
1992 onclick="toggleCode('M000113-source');return false;">[Source]</a></p>
1993 <div class="method-source-code" id="M000113-source">
1995 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 697</span>
1996 697: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rpc_result_from_reply</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">reply</span>)
1997 698: <span class="ruby-constant">Result</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">action</span>, {<span class="ruby-identifier">:sender</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:senderid</span>], <span class="ruby-identifier">:statuscode</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>],
1998 699: <span class="ruby-identifier">:statusmsg</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>], <span class="ruby-identifier">:data</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:data</span>]})
1999 700: <span class="ruby-keyword kw">end</span>
2005 <div id="method-M000089" class="method-detail">
2006 <a name="M000089"></a>
2008 <div class="method-heading">
2009 <a href="#M000089" class="method-signature">
2010 <span class="method-name">validate_request</span><span class="method-args">(action, args)</span>
2014 <div class="method-description">
2016 For the provided arguments and action the input arguments get modified by
2017 supplying any defaults provided in the <a href="../DDL.html">DDL</a> for
2018 arguments that were not supplied in the request
2021 We then pass the modified arguments to the <a href="../DDL.html">DDL</a>
2024 <p><a class="source-toggle" href="#"
2025 onclick="toggleCode('M000089-source');return false;">[Source]</a></p>
2026 <div class="method-source-code" id="M000089-source">
2028 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 165</span>
2029 165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
2030 166: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"No DDL found for agent %s cannot validate inputs"</span> <span class="ruby-operator">%</span> <span class="ruby-ivar">@agent</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@ddl</span>
2032 168: <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">set_default_input_arguments</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
2033 169: <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">validate_rpc_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
2034 170: <span class="ruby-keyword kw">end</span>
2047 <div id="validator-badges">
2048 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>