tools/cpee in cpee-1.5.10 vs tools/cpee in cpee-1.5.11
- old
+ new
@@ -31,15 +31,15 @@
opt.summary_indent = ' ' * 2
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. Examples:\ncpee archive ./archive http://localhost:9298/\ncpee archive ./archive http://localhost:9298/1/\ncpee archive ./archive http://localhost:9298/1-200"))
+ opt.on(wrap("[archive DIR URL] save properties from all finished instances listed at URL into DIR. Examples:\ncpee archive ./archive http://localhost:9298/1/\ncpee archive ./archive http://localhost:9298/1-200\ncpee archive ./archive http://localhost:9298/*"))
opt.on("")
- opt.on(wrap("[abandon URL] running processes are stopped; ready or stopped processes are abandoned. Examples:\ncpee abandon http://localhost:9298/1/\ncpee abandon http://localhost:9298/1-200"))
+ opt.on(wrap("[abandon URL] running processes are stopped; ready or stopped processes are abandoned. Examples:\ncpee abandon http://localhost:9298/1/\ncpee abandon http://localhost:9298/1-200\ncpee abandon http://localhost:9298/*"))
opt.on("")
- opt.on(wrap("[start URL] stopped processes are started; all others are not touched. Examples:\ncpee start http://localhost:9298/1-200"))
+ opt.on(wrap("[start URL] stopped processes are started; all others are not touched. Examples:\ncpee start http://localhost:9298/1\ncpee start http://localhost:9298/1-200\ncpee start http://localhost:9298/*"))
opt.on("")
opt.on(wrap("[delete! URL] DANGER ZONE. Vanishes forever. Not in archive. Examples:\ncpee 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("")
@@ -105,14 +105,27 @@
FileUtils.cp_r("#{curpath}/instantiation/",p1)
else
puts 'Directory already exists.'
end
elsif command == 'archive'
+ p2 = File.join(p2,'*') if p2 =~ /([a-zA-Z]|\/)$/
base = File.dirname(p2)
names = []
if File.basename(p2) =~ /(\d+)-(\d+)/
names = ($1.to_i..$2.to_i).to_a
+ elsif File.basename(p2) == '*'
+ res = Typhoeus.get(File.join(base))
+ if res.success?
+ XML::Smart.string(res.response_body) do |doc|
+ doc.find('//instance/@id').each do |ele|
+ names << ele.value
+ end
+ end
+ names.reverse!
+ else
+ exit
+ end
else
names << File.basename(p2)
end
names.each do |name|
res = Typhoeus.get(File.join(base,name.to_s,'/'))
@@ -145,49 +158,74 @@
end
end
end
end
elsif command == 'abandon'
+ p1 = File.join(p1,'*') if p1 =~ /([a-zA-Z]|\/)$/
base = File.dirname(p1)
names = []
if File.basename(p1) =~ /(\d+)-(\d+)/
names = ($1.to_i..$2.to_i).to_a
+ elsif File.basename(p1) == '*'
+ res = Typhoeus.get(File.join(base))
+ if res.success?
+ XML::Smart.string(res.response_body) do |doc|
+ doc.find('//instance/@id').each do |ele|
+ names << ele.value
+ end
+ end
+ names.reverse!
+ else
+ exit
+ end
else
names << File.basename(p1)
end
names.each do |name|
res = Typhoeus.get(File.join(base,name.to_s,'properties','values','state','/'))
if res.success?
case res.response_body
when "ready", "stopped" then
Typhoeus.put(File.join(base,name.to_s,'properties','values','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=abandoned")
- when "running" then
- Typhoeus.put(File.join(base,name.to_s,'properties','values','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=stopped")
- sleep 1
- Typhoeus.put(File.join(base,name.to_s,'properties','values','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=abandoned")
end
end
end
elsif command == 'start'
+ p1 = File.join(p1,'*') if p1 =~ /([a-zA-Z]|\/)$/
base = File.dirname(p1)
names = []
if File.basename(p1) =~ /(\d+)-(\d+)/
names = ($1.to_i..$2.to_i).to_a
+ elsif File.basename(p1) == '*'
+ res = Typhoeus.get(File.join(base))
+ if res.success?
+ XML::Smart.string(res.response_body) do |doc|
+ doc.find('//instance/@id').each do |ele|
+ names << ele.value
+ end
+ end
+ names.reverse!
+ else
+ exit
+ end
else
names << File.basename(p1)
end
names.each do |name|
res = Typhoeus.get(File.join(base,name.to_s,'properties','values','state','/'))
if res.success?
case res.response_body
when "stopped" then
- Typhoeus.put(File.join(base,name.to_s,'properties','values','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=running")
+ keep_alive = Typhoeus.get(File.join(base,name.to_s,'properties','values','attributes','keep_alive','/'))
+ if keep_alive.success?
+ Typhoeus.put(File.join(base,name.to_s,'properties','values','state','/'), headers: {'Content-Type' => 'application/x-www-form-urlencoded'}, body: "value=running")
+ end
end
end
end
elsif command == 'delete!'
Typhoeus.delete(File.join(p1,'/'))
-else
+elsif command == 'new'
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