Skip to content

Commit 752e825

Browse files
committed
fix: add storeDir output to TES request
1 parent 650551c commit 752e825

2 files changed

Lines changed: 96 additions & 14 deletions

File tree

plugins/nf-ga4gh/src/main/nextflow/ga4gh/tes/executor/TesTaskHandler.groovy

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ class TesTaskHandler extends TaskHandler {
218218
final type = param.type == 'dir'
219219
? 'DIRECTORY'
220220
: 'FILE'
221-
for( final pattern : param.getFilePatterns(task.context, task.workDir) )
222-
body.addOutputsItem(outItem(pattern, type))
221+
for( final pattern : param.getFilePatterns(task.context, task.workDir) ) {
222+
def storeDir = task.config.get('storeDir')?.toString()
223+
body.addOutputsItem(outItem(pattern, type, storeDir))
224+
}
223225
}
224226

225227
body.setName(task.getName())
@@ -272,27 +274,32 @@ class TesTaskHandler extends TaskHandler {
272274
return result
273275
}
274276

275-
private TesOutput outItem( String fileName, String type = null ) {
277+
private TesOutput outItem(String fileName, String type = null, String storeDir = null) {
276278
final result = new TesOutput()
277-
if( fileName.contains('*') || fileName.contains('?') ) {
278-
result.path = "$WORK_DIR/$fileName"
279+
280+
result.path = "$WORK_DIR/$fileName"
281+
282+
if (fileName.contains('*') || fileName.contains('?')) {
279283
result.pathPrefix = WORK_DIR
280-
result.url = task.workDir.toUriString()
281284
}
282-
else {
283-
result.path = "$WORK_DIR/$fileName"
284-
result.url = task.workDir.resolve(fileName).toUriString()
285+
286+
if (storeDir) {
287+
result.url = storeDir.endsWith('/') ? "${storeDir}${fileName}" : "${storeDir}/${fileName}"
288+
} else {
289+
result.url = fileName.contains('*') || fileName.contains('?')
290+
? task.workDir.toUriString()
291+
: task.workDir.resolve(fileName).toUriString()
292+
293+
// fix local path for TES Azure only when using task.workDir
294+
result.url = fixTesAzureLocalPath(result.url)
285295
}
286-
if( type != null )
287-
result.type = type
288296

289-
// fix local path for TES Azure
290-
result.url = fixTesAzureLocalPath(result.url)
297+
if (type != null)
298+
result.type = type
291299

292300
log.trace "[TES] Adding OUTPUT file: $result"
293301
return result
294302
}
295-
296303
/**
297304
* Fix local paths when using TES Azure, which requires the
298305
* following AZ path:

plugins/nf-ga4gh/src/test/nextflow/ga4gh/tes/executor/TesTaskHandlerTest.groovy

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import nextflow.ga4gh.tes.client.api.TaskServiceApi
2020
import nextflow.ga4gh.tes.client.model.TesCreateTaskResponse
2121
import nextflow.ga4gh.tes.client.model.TesTask
2222
import nextflow.processor.TaskStatus
23+
import nextflow.script.params.FileOutParam
2324

2425
import java.nio.file.Path
2526
import java.nio.file.Paths
@@ -89,4 +90,78 @@ class TesTaskHandlerTest extends Specification {
8990
handler.requestId == '12345'
9091
}
9192

93+
def 'should add outputs to both workDir and storeDir when storeDir is configured' () {
94+
95+
given:
96+
def executor = Mock(TesExecutor)
97+
def storeDirUri = "s3://some/store/dir"
98+
def workDir = Paths.get("/work/dir")
99+
def fileOutParam = Mock(FileOutParam)
100+
fileOutParam.type >> 'file'
101+
fileOutParam.getFilePatterns(_, _) >> ['output.txt', 'result.log']
102+
103+
def task = Mock(TaskRun) {
104+
getInputFilesMap() >> [:]
105+
getOutputFilesNames() >> []
106+
getOutputsByType(FileOutParam) >> [(fileOutParam): null]
107+
getWorkDir() >> workDir
108+
}
109+
task.getName() >> 'tes-task'
110+
def config = Mock(TaskConfig)
111+
config.get('storeDir') >> storeDirUri
112+
task.getConfig() >> config
113+
task.getContainer() >> 'foo'
114+
def handler = new TesTaskHandler(task, executor)
115+
116+
when:
117+
def tesTask = handler.newTesTask()
118+
119+
then:
120+
def outputs = tesTask.getOutputs()
121+
122+
def workDirOutputs = outputs.findAll { it.url.startsWith(workDir.toUriString()) }
123+
124+
def storeDirOutputs = outputs.findAll { it.url.startsWith(storeDirUri) }
125+
126+
storeDirOutputs.size() == 2
127+
storeDirOutputs.any { it.url.endsWith('output.txt') }
128+
storeDirOutputs.any { it.url.endsWith('result.log') }
129+
130+
workDirOutputs.size() >= 2
131+
}
132+
133+
def 'should not add storeDir outputs when storeDir is not configured' () {
134+
135+
given:
136+
def executor = Mock(TesExecutor)
137+
def workDir = Paths.get("/work/dir")
138+
def fileOutParam = Mock(FileOutParam)
139+
fileOutParam.type >> 'file'
140+
fileOutParam.getFilePatterns(_, _) >> ['output.txt']
141+
142+
def task = Mock(TaskRun) {
143+
getInputFilesMap() >> [:]
144+
getOutputFilesNames() >> []
145+
getOutputsByType(FileOutParam) >> [(fileOutParam): null]
146+
getWorkDir() >> workDir
147+
}
148+
task.getName() >> 'tes-task'
149+
def config = Mock(TaskConfig)
150+
config.get('storeDir') >> null
151+
task.getConfig() >> config
152+
task.getContainer() >> 'foo'
153+
def handler = new TesTaskHandler(task, executor)
154+
155+
when:
156+
def tesTask = handler.newTesTask()
157+
158+
then:
159+
def outputs = tesTask.getOutputs()
160+
161+
def workDirOutputs = outputs.findAll { it.url.startsWith(workDir.toUriString()) }
162+
workDirOutputs.size() >= 1
163+
164+
outputs.every { it.url.startsWith(workDir.toUriString()) }
165+
}
166+
92167
}

0 commit comments

Comments
 (0)