]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java
Remote shutdown
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / main / java / org / argeo / slc / process / SlcExecutionStep.java
1 package org.argeo.slc.process;
2
3 import java.io.IOException;
4 import java.io.StringReader;
5 import java.util.ArrayList;
6 import java.util.Date;
7 import java.util.List;
8 import java.util.UUID;
9
10 import org.apache.commons.io.IOUtils;
11
12 public class SlcExecutionStep {
13 public final static String TYPE_START = "START";
14 public final static String TYPE_END = "END";
15 public final static String TYPE_PHASE_START = "PHASE_START";
16 public final static String TYPE_PHASE_END = "PHASE_END";
17 public final static String TYPE_LOG = "LOG";
18
19 private String uuid = UUID.randomUUID().toString();
20 private String type;
21 private Date begin = new Date();
22 private List<String> logLines = new ArrayList<String>();
23
24 /** Empty constructor */
25 public SlcExecutionStep() {
26 }
27
28 /** Creates a step of type LOG. */
29 public SlcExecutionStep(String log) {
30 this(TYPE_LOG, log);
31 }
32
33 /** Creates a step of the given type. */
34 public SlcExecutionStep(String type, String log) {
35 this.type = type;
36 addLog(log);
37 }
38
39 public String getUuid() {
40 return uuid;
41 }
42
43 public void setUuid(String uuid) {
44 this.uuid = uuid;
45 }
46
47 public String getType() {
48 return type;
49 }
50
51 public void setType(String type) {
52 this.type = type;
53 }
54
55 public Date getBegin() {
56 return begin;
57 }
58
59 public void setBegin(Date begin) {
60 this.begin = begin;
61 }
62
63 public List<String> getLogLines() {
64 return logLines;
65 }
66
67 public void setLogLines(List<String> logLines) {
68 this.logLines = logLines;
69 }
70
71 @SuppressWarnings(value = { "unchecked" })
72 public void addLog(String log) {
73 if (log == null)
74 return;
75
76 try {
77 List<String> lines = IOUtils.readLines(new StringReader(log));
78 logLines.addAll(lines);
79 } catch (IOException e) {
80 throw new RuntimeException("Cannot add log", e);
81 }
82 }
83
84 @Override
85 public String toString() {
86 return getClass().getSimpleName() + "#" + uuid;
87 }
88
89 }