bin/omf_ec in omf_ec-6.0.0.pre.4 vs bin/omf_ec in omf_ec-6.0.0.pre.5

- old
+ new

@@ -1,7 +1,9 @@ #!/usr/bin/env ruby -# + +abort "Please use Ruby 1.9.3 or higher" if RUBY_VERSION < "1.9.3" + require 'gli' require 'omf_ec' $stdout.sync = true include GLI::App @@ -11,26 +13,18 @@ version OmfEc::VERSION desc "Debug mode (printing debug logging messages)" switch [:d, :debug] +desc "URI for communication layer" +arg_name "URI" +default_value "xmpp://bob:password@localhost" +flag [:u, :uri] + desc "Debug XMPP traffic mode (include XMPP debug logging messages under debug mode)." switch [:x, :xmpp] -desc "XMPP user name" -arg_name "user" -flag [:u, :user] - -desc "XMPP user password" -arg_name "password" -flag [:p, :password] - -desc "XMPP server domain" -arg_name "domain" -default_value "localhost" -flag [:s, :server] - desc "Private key file" arg_name "key", :optional flag [:private_key] desc "Log file directory" @@ -56,25 +50,29 @@ c.action do |global_options, options, args| help_now! "Missing experiment script" if args[0].nil? help_now! "Experiment script not found" unless File.exist?(args[0]) - # User provided exp properties + # User-provided command line values for Experiment Properties cannot be + # set here as the propertties have not been defined yet by the experiment. + # Thus just pass them to the experiment, which will be responsible + # for setting them later + properties = {} if args.size > 1 exp_properties = args[1..-1] - exp_properties.in_groups_of(2) do |p| unless p[0] =~ /^--(.+)/ && !p[1].nil? help_now! "Malformatted properties '#{exp_properties.join(' ')}'" else - OmfEc.exp.property[$1.to_sym] = p[1].ducktype + properties[$1.to_sym] = p[1].ducktype end end + OmfEc.experiment.cmdline_properties = properties end # FIXME this loading script is way too simple - load_exp(args[0], global_options, options) + load_exp(args[0], global_options, options, properties) end end desc "Load an image onto the nodes" command :load do |c| @@ -173,39 +171,30 @@ 'on' turn node(s) ON - 'offs' turn node(s) OFF (soft) - 'offh' turn node(s) OFF (hard) - 'reboot' reboots node(s) (soft) - 'reset' resets node(s) (hard)" - c.arg_name "ACTION" - c.flag [:a, :action] + c.arg_name "ACTION" + c.flag [:a, :action] - c.action do |global_options, options, args| - @cmd = "omf-5.4 tell -c #{options[:c]} -t #{options[:t]} " - @cmd += "-a #{options[:a]} " if options[:a] - load_exp(@testbed_exp_path, global_options, options) - end + c.action do |global_options, options, args| + @cmd = "omf-5.4 tell -c #{options[:c]} -t #{options[:t]} " + @cmd += "-a #{options[:a]} " if options[:a] + load_exp(@testbed_exp_path, global_options, options) + end end on_error do |exception| true end pre do |global_options, command, options, args| - unless global_options[:user] && global_options[:password] && global_options[:server] - help_now! "Incomplete options" + unless global_options[:uri] + help_now! "Incomplete options. Need communication URI" end - if global_options[:xmpp] - Blather.logger = logger - end - if global_options[:debug] - Logging.logger.root.level = :debug - else - Logging.consolidate 'OmfCommon', 'OmfEc', 'OmfRc' - end - # Import private key if global_options[:private_key] OmfCommon::Key.instance.import(global_options[:private_key]) end @@ -220,41 +209,70 @@ end end include OmfEc::DSL - OmfEc.exp.name = options[:experiment] if options[:experiment] - OmfEc.exp.oml_uri = options[:oml_uri] if options[:oml_uri] + OmfEc.experiment.name = options[:experiment] if options[:experiment] + OmfEc.experiment.oml_uri = options[:oml_uri] if options[:oml_uri] + @testbed_exp_path = File.join(OmfEc.lib_root, "omf_ec/backward/exp/testbed.rb") +end + +def setup_logging(global_options = {}) + if global_options[:xmpp] + require 'blather' + Blather.logger = logger + end + + unless global_options[:debug] + Logging.consolidate 'OmfCommon', 'OmfEc', 'OmfRc' + end + + # FIXME this should go to common setup if global_options[:log_file_dir] && File.exist?(global_options[:log_file_dir]) Logging.logger.root.add_appenders( Logging.appenders.file( - "#{global_options[:log_file_dir]}/#{OmfEc.exp.id}.log", + "#{global_options[:log_file_dir]}/#{OmfEc.experiment.id}.log", :layout => Logging.layouts.pattern(:date_pattern => '%F %T %z', :pattern => '[%d] %-5l %c: %m\n'))) end - - @testbed_exp_path = File.join(OmfEc.lib_root, "omf_ec/backward/exp/testbed.rb") end -def load_exp(exp_path, global_options = {} , options = {}) +def load_exp(exp_path, global_options = {} , options = {}, properties = {}) begin - OmfEc.comm.when_ready do - logger.info "Connected: #{OmfEc.comm.jid.inspect}" - logger.info "Start experiment: #{OmfEc.exp.id}" - begin - include OmfEc::Backward::DefaultEvents - load exp_path - rescue => e - logger.error e.message - logger.error e.backtrace.join("\n") - end - end + opts = { + communication: { url: global_options[:uri] }, + eventloop: { type: :em }, + logging: { + level: global_options[:debug] ? 'debug' : 'info', + appenders: { + stdout: { + date_pattern: '%H:%M:%S', + pattern: '%d %-5l %c{2}: %m\n', + color_scheme: 'default' + } + } + } + } - EM.run do - OmfEc.comm.connect(global_options[:user], global_options[:password], global_options[:server]) - trap(:INT) { Experiment.done } - trap(:TERM) { Experiment.done } + OmfCommon.init(:development, opts) do |el| + setup_logging(global_options) + + OmfCommon.comm.on_connected do |comm| + info "Connected" + info "Start experiment: #{OmfEc.experiment.id}" + + begin + include OmfEc::Backward::DefaultEvents + load exp_path + rescue => e + error e.message + error e.backtrace.join("\n") + end + + #comm.on_interrupted { Experiment.done } + comm.on_interrupted { comm.disconnect } + end end rescue => e logger.fatal e.message logger.fatal e.backtrace.join("\n") end