Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit 9264fa3

Browse files
committed
Add a webdav archive worker
1 parent f917564 commit 9264fa3

File tree

4 files changed

+108
-12
lines changed

4 files changed

+108
-12
lines changed

archive/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@
1212
<groupId>taskworker.workers</groupId>
1313
<artifactId>archive</artifactId>
1414

15+
<dependencies>
16+
<dependency>
17+
<groupId>com.github.lookfirst</groupId>
18+
<artifactId>sardine</artifactId>
19+
<version>5.0.1</version>
20+
</dependency>
21+
</dependencies>
1522
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Copyright 2013 KU Leuven Research and Development - iMinds - Distrinet
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
Administrative Contact: [email protected]
17+
Technical Contact: [email protected]
18+
*/
19+
20+
package drm.taskworker.workers;
21+
22+
import static drm.taskworker.config.Config.cfg;
23+
24+
import java.io.IOException;
25+
import java.util.List;
26+
import java.util.logging.Level;
27+
28+
import com.github.sardine.DavResource;
29+
import com.github.sardine.Sardine;
30+
import com.github.sardine.SardineFactory;
31+
32+
import drm.taskworker.Worker;
33+
import drm.taskworker.tasks.ParameterFoundException;
34+
import drm.taskworker.tasks.Task;
35+
import drm.taskworker.tasks.TaskResult;
36+
37+
/**
38+
* Collect all files in a workflow and zip them when an end of workflow task
39+
* is received.
40+
*
41+
* @author Bart Vanbrabant <[email protected]>
42+
*/
43+
public class WebdavArchiveWorker extends Worker {
44+
/**
45+
* Creates a new work with the name blob-to-cache
46+
*/
47+
public WebdavArchiveWorker(String workerName) {
48+
super(workerName);
49+
}
50+
51+
/**
52+
* Archive the result of the previous task
53+
*/
54+
public TaskResult work(Task task) {
55+
logger.info("Archiving file");
56+
TaskResult result = new TaskResult();
57+
58+
byte[] fileData = null;
59+
60+
try {
61+
fileData = (byte[])task.getParam("arg0");
62+
} catch (ParameterFoundException e) {
63+
return result.setResult(TaskResult.Result.ARGUMENT_ERROR);
64+
}
65+
66+
try {
67+
// WebDAV URL:
68+
final String baseUrl = cfg().getProperty("taskworker.archive.url");
69+
if (baseUrl == null) {
70+
logger.log(Level.SEVERE, "No base url configured to upload result to.");
71+
return result.setResult(TaskResult.Result.ARGUMENT_ERROR);
72+
}
73+
74+
Sardine sardine = SardineFactory.begin(cfg().getProperty("taskworker.archive.username", "admin"),
75+
cfg().getProperty("taskworker.archive.password", "admin"));
76+
List<DavResource> resources = sardine.list(baseUrl);
77+
78+
sardine.put(baseUrl + task.getJobId().toString(), fileData, "application/zip");
79+
80+
Task newTask = new Task(task, this.getNextWorker(task.getJobId()));
81+
result.addNextTask(newTask);
82+
83+
} catch (IOException e) {
84+
result.setResult(TaskResult.Result.EXCEPTION);
85+
result.setException(e);
86+
return result;
87+
}
88+
89+
return result.setResult(TaskResult.Result.SUCCESS);
90+
}
91+
}

join/src/main/java/drm/taskworker/workers/JoinWorker.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ public TaskResult work(Task task) {
8686

8787
// load all parents and build the map of parameters
8888
Map<String, List<Object>> varMap = new HashMap<>();
89+
List<Task> parents = newTask.getParents();
90+
logger.info("Joining the results of " + parents.size() + " parents");
8991

90-
for (Task parentTask : newTask.getParents()) {
92+
for (Task parentTask : parents) {
9193
for (String paramName : parentTask.getParamNames()) {
9294
if (!varMap.containsKey(paramName)) {
9395
varMap.put(paramName, new ArrayList<Object>());

workflow-upnxt/config.yaml

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
workers:
3-
- {name: csv-to-task, class: drm.taskworker.workers.CSVtoTaskWorker, threads: 2, code: "target/upnxt-0.2.0-SNAPSHOT-jar-with-dependencies.jar"}
4-
- {name: template-to-xml, class: drm.taskworker.workers.TemplateWorker, threads: 2, code: "target/upnxt-0.2.0-SNAPSHOT-jar-with-dependencies.jar"}
5-
- {name: xsl-fo-render, class: drm.taskworker.workers.XslFoRenderWorker, threads: 2, code: "target/upnxt-0.2.0-SNAPSHOT-jar-with-dependencies.jar"}
6-
- {name: zip-files, class: drm.taskworker.workers.ZipWorker, threads: 2, code: "target/upnxt-0.2.0-SNAPSHOT-jar-with-dependencies.jar"}
7-
- {name: join, class: drm.taskworker.workers.JoinWorker, threads: 2, code: "target/upnxt-0.2.0-SNAPSHOT-jar-with-dependencies.jar"}
8-
- {name: archive, class: drm.taskworker.workers.ArchiveWorker, threads: 2, code: "target/upnxt-0.2.0-SNAPSHOT-jar-with-dependencies.jar"}
9-
- {name: end, class: drm.taskworker.workers.EndWorker, threads: 1, code: "target/upnxt-0.2.0-SNAPSHOT-jar-with-dependencies.jar"}
3+
- {name: csv-to-task, class: drm.taskworker.workers.CSVtoTaskWorker, threads: 2, code: "target/upnxt-0.4.0-SNAPSHOT-jar-with-dependencies.jar"}
4+
- {name: template-to-xml, class: drm.taskworker.workers.TemplateWorker, threads: 2, code: "target/upnxt-0.4.0-SNAPSHOT-jar-with-dependencies.jar"}
5+
- {name: xsl-fo-render, class: drm.taskworker.workers.XslFoRenderWorker, threads: 2, code: "target/upnxt-0.4.0-SNAPSHOT-jar-with-dependencies.jar"}
6+
- {name: zip-files, class: drm.taskworker.workers.ZipWorker, threads: 2, code: "target/upnxt-0.4.0-SNAPSHOT-jar-with-dependencies.jar"}
7+
- {name: join, class: drm.taskworker.workers.JoinWorker, threads: 2, code: "target/upnxt-0.4.0-SNAPSHOT-jar-with-dependencies.jar"}
8+
- {name: archive, class: drm.taskworker.workers.WebdavArchiveWorker, threads: 2, code: "target/upnxt-0.4.0-SNAPSHOT-jar-with-dependencies.jar"}
9+
- {name: end, class: drm.taskworker.workers.EndWorker, threads: 1, code: "target/upnxt-0.4.0-SNAPSHOT-jar-with-dependencies.jar"}
1010

1111

1212
workflows:
@@ -20,10 +20,6 @@ workflows:
2020
archive: {next: end}
2121
start: csv-to-task
2222
end: end
23-
timeout: {
24-
default: 15,
25-
xsl-fo-render: 30
26-
}
2723

2824
scheduler:
2925
class: drm.taskworker.schedule.FairShare

0 commit comments

Comments
 (0)