Class: OAR::Scripting::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/oar/scripting/script.rb

Direct Known Subclasses

Epilogue, Prologue

Class Method Summary collapse

Class Method Details

.disable_steps(steps) ⇒ Object

def

self.disabled_steps



94
95
96
97
98
99
100
# File 'lib/oar/scripting/script.rb', line 94

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_stepsObject

def

self.stats



90
91
92
# File 'lib/oar/scripting/script.rb', line 90

def self.disabled_steps
  @@disabled_steps
end

.executeObject

def

self.oarstat



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/oar/scripting/script.rb', line 65

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.message
      @@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

.getargsObject

def

self.load_scripts



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oar/scripting/script.rb', line 31

def self.getargs
  job = { :id         => ARGV[0],
          :user       => ARGV[1],
          :nodesfile  => ARGV[2] }
  begin
    File.open(job[:nodesfile]).each { |line| @@resources << line.chomp }
  rescue
    # let @@resources empty
  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
# File 'lib/oar/scripting/script.rb', line 10

def self.init(type)
  @@resources = []
  @@start_at = Time.new
  @@job = getargs
  @@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

.jobObject

def

type



53
54
55
# File 'lib/oar/scripting/script.rb', line 53

def self.job
  @@job
end

.load_stepsObject

def

initialize



22
23
24
25
26
27
28
29
# File 'lib/oar/scripting/script.rb', line 22

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

.loggerObject

def

getargs



45
46
47
# File 'lib/oar/scripting/script.rb', line 45

def self.logger
  @@logger
end

.oarstatObject

def

self.steps



61
62
63
# File 'lib/oar/scripting/script.rb', line 61

def self.oarstat
  @@oarstat ||= JSON.parse(%x[oarstat -f -j #{@@job[:id]} -J])[@@job[:id]]
end

.statsObject

def

execute



86
87
88
# File 'lib/oar/scripting/script.rb', line 86

def self.stats
  @@stats
end

.stepsObject

def

self.job



57
58
59
# File 'lib/oar/scripting/script.rb', line 57

def self.steps
  @@steps
end

.typeObject

def

logger



49
50
51
# File 'lib/oar/scripting/script.rb', line 49

def self.type
  @@type
end