19
19
20
20
package org .commonwl .view .cwl ;
21
21
22
+ import java .io .IOException ;
23
+ import java .nio .file .Path ;
24
+ import java .util .Date ;
25
+
22
26
import org .apache .jena .query .QueryException ;
27
+ import org .commonwl .view .git .GitDetails ;
28
+ import org .commonwl .view .git .GitSemaphore ;
29
+ import org .commonwl .view .git .GitService ;
23
30
import org .commonwl .view .researchobject .ROBundleFactory ;
24
31
import org .commonwl .view .workflow .QueuedWorkflow ;
25
32
import org .commonwl .view .workflow .QueuedWorkflowRepository ;
26
33
import org .commonwl .view .workflow .Workflow ;
27
34
import org .commonwl .view .workflow .WorkflowRepository ;
35
+ import org .eclipse .jgit .api .Git ;
28
36
import org .slf4j .Logger ;
29
37
import org .slf4j .LoggerFactory ;
30
38
import org .springframework .beans .factory .annotation .Autowired ;
31
39
import org .springframework .scheduling .annotation .Async ;
32
40
import org .springframework .scheduling .annotation .EnableAsync ;
33
41
import org .springframework .stereotype .Component ;
34
42
35
- import java .io .File ;
36
- import java .io .IOException ;
37
- import java .util .Date ;
38
-
39
43
/**
40
44
* Replace existing workflow with the one given by cwltool
41
45
*/
@@ -50,31 +54,38 @@ public class CWLToolRunner {
50
54
private final CWLService cwlService ;
51
55
private final ROBundleFactory roBundleFactory ;
52
56
private final String cwlToolVersion ;
57
+ private final GitSemaphore gitSemaphore ;
58
+ private final GitService gitService ;
53
59
54
60
@ Autowired
55
- public CWLToolRunner (WorkflowRepository workflowRepository ,
56
- QueuedWorkflowRepository queuedWorkflowRepository ,
57
- CWLService cwlService ,
58
- CWLTool cwlTool ,
59
- ROBundleFactory roBundleFactory ) {
61
+ public CWLToolRunner (WorkflowRepository workflowRepository , QueuedWorkflowRepository queuedWorkflowRepository ,
62
+ CWLService cwlService , CWLTool cwlTool , ROBundleFactory roBundleFactory , GitSemaphore gitSemaphore ,
63
+ GitService gitService ) {
60
64
this .workflowRepository = workflowRepository ;
61
65
this .queuedWorkflowRepository = queuedWorkflowRepository ;
62
66
this .cwlService = cwlService ;
63
67
this .cwlToolVersion = cwlTool .getVersion ();
64
68
this .roBundleFactory = roBundleFactory ;
69
+ this .gitSemaphore = gitSemaphore ;
70
+ this .gitService = gitService ;
65
71
}
66
72
67
73
@ Async
68
- public void createWorkflowFromQueued (QueuedWorkflow queuedWorkflow , File workflowFile )
74
+ public void createWorkflowFromQueued (QueuedWorkflow queuedWorkflow )
69
75
throws IOException , InterruptedException {
70
76
71
77
Workflow tempWorkflow = queuedWorkflow .getTempRepresentation ();
72
-
78
+ GitDetails gitInfo = tempWorkflow .getRetrievedFrom ();
79
+ final String repoUrl = gitInfo .getRepoUrl ();
73
80
// Parse using cwltool and replace in database
74
81
try {
82
+ boolean safeToAccess = gitSemaphore .acquire (repoUrl );
83
+ Git repo = gitService .getRepository (gitInfo , safeToAccess );
84
+ Path localPath = repo .getRepository ().getWorkTree ().toPath ();
85
+ Path workflowFile = localPath .resolve (gitInfo .getPath ()).normalize ().toAbsolutePath ();
75
86
Workflow newWorkflow = cwlService .parseWorkflowWithCwltool (
76
87
tempWorkflow ,
77
- workflowFile );
88
+ workflowFile . toFile () );
78
89
79
90
// Success
80
91
newWorkflow .setRetrievedFrom (tempWorkflow .getRetrievedFrom ());
@@ -105,6 +116,7 @@ public void createWorkflowFromQueued(QueuedWorkflow queuedWorkflow, File workflo
105
116
"error occurred in CWLViewer!\n " +
106
117
"Help us by reporting it on Gitter or a Github issue\n " );
107
118
} finally {
119
+ gitSemaphore .release (repoUrl );
108
120
queuedWorkflowRepository .save (queuedWorkflow );
109
121
}
110
122
0 commit comments