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



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_stepsObject

def

self.stats



101
102
103
# File 'lib/oar/scripting/script.rb', line 101

def self.disabled_steps
  @@disabled_steps
end

.executeObject

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



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

.jobObject

def

type



64
65
66
# File 'lib/oar/scripting/script.rb', line 64

def self.job
  @@job
end

.load_stepsObject

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

.loggerObject

def

getargs



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

def self.logger
  @@logger
end

.oarstatObject

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

.statsObject

def

execute



97
98
99
# File 'lib/oar/scripting/script.rb', line 97

def self.stats
  @@stats
end

.stepsObject

def

self.job



68
69
70
# File 'lib/oar/scripting/script.rb', line 68

def self.steps
  @@steps
end

.typeObject

def

logger



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

def self.type
  @@type
end