Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow LSF commands via ssh #283

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: batchtools
Title: Tools for Computation on Batch Systems
Version: 0.9.16
Version: 0.9.15.9006
Authors@R: c(
person("Michel", "Lang", NULL, "[email protected]",
role = c("cre", "aut"), comment = c(ORCID = "0000-0001-9754-0393")),
Expand Down Expand Up @@ -63,4 +63,4 @@ Suggests:
tibble
VignetteBuilder: knitr
Roxygen: list(r6 = FALSE)
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
34 changes: 24 additions & 10 deletions R/clusterFunctionsLSF.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@
#' It is the template file's job to choose a queue for the job and handle the desired resource
#' allocations.
#'
#' @note
#' Array jobs are currently not supported.
#'
#' @template template
#' @param array.jobs [\code{logical(1)}]\cr
#' If array jobs are disabled on the computing site, set to \code{FALSE}.
#' @template nodename
#' @inheritParams makeClusterFunctions
#' @return [\code{\link{ClusterFunctions}}].
#' @family ClusterFunctions
#' @export
makeClusterFunctionsLSF = function(template = "lsf", scheduler.latency = 1, fs.latency = 65) { # nocov start
makeClusterFunctionsLSF = function(template = "lsf", array.jobs=TRUE, nodename = "localhost", scheduler.latency = 1, fs.latency = 65) { # nocov start
assertFlag(array.jobs)
assertString(nodename)
template = findTemplateFile(template)
if (testScalarNA(template))
stopf("Argument 'template' (=\"%s\") must point to a readable template file or contain the template itself as string (containing at least one newline)", template)
template = cfReadBrewTemplate(template)
template = cfReadBrewTemplate(template, '##')
quote = if (isLocalHost(nodename)) identity else shQuote

# When LSB_BJOBS_CONSISTENT_EXIT_CODE = Y, the bjobs command exits with 0 only
# when unfinished jobs are found, and 255 when no jobs are found,
Expand All @@ -37,20 +40,31 @@ makeClusterFunctionsLSF = function(template = "lsf", scheduler.latency = 1, fs.l
submitJob = function(reg, jc) {
assertRegistry(reg, writeable = TRUE)
assertClass(jc, "JobCollection")
if (jc$array.jobs) {
logs = sprintf("%s_%i", fs::path_file(jc$log.file), seq_row(jc$jobs))
jc$log.file = stri_join(jc$log.file, "_%I")
}
outfile = cfBrewTemplate(reg, template, jc)
res = runOSCommand("bsub", stdin = outfile)
res = runOSCommand("bsub", stdin = outfile, nodename = nodename)
output = stri_flatten(stri_trim_both(res$output), "\n")

if (res$exit.code > 0L) {
cfHandleUnknownSubmitError("bsub", res$exit.code, res$output)
} else {
batch.id = stri_extract_first_regex(stri_flatten(res$output, " "), "\\d+")
makeSubmitJobResult(status = 0L, batch.id = batch.id)
if (jc$array.jobs) {
if (!array.jobs)
stop("Array jobs not supported by cluster function")
makeSubmitJobResult(status = 0L, batch.id = sprintf("%s_%i", batch.id, seq_row(jc$jobs)), log.file = logs)
} else {
makeSubmitJobResult(status = 0L, batch.id = batch.id)
}
}
}

listJobs = function(reg, args) {
assertRegistry(reg, writeable = FALSE)
res = runOSCommand("bjobs", args)
res = runOSCommand("bjobs", args, nodename = nodename)
if (res$exit.code > 0L) {
if (res$exit.code == 255L || any(stri_detect_regex(res$output, "No (unfinished|pending|running) job found")))
return(character(0L))
Expand All @@ -70,9 +84,9 @@ makeClusterFunctionsLSF = function(template = "lsf", scheduler.latency = 1, fs.l
killJob = function(reg, batch.id) {
assertRegistry(reg, writeable = TRUE)
assertString(batch.id)
cfKillJob(reg, "bkill", batch.id)
cfKillJob(reg, "bkill", batch.id, nodename = nodename)
}

makeClusterFunctions(name = "LSF", submitJob = submitJob, killJob = killJob, listJobsQueued = listJobsQueued,
makeClusterFunctions(name = "LSF", submitJob = submitJob, killJob = killJob, listJobsQueued = listJobsQueued, array.var = "LSB_JOBINDEX",
listJobsRunning = listJobsRunning, store.job.collection = TRUE, scheduler.latency = scheduler.latency, fs.latency = fs.latency)
} # nocov end
16 changes: 13 additions & 3 deletions man/makeClusterFunctionsLSF.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test_ClusterFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test_that("clusterFunctions constructor", {
check(makeClusterFunctionsTORQUE("torque-lido"))
check(makeClusterFunctionsSlurm("slurm-dortmund"))
check(makeClusterFunctionsDocker("image"))
expect_error(makeClusterFunctionsLSF(), "point to a readable template file")
expect_error(makeClusterFunctionsLSF(template = "doesnotexist"), "point to a readable template file")

skip_on_os(c("windows", "solaris")) # system2 is broken on solaris
check(makeClusterFunctionsSSH(workers = list(Worker$new(nodename = "localhost", ncpus = 1L))))
Expand Down