@@ -32,9 +32,8 @@ import nextflow.lineage.model.Checksum
32
32
import nextflow.lineage.model.FileOutput
33
33
import nextflow.lineage.model.DataPath
34
34
import nextflow.lineage.model.Parameter
35
- import nextflow.lineage.model.TaskOutput
36
35
import nextflow.lineage.model.Workflow
37
- import nextflow.lineage.model.WorkflowOutput
36
+ import nextflow.lineage.model.WorkflowLaunch
38
37
import nextflow.lineage.model.WorkflowRun
39
38
import nextflow.file.FileHelper
40
39
import nextflow.file.FileHolder
@@ -84,10 +83,10 @@ class LinObserver implements TraceObserverV2 {
84
83
(EachInParam ) : " each"
85
84
]
86
85
87
- private String executionHash
86
+ private String launchId
88
87
private LinStore store
89
88
private Session session
90
- private WorkflowOutput workflowOutput
89
+ private List< Parameter > outputs = new LinkedList< Parameter > ()
91
90
private Map<String ,String > outputsStoreDirLid = new HashMap<String ,String > (10 )
92
91
private PathNormalizer normalizer
93
92
@@ -97,34 +96,32 @@ class LinObserver implements TraceObserverV2 {
97
96
}
98
97
99
98
@TestOnly
100
- String getExecutionHash (){ executionHash }
101
-
102
- @TestOnly
103
- String setExecutionHash (String hash ){ this . executionHash = hash }
99
+ String setLaunchId (String hash ){ this . launchId = hash }
104
100
105
101
@TestOnly
106
102
String setNormalizer (PathNormalizer normalizer ){ this . normalizer = normalizer }
107
103
108
104
@Override
109
105
void onFlowBegin () {
110
106
normalizer = new PathNormalizer (session. workflowMetadata)
111
- executionHash = storeWorkflowRun(normalizer)
112
- final executionUri = asUriString(executionHash)
113
- workflowOutput = new WorkflowOutput (
114
- OffsetDateTime . now(),
115
- executionUri,
116
- new LinkedList<Parameter > ()
117
- )
118
- this . store. getHistoryLog(). write(session. runName, session. uniqueId, executionUri)
107
+ launchId = storeWorkflowLaunch(normalizer)
108
+ this . store. getHistoryLog(). write(session. runName, session. uniqueId, asUriString(launchId))
119
109
}
120
110
121
111
@Override
122
- void onFlowComplete (){
123
- if (workflowOutput?. output ){
124
- workflowOutput. createdAt = OffsetDateTime . now()
125
- final key = executionHash + ' #output'
126
- this . store. save(key, workflowOutput)
127
- }
112
+ void onFlowComplete () {
113
+ final status = session. isCancelled()
114
+ ? " CANCELLED"
115
+ : session. isSuccess() ? " SUCCEEDED" : " FAILED"
116
+ final workflowRun = new WorkflowRun (
117
+ OffsetDateTime . now(),
118
+ asUriString(launchId),
119
+ status,
120
+ outputs
121
+ )
122
+ final runId = CacheHelper . hasher(workflowRun). hash(). toString()
123
+ this . store. save(runId, workflowRun)
124
+ this . store. getHistoryLog(). finalize(session. uniqueId, asUriString(runId), status)
128
125
}
129
126
130
127
protected Collection<Path > allScriptFiles () {
@@ -150,24 +147,24 @@ class LinObserver implements TraceObserverV2 {
150
147
return result. sort{it. path}
151
148
}
152
149
153
- protected String storeWorkflowRun (PathNormalizer normalizer ) {
150
+ protected String storeWorkflowLaunch (PathNormalizer normalizer ) {
154
151
// create the workflow object holding script files and repo tracking info
155
152
final workflow = new Workflow (
156
153
collectScriptDataPaths(normalizer),
157
154
session. workflowMetadata. repository,
158
155
session. workflowMetadata. commitId
159
156
)
160
157
// create the workflow run main object
161
- final value = new WorkflowRun (
158
+ final value = new WorkflowLaunch (
162
159
workflow,
163
160
session. uniqueId. toString(),
164
161
session. runName,
165
162
getNormalizedParams(session. params, normalizer),
166
163
SecretHelper . hideSecrets(session. config. deepClone()) as Map
167
164
)
168
- final executionHash = CacheHelper . hasher(value). hash(). toString()
169
- store. save(executionHash , value)
170
- return executionHash
165
+ final launchId = CacheHelper . hasher(value). hash(). toString()
166
+ store. save(launchId , value)
167
+ return launchId
171
168
}
172
169
173
170
protected static List<Parameter > getNormalizedParams (Map<String , Object > params , PathNormalizer normalizer ){
@@ -180,43 +177,6 @@ class LinObserver implements TraceObserverV2 {
180
177
return normalizedParams
181
178
}
182
179
183
- @Override
184
- void onTaskComplete (TaskEvent event ) {
185
- storeTaskInfo(event. handler. task)
186
- }
187
-
188
- protected void storeTaskInfo (TaskRun task ) {
189
- // store the task run entry
190
- storeTaskRun(task, normalizer)
191
- // store all task results
192
- storeTaskResults(task, normalizer)
193
- }
194
-
195
- protected String storeTaskResults (TaskRun task , PathNormalizer normalizer ){
196
- final outputParams = getNormalizedTaskOutputs(task, normalizer)
197
- final value = new TaskOutput ( asUriString(task. hash. toString()), asUriString(executionHash), OffsetDateTime . now(), outputParams )
198
- final key = task. hash. toString() + ' #output'
199
- store. save(key,value)
200
- return key
201
- }
202
-
203
- private List<Parameter > getNormalizedTaskOutputs (TaskRun task , PathNormalizer normalizer ){
204
- final outputs = task. getOutputs()
205
- final outputParams = new LinkedList<Parameter > ()
206
- for ( Map.Entry < OutParam ,Object > entry : outputs ) {
207
- manageTaskOutputParameter(entry. key, outputParams, entry. value, task, normalizer)
208
- }
209
- return outputParams
210
- }
211
-
212
- private void manageTaskOutputParameter (OutParam key , LinkedList<Parameter > outputParams , value , TaskRun task , PathNormalizer normalizer ) {
213
- if (key instanceof FileOutParam ) {
214
- outputParams. add(new Parameter (getParameterType(key), key. name, manageFileOutParam(value, task)))
215
- } else {
216
- outputParams. add(new Parameter (getParameterType(key), key. name, normalizeValue(value, normalizer)))
217
- }
218
- }
219
-
220
180
private static Object normalizeValue (Object value , PathNormalizer normalizer ) {
221
181
if (value instanceof Path )
222
182
return normalizer. normalizePath((Path )value)
@@ -226,6 +186,11 @@ class LinObserver implements TraceObserverV2 {
226
186
return value
227
187
}
228
188
189
+ @Override
190
+ void onTaskComplete (TaskEvent event ) {
191
+ storeTaskRun(event. handler. task, normalizer)
192
+ }
193
+
229
194
private Object manageFileOutParam (Object value , TaskRun task ) {
230
195
if (value == null ) {
231
196
log. debug " Unexpected lineage File output value null"
@@ -247,7 +212,7 @@ class LinObserver implements TraceObserverV2 {
247
212
248
213
protected String storeTaskRun (TaskRun task , PathNormalizer normalizer ) {
249
214
final codeChecksum = Checksum . ofNextflow(session. stubRun ? task. stubSource : task. source)
250
- final value = new nextflow.lineage.model.TaskRun (
215
+ final taskRun = new nextflow.lineage.model.TaskRun (
251
216
session. uniqueId. toString(),
252
217
task. getName(),
253
218
codeChecksum,
@@ -262,12 +227,19 @@ class LinObserver implements TraceObserverV2 {
262
227
normalizer. normalizePath(p. normalize()),
263
228
Checksum . ofNextflow(p) )
264
229
},
265
- asUriString(executionHash )
230
+ asUriString(launchId )
266
231
)
267
232
268
233
// store in the underlying persistence
269
234
final key = task. hash. toString()
270
- store. save(key, value)
235
+ store. save(key, taskRun)
236
+
237
+ // store file outputs
238
+ task. outputs. forEach { OutParam param , Object value ->
239
+ if (param instanceof FileOutParam )
240
+ manageFileOutParam(value, task)
241
+ }
242
+
271
243
return key
272
244
}
273
245
@@ -280,7 +252,7 @@ class LinObserver implements TraceObserverV2 {
280
252
path. toUriString(),
281
253
checksum,
282
254
asUriString(task. hash. toString()),
283
- asUriString(executionHash ),
255
+ asUriString(launchId ),
284
256
asUriString(task. hash. toString()),
285
257
attrs. size(),
286
258
LinUtils . toDate(attrs?. creationTime()),
@@ -300,7 +272,7 @@ class LinObserver implements TraceObserverV2 {
300
272
301
273
protected String getWorkflowOutputKey (Path target ) {
302
274
final rel = getWorkflowRelative(target)
303
- return executionHash + SEPARATOR + rel
275
+ return launchId + SEPARATOR + rel
304
276
}
305
277
306
278
protected String getTaskRelative (TaskRun task , Path path ){
@@ -345,13 +317,13 @@ class LinObserver implements TraceObserverV2 {
345
317
final key = getWorkflowOutputKey(event. target)
346
318
final sourceReference = event. source
347
319
? getSourceReference(event. source)
348
- : asUriString(executionHash )
320
+ : asUriString(launchId )
349
321
final attrs = readAttributes(event. target)
350
322
final value = new FileOutput (
351
323
event. target. toUriString(),
352
324
checksum,
353
325
sourceReference,
354
- asUriString(executionHash ),
326
+ asUriString(launchId ),
355
327
null ,
356
328
attrs. size(),
357
329
LinUtils . toDate(attrs?. creationTime()),
@@ -363,7 +335,7 @@ class LinObserver implements TraceObserverV2 {
363
335
log. warn1(" Lineage for workflow output is not supported by publishDir directive" )
364
336
}
365
337
catch (Throwable e) {
366
- log. warn(" Unexpected error storing published file '${ event.target.toUriString()} ' for workflow '${ executionHash } '" , e)
338
+ log. warn(" Unexpected error storing published file '${ event.target.toUriString()} ' for workflow '${ launchId } '" , e)
367
339
}
368
340
}
369
341
@@ -381,7 +353,7 @@ class LinObserver implements TraceObserverV2 {
381
353
void onWorkflowOutput (WorkflowOutputEvent event ) {
382
354
final type = getParameterType(event. value)
383
355
final value = convertPathsToLidReferences(event. index ?: event. value)
384
- workflowOutput . output . add(new Parameter (type, event. name, value))
356
+ outputs . add(new Parameter (type, event. name, value))
385
357
}
386
358
387
359
protected static String getParameterType (Object param ) {
0 commit comments