Class: QstatXmlJRListener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb

Overview

An XML stream listener to build an array of OodCore::Job::Info from qstat output

Handles parsing `qstat -xml -r -j` which provides: :accounting_id :id :job_name :job_owner :procs :queue_name :status :wallclock_limit :wallclock_time

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQstatXmlJRListener

Returns a new instance of QstatXmlJRListener.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 25

def initialize
  @parsed_job = {
    :tasks => [],
    :status => :queued,
    :procs => 1,
    :native => {
      :ST_name => ''
    } 
  }
  @current_text = nil
  @current_request = nil
  @processing_JB_stdout_path_list = false

  @processing_job_array_spec = false
  @adding_slots = false

  @job_array_spec = {
    start: nil,
    stop: nil,
    step: 1,  # Step can have a default of 1
  }
  @running_tasks = []
  @native_tags = ['JB_job_number', 'JB_job_name', 'JB_version', 'JB_project', 'JB_exec_file', 'JB_script_file', 'JB_script_size', 'JB_submission_time', 'JB_execution_time', 'JB_deadline', 'JB_owner', 'JB_uid', 'JB_group', 'JB_gid', 'JB_account', 'JB_cwd', 'JB_notify', 'JB_type', 'JB_reserve', 'JB_priority', 'JB_jobshare', 'JB_verify', 'JB_checkpoint_attr', 'JB_checkpoint_interval', 'JB_restart']
end

Instance Attribute Details

#parsed_jobObject (readonly)

Hash


21
22
23
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 21

def parsed_job
  @parsed_job
end

Instance Method Details

#build_tasksObject



192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 192

def build_tasks
  all_task_ids = OodCore::Job::ArrayIds.new(spec_string).ids
  highest_id_running = @running_tasks.sort.last.to_i
  
  @running_tasks.sort.map{
    |task_id| { :id => task_id, :status => :running }
  } + all_task_ids.select{
    |task_id| task_id > highest_id_running
  }.map{
    |task_id| { :id => task_id, :status => :queued }
  }
end

#end_CE_nameObject



148
149
150
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 148

def end_CE_name
  @current_request = @current_text
end

#end_CE_stringvalObject



152
153
154
155
156
157
158
159
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 152

def end_CE_stringval
  return nil if @current_request.nil?

  case @current_request
  when 'h_rt'  # hard run time limit
    @parsed_job[:wallclock_limit] = @current_text.to_i
  end
end

#end_JAT_start_timeObject



142
143
144
145
146
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 142

def end_JAT_start_time
  @parsed_job[:status] = :running
  @parsed_job[:dispatch_time] = ms_to_seconds(@current_text.to_i)
  @parsed_job[:wallclock_time] = Time.now.to_i - @parsed_job[:dispatch_time]
end

#end_JAT_task_numberObject

Used to record a running Job Array task



166
167
168
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 166

def end_JAT_task_number
  @running_tasks << @current_text
end

#end_JB_ja_tasksObject



138
139
140
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 138

def end_JB_ja_tasks
  @parsed_job[:status] = :running
end

#end_JB_job_nameObject



130
131
132
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 130

def end_JB_job_name
  @parsed_job[:job_name] = @current_text
end

#end_JB_job_numberObject

Attributes we need



118
119
120
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 118

def end_JB_job_number
  @parsed_job[:id] = @current_text
end

#end_JB_ownerObject



122
123
124
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 122

def end_JB_owner
  @parsed_job[:job_owner] = @current_text
end

#end_JB_projectObject



126
127
128
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 126

def end_JB_project
  @parsed_job[:accounting_id] = @current_text
end

#end_JB_submission_timeObject



134
135
136
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 134

def end_JB_submission_time
  @parsed_job[:submission_time] = ms_to_seconds(@current_text.to_i)
end

#end_PN_pathObject



170
171
172
173
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 170

def end_PN_path
  @parsed_job[:native][:PN_path] = @current_text if @processing_JB_stdout_path_list
  @processing_JB_stdout_path_list = false
end

#end_QR_nameObject



161
162
163
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 161

def end_QR_name
  @parsed_job[:queue_name] = @current_text
end

#end_ST_nameObject



175
176
177
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 175

def end_ST_name
  @parsed_job[:native][:ST_name] = @parsed_job[:native][:ST_name] + @current_text + ' '
end

#finalize_parsed_jobObject

Used to finalize the parsed job



206
207
208
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 206

def finalize_parsed_job
  @parsed_job[:tasks] = build_tasks if need_to_build_job_array?
end

#need_to_build_job_array?Boolean

The XML output will always contain nodes for task_id_range, even when the job is not an array job.

Returns:

  • (Boolean)


212
213
214
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 212

def need_to_build_job_array?
  spec_string != '1-1:1'
end

#set_job_array_piece(key) ⇒ Object



179
180
181
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 179

def set_job_array_piece(key)
  @job_array_spec[key] = @current_text if @processing_job_array_spec
end

#set_slotsObject



224
225
226
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 224

def set_slots
  @parsed_job[:procs] = @current_text.to_i
end

#spec_stringObject



183
184
185
186
187
188
189
190
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 183

def spec_string
  # If any of the job_array_spec values are nil then return a default spec_string
  if @job_array_spec.values.any? { |value| value.nil? } 
    '1-1:1'
  else
    '%{start}-%{stop}:%{step}' % @job_array_spec
  end
end

#tag_end(name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 61

def tag_end(name)
  #Add to native hash if in native_tags
  if (@native_tags.include?(name))
    @parsed_job[:native][:"#{name}"] = @current_text
  end

  case name
  when 'JB_ja_tasks'
    end_JB_ja_tasks
  when 'JB_job_number'
    end_JB_job_number
  when 'JB_job_name'
    end_JB_job_name
  when 'JB_owner'
    end_JB_owner
  when 'JB_project'
    end_JB_project
  when 'JB_submission_time'
    end_JB_submission_time
  when 'hard_request'
    end_hard_request
  when 'JAT_start_time'
    end_JAT_start_time
  when 'CE_name'
    end_CE_name
  when 'CE_stringval'
    end_CE_stringval
  when 'QR_name'
    end_QR_name
  when 'JAT_task_number'
    end_JAT_task_number
  when 'djob_info'
    finalize_parsed_job
  when 'RN_min'
    set_job_array_piece(:start) if @processing_job_array_spec
    set_slots if @adding_slots
  when 'RN_max'
    set_job_array_piece(:stop) if @processing_job_array_spec
  when 'RN_step'
    set_job_array_piece(:step) if @processing_job_array_spec
  when 'task_id_range'
    toggle_processing_array_spec
  when 'JB_pe_range'
    toggle_adding_slots
  when 'PN_path' 
    end_PN_path
  when 'ST_name'
    end_ST_name
  end
end

#tag_start(name, attrs) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 50

def tag_start(name, attrs)
  case name
  when 'task_id_range'
    toggle_processing_array_spec
  when 'JB_pe_range'
    toggle_adding_slots
  when 'JB_stdout_path_list'
    @processing_JB_stdout_path_list = true
  end
end

#text(text) ⇒ Object

Always store text nodes temporarily



113
114
115
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 113

def text(text)
  @current_text = text
end

#toggle_adding_slotsObject



220
221
222
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 220

def toggle_adding_slots
  @adding_slots = ! @adding_slots
end

#toggle_processing_array_specObject



216
217
218
# File 'lib/ood_core/job/adapters/sge/qstat_xml_j_r_listener.rb', line 216

def toggle_processing_array_spec
  @processing_job_array_spec = ! @processing_job_array_spec
end