1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.app.daemon.domain;
18
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.io.OutputStream;
22 import java.util.UUID;
23
24 import org.gwe.GWEAppContext;
25 import org.gwe.persistence.model.DaemonConfigDesc;
26 import org.gwe.persistence.model.DaemonInstallation;
27 import org.gwe.persistence.model.OrderInfo;
28 import org.gwe.utils.IOUtils;
29
30 import com.thoughtworks.xstream.XStream;
31 import com.thoughtworks.xstream.io.xml.DomDriver;
32
33
34
35
36
37 public class ResultsPublisher {
38
39 private DaemonConfigDesc config;
40
41 public ResultsPublisher(DaemonConfigDesc config) {
42 this.config = config;
43 }
44
45 public void publishOrder(OrderInfo order, String publisherURI) {
46 try {
47 publish(order, publisherURI);
48 } catch (Exception e) {
49
50 e.printStackTrace();
51 }
52 }
53
54 private void publish(OrderInfo order, String publisherURI) throws Exception {
55 String wsPath = config.getHeadResource().getInstallation().getWorkspacePath();
56 String destURI = IOUtils.concatenatePaths(publisherURI, UUID.randomUUID().toString());
57 String sourceDir = serializeOrder(order, wsPath);
58 GWEAppContext.getGridFileSystem().uploadFile(sourceDir, destURI, config.getKeys());
59 }
60
61 private String serializeOrder(OrderInfo order, String wsPath) throws IOException {
62 String sourceDir = IOUtils.concatenatePaths(wsPath, "tmp", "results", order.getUniversalId());
63 DaemonInstallation.createIfNonExistent(sourceDir);
64 XStream result = new XStream(new DomDriver());
65 OutputStream fos = new FileOutputStream(IOUtils.concatenatePaths(sourceDir, "order.xml"));
66 result.toXML(order, fos);
67 return sourceDir;
68 }
69
70 public static void main(String[] args) throws IOException {
71 ResultsPublisher publisher = new ResultsPublisher(null);
72 OrderInfo order = new OrderInfo();
73 order.stampWhenCreated();
74 System.out.println(publisher.serializeOrder(order, "/Users/admin/gwe-daemon/test-workspace"));
75 }
76 }
77