Class: OAR::Scripting::Script
- Inherits:
-
Object
- Object
- OAR::Scripting::Script
- Defined in:
- lib/oar/scripting/script.rb
Class Method Summary collapse
-
.disable_steps(steps) ⇒ Object
- def
-
self.disabled_steps.
-
.disabled_steps ⇒ Object
- def
-
self.stats.
-
.execute ⇒ Object
- def
-
self.oarstat.
-
.getargs ⇒ Object
- def
-
self.load_scripts.
- .init(type) ⇒ Object
-
.job ⇒ Object
- def
-
type.
-
.load_steps ⇒ Object
- def
-
initialize.
-
.logger ⇒ Object
- def
-
getargs.
-
.oarstat ⇒ Object
- def
-
self.steps.
-
.stats ⇒ Object
- def
-
execute.
-
.steps ⇒ Object
- def
-
self.job.
-
.type ⇒ Object
- def
-
logger.
Class Method Details
.disable_steps(steps) ⇒ Object
- def
-
self.disabled_steps
105 106 107 108 109 110 111 |
# File 'lib/oar/scripting/script.rb', line 105 def self.disable_steps(steps) steps = [steps] unless steps.class == Array @@disabled_steps += steps steps2disable = Script.steps.select { |step| steps.include? step[:name] } Script.logger.info "[disable_loaded_steps]#{steps2disable.inspect}" @@steps -= steps2disable end |
.disabled_steps ⇒ Object
- def
-
self.stats
101 102 103 |
# File 'lib/oar/scripting/script.rb', line 101 def self.disabled_steps @@disabled_steps end |
.execute ⇒ Object
- def
-
self.oarstat
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/oar/scripting/script.rb', line 76 def self.execute @@steps.sort! { |a,b| a[:order] <=> b[:order] } @@steps.each do |step| @@logger.info "[begin_step]#{step[:name]}" start = Time.new begin step[:proc].call rescue Exception => e @@logger.debug "[Error] step #{step[:name]} failed (describe in #{step[:file]}" @@logger.debug e. @@logger.debug e.backtrace raise unless step[:continue] end @@logger.info "[end_step]#{step[:name]}" @@stats["steps"] << { "name" => step[:name].to_s, "duration" => (Time.now - start), "order" => step[:order] } end @@logger.info "[end]" @@stats["duration"] = Time.now - @@start_at @@logger.info "[stats]" + @@stats.to_json end |
.getargs ⇒ Object
- def
-
self.load_scripts
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/oar/scripting/script.rb', line 38 def self.getargs job = { :id => ARGV[0] } unless ARGV.length < 3 job[:user] = ARGV[1] job[:nodesfile] = ARGV[2] else job[:uncomplete] = true end begin File.open(job[:nodesfile]).each { |line| @@resources << line.chomp } rescue job[:uncomplete] = true end job[:resources_count] = @@resources.length job[:host_count] = @@resources.uniq.length job end |
.init(type) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/oar/scripting/script.rb', line 10 def self.init(type) @@resources = [] @@start_at = Time.new @@job = getargs if job[:uncomplete] # get missing data from oarstat job[:user] = self.oarstat['job_user'] job[:resources_count] = self.oarstat['assigned_resources'].length job[:host_count] = self.oarstat['assigned_network_address'].length job.delete(:uncomplete) end @@type ||= type @@logger ||= Logger.new(File.join(OAR::Scripting::Config[:log_path], "#{@@job[:id]}-#{@@type.to_s}-#{@@job[:user]}.log")) @@logger.info "[begin]" @@stats = { "job" => @@job, "steps" => [] } @@steps = [] @@disabled_steps = [] end |
.job ⇒ Object
- def
-
type
64 65 66 |
# File 'lib/oar/scripting/script.rb', line 64 def self.job @@job end |
.load_steps ⇒ Object
- def
-
initialize
29 30 31 32 33 34 35 36 |
# File 'lib/oar/scripting/script.rb', line 29 def self.load_steps dir = OAR::Scripting::Config["#{@@type}_d_path".to_sym] if File.exist? dir Dir[File.join dir, "*.rb"].each do |file| load file end end end |
.logger ⇒ Object
- def
-
getargs
56 57 58 |
# File 'lib/oar/scripting/script.rb', line 56 def self.logger @@logger end |
.oarstat ⇒ Object
- def
-
self.steps
72 73 74 |
# File 'lib/oar/scripting/script.rb', line 72 def self.oarstat @@oarstat ||= JSON.parse(%x[oarstat -f -j #{@@job[:id]} -J])[@@job[:id]] end |
.stats ⇒ Object
- def
-
execute
97 98 99 |
# File 'lib/oar/scripting/script.rb', line 97 def self.stats @@stats end |
.steps ⇒ Object
- def
-
self.job
68 69 70 |
# File 'lib/oar/scripting/script.rb', line 68 def self.steps @@steps end |
.type ⇒ Object
- def
-
logger
60 61 62 |
# File 'lib/oar/scripting/script.rb', line 60 def self.type @@type end |