Class: OmfEc::Runner
Instance Attribute Summary collapse
-
#oedl_path ⇒ Object
readonly
Returns the value of attribute oedl_path.
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #load_experiment ⇒ Object
- #oml_init ⇒ Object
- #parse_cmd_opts ⇒ Object
- #parse_config_file ⇒ Object
- #remove_cmd_opts_from_argv(*args) ⇒ Object
- #run ⇒ Object
- #setup_experiment ⇒ Object
- #setup_logging ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/omf_ec/runner.rb', line 14 def initialize @gem_version = OmfEc::VERSION @oml_enabled = false @executable_name = File.basename($PROGRAM_NAME) @oml_opts = { appName: @executable_name, afterParse: lambda { |o| parse_cmd_opts } } # Default configuration options @config_opts = Mash.new( environment: 'development', communication: { url: "amqp://localhost" }, logging: { level: { default: 'debug' }, appenders: { stdout: { level: :info, date_pattern: '%H:%M:%S', pattern: '%d %5l %c{2}: %m\n' }, rolling_file: { level: :debug, log_dir: '/var/tmp', size: 1024*10, # max 510k of each log file keep: 1, # keep 1 log in total date_pattern: '%F %T %z', pattern: '[%d] %-5l %c: %m\n' } } } ) @cmd_opts = Mash.new @argv = ARGV.dup end |
Instance Attribute Details
#oedl_path ⇒ Object (readonly)
Returns the value of attribute oedl_path.
12 13 14 |
# File 'lib/omf_ec/runner.rb', line 12 def oedl_path @oedl_path end |
Instance Method Details
#init ⇒ Object
324 325 326 327 |
# File 'lib/omf_ec/runner.rb', line 324 def init oml_init setup_experiment end |
#load_experiment ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/omf_ec/runner.rb', line 275 def load_experiment begin OmfCommon.init(@config_opts.delete(:environment), @config_opts) do |el| setup_logging OmfCommon.comm.on_connected do |comm| info "OMF Experiment Controller #{OmfEc::VERSION} - Start" info "Connected using #{comm.conn_info}" info "Execute: #{@oedl_path}" info "Properties: #{OmfEc.experiment.cmdline_properties}" if @config_opts[:communication][:auth] && @config_opts[:communication][:auth][:authenticate] ec_cert = OmfCommon.load_credentials( root_cert_dir: @config_opts[:root_cert_dir], entity_cert: @config_opts[:cert], entity_key: @config_opts[:key] ) ec_cert.resource_id = OmfCommon.comm.local_address OmfCommon::Auth::CertificateStore.instance.register(ec_cert) end OmfEc.experiment.("ec_version", "#{OmfEc::VERSION}") OmfEc.experiment.("exp_path", @oedl_path) OmfEc.experiment.("ec_pid", "#{Process.pid}") OmfEc.experiment.archive_oedl(@oedl_path) OmfEc.experiment.create_job begin load @oedl_path OmfEc::Experiment.start rescue => e OmfEc.experiment.("state", "error") error e. error e.backtrace.join("\n") end trap(:TERM) { OmfEc::Experiment.done } trap(:INT) { OmfEc::Experiment.done } end end rescue => e logger.fatal e. logger.fatal e.backtrace.join("\n") puts "Experiment controller exits unexpectedly" puts e exit(1) end end |
#oml_init ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/omf_ec/runner.rb', line 53 def oml_init begin @oml_enabled = OML4R::init(ARGV, @oml_opts) do |op| op. = "OMF Experiment Controller version '#{@gem_version}'\n" op. += "Usage: #{@executable_name} [options] path_to_oedl_file [-- --experiment_property value]" op.on("-u", "--uri ADDRESS", "URI for communication layer [amqp://localhost]") do |uri| @cmd_opts[:uri] = uri remove_cmd_opts_from_argv("-u", "--uri", uri) end op.on("-c CONFIGFILE", "Configuration File") do |file| @cmd_opts[:config_file] = file remove_cmd_opts_from_argv("-c", file) end op.on("--log_config CONFIGFILE", "Logging Configuration File") do |file| @cmd_opts[:logging_configfile] = file remove_cmd_opts_from_argv("--log_config", file) end op.on("-e ENVIRONMENT", "Environment (development, production ...) [#{@config_opts[:environment]}]") do |e| @cmd_opts[:environment] = e remove_cmd_opts_from_argv("-e", e) end op.on("--root_cert_dir DIRECTORY", "Directory containing root certificates") do |dir| @cmd_opts[:root_cert_dir] = dir remove_cmd_opts_from_argv("--root_cert_dir", dir) end op.on("--cert CERTIFICATE", "Your certificate") do |cert| @cmd_opts[:cert] = cert remove_cmd_opts_from_argv("--cert", cert) end op.on("--key KEY", "Your private key") do |key| @cmd_opts[:key] = key remove_cmd_opts_from_argv("--key", key) end op.on("--name", "--experiment EXPERIMENT_NAME", "Experiment name") do |e_name| @cmd_opts[:experiment_name] = e_name OmfEc.experiment.name = e_name remove_cmd_opts_from_argv("--name", "--experiment", e_name) end op.on("--slice SLICE_NAME", "Slice name [optional]") do |slice| @cmd_opts[:slice] = slice OmfEc.experiment.sliceID = slice remove_cmd_opts_from_argv("--slice", slice) end op.on("--job-service URL", "URL to the JobService [optional]") do |url| OmfEc.experiment.js_url = url remove_cmd_opts_from_argv("--job-service", url) end op.on("--job-url URL", "URL to the Job for this experiment trial [optional]") do |url| OmfEc.experiment.job_url = url remove_cmd_opts_from_argv("--job-url", url) end op.on("--slice-service URL", "URL to the SliceService [optional]") do |url| OmfEc.experiment.ss_url = url remove_cmd_opts_from_argv("--slice-service", url) end op.on("--oml_uri URI", "URI for the OML data collection of experiment applications") do |uri| @cmd_opts[:oml_uri] = uri remove_cmd_opts_from_argv("--oml_uri", uri) end op.on("--inst_oml_uri URI", "EC Instrumentation: OML URI to use") do |uri| @cmd_opts[:inst_oml_uri] = uri remove_cmd_opts_from_argv("--inst_oml_uri", uri) end op.on("--inst_oml_id ID", "EC Instrumentation: OML ID to use") do |id| @cmd_opts[:inst_oml_id] = id remove_cmd_opts_from_argv("--inst_oml_id", id) end op.on("--inst_oml_domain DOMAIN", "EC Instrumentation: OML Domain to use") do |domain| @cmd_opts[:inst_oml_domain] = domain remove_cmd_opts_from_argv("--inst_oml_domain", domain) end op.on("-g", "--show-graph", "Parse graph definition to construct graph information in log output") do @cmd_opts['show-graph'] = true remove_cmd_opts_from_argv("--show-graph") end op.on("-v", "--version", "Show version") do puts "OMF Experiment Controller version '#{@gem_version}'" exit end op.on("-d", "--debug", "Debug mode (Set logging level in Stdout to :debug)") do @cmd_opts[:debug] = true remove_cmd_opts_from_argv("-d", "--debug") end op.on("-h", "--help", "Show this message") do puts op exit end end rescue OML4R::MissingArgumentException => e puts "Warning: #{e.} to instrument, so it will run without instrumentation. (see --oml-help)" rescue => e puts e. puts e.backtrace.join("\n") exit(1) end end |
#parse_cmd_opts ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/omf_ec/runner.rb', line 170 def parse_cmd_opts parse_config_file # uri in command line is short for communication/url uri = @cmd_opts.delete(:uri) @config_opts[:communication][:url] = uri if uri @config_opts[:communication][:auth] = { authenticate: true } if @cmd_opts[:cert] @config_opts.merge!(@cmd_opts) if @config_opts[:oml_uri] # Only change default if they are not set in config file @config_opts[:logging][:appenders][:oml4r] ||= { level: :debug, # Log everything to OML appName: 'omf_ec', domain: OmfEc.experiment.id, collect: @config_opts[:oml_uri] } end end |
#parse_config_file ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/omf_ec/runner.rb', line 192 def parse_config_file if (config_file = @cmd_opts.delete(:config_file)) if File.exist?(config_file) @config_opts.merge!(OmfCommon.load_yaml(config_file, erb_process: true)) else puts "Config file '#{config_file}' doesn't exist" exit(1) end end end |
#remove_cmd_opts_from_argv(*args) ⇒ Object
203 204 205 |
# File 'lib/omf_ec/runner.rb', line 203 def remove_cmd_opts_from_argv(*args) args.each { |v| @argv.slice!(@argv.index(v)) if @argv.index(v) } end |
#run ⇒ Object
329 330 331 |
# File 'lib/omf_ec/runner.rb', line 329 def run load_experiment end |
#setup_experiment ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/omf_ec/runner.rb', line 207 def setup_experiment OmfEc.experiment.oml_uri = @config_opts[:oml_uri] if @config_opts[:oml_uri] OmfEc.experiment.show_graph = @config_opts['show-graph'] # Instrument EC if @config_opts[:inst_oml_uri] && @config_opts[:inst_oml_id] && @config_opts[:inst_oml_domain] instrument_ec = OML4R::init(nil, { collect: @config_opts[:inst_oml_uri], nodeID: @config_opts[:inst_oml_id], domain: @config_opts[:inst_oml_domain], appName: @executable_name }) OmfCommon::Measure.enable if instrument_ec end remove_cmd_opts_from_argv("exec") index_of_dividing_hyphen = @argv.index("--") @argv[0..index_of_dividing_hyphen || -1].in_groups_of(2) do |arg_g| if arg_g[0] =~ /^--(.+)/ && !arg_g[1].nil? remove_cmd_opts_from_argv(*arg_g) end end @oedl_path = @argv[0] && File.(@argv[0]) if @oedl_path.nil? || !File.exist?(@oedl_path) puts "Experiment script '#{@argv[0]}' not found" exit(1) end @argv.slice!(0) # User-provided command line values for Experiment Properties cannot be # set here as the properties 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 index_of_dividing_hyphen remove_cmd_opts_from_argv("--") exp_properties = @argv exp_properties.in_groups_of(2) do |p| unless p[0] =~ /^--(.+)/ && !p[1].nil? puts "Malformatted properties '#{exp_properties.join(' ')}'" exit(1) else properties[$1.to_sym] = p[1].ducktype remove_cmd_opts_from_argv(*p) end end OmfEc.experiment.cmdline_properties = properties end end |
#setup_logging ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/omf_ec/runner.rb', line 263 def setup_logging OmfCommon.load_logging_config(@config_opts[:logging_configfile]) if @config_opts[:debug] Logging.logger.root.level = 'debug' stdout_appender = Logging.logger.root.appenders.find { |a| a.class == Logging::Appenders::Stdout } stdout_appender.level = 'debug' if stdout_appender else Logging.consolidate 'OmfCommon', 'OmfRc' end end |