rjobs 0.1.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.codeintel/config +26 -0
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/Guardfile +15 -0
- data/README.md +1 -0
- data/Rakefile +34 -0
- data/bin/rjharvest +34 -0
- data/bin/rjstatus +35 -0
- data/bin/rjsubmit +49 -0
- data/features/harvest.feature +32 -0
- data/features/listJobs.feature +22 -0
- data/features/step_definitions/listJobs_steps.rb +19 -0
- data/features/step_definitions/submit_steps.rb +2 -0
- data/features/submit.feature +27 -0
- data/features/support/env.rb +6 -0
- data/features/support/setup.rb +1 -0
- data/lib/rjobs.rb +5 -0
- data/lib/rjobs/cli_helper.rb +14 -0
- data/lib/rjobs/color_helper.rb +12 -0
- data/lib/rjobs/command_builder.rb +23 -0
- data/lib/rjobs/job.rb +53 -0
- data/lib/rjobs/job_handler.rb +58 -0
- data/lib/rjobs/job_input_file.rb +22 -0
- data/lib/rjobs/jobs_file.rb +44 -0
- data/lib/rjobs/process.rb +15 -0
- data/lib/rjobs/rj_status_cli.rb +25 -0
- data/lib/rjobs/version.rb +3 -0
- data/rjobs.gemspec +32 -0
- data/samples/jobAttributes.xml +31 -0
- data/samples/jobList.xml +16 -0
- data/samples/jobSepcification.xml +338 -0
- data/spec/data_helper.rb +52 -0
- data/spec/lib/command_builder_spec.rb +24 -0
- data/spec/lib/job_handler_spec.rb +29 -0
- data/spec/lib/job_spec.rb +48 -0
- data/spec/lib/process_spec.rb +18 -0
- metadata +234 -0
data/.codeintel/config
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"PHP": {
|
3
|
+
"php": '/usr/bin/php',
|
4
|
+
"phpExtraPaths": [],
|
5
|
+
"phpConfigFile": 'php.ini'
|
6
|
+
},
|
7
|
+
"JavaScript": {
|
8
|
+
"javascriptExtraPaths": []
|
9
|
+
},
|
10
|
+
"Perl": {
|
11
|
+
"perl": "/usr/bin/perl",
|
12
|
+
"perlExtraPaths": []
|
13
|
+
},
|
14
|
+
"Ruby": {
|
15
|
+
"ruby": "/Users/merlin/.rvm/rubies/ruby-1.9.2-p290/bin/ruby",
|
16
|
+
"rubyExtraPaths": []
|
17
|
+
},
|
18
|
+
"Python": {
|
19
|
+
"python": '/usr/bin/python',
|
20
|
+
"pythonExtraPaths": []
|
21
|
+
},
|
22
|
+
"Python3": {
|
23
|
+
"python": '/usr/bin/python3',
|
24
|
+
"pythonExtraPaths": []
|
25
|
+
}
|
26
|
+
}
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'cucumber' do
|
5
|
+
watch(%r{^features/.+\.feature$})
|
6
|
+
watch(%r{^features/support/.+$}) { 'features' }
|
7
|
+
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
guard 'rspec' do
|
12
|
+
watch(%r{^spec/.+_spec\.rb$})
|
13
|
+
watch(%r{^lib/(.+)\.rb$}) {|m| "spec/lib/#{m[1]}_spec.rb" }
|
14
|
+
watch('spec/spec_helper.rb') { "spec" }
|
15
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is the readme file
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
|
4
|
+
desc 'List all defined steps'
|
5
|
+
task :steps do
|
6
|
+
require 'hirb'
|
7
|
+
extend Hirb::Console
|
8
|
+
puts "CUCUMBER steps:"
|
9
|
+
puts ""
|
10
|
+
#step_definition_dir = "features/step_definitions"
|
11
|
+
step_definition_dir = "."
|
12
|
+
#step_definition_dir = "/Users/merlin/.rvm/gems/ruby-1.9.2-p290/gems/aruba-0.4.7/lib/aruba/"
|
13
|
+
|
14
|
+
Dir.glob(File.join(step_definition_dir,'**/*.rb')).each do |step_file|
|
15
|
+
|
16
|
+
puts "File: #{step_file}"
|
17
|
+
puts ""
|
18
|
+
results = []
|
19
|
+
File.new(step_file).read.each_line.each_with_index do |line, number|
|
20
|
+
|
21
|
+
next unless line =~ /^\s*(?:Given|When|Then)\s+|\//
|
22
|
+
res = /(?:Given|When|Then)[\s\(]*\/(.*)\/([imxo]*)[\s\)]*do\s*(?:$|\|(.*)\|)/.match(line)
|
23
|
+
next unless res
|
24
|
+
matches = res.captures
|
25
|
+
results << OpenStruct.new(
|
26
|
+
:steps => matches[0],
|
27
|
+
:modifier => matches[1],
|
28
|
+
:args => matches[2]
|
29
|
+
)
|
30
|
+
end
|
31
|
+
table results, :resize => false, :fields=>[:steps, :modifier, :args]
|
32
|
+
puts ""
|
33
|
+
end
|
34
|
+
end
|
data/bin/rjharvest
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'trollop'
|
6
|
+
require "rjobs/jobs_file"
|
7
|
+
require "rjobs/job"
|
8
|
+
require "rjobs/job_handler"
|
9
|
+
require 'rjobs/cli_helper'
|
10
|
+
include Rjobs::CliHelper
|
11
|
+
|
12
|
+
p = Trollop::Parser.new do
|
13
|
+
banner <<-EOS
|
14
|
+
Harvest all finished jobs described in the jobs file.
|
15
|
+
|
16
|
+
Usage:
|
17
|
+
rjharvest [options] <filename>
|
18
|
+
where [options] are:
|
19
|
+
EOS
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
opts = Trollop::with_standard_exception_handling p do
|
24
|
+
o = p.parse ARGV
|
25
|
+
raise Trollop::HelpNeeded if ARGV.empty? # show help screen
|
26
|
+
end
|
27
|
+
|
28
|
+
jobs_file = ARGV[0]
|
29
|
+
|
30
|
+
jobs = get_jobs_info(jobs_file)
|
31
|
+
jobs.each do |job|
|
32
|
+
Rjobs::JobHandler.get_job_results(job)
|
33
|
+
end
|
34
|
+
|
data/bin/rjstatus
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'trollop'
|
6
|
+
require "rjobs/jobs_file"
|
7
|
+
require "rjobs/job"
|
8
|
+
require "rjobs/job_handler"
|
9
|
+
require 'rjobs/cli_helper'
|
10
|
+
include Rjobs::CliHelper
|
11
|
+
|
12
|
+
p = Trollop::Parser.new do
|
13
|
+
banner <<-EOS
|
14
|
+
Get the status of jobs described in the jobs file.
|
15
|
+
|
16
|
+
Usage:
|
17
|
+
rjstatus [options] <filename>
|
18
|
+
where [options] are:
|
19
|
+
EOS
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
opts = Trollop::with_standard_exception_handling p do
|
24
|
+
o = p.parse ARGV
|
25
|
+
raise Trollop::HelpNeeded if ARGV.empty? # show help screen
|
26
|
+
end
|
27
|
+
|
28
|
+
jobs_file = ARGV[0]
|
29
|
+
|
30
|
+
jobs = get_jobs_info(jobs_file)
|
31
|
+
|
32
|
+
jobs.each do |job|
|
33
|
+
puts "#{job.name} - #{job.status_with_color}"
|
34
|
+
end
|
35
|
+
|
data/bin/rjsubmit
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'trollop'
|
6
|
+
require "rjobs/jobs_file"
|
7
|
+
require "rjobs/job_input_file"
|
8
|
+
require "rjobs/job"
|
9
|
+
require "rjobs/job_handler"
|
10
|
+
require 'rjobs/cli_helper'
|
11
|
+
include Rjobs::CliHelper
|
12
|
+
|
13
|
+
p = Trollop::Parser.new do
|
14
|
+
banner <<-EOS
|
15
|
+
Submit jobs described in the YAML input file.
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
rjsubmit [options] <filename>
|
19
|
+
where [options] are:
|
20
|
+
EOS
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
opts = Trollop::with_standard_exception_handling p do
|
25
|
+
o = p.parse ARGV
|
26
|
+
raise Trollop::HelpNeeded if ARGV.empty? # show help screen
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
jobs_input_file = ARGV[0]
|
31
|
+
|
32
|
+
jif = Rjobs::JobInputFile.new(jobs_input_file)
|
33
|
+
jobs = []
|
34
|
+
length = jif.jobIdTo.length
|
35
|
+
(jif.jobIdFrom .. jif.jobIdTo).each do |id|
|
36
|
+
j = Rjobs::Job.new()
|
37
|
+
j.name = "%s%0#{length}d" % [jif.jobName,id]
|
38
|
+
j.command = jif.command
|
39
|
+
jobs << j
|
40
|
+
end
|
41
|
+
|
42
|
+
jobs.each do |job|
|
43
|
+
Rjobs::JobHandler.submit_job(job)
|
44
|
+
end
|
45
|
+
|
46
|
+
jf = Rjobs::JobsFile.new()
|
47
|
+
jf.write(jif.jobName+".rjobs",jobs)
|
48
|
+
|
49
|
+
puts "#{jobs.count} job(s) submited.".green
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature: Submit
|
2
|
+
As a user
|
3
|
+
I want to harvest jobs' results
|
4
|
+
So that I can analyse it later
|
5
|
+
|
6
|
+
Scenario: Have a harvest command
|
7
|
+
When I successfully run `rjharvest`
|
8
|
+
Then the output should contain "rjharvest [options] <filename>"
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
Scenario: Submit a job input files will return a jobs result file
|
13
|
+
Given a file named "VAA.rjobs" with:
|
14
|
+
"""
|
15
|
+
VAA1 1
|
16
|
+
VAA2 2
|
17
|
+
VAA3 3
|
18
|
+
VAA4 4
|
19
|
+
VAA5 5
|
20
|
+
VAA6 6
|
21
|
+
VAA7 7
|
22
|
+
"""
|
23
|
+
When I successfully run `rjharvest VAA.rjobs`
|
24
|
+
Then show me the output
|
25
|
+
Then a file named "VAA1.out" should exist
|
26
|
+
And the file "VAA1.out" should match /Hello world/
|
27
|
+
# And a file named "VAA.out" should exist
|
28
|
+
# And the file "VAA.out" should match /Hello World/
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: List Jobs
|
2
|
+
As a user
|
3
|
+
I want to have a function to list all jobs
|
4
|
+
So as I can see a list of jobs
|
5
|
+
|
6
|
+
Background:
|
7
|
+
|
8
|
+
|
9
|
+
Scenario: list all jobs
|
10
|
+
Given a file named "test_jobs.rjob" with:
|
11
|
+
"""
|
12
|
+
VAA1 1
|
13
|
+
VAA2 2
|
14
|
+
VAA3 3
|
15
|
+
VAA4 4
|
16
|
+
VAA5 5
|
17
|
+
VAA6 6
|
18
|
+
VAA7 7
|
19
|
+
"""
|
20
|
+
When I successfully run `rjstatus test_jobs.rjob`
|
21
|
+
Then each line of the output should match /VAA\d+ - (Finished|Failed|Not Exist)/
|
22
|
+
And show me the output
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rjobs/process'
|
2
|
+
require 'rjobs/job_handler'
|
3
|
+
require 'cucumber/rspec/doubles'
|
4
|
+
require 'aruba/api'
|
5
|
+
require 'aruba/hooks'
|
6
|
+
require 'aruba/reporting'
|
7
|
+
|
8
|
+
World(Aruba::Api)
|
9
|
+
|
10
|
+
Then /^show me the output$/ do
|
11
|
+
puts all_stdout
|
12
|
+
end
|
13
|
+
|
14
|
+
Then /^each line of the output should match \/([^\/]*)\/$/ do |expected|
|
15
|
+
all_stdout.split("\n").each do |line|
|
16
|
+
# puts line
|
17
|
+
line.should match expected
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Submit
|
2
|
+
As a user
|
3
|
+
I want to submit jobs
|
4
|
+
So that jobs can be run on the xgrid
|
5
|
+
|
6
|
+
Scenario: Have a submit command
|
7
|
+
When I successfully run `rjsubmit`
|
8
|
+
Then the output should contain "rjsubmit [options] <filename>"
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
Scenario: Submit a job input files will return a jobs file
|
13
|
+
Given a file named "VAA.myJobs" with:
|
14
|
+
"""
|
15
|
+
JobName: VAA
|
16
|
+
JobId: 1-10
|
17
|
+
Command: ~/plays/cpp/testGrid/a.out
|
18
|
+
"""
|
19
|
+
When I successfully run `rjsubmit VAA.myJobs`
|
20
|
+
Then show me the output
|
21
|
+
Then a file named "VAA.rjobs" should exist
|
22
|
+
And the file "VAA.rjobs" should match /(VAA\d+\t\d+\n)+/
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
require 'aruba'
|
2
|
+
require 'cucumber/rspec/doubles'
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] ||= "cucumber"
|
5
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../../lib')
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
data/lib/rjobs.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rjobs
|
2
|
+
module CliHelper
|
3
|
+
def get_jobs_info(jobs_file)
|
4
|
+
jf = JobsFile.new(jobs_file)
|
5
|
+
jobs= []
|
6
|
+
jf.ids.each_with_index do |jobId,index|
|
7
|
+
job = Rjobs::Job.new(jobId, Rjobs::JobHandler.get_job_attributes(jobId))
|
8
|
+
job.name = jf.job_names[index]
|
9
|
+
jobs << job
|
10
|
+
end
|
11
|
+
jobs
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rjobs
|
2
|
+
class CommandBuilder
|
3
|
+
attr_accessor :command, :params
|
4
|
+
def initialize(command = "", params = "")
|
5
|
+
@command = command
|
6
|
+
@params = params
|
7
|
+
end
|
8
|
+
|
9
|
+
def build()
|
10
|
+
cmd = []
|
11
|
+
cmd << @command
|
12
|
+
@params.each do |key, value|
|
13
|
+
if value == ""
|
14
|
+
cmd << "#{key}"
|
15
|
+
else
|
16
|
+
cmd << "-#{key}"
|
17
|
+
cmd << value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
cmd.join(" ")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/rjobs/job.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'plist'
|
2
|
+
require 'rjobs/command_builder'
|
3
|
+
require 'colorize'
|
4
|
+
|
5
|
+
module Rjobs
|
6
|
+
class Job
|
7
|
+
attr_accessor :id, :name, :status
|
8
|
+
attr_writer :params, :command
|
9
|
+
|
10
|
+
def initialize(id=0,xml="")
|
11
|
+
@id = id
|
12
|
+
parse(xml)
|
13
|
+
@params= {}
|
14
|
+
@command = ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def xml=(xml)
|
18
|
+
parse(xml)
|
19
|
+
end
|
20
|
+
|
21
|
+
def command
|
22
|
+
cb = Rjobs::CommandBuilder.new(@command,@params)
|
23
|
+
cb.build
|
24
|
+
end
|
25
|
+
|
26
|
+
def status_with_color
|
27
|
+
case @status
|
28
|
+
when /Finished/
|
29
|
+
@status.green
|
30
|
+
when /Failed/
|
31
|
+
@status.light_red
|
32
|
+
when /Not Exist/
|
33
|
+
@status.red
|
34
|
+
else
|
35
|
+
@status
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
private
|
41
|
+
def parse(xml)
|
42
|
+
return if xml.empty?
|
43
|
+
result = Plist::parse_xml(xml)
|
44
|
+
@name = result['jobAttributes'].nil? ? "" : result['jobAttributes']['name']
|
45
|
+
@status = result['jobAttributes'].nil? ? "Not Exist" : result['jobAttributes']['jobStatus']
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|