Skip to content

Commit

Permalink
Handle quoted params in extra.
Browse files Browse the repository at this point in the history
Properly handle the quoted parameters in `extra` or `commonExtra`.
  • Loading branch information
jealous committed Sep 8, 2023
1 parent dbf06b5 commit 2b117c4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import nextflow.util.ServiceName

import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.regex.Matcher
import java.util.regex.Pattern
import java.util.stream.Collectors

/**
Expand Down Expand Up @@ -142,10 +144,33 @@ class FloatGridExecutor extends AbstractGridExecutor {
if (common) {
extra = common.trim() + " " + extra.trim()
}
def ret = extra.split('\\s+')
def ret = splitWithQuotes(extra)
return ret.findAll { it.length() > 0 }
}

private static List<String> splitWithQuotes(String input) {
List<String> ret = new ArrayList<String>()
int start = 0
boolean inQuotes = false
for (int i = 0; i < input.size(); i++) {
if (input[i] == '"') {
inQuotes = !inQuotes
}
if ((input[i] == '\t' || input[i] == ' ') && !inQuotes) {
String token = input.substring(start, i).trim()
if (token.size() > 0) {
ret.add(token)
}
start = i
}
}
String token = input.substring(start).trim()
if (token.size() > 0) {
ret.add(token)
}
return ret
}

private List<String> getCmdPrefixForJob(String floatJobID) {
final oc = floatJobs.getOc(floatJobID)
return floatConf.getCliPrefix(oc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ class FloatGridExecutorTest extends FloatBaseTest {
cmd.join(" ") == expected.join(" ")
}

def "quoted arguments in extra"() {
given:
final exec = newTestExecutor(
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
commonExtra: '--dataVolume [opts="-o allow_other"]s3://1.2.3.4:/a:/a --rootVolSize 10']]
)
final task = newTask(exec)

when:
final cmd = exec.getSubmitCommandLine(task, Paths.get(script))
final expected = submitCmd() + [
'--dataVolume',
'[opts="-o allow_other"]s3://1.2.3.4:/a:/a',
'--rootVolSize',
'10']

then:
cmd == expected
}

def "add specific extras"() {
given:
final exec = newTestExecutor()
Expand Down Expand Up @@ -317,10 +340,10 @@ class FloatGridExecutorTest extends FloatBaseTest {
def "use timeout factor"() {
given:
final exec = newTestExecutor(
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
timeFactor: 1.1]])
final task = newTask(exec, new TaskConfig(
container: image,
Expand All @@ -337,10 +360,10 @@ class FloatGridExecutorTest extends FloatBaseTest {
def "use on-demand for retry"() {
given:
final exec = newTestExecutor(
[float: [address : addr,
username : user,
password : pass,
nfs : nfs]])
[float: [address : addr,
username: user,
password: pass,
nfs : nfs]])
final task = newTask(exec, new TaskConfig(
container: image,
time: '1h',
Expand All @@ -357,10 +380,10 @@ class FloatGridExecutorTest extends FloatBaseTest {
def "use cpu factor"() {
given:
final exec = newTestExecutor(
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
cpuFactor: 1.5]])
final task = newTask(exec, new TaskConfig(
container: image,
Expand All @@ -377,10 +400,10 @@ class FloatGridExecutorTest extends FloatBaseTest {
def "use invalid cpu"() {
given:
final exec = newTestExecutor(
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
cpuFactor: 0.2]])
final task = newTask(exec, new TaskConfig(
container: image,
Expand All @@ -397,10 +420,10 @@ class FloatGridExecutorTest extends FloatBaseTest {
def "use memory factor"() {
given:
final exec = newTestExecutor(
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
memoryFactor: 0.5]])
final task = newTask(exec, new TaskConfig(
container: image,
Expand All @@ -417,10 +440,10 @@ class FloatGridExecutorTest extends FloatBaseTest {
def "use invalid memory"() {
given:
final exec = newTestExecutor(
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
[float: [address : addr,
username : user,
password : pass,
nfs : nfs,
memoryFactor: 0.5]])
final task = newTask(exec, new TaskConfig(
container: image,
Expand Down

0 comments on commit 2b117c4

Please sign in to comment.