Skip to content

Commit

Permalink
allow qstat_factor to be a config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Nicklas committed Jul 5, 2017
1 parent 3dd252a commit 3cd5e65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
24 changes: 12 additions & 12 deletions lib/ood_core/job/adapters/pbspro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ class Factory
# @param config [#to_h] the configuration for job adapter
# @option config [Object] :host (nil) The batch server host
# @option config [Object] :exec (nil) Path to PBS Pro executables
# @option config [Object] :qstat_factor (nil) Deciding factor on how to
# call qstat for a user
def self.build_pbspro(config)
c = config.to_h.compact.symbolize_keys
host = c.fetch(:host, nil)
exec = c.fetch(:exec, nil)
qstat_factor = c.fetch(:qstat_factor, nil)
pbspro = Adapters::PBSPro::Batch.new(host: host, exec: exec)
Adapters::PBSPro.new(pbspro: pbspro)
Adapters::PBSPro.new(pbspro: pbspro, qstat_factor: qstat_factor)
end
end

Expand Down Expand Up @@ -171,25 +174,22 @@ def call(cmd, *args, env: {}, stdin: "", chdir: nil)
# ignore B as it signifies a job array
}

class << self
# Factor used to decide when we filter owner from all job info's or
# we get job info's for all jobs owned by owner
# @return [Fixnum] deciding factor
def factor
@factor || 0.10
end

attr_writer :factor
end
# What percentage of jobs a user owns out of all jobs, used to decide
# whether we filter the owner's jobs from a `qstat` of all jobs or call
# `qstat` on each of the owner's individual jobs
# @return [Float] ratio of owner's jobs to all jobs
attr_reader :qstat_factor

# @api private
# @param opts [#to_h] the options defining this adapter
# @option opts [Batch] :pbspro The PBS Pro batch object
# @option opts [#to_f] :qstat_factor (0.10) The qstat deciding factor
# @see Factory.build_pbspro
def initialize(opts = {})
o = opts.to_h.compact.symbolize_keys

@pbspro = o.fetch(:pbspro) { raise ArgumentError, "No pbspro object specified. Missing argument: pbspro" }
@qstat_factor = o.fetch(:qstat_factor, 0.10).to_f
end

# Submit a job with the attributes defined in the job template instance
Expand Down Expand Up @@ -288,7 +288,7 @@ def info_where_owner(owner)

# `qstat` all jobs if user has too many jobs, otherwise `qstat` each
# individual job (default factor is 10%)
if usr_jobs.size > (self.class.factor * all_jobs.size)
if usr_jobs.size > (qstat_factor * all_jobs.size)
super
else
usr_jobs.map { |id| info(id) }
Expand Down
5 changes: 3 additions & 2 deletions spec/job/adapters/pbspro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
describe OodCore::Job::Adapters::PBSPro do
# Required arguments
let(:pbspro) { double() }
let(:qstat_factor) { nil }

# Subject
subject(:adapter) { described_class.new(pbspro: pbspro) }
subject(:adapter) { described_class.new(pbspro: pbspro, qstat_factor: qstat_factor) }

it { is_expected.to respond_to(:submit).with(1).argument.and_keywords(:after, :afterok, :afternotok, :afterany) }
it { is_expected.to respond_to(:info_all).with(0).arguments }
Expand Down Expand Up @@ -267,6 +268,7 @@ def build_script(opts = {})
end

context "when owner has multiple jobs" do
let(:qstat_factor) { 1.00 }
let(:job_ids) { [ "job_id_1", "job_id_2" ] }
let(:job_hash_1) {
{
Expand All @@ -284,7 +286,6 @@ def build_script(opts = {})
}

before do
allow(described_class).to receive(:factor) { 2.00 }
allow(pbspro).to receive(:get_jobs).with(id: "job_id_1").and_return([job_hash_1])
allow(pbspro).to receive(:get_jobs).with(id: "job_id_2").and_return([job_hash_2])
end
Expand Down

0 comments on commit 3cd5e65

Please sign in to comment.