From 0b7f44e5a0cadfbd59c25e1b0eb0a79fad5946a9 Mon Sep 17 00:00:00 2001 From: Masahiro Nakao Date: Thu, 2 Nov 2023 22:26:25 +0900 Subject: [PATCH] Add working_dir option for Fujitsu TCS job scheduler (#816) Add working_dir option for Fujitsu TCS job scheduler that can be read from the cluster.d file. --- lib/ood_core/job/adapters/fujitsu_tcs.rb | 29 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/ood_core/job/adapters/fujitsu_tcs.rb b/lib/ood_core/job/adapters/fujitsu_tcs.rb index c6d974529..df906e7cd 100644 --- a/lib/ood_core/job/adapters/fujitsu_tcs.rb +++ b/lib/ood_core/job/adapters/fujitsu_tcs.rb @@ -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 @@ -43,6 +45,11 @@ class Batch # @return Hash 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 @@ -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 @@ -79,7 +94,7 @@ def initialize(bin: nil, bin_overrides: {}) # @raise [Error] if `pjstat` command exited unsuccessfully # @return [Array] 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? @@ -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 @@ -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 }