1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.savvis.vpdc.domain;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import java.net.URI;
24 import java.util.Date;
25
26 import javax.annotation.Nullable;
27
28
29
30
31
32
33
34
35 public class Task extends ResourceImpl {
36 public static Builder builder() {
37 return new Builder();
38 }
39
40 public static class Builder extends ResourceImpl.Builder {
41 private Status status;
42 private Date startTime;
43 private Date endTime;
44 private Resource owner;
45 private Resource result;
46 private TaskError error;
47
48 public Builder status(Status status) {
49 this.status = status;
50 return this;
51 }
52
53 public Builder startTime(Date startTime) {
54 this.startTime = startTime;
55 return this;
56 }
57
58 public Builder endTime(Date endTime) {
59 this.endTime = endTime;
60 return this;
61 }
62
63 public Builder owner(Resource owner) {
64 this.owner = owner;
65 return this;
66 }
67
68 public Builder result(Resource result) {
69 this.result = result;
70 return this;
71 }
72
73 public Builder error(TaskError error) {
74 this.error = error;
75 return this;
76 }
77
78 @Override
79 public Builder id(String id) {
80 return Builder.class.cast(super.id(id));
81 }
82
83 @Override
84 public Builder name(String name) {
85 return Builder.class.cast(super.name(name));
86 }
87
88 @Override
89 public Builder type(String type) {
90 return Builder.class.cast(super.type(type));
91 }
92
93 @Override
94 public Builder href(URI href) {
95 return Builder.class.cast(super.href(href));
96 }
97
98 @Override
99 public Task build() {
100 return new Task(id, name, type, href, status, startTime, endTime, owner, result, error);
101 }
102
103 public static Builder fromTask(Task in) {
104 return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
105 .status(in.getStatus()).startTime(in.getStartTime()).endTime(in.getEndTime()).owner(in.getOwner())
106 .error(in.getError()).result(in.getResult());
107 }
108 }
109
110 public enum Status {
111
112
113
114 SUCCESS,
115
116
117
118
119 RUNNING,
120
121
122
123
124
125 QUEUED,
126
127
128
129
130 ERROR,
131
132
133
134
135 NONE, UNRECOGNIZED;
136 public String value() {
137 return name().toLowerCase();
138 }
139
140 @Override
141 public String toString() {
142 return value();
143 }
144
145 public static Status fromValue(String status) {
146 try {
147 return valueOf(checkNotNull(status, "status").toUpperCase());
148 } catch (IllegalArgumentException e) {
149 return UNRECOGNIZED;
150 }
151 }
152
153 }
154
155 private final Status status;
156 private final Date startTime;
157 private final Date endTime;
158 private final Resource owner;
159 private final Resource result;
160 private final TaskError error;
161
162 public Task(String id, String name, String type, URI href, Status status, Date startTime, Date endTime,
163 Resource result, Resource owner, TaskError error) {
164 super(id, name, type, href);
165 this.status = status;
166 this.startTime = startTime;
167 this.endTime = endTime;
168 this.owner = owner;
169 this.result = result;
170 this.error = error;
171 }
172
173
174
175
176 public Status getStatus() {
177 return status;
178 }
179
180
181
182
183 public Date getStartTime() {
184 return startTime;
185 }
186
187
188
189
190 @Nullable
191 public Date getEndTime() {
192 return endTime;
193 }
194
195
196
197
198
199
200 @Nullable
201 public Resource getOwner() {
202 return owner;
203 }
204
205
206
207
208
209 @Nullable
210 public Resource getResult() {
211 return result;
212 }
213
214
215
216
217 @Nullable
218 public TaskError getError() {
219 return error;
220 }
221
222 public Builder toBuilder() {
223 return Builder.fromTask(this);
224 }
225
226 @Override
227 public String toString() {
228 return "[id=" + id + ", name=" + name + ", type=" + type + ", href=" + href + ", status=" + status
229 + ", startTime=" + startTime + ", endTime=" + endTime + ", owner=" + owner + ", result=" + result
230 + ", error=" + error + "]";
231 }
232
233 }