Skip to content

Commit f4600d2

Browse files
committed
Fix container meta deduplication
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
1 parent 20ddf23 commit f4600d2

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

plugins/nf-tower/src/main/io/seqera/tower/plugin/TowerClient.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class TowerClient implements TraceObserver {
141141

142142
private TowerReports reports
143143

144-
private Map<String,Map<String,Object>> allContainers = new ConcurrentHashMap<>()
144+
private Map<String,Boolean> allContainers = new ConcurrentHashMap<>()
145145

146146
/**
147147
* Constructor that consumes a URL and creates
@@ -720,8 +720,10 @@ class TowerClient implements TraceObserver {
720720
final result = new ArrayList<ContainerMeta>()
721721
for( TraceRecord it : tasks ) {
722722
final meta = it.getContainerMeta()
723-
if( meta && !allContainers.containsKey(meta.targetImage) )
723+
if( meta && !allContainers.get(meta.targetImage) ) {
724+
allContainers.put(meta.targetImage, Boolean.TRUE)
724725
result.add(meta)
726+
}
725727
}
726728
return result
727729
}

plugins/nf-tower/src/test/io/seqera/tower/plugin/TowerClientTest.groovy

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,49 @@ class TowerClientTest extends Specification {
479479
"local-platform::${ProcessHelper.selfPid()}" | null | null | [TOWER_ALLOW_NEXTFLOW_LOGS:'true']
480480
'aws-batch::1234z' | 'xyz.out' | 'hola.log' | [TOWER_ALLOW_NEXTFLOW_LOGS:'true', AWS_BATCH_JOB_ID: '1234z', NXF_OUT_FILE: 'xyz.out', NXF_LOG_FILE: 'hola.log']
481481
}
482+
483+
def 'should deduplicate containers' () {
484+
given:
485+
def client = Spy(new TowerClient())
486+
and:
487+
def c1 = new ContainerMeta(requestId: '12345', sourceImage: 'ubuntu:latest', targetImage: 'wave.io/12345/ubuntu:latest')
488+
def c2 = new ContainerMeta(requestId: '54321', sourceImage: 'ubuntu:latest', targetImage: 'wave.io/54321/ubuntu:latest')
489+
and:
490+
def trace1 = new TraceRecord(
491+
taskId: 1,
492+
process: 'foo',
493+
workdir: "/work/dir",
494+
cpus: 1,
495+
submit: System.currentTimeMillis(),
496+
start: System.currentTimeMillis(),
497+
complete: System.currentTimeMillis())
498+
trace1.containerMeta = c1
499+
and:
500+
def trace2 = new TraceRecord(
501+
taskId: 2,
502+
process: 'foo',
503+
workdir: "/work/dir",
504+
cpus: 1,
505+
submit: System.currentTimeMillis(),
506+
start: System.currentTimeMillis(),
507+
complete: System.currentTimeMillis())
508+
trace2.containerMeta = c2
509+
and:
510+
def trace3 = new TraceRecord(
511+
taskId: 3,
512+
process: 'foo',
513+
workdir: "/work/dir",
514+
cpus: 1,
515+
submit: System.currentTimeMillis(),
516+
start: System.currentTimeMillis(),
517+
complete: System.currentTimeMillis())
518+
trace3.containerMeta = c2
519+
520+
expect:
521+
client.getNewContainers([trace1]) == [c1]
522+
and:
523+
client.getNewContainers([trace1]) == []
524+
and:
525+
client.getNewContainers([trace1, trace2, trace3]) == [c2]
526+
}
482527
}

0 commit comments

Comments
 (0)