Skip to content

Commit

Permalink
Merge pull request #79 from OSC/lsf_multicluster
Browse files Browse the repository at this point in the history
add basic lsf multi-cluster support
  • Loading branch information
ericfranz authored Mar 20, 2018
2 parents 630f4de + 898a763 commit 16b03ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/ood_core/job/adapters/lsf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Factory
# @option config [#to_s] :libdir ('') Path to lsf client lib dir
# @option config [#to_s] :envdir ('') Path to lsf client conf dir
# @option config [#to_s] :serverdir ('') Path to lsf client etc dir
# @option config [#to_s] :cluster ('') name of cluster, if in multi-cluster mode
def self.build_lsf(config)
batch = Adapters::Lsf::Batch.new(config.to_h.symbolize_keys)
Adapters::Lsf.new(batch: batch)
Expand Down
15 changes: 12 additions & 3 deletions lib/ood_core/job/adapters/lsf/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
#
# @api private
class OodCore::Job::Adapters::Lsf::Batch
attr_reader :bindir, :libdir, :envdir, :serverdir
attr_reader :bindir, :libdir, :envdir, :serverdir, :cluster

# The root exception class that all LSF-specific exceptions inherit
# from
class Error < StandardError; end

# @param bin [#to_s] path to LSF installation binaries
def initialize(bindir: "", envdir: "", libdir: "", serverdir: "", **_)
def initialize(bindir: "", envdir: "", libdir: "", serverdir: "", cluster: "", **_)
@bindir = Pathname.new(bindir.to_s)

@envdir = Pathname.new(envdir.to_s)
@libdir = Pathname.new(libdir.to_s)
@serverdir = Pathname.new(serverdir.to_s)
@cluster = cluster.to_s
end

def default_env
Expand Down Expand Up @@ -127,11 +128,19 @@ def parse_bsub_output(response)
end
end

def cluster_args
if cluster.nil? || cluster.strip.empty?
[]
else
["-m", cluster]
end
end

private
# Call a forked Lsf command for a given cluster
def call(cmd, *args, env: {}, stdin: "")
cmd = bindir.join(cmd.to_s).to_s
#TODO: args = ["-m", cluster] + args.map(&:to_s)
args = cluster_args + args
env = default_env.merge(env.to_h)
o, e, s = Open3.capture3(env, cmd, *(args.map(&:to_s)), stdin_data: stdin.to_s)
s.success? ? o : raise(Error, e)
Expand Down
27 changes: 27 additions & 0 deletions spec/job/adapters/lsf/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,31 @@
)}
end
end

describe "multinode" do
subject(:batch) { described_class.new(config).cluster_args }
context "when cluster not set" do
let(:config) {
{
bindir: "/opt/lsf/8.3/bin",
libdir: "/opt/lsf/8.3/lib",
envdir: "/opt/lsf/conf",
serverdir: "/opt/lsf/8.3/etc"
}
}
it { is_expected.to eq([]) }
end
context "when cluster not set" do
let(:config) {
{
bindir: "/opt/lsf/8.3/bin",
libdir: "/opt/lsf/8.3/lib",
envdir: "/opt/lsf/conf",
serverdir: "/opt/lsf/8.3/etc",
cluster: "curie"
}
}
it { is_expected.to eq(["-m", "curie"]) }
end
end
end

0 comments on commit 16b03ed

Please sign in to comment.