Skip to content

Commit

Permalink
Add working_dir option for Fujitsu TCS job scheduler (#816)
Browse files Browse the repository at this point in the history
Add working_dir option for Fujitsu TCS job scheduler
that can be read from the cluster.d file.
  • Loading branch information
mnakao authored Nov 2, 2023
1 parent 9cb9dd3 commit 0b7f44e
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/ood_core/job/adapters/fujitsu_tcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class Factory
# @param config [#to_h] the configuration for job adapter
# @option config [Object] :bin (nil) Path to Fujitsu TCS resource manager binaries
# @option config [#to_h] :bin_overrides ({}) Optional overrides to Fujitsu TCS resource manager executables
# @option config [Object] :working_dir (nil) Working directory for submitting a batch script
def self.build_fujitsu_tcs(config)
c = config.to_h.symbolize_keys
bin = c.fetch(:bin, nil)
bin_overrides = c.fetch(:bin_overrides, {})
fujitsu_tcs = Adapters::Fujitsu_TCS::Batch.new(bin: bin, bin_overrides: bin_overrides)
working_dir = c.fetch(:working_dir, nil)
fujitsu_tcs = Adapters::Fujitsu_TCS::Batch.new(bin: bin, bin_overrides: bin_overrides, working_dir: working_dir)
Adapters::Fujitsu_TCS.new(fujitsu_tcs: fujitsu_tcs)
end
end
Expand All @@ -43,6 +45,11 @@ class Batch
# @return Hash<String, String>
attr_reader :bin_overrides

# Working directory for submitting a batch script
# @example
# my_batch.working_dir #=> "HOME" or Dir.pwd
attr_reader :working_dir

# The root exception class that all Fujitsu TCS specific exceptions inherit
# from
class Error < StandardError; end
Expand All @@ -52,9 +59,17 @@ class Fujitsu_TCS_TimeoutError < Error; end

# @param bin [#to_s] path to Fujitsu TCS installation binaries
# @param bin_overrides [#to_h] a hash of bin ovverides to be used in job
def initialize(bin: nil, bin_overrides: {})
# @param working_dir [] Working directory for submitting a batch script
def initialize(bin: nil, bin_overrides: {}, working_dir: nil)
@bin = Pathname.new(bin.to_s)
@bin_overrides = bin_overrides
if working_dir == nil
@working_dir = Dir.pwd
elsif working_dir == "HOME"
@working_dir = Dir.home
else
raise(StandardError, "Unknown working_dir")
end
end

# Get a list of hashes detailing each of the jobs on the batch server
Expand All @@ -79,7 +94,7 @@ def initialize(bin: nil, bin_overrides: {})
# @raise [Error] if `pjstat` command exited unsuccessfully
# @return [Array<Hash>] list of details for jobs
def get_jobs(id: "", owner: nil)
args = ["-s", "--data", "--choose=jid,jnam,rscg,st,std,stde,adt,sdt,nnumr,usr,elpl,elp"]
args = ["-A", "-s", "--data", "--choose=jid,jnam,rscg,st,std,stde,adt,sdt,nnumr,usr,elpl,elp"]
args.concat ["--filter", "jid=" + id.to_s] unless id.to_s.empty?
args.concat ["--filter", "usr=" + owner.to_s] unless owner.to_s.empty?

Expand Down Expand Up @@ -144,8 +159,10 @@ def submit_string(str, args: [])
def call(cmd, *args, stdin: "")
cmd = OodCore::Job::Adapters::Helper.bin_path(cmd, bin, bin_overrides)
args = args.map(&:to_s)
o, e, s = Open3.capture3(cmd, *(args.map(&:to_s)), stdin_data: stdin.to_s)
s.success? ? o : raise(Error, e)
Dir.chdir(working_dir) do
o, e, s = Open3.capture3(cmd, *(args.map(&:to_s)), stdin_data: stdin.to_s)
s.success? ? o : raise(Error, e)
end
end
end

Expand Down Expand Up @@ -368,7 +385,7 @@ def directive_prefix
private
# Convert duration to seconds
def duration_in_seconds(time)
return 0 if time.nil?
return 0 if time.nil? or time == "-"
time, days = time.split("-").reverse
days.to_i * 24 * 3600 +
time.split(':').map { |v| v.to_i }.inject(0) { |total, v| total * 60 + v }
Expand Down

0 comments on commit 0b7f44e

Please sign in to comment.