diff --git a/ep3-runner b/ep3-runner index 46cbf71..be8f201 100755 --- a/ep3-runner +++ b/ep3-runner @@ -23,13 +23,15 @@ def run_cmd(cmd, loglevel) pid = spawn(cmd) _, status = Process.wait2 pid pid = nil + succ = status.exited? && status.exitstatus == 0 + lv = if succ then 'info' else 'error' end hash = { - 'log-level' => 'info', - 'success' => status.exited?, + 'log-level' => lv, + 'success' => succ, 'commmand' => cmd, 'return' => status.exitstatus, 'tag' => 'ep3.system', 'timestamp' => Time.now.iso8601(7), } - if loglevel >= Verbose + if lv == 'error' || loglevel >= Verbose warn JSON.dump hash end hash diff --git a/lib/ep3/ep3-run.rb b/lib/ep3/ep3-run.rb index ef10cf5..da69f2a 100755 --- a/lib/ep3/ep3-run.rb +++ b/lib/ep3/ep3-run.rb @@ -62,8 +62,8 @@ def ep3_run(args) } lopt = case loglevel - when Quiet then '--quiet' - when Normal then '--sys-quiet' + when Quiet then '--sys-silent --app-quiet' + when Normal then '--sys-silent' when Verbose then '--app-verbose' when VeryVerbose then '--verbose' end @@ -87,8 +87,10 @@ def ep3_run(args) } ensure rest = io.read - warn rest - log.puts rest + unless rest.empty? + warn rest + log.puts rest + end log.flush end } diff --git a/lib/ep3/init/cwl2wfnet.rb b/lib/ep3/init/cwl2wfnet.rb index de06b77..106f2f5 100755 --- a/lib/ep3/init/cwl2wfnet.rb +++ b/lib/ep3/init/cwl2wfnet.rb @@ -120,7 +120,7 @@ def cmdnet(cwl) out: [Place.new('StageIn', 'success'), Place.new('cwl.input.json', '~(tr.stdout)'), Place.new('StageIn.err', '~(tr.stderr)')], command: %q!mkdir -p $MEDAL_TMPDIR/outputs; stage-in.rb --outdir=$MEDAL_TMPDIR/outputs job.cwl ~(in.input.json)!, - failureLog: LogEntry.new(level: 'critical', command: 'generalFailureLog stage-in ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag)'), + failureLog: 'generalFailureLog stage-in ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag) ~(interrupted)', name: 'stage-in') net << Transition.new(in_: [Place.new('CommandGeneration', 'not-started'), Place.new('StageIn', 'success'), @@ -129,14 +129,14 @@ def cmdnet(cwl) Place.new('CommandGeneration.command', '~(tr.stdout)'), Place.new('CommandGeneration.err', '~(tr.stderr)')], command: %Q!inspector.rb job.cwl commandline -i ~(in.cwl.input.json) --outdir=$MEDAL_TMPDIR/outputs!, - failureLog: LogEntry.new(level: 'critical', command: 'generalFailureLog command-generation ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag)'), + failureLog: 'generalFailureLog command-generation ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag) ~(interrupted)', name: 'generate-command') net << Transition.new(in_: [Place.new('Execution', 'not-started'), Place.new('CommandGeneration', 'success'), Place.new('CommandGeneration.command', any)], out: [Place.new('Execution.return', '~(tr.return)'), Place.new('Execution.out', '~(tr.stdout)'), Place.new('Execution.err', '~(tr.stderr)')], command: %Q!executor ~(in.CommandGeneration.command)!, - failureLog: LogEntry.new(level: 'critical', command: 'commandFailureLog ~(in.CommandGeneration.command) ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag)'), + failureLog: 'commandFailureLog ~(in.CommandGeneration.command) ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag) ~(interrupted)', name: 'execute') successCodes = case cwl.class_ @@ -190,7 +190,7 @@ def cmdnet(cwl) out: [Place.new('StageOut', 'success'), Place.new('ExecutionState', 'success'), Place.new('cwl.output.json', '~(tr.stdout)'), Place.new('StageOut.err', '~(tr.stderr)')], command: %Q!inspector.rb job.cwl list -i ~(in.cwl.input.json) --json --outdir=$MEDAL_TMPDIR/outputs!, - failureLog: LogEntry.new(level: 'critical', command: 'generalFailureLog stage-out ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag)'), + failureLog: 'generalFailureLog stage-out ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag) ~(interrupted)', name: 'stage-out') net end @@ -216,7 +216,7 @@ def expnet(cwl) Place.new('CommandGeneration.command', '~(tr.stdout)'), Place.new('CommandGeneration.err', '~(tr.stderr)')], command: %Q!inspector.rb job.cwl commandline -i ~(in.cwl.input.json) --outdir=$MEDAL_TMPDIR/outputs!, - failureLog: LogEntry.new(level: 'critical', command: 'generalFailureLog command-generation ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag)'), + failureLog: 'generalFailureLog command-generation ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag) ~(interrupted)', name: 'generate-command') net << Transition.new(in_: [Place.new('Execution', 'not-started'), Place.new('CommandGeneration', 'success'), @@ -276,7 +276,7 @@ def expnet(cwl) out: [Place.new('StageOut', 'success'), Place.new('ExecutionState', 'success'), Place.new('cwl.output.json', '~(tr.stdout)'), Place.new('StageOut.err', '~(tr.stderr)')], command: %Q!inspector.rb job.cwl list -i ~(in.cwl.input.json) --json --outdir=$MEDAL_TMPDIR/outputs!, - failureLog: LogEntry.new(level: 'critical', command: 'generalFailureLog stage-out ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag)'), + failureLog: 'generalFailureLog stage-out ~(tr.stdout) ~(tr.stderr) ~(tr.return) ~(tag) ~(interrupted)', name: 'stage-out') net end diff --git a/lib/ep3/init/workflownet.rb b/lib/ep3/init/workflownet.rb index 13cffc2..2808f8d 100755 --- a/lib/ep3/init/workflownet.rb +++ b/lib/ep3/init/workflownet.rb @@ -46,9 +46,9 @@ def to_h 'out' => @out.map{ |o| o.to_h }, 'command' => cmd, 'log' => { - 'pre' => @preLog.to_h, - 'success' => @successLog.to_h, - 'failure' => @failureLog.to_h, + 'pre' => @preLog, + 'success' => @successLog, + 'failure' => @failureLog, }.compact, }.compact end @@ -101,30 +101,14 @@ def to_h 'in' => @in.map{ |i| i.to_h }, 'out' => @out.map{ |o| o.to_h }, 'log' => { - 'pre' => @preLog.to_h, - 'success' => @successLog.to_h, - 'failure' => @failureLog.to_h - }.compact + 'pre' => @preLog, + 'success' => @successLog, + 'failure' => @failureLog, + }.compact, }.compact end end -class LogEntry - attr_reader :command, :level - - def initialize(command:, level:) - @command = command - @level = level - end - - def to_h - { - 'command' => @command, - 'level' => @level, - } - end -end - class PetriNet attr_reader :transitions, :tag, :name, :application attr_accessor :preLog, :successLog, :failureLog @@ -176,18 +160,9 @@ def to_h ], 'transitions' => @transitions.map{ |t| t.to_h }, 'log' => { - 'pre' => { - 'level' => 'info', - 'command' => 'classStartLog job.cwl ~(in.entrypoint) ~(tag)', - }, - 'success' => { - 'level' => 'info', - 'command' => 'classSuccessLog ~(out.cwl.output.json) ~(tag)', - }, - 'failure' => { - 'level' => 'critical', - 'command' => 'classFailureLog ~(tag)', - } + 'pre' => 'classStartLog job.cwl ~(in.entrypoint) ~(tag)', + 'success' => 'classSuccessLog ~(out.cwl.output.json) ~(tag)', + 'failure' => 'classFailureLog ~(tag) ~(interrupted)', }, }.compact end diff --git a/lib/ep3/runtime/classFailureLog b/lib/ep3/runtime/classFailureLog index c9f9937..330bcef 100755 --- a/lib/ep3/runtime/classFailureLog +++ b/lib/ep3/runtime/classFailureLog @@ -4,21 +4,28 @@ require 'optparse' if $0 == __FILE__ opt = OptionParser.new - opt.banner = "#{$0} [options] " + opt.banner = "#{$0} [options] " opt.parse!(ARGV) - unless ARGV.length == 1 + unless ARGV.length == 2 puts opt.help exit end - tag = ARGV.first + tag, interrupted = *ARGV + level = if interrupted == 'true' + 'warning' + else + 'error' + end ret = { - tag: tag, - message: "Finished #{tag.split('.')[2..-1].join('.')}", - result: 'permanentFailure', + 'log-level' => level, + 'interrupted' => interrupted == 'true', + 'tag' => tag, + 'message' => "Finished #{tag.split('.')[2..-1].join('.')}", + 'result' => 'permanentFailure', } puts JSON.dump(ret) diff --git a/lib/ep3/runtime/commandFailureLog b/lib/ep3/runtime/commandFailureLog index 6b4a4eb..ffb7688 100755 --- a/lib/ep3/runtime/commandFailureLog +++ b/lib/ep3/runtime/commandFailureLog @@ -4,15 +4,15 @@ require 'optparse' if $0 == __FILE__ opt = OptionParser.new - opt.banner = "#{$0} [options] " + opt.banner = "#{$0} [options] " opt.parse!(ARGV) - unless ARGV.length == 5 + unless ARGV.length == 6 puts opt.help exit end - comfile, outfile, errfile, code, tag = *ARGV + comfile, outfile, errfile, code, tag, interrupted = *ARGV unless File.exist? comfile raise "File not found: #{comfile}" @@ -29,13 +29,21 @@ if $0 == __FILE__ end err = open(errfile).read(1024) + level = if interrupted == 'true' + 'warning' + else + 'error' + end + ret = { - tag: tag, - message: "#{tag.split('.')[2..-1].join('.')} failed in command-execution", - command: com, - stdout: out, - stderr: err, - return: code.to_i, + 'log-level' => level, + 'interrupted' => interrupted == 'true', + 'tag' => tag, + 'message' => "#{tag.split('.')[2..-1].join('.')} failed in command-execution", + 'command' => com, + 'stdout' => out, + 'stderr' => err, + 'return' => code.to_i, } puts JSON.dump(ret) diff --git a/lib/ep3/runtime/generalFailureLog b/lib/ep3/runtime/generalFailureLog index e28ae99..ac5a69f 100755 --- a/lib/ep3/runtime/generalFailureLog +++ b/lib/ep3/runtime/generalFailureLog @@ -4,15 +4,15 @@ require 'optparse' if $0 == __FILE__ opt = OptionParser.new - opt.banner = "#{$0} [options] " + opt.banner = "#{$0} [options] " opt.parse!(ARGV) - unless ARGV.length == 5 + unless ARGV.length == 6 puts opt.help exit end - com, outfile, errfile, code, tag = *ARGV + com, outfile, errfile, code, tag, interrupted = *ARGV unless File.exist? outfile raise "File not found: #{outfile}" @@ -24,12 +24,20 @@ if $0 == __FILE__ end err = open(errfile).read + level = if interrupted == 'true' + 'warning' + else + 'error' + end + ret = { - tag: tag, - message: "#{tag.split('.')[2..-1].join('.')} failed in #{com}", - stdout: out, - stderr: err, - return: code.to_i, + 'log-level' => level, + 'interrupted' => interrupted == 'true', + 'tag' => tag, + 'message' => "#{tag.split('.')[2..-1].join('.')} failed in #{com}", + 'stdout' => out, + 'stderr' => err, + 'return' => code.to_i, } puts JSON.dump(ret)