class TORQUE::Qstat

Public Class Methods

fields() click to toggle source
# File lib/torque_rm/qstat.rb, line 264
def self.fields
  FIELDS
end
new() click to toggle source

class Trans < Parslet::Transform

rule(:datetime => simple(:datetime)) {DateTime.parse(datetime)}
rule(:string => simple(:string))     {String(string)}
rule(:integer => simple(:integer))   {Integer(integer)}
rule(:boolean => simple(:boolean))   {String(boolean) == "True"}

end #Trans

# File lib/torque_rm/qstat.rb, line 258
def initialize
    # @parser = Parser.new #DEPRECATED
    # @transformer = Trans.new #DEPRECATED
    @last_query = nil #cache last query, it can be useful to generate some kind of statistics ?
end

Public Instance Methods

display(hash={}) click to toggle source
# File lib/torque_rm/qstat.rb, line 324
def display(hash={})
  query(hash)
  print_jobs_table(@last_query)
end
fields() click to toggle source
# File lib/torque_rm/qstat.rb, line 268
def fields
  FIELDS
end
mock(results) click to toggle source
# File lib/torque_rm/qstat.rb, line 329
def mock(results)
  from_parselet_to_jobs(results)
end
query(hash={}) click to toggle source

hash can contain keys: type = :raw just print a string job_id = job.id it will print info only about the specified job job_ids = [“1.server”, “2.server”, “3.server”] get an array for requested jobs returns results which is an Array of Job

# File lib/torque_rm/qstat.rb, line 277
def query(hash={})
    # result = TORQUE.server.qstat('-f')
    if hash[:type] == :raw
      TORQUE.server.qstat('-f').to_s  #returns
    elsif hash[:type] == :xml
      TORQUE.server.qstat('-f','-x')  #returns
    else
      # begin
        data_xml = Hash.from_xml(TORQUE.server.qstat('-f','-x').to_s)
        @last_query = if data_xml.nil?
          [] #returns
        else
          data_array = data_xml["Data"]["Job"].is_a?(Hash) ? [data_xml["Data"]["Job"]] : data_xml["Data"]["Job"]
          jobs = data_array.map do |job_xml|
            Job.new job_xml
          end # do
          if hash.key? :job_id
            # if hash[:job_id]..is_a? String
              jobs.select {|job| (hash[:job_id].to_s == job.job_id || hash[:job_id].to_s == job.job_id.split(".").first)}
            # else
              # warn "You gave me #{hash[:job_id].class}, only String is supported."
            # end
          elsif hash.key? :job_ids
            if hash[:job_ids].is_a? Array
              jobs.select {|job| (hash[:job_ids].include?(job.job_id) || hash[:job_ids].include?(job.job_id.split(".").first))}
            elsif hash[:job_ids].is_a? String
              warn "To be implemented for String object."
            else
              warm "To be implemented for #{hash[:job_ids].class}"
            end 
          else
            jobs
          end
        end # else

        # puts result.to_s.inspect
        # puts result.to_s.gsub(/\n\t/,'').inspect
        # results = @transformer.apply(@parser.parse(result.to_s.gsub(/\n\t/,'')))
      # rescue Parslet::ParseFailed => failure
      #   puts failure.cause.ascii_tree
      # end

      # results = [] if results.is_a?(String) && results.empty?
    # @last_query = from_parselet_to_jobs(results)
    end
end

Private Instance Methods

from_parselet_to_jobs(results) click to toggle source
# File lib/torque_rm/qstat.rb, line 336
def from_parselet_to_jobs(results)
    results.map do |raw_job|
      job = Job.new
       raw_job.each_pair do |key, value|
          job.send "#{key}=", value
      end #each pair
      job
    end #each_job
end
print_jobs_table(jobs_info) click to toggle source