application_failure(e, err_dest=STDERR)
click to toggle source
Handles failure, if we’re far enough in the initialization phase it
will log backtraces if its in verbose mode only
253: def application_failure(e, err_dest=STDERR)
254:
255: if e.is_a?(SystemExit)
256: disconnect
257: raise(e)
258: end
259:
260: if e.is_a?(CodedError)
261: err_dest.puts "\nThe %s application failed to run: %s: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:bold, e.code), Util.colorize(:red, e.to_s)]
262:
263: err_dest.puts
264: if options[:verbose]
265: err_dest.puts "Use the 'mco doc %s' command for details about this error" % e.code
266: else
267: err_dest.puts "Use the 'mco doc %s' command for details about this error, use -v for full error backtrace details" % e.code
268: end
269: else
270: if options[:verbose]
271: err_dest.puts "\nThe %s application failed to run: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
272: else
273: err_dest.puts "\nThe %s application failed to run, use -v for full error backtrace details: %s\n" % [ Util.colorize(:bold, $0), Util.colorize(:red, e.to_s)]
274: end
275: end
276:
277: if options.nil? || options[:verbose]
278: e.backtrace.first << Util.colorize(:red, " <----")
279: err_dest.puts "\n%s %s" % [ Util.colorize(:red, e.to_s), Util.colorize(:bold, "(#{e.class.to_s})")]
280: e.backtrace.each{|l| err_dest.puts "\tfrom #{l}"}
281: end
282:
283: disconnect
284:
285: exit 1
286: end
halt(stats)
click to toggle source
A helper that creates a consistent exit code for applications by looking at
an instance of MCollective::RPC::Stats
Exit with 0 if nodes were discovered and all passed Exit with 0 if no
discovery were done and > 0 responses were received, all ok Exit with 1 if
no nodes were discovered Exit with 2 if nodes were discovered but some RPC requests failed Exit with 3 if nodes were
discovered, but no responses received Exit with 4 if no discovery were done
and no responses were received
345: def halt(stats)
346: exit(halt_code(stats))
347: end
main()
click to toggle source
Fake abstract class that logs if the user tries to use an application
without supplying a main override method.
317: def main
318: STDERR.puts "Applications need to supply a 'main' method"
319: exit 1
320: end
rpcclient(agent, flags = {})
click to toggle source
Wrapper around MC::RPC#rpcclient that forcably supplies our options hash if
someone forgets to pass in options in an application the filters and other
cli options wouldnt take effect which could have a disasterous outcome
352: def rpcclient(agent, flags = {})
353: flags[:options] = options unless flags.include?(:options)
354: flags[:exit_on_failure] = false
355:
356: super
357: end
validate_option(blk, name, value)
click to toggle source
Calls the supplied block in an option for validation, an error raised will
log to STDERR and exit the application
100: def validate_option(blk, name, value)
101: validation_result = blk.call(value)
102:
103: unless validation_result == true
104: STDERR.puts "Validation of #{name} failed: #{validation_result}"
105: exit 1
106: end
107: end