tools/cpee in cpee-1.4.17 vs tools/cpee in cpee-1.4.18
- old
+ new
@@ -4,10 +4,11 @@
require 'optparse'
require 'fileutils'
require 'webrick'
require 'typhoeus'
require 'xml/smart'
+require 'pp'
def wrap(s, width=78, indent=18)
lines = []
line, s = s[0..indent-2], s[indent..-1]
s.split(/\n/).each do |ss|
@@ -25,69 +26,91 @@
return lines.join "\n"
end
ARGV.options { |opt|
opt.summary_indent = ' ' * 2
- opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [options] ui | cpui DIR | new DIR\n"
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [options] ui | cpui DIR | new DIR | archive DIR URL | abandon URL\n"
opt.on("Options:")
opt.on("--help", "-h", "This text") { puts opt; exit }
opt.on("")
- opt.on(wrap("[archive DIR URL] save properties from all finished instances listed at URL into DIR.\ne.g. cpee ./archive http://localhost:9298/"))
+ opt.on(wrap("[archive DIR URL] save properties from all finished instances listed at URL into DIR.\ne.g. cpee archive ./archive http://localhost:9298/"))
opt.on("")
+ opt.on(wrap("[abandon URL] running processes are stopped; ready or stopped processes are abandoned.\ne.g. cpee abandon http://localhost:9298/1/"))
+ opt.on("")
+ opt.on(wrap("[delete! URL] DANGER ZONE.\ne.g. cpee delete! http://localhost:9298/1/"))
+ opt.on("")
opt.on(wrap("[new DIR] scaffolds a sample execution engine. Everything except instances can be removed for default behaviour."))
opt.on("")
opt.on(wrap("[inst DIR] scaffolds a sample instantiation service. Post a testset to a model to keep going in one operation."))
opt.on("")
opt.on(wrap("[cpui DIR] scaffolds a sample html client. New versions might require manual merging if you changed something."))
opt.on("")
opt.on(wrap("[ui] starts a simple static web server with the ui on http://localhost:8080. Use [cpui DIR] if you want stuff in apache or nginx."))
opt.parse!
}
-if ARGV.length == 0 || (ARGV.length == 1 && ARGV[0] != 'ui') || (ARGV.length == 2 && %w(cpui new).include?(ARGV[1])) || (ARGV.length == 3 && ARGV[0] != 'archive') || ARGV.length > 3
+if (ARGV.length == 0) ||
+ (ARGV.length == 1 && ARGV[0] != 'ui') ||
+ (ARGV.length == 2 && %w(abandon delete! cpui new).include?(ARGV[1])) ||
+ (ARGV.length == 3 && ARGV[0] != 'archive') ||
+ (ARGV.length > 3)
puts ARGV.options
exit
end
command = ARGV[0]
-dir = ARGV[1]
-url = ARGV[2]
+p1 = ARGV[1]
+p2 = ARGV[2]
if command == 'ui'
s = WEBrick::HTTPServer.new(:Port => 8080, :DocumentRoot => "#{curpath}/../cockpit/")
trap("INT"){ s.shutdown }
s.start
elsif command == 'cpui'
- if !File.exists?(dir)
- FileUtils.cp_r("#{curpath}/../cockpit/",dir)
+ if !File.exists?(p1)
+ FileUtils.cp_r("#{curpath}/../cockpit/",p1)
else
puts "Directory already exists."
end
elsif command == 'inst'
- if !File.exists?(dir)
- FileUtils.cp_r("#{curpath}/instantiation/",dir)
+ if !File.exists?(p1)
+ FileUtils.cp_r("#{curpath}/instantiation/",p1)
else
puts 'Directory already exists.'
end
elsif command == 'archive'
- res = Typhoeus.get(url)
+ res = Typhoeus.get(File.join(p2,'/'))
if res.success?
- if res.headers['content-type'] == 'text/xml'
- XML::Smart.string(res.body) do |doc|
- puts doc.to_s
- tcount = 0
- fcount = 0
+ if res.headers['Content-Type'] =~ /^(text|application)\/xml/
+ XML::Smart.string(res.response_body) do |doc|
doc.root.children.each do |i|
- p i.attributes['id']
- p i.attributes['state']
+ if ["finished","abandoned"].include?(i.attributes['state'])
+ prop = Typhoeus.get(File.join(p2,i.attributes['id'],'properties','/'))
+ if prop.success?
+ File.write(File.join(p1,i.attributes['uuid'] + '.xml'),prop.response_body) if prop.headers['Content-Type'] =~ /^(text|application)\/xml/
+ Typhoeus.delete(File.join(p2,i.attributes['id'],'/'))
+ end
+ end
end
end
end
end
+elsif command == 'abandon'
+ res = Typhoeus.get(File.join(p1,'properties','values','state','/'))
+ if res.success?
+ case res.response_body
+ when "ready", "stopped" then
+ Typhoeus.put(File.join(p1,'properties','values','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=abandoned")
+ when "running" then
+ Typhoeus.put(File.join(p1,'properties','values','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=stopped")
+ end
+ end
+elsif command == 'delete!'
+ Typhoeus.delete(File.join(p1,'/'))
else
- if !File.exists?(dir)
- FileUtils.cp_r("#{curpath}/server/",dir)
- FileUtils.mkdir("#{dir}/instances") rescue nil
- FileUtils.mkdir("#{dir}/resources") rescue nil
- FileUtils.mkdir("#{dir}/handlerwrappers") rescue nil
+ if !File.exists?(p1)
+ FileUtils.cp_r("#{curpath}/server/",p1)
+ FileUtils.mkdir("#{p1}/instances") rescue nil
+ FileUtils.mkdir("#{p1}/resources") rescue nil
+ FileUtils.mkdir("#{p1}/handlerwrappers") rescue nil
else
puts 'Directory already exists.'
end
end