Skip to content

Commit 7c6dee3

Browse files
authored
Merge pull request #382 from JosuaCarl/adapt-to-nextflow-26
Chore: Adapt to Nextflow 26.04.0
2 parents 52b50ea + 695469a commit 7c6dee3

25 files changed

Lines changed: 116 additions & 132 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
## Misc:
77
- Improved workflow reporting form extension/CLI by deriving and injecting workflow metadata from the provided trace file
88
- Added full integration test
9+
- Adapted to Nextflow 26
910

1011
## Features:
1112
- Transformation of data file to provenance file with schema.org / bioschemas.org type annotation in JSON-LD data format

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ sourceSets {
5858

5959
// Versioning of important packages
6060
ext {
61-
nextflowVersion = '24.10.6'
61+
nextflowVersion = '26.04.0'
6262
}
6363
String groovyVersion = '4.0.27'
6464
String pf4jVersion = '3.13.0'

src/main/nextflow/co2footprint/CO2FootprintCLI.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package nextflow.co2footprint
22

33
import groovy.util.logging.Slf4j
4-
import nextflow.BuildInfo
54
import nextflow.Session
65
import nextflow.co2footprint.DataContainers.CIDataMatrix
76
import nextflow.co2footprint.DataContainers.TDPDataMatrix
@@ -13,12 +12,9 @@ import nextflow.script.ScriptFile
1312
import nextflow.script.WorkflowMetadata
1413
import nextflow.trace.TraceRecord
1514
import nextflow.util.Duration
16-
import nextflow.util.VersionNumber
1715

1816
import java.nio.file.Path
19-
import java.nio.file.Paths
2017
import java.time.Instant
21-
import java.time.OffsetDateTime
2218
import java.time.ZoneOffset
2319

2420
/**
@@ -72,7 +68,6 @@ class CO2FootprintCLI {
7268
// Collect CO2Records from traces & optionally write the corresponding files
7369
List<CO2Record> co2Records = []
7470
traceRecords.each { TraceRecord traceRecord ->
75-
observer.recordStarted(traceRecord)
7671
co2Records.add(observer.aggregateRecords(traceRecord))
7772
}
7873

src/main/nextflow/co2footprint/CO2FootprintConfig.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import nextflow.co2footprint.Config.ReportFileConfig
66
import nextflow.co2footprint.Config.SummaryFileConfig
77
import nextflow.co2footprint.Config.TraceFileConfig
88
import nextflow.co2footprint.DataContainers.AWSRegionsDataMatrix
9-
import nextflow.co2footprint.DataContainers.MachineTypeDataMatrix
10-
import nextflow.config.spec.ScopeName
11-
import nextflow.config.spec.ConfigScope
12-
import nextflow.config.spec.ConfigOption
13-
import nextflow.script.dsl.Description
149
import nextflow.co2footprint.DataContainers.CIDataMatrix
10+
import nextflow.co2footprint.DataContainers.MachineTypeDataMatrix
1511
import nextflow.co2footprint.DataContainers.TDPDataMatrix
1612
import nextflow.co2footprint.Records.CiRecord
13+
import nextflow.config.spec.ConfigOption
14+
import nextflow.config.spec.ConfigScope
15+
import nextflow.config.spec.ScopeName
16+
import nextflow.script.dsl.Description
1717
import nextflow.trace.TraceHelper
1818

1919
import java.nio.file.Path

src/main/nextflow/co2footprint/CO2FootprintExtension.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class CO2FootprintExtension extends PluginExtensionPoint {
7777
// Collect CO2Records from traces & optionally write the corresponding files
7878
List<CO2Record> co2Records = []
7979
traceRecords.each { TraceRecord traceRecord ->
80-
observer.recordStarted(traceRecord)
8180
co2Records.add(observer.aggregateRecords(traceRecord))
8281
}
8382

src/main/nextflow/co2footprint/CO2FootprintFactory.groovy

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package nextflow.co2footprint
22

3-
import nextflow.co2footprint.DataContainers.CIDataMatrix
4-
import nextflow.co2footprint.DataContainers.TDPDataMatrix
5-
import nextflow.co2footprint.Logging.LoggingAdapter
6-
3+
import groovy.transform.CompileStatic
74
import groovy.transform.PackageScope
85
import groovy.transform.PackageScopeTarget
9-
import groovy.transform.CompileStatic
10-
116
import groovy.util.logging.Slf4j
12-
137
import nextflow.Session
14-
import nextflow.trace.TraceObserver
15-
import nextflow.trace.TraceObserverFactory
8+
import nextflow.co2footprint.DataContainers.CIDataMatrix
9+
import nextflow.co2footprint.DataContainers.TDPDataMatrix
10+
import nextflow.co2footprint.Logging.LoggingAdapter
11+
import nextflow.trace.TraceObserverFactoryV2
12+
import nextflow.trace.TraceObserverV2
1613

1714
/**
1815
* Factory class for creating the CO2Footprint trace observer.
@@ -25,7 +22,7 @@ import nextflow.trace.TraceObserverFactory
2522
@Slf4j
2623
@CompileStatic
2724
@PackageScope(PackageScopeTarget.FIELDS)
28-
class CO2FootprintFactory implements TraceObserverFactory {
25+
class CO2FootprintFactory implements TraceObserverFactoryV2 {
2926
// Nextflow Session
3027
private Session session = null
3128

@@ -71,10 +68,10 @@ class CO2FootprintFactory implements TraceObserverFactory {
7168
* Loads configuration, sets up the observer, and injects all required data.
7269
*
7370
* @param session The Nextflow session
74-
* @return Collection of TraceObserver (with one CO2FootprintObserver)
71+
* @return Collection of TraceObserverV2 (with one CO2FootprintObserver)
7572
*/
7673
@Override
77-
Collection<TraceObserver> create(Session session) {
74+
Collection<TraceObserverV2> create(Session session) {
7875
this.session = session
7976
adaptLogging()
8077

@@ -85,10 +82,10 @@ class CO2FootprintFactory implements TraceObserverFactory {
8582
CO2FootprintCalculator co2FootprintCalculator = new CO2FootprintCalculator(TDPDataMatrix.tdpDataMatrix, config)
8683

8784
// Define list of observers
88-
TraceObserver observer = new CO2FootprintObserver(config, co2FootprintCalculator)
85+
TraceObserverV2 observer = new CO2FootprintObserver(config, co2FootprintCalculator)
8986
CO2FootprintPlugin co2FootprintPlugin = CO2FootprintPlugin.getPlugin()
9087
co2FootprintPlugin?.observer = observer
91-
final ArrayList<TraceObserver> result = [ observer ]
88+
final ArrayList<TraceObserverV2> result = [ observer ]
9289
return result
9390
}
9491
}

src/main/nextflow/co2footprint/CO2FootprintObserver.groovy

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import nextflow.co2footprint.FileCreation.TraceFileCreator
1010
import nextflow.co2footprint.Records.CO2Record
1111
import nextflow.co2footprint.Records.CO2RecordTree
1212
import nextflow.co2footprint.Records.CiRecordCollector
13-
import nextflow.processor.TaskHandler
1413
import nextflow.processor.TaskId
15-
import nextflow.processor.TaskProcessor
1614
import nextflow.script.WorkflowMetadata
17-
import nextflow.trace.TraceObserver
15+
import nextflow.trace.TraceObserverV2
1816
import nextflow.trace.TraceRecord
17+
import nextflow.trace.event.TaskEvent
1918

2019
import java.util.concurrent.ConcurrentHashMap
2120

@@ -30,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap
3029
* Josua Carl <josua.carl@uni-tuebingen.de>
3130
*/
3231
@Slf4j
33-
class CO2FootprintObserver implements TraceObserver {
32+
class CO2FootprintObserver implements TraceObserverV2 {
3433
// Holds workflow session
3534
Session session
3635

@@ -97,20 +96,15 @@ class CO2FootprintObserver implements TraceObserver {
9796
boolean enableMetrics() { return true }
9897

9998
// ------ HELPER METHODS ------
100-
99+
101100
/**
102101
* Records the start of a task by storing its {@link TraceRecord}.
103102
*
104103
* @param trace the TraceRecord of the task that just started
105104
*/
106-
synchronized void recordStarted(TraceRecord traceRecord) {
105+
synchronized void recordStartedTask(TraceRecord traceRecord) {
107106
// Keep started tasks
108107
runningTasks[traceRecord.taskId] = traceRecord
109-
110-
// Add a process node under the workflow if it doesn’t exist yet
111-
if(!workflowStats.getChild(traceRecord.processName)) {
112-
workflowStats.addChild(new CO2RecordTree(traceRecord.processName, [level: 'process']))
113-
}
114108
}
115109

116110
/**
@@ -136,8 +130,13 @@ class CO2FootprintObserver implements TraceObserver {
136130
// Optionally write to trace file
137131
this.traceFile.write(co2Record)
138132

139-
// Add a task node with its CO2Record to the corresponding process
133+
// Add a process node under the workflow if it doesn’t exist yet
140134
CO2RecordTree processNode = workflowStats.getChild(traceRecord.processName)
135+
if(!processNode) {
136+
processNode = workflowStats.addChild(new CO2RecordTree(traceRecord.processName, [level: 'process']))
137+
}
138+
139+
// Add a task node with its CO2Record to the corresponding process
141140
processNode.addChild(new CO2RecordTree(traceRecord.taskId, [level: 'task'], co2Record))
142141

143142
return co2Record
@@ -155,15 +154,14 @@ class CO2FootprintObserver implements TraceObserver {
155154
co2RecordTree.collectAdditionalMetrics()
156155

157156
// Create report and summary if any content exists to write to the file
158-
if (workflowStats) {
157+
if (co2RecordTree) {
159158
summaryFile.create()
160159
summaryFile.write(co2RecordTree, co2FootprintCalculator, config)
161160

162161
reportFile.create()
163162
reportFile.addEntries(co2RecordTree, co2FootprintCalculator, config, timeCiRecordCollector, workflowMetadata)
164163
reportFile.write()
165-
}
166-
if (co2RecordTree) {
164+
167165
provenanceFile.create()
168166
provenanceFile.write(co2RecordTree)
169167
}
@@ -226,77 +224,68 @@ class CO2FootprintObserver implements TraceObserver {
226224
)
227225
}
228226

229-
230-
// ---- PROCESS LEVEL ----
227+
// ---- TASK LEVEL ----
231228

232229
/**
233-
* This method is invoked when a process is created
230+
* Invoked when a task is submitted by an executor to the
231+
* underlying execution backend.
234232
*
235-
* @param process The process created ({@link nextflow.processor.TaskProcessor})
233+
* @param event A task event containing the ({@link nextflow.processor.TaskHandler})
234+
* and ({@link nextflow.trace.TraceRecord}) for the task
236235
*/
237236
@Override
238-
void onProcessCreate(TaskProcessor process) {}
237+
void onTaskSubmit(TaskEvent event) {
238+
log.trace("Trace report - submit process > ${event.handler}")
239239

240-
/**
241-
* This method is invoked before a process run is going to be submitted.
242-
*
243-
* @param handler The task handler ({@link nextflow.processor.TaskHandler})
244-
* @param trace The trace record for the task ({@link nextflow.trace.TraceRecord})
245-
*/
246-
@Override
247-
void onProcessSubmit(TaskHandler handler, TraceRecord trace) {
248-
log.trace("Trace report - submit process > ${handler}")
249-
250-
recordStarted(trace)
240+
recordStartedTask(event.trace)
251241
}
252242

253243
/**
254-
* This method is invoked when a process run is going to start.
244+
* Invoked when a task is running in the underlying execution backend.
255245
*
256-
* @param handler The task handler ({@link nextflow.processor.TaskHandler})
257-
* @param trace The trace record for the task ({@link nextflow.trace.TraceRecord})
246+
* @param event A task event containing the ({@link nextflow.processor.TaskHandler})
247+
* and ({@link nextflow.trace.TraceRecord}) for the task
258248
*/
259-
@Override
260-
void onProcessStart(TaskHandler handler, TraceRecord trace) {
261-
log.trace("Trace report - start process > ${handler}")
249+
void onTaskStart(TaskEvent event) {
250+
log.trace("Trace report - start process > ${event.handler}")
262251

263-
recordStarted(trace)
252+
recordStartedTask(event.trace)
264253
}
265254

266255
/**
267-
* This method is invoked when a process run completes.
256+
* Invoked when a task completes.
268257
*
269-
* @param handler The task handler ({@link nextflow.processor.TaskHandler})
270-
* @param trace The trace record for the task ({@link nextflow.trace.TraceRecord})
258+
* @param event A task event containing the ({@link nextflow.processor.TaskHandler})
259+
* and ({@link nextflow.trace.TraceRecord}) for the task
271260
*/
272261
@Override
273-
void onProcessComplete(TaskHandler handler, TraceRecord trace) {
274-
log.trace("Trace report - complete process > ${handler}")
262+
void onTaskComplete(TaskEvent event) {
263+
log.trace("Trace report - complete process > ${event.handler}")
275264

276265
// Ensure the presence of a Trace BaseRecord
277-
if (!trace) {
278-
log.warn("Unable to find TraceRecord for task with id: ${handler.task.id}")
266+
if (!event.trace) {
267+
log.warn("Unable to find TraceRecord for task with id: ${event.handler.task.id}")
279268
return
280269
}
281270

282-
aggregateRecords(trace)
271+
aggregateRecords(event.trace)
283272
}
284273

285274
/**
286-
* This method is invoked when a process was cached.
275+
* Invoked when a task execution is skipped because the result is cached (already computed)
276+
* or stored (using the `storeDir` directive).
287277
*
288-
* @param handler The task handler ({@link nextflow.processor.TaskHandler})
289-
* @param trace The trace record for the task ({@link nextflow.trace.TraceRecord})
278+
* @param event A task event containing the ({@link nextflow.processor.TaskHandler})
279+
* and ({@link nextflow.trace.TraceRecord}) for the task
290280
*/
291281
@Override
292-
void onProcessCached(TaskHandler handler, TraceRecord trace) {
293-
log.trace("Trace report - cached process > ${handler}")
282+
void onTaskCached(TaskEvent event) {
283+
log.trace("Trace report - cached process > ${event.handler}")
294284

295285
// Event was triggered by a stored task, ignore it
296-
if (trace == null) { return }
297-
298-
recordStarted(trace) // add also cashed tasks to the runningTasks to be able to report them in the output files
299-
aggregateRecords(trace)
300-
}
286+
if (event.trace == null) { return }
301287

288+
recordStartedTask(event.trace) // add also cashed tasks to the runningTasks to be able to report them in the output files
289+
aggregateRecords(event.trace)
290+
}
302291
}

src/main/nextflow/co2footprint/CO2FootprintPlugin.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ package nextflow.co2footprint
1919
import groovy.transform.CompileStatic
2020
import groovy.util.logging.Slf4j
2121
import nextflow.cli.PluginAbstractExec
22-
23-
import nextflow.co2footprint.Recorders.SessionTraceRecorder
2422
import nextflow.co2footprint.Parsers.ArgsParser
23+
import nextflow.co2footprint.Recorders.SessionTraceRecorder
2524
import nextflow.co2footprint.Records.CO2Record
2625
import nextflow.co2footprint.Records.CO2RecordTree
2726
import nextflow.plugin.BasePlugin

src/main/nextflow/co2footprint/Config/BaseFileConfig.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import groovy.util.logging.Slf4j
44
import nextflow.co2footprint.CO2FootprintConfig
55
import nextflow.config.spec.ConfigOption
66
import nextflow.script.dsl.Description
7+
78
import java.nio.file.Path
89

910
/**

src/main/nextflow/co2footprint/FileCreation/ProvenanceFileCreator.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package nextflow.co2footprint.FileCreation
22

3+
import groovy.json.JsonBuilder
34
import groovyx.gpars.agent.Agent
45
import nextflow.co2footprint.Config.ProvenanceFileConfig
56
import nextflow.co2footprint.Records.CO2RecordTree
67
import nextflow.trace.TraceHelper
7-
import groovy.json.JsonBuilder
88

99
import java.time.Duration
1010
import java.time.Instant

0 commit comments

Comments
 (0)