Skip to content

Commit

Permalink
Fix user log for medal v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan committed Apr 16, 2021
1 parent e1c347f commit a973ebb
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 71 deletions.
8 changes: 5 additions & 3 deletions ep3-runner
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions lib/ep3/ep3-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions lib/ep3/init/cwl2wfnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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_
Expand Down Expand Up @@ -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
Expand All @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
45 changes: 10 additions & 35 deletions lib/ep3/init/workflownet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions lib/ep3/runtime/classFailureLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ require 'optparse'

if $0 == __FILE__
opt = OptionParser.new
opt.banner = "#{$0} [options] <tag>"
opt.banner = "#{$0} [options] <tag> <interrupted>"

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)
Expand Down
26 changes: 17 additions & 9 deletions lib/ep3/runtime/commandFailureLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ require 'optparse'

if $0 == __FILE__
opt = OptionParser.new
opt.banner = "#{$0} [options] <comfile> <outfile> <errfile> <return> <tag>"
opt.banner = "#{$0} [options] <comfile> <outfile> <errfile> <return> <tag> <interrupted>"

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}"
Expand All @@ -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)
Expand Down
24 changes: 16 additions & 8 deletions lib/ep3/runtime/generalFailureLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ require 'optparse'

if $0 == __FILE__
opt = OptionParser.new
opt.banner = "#{$0} [options] <com> <outfile> <errfile> <return> <tag>"
opt.banner = "#{$0} [options] <com> <outfile> <errfile> <return> <tag> <interrupted>"

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}"
Expand All @@ -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)
Expand Down

0 comments on commit a973ebb

Please sign in to comment.