This project has retired. For details please refer to its
Attic page.
001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.oozie.client.rest;
019
020 import org.apache.oozie.client.WorkflowAction;
021 import org.json.simple.JSONArray;
022 import org.json.simple.JSONObject;
023
024 import java.text.MessageFormat;
025 import java.util.Date;
026 import java.util.List;
027
028 import javax.persistence.*;
029
030 /**
031 * Json Bean that represents an Oozie workflow node.
032 */
033 @Entity
034 @Table(name = "WF_ACTIONS")
035 @DiscriminatorColumn(name = "bean_type", discriminatorType = DiscriminatorType.STRING)
036
037 public class JsonWorkflowAction implements WorkflowAction, JsonBean {
038 @Id
039 private String id;
040
041 @Basic
042 @Column(name = "name")
043 private String name = null;
044
045 @Basic
046 @Column(name = "cred")
047 private String cred = null;
048
049 @Basic
050 @Column(name = "type")
051 private String type = null;
052
053 @Basic
054 @Column(name = "conf")
055 @Lob
056 private String conf = null;
057
058 @Transient
059 private Status status = WorkflowAction.Status.PREP;
060
061 @Basic
062 @Column(name = "retries")
063 private int retries;
064
065 @Basic
066 @Column(name = "user_retry_count")
067 private int userRetryCount;
068
069 @Basic
070 @Column(name = "user_retry_max")
071 private int userRetryMax;
072
073 @Basic
074 @Column(name = "user_retry_interval")
075 private int userRetryInterval;
076
077 @Transient
078 private Date startTime;
079
080 @Transient
081 private Date endTime;
082
083 @Basic
084 @Column(name = "transition")
085 private String transition = null;
086
087 @Column(name = "data")
088 @Lob
089 private String data = null;
090
091 @Column(name = "stats")
092 @Lob
093 private String stats = null;
094
095 @Column(name = "external_child_ids")
096 @Lob
097 private String externalChildIDs = null;
098
099 @Basic
100 @Column(name = "external_id")
101 private String externalId = null;
102
103 @Basic
104 @Column(name = "external_status")
105 private String externalStatus = null;
106
107 @Basic
108 @Column(name = "tracker_uri")
109 private String trackerUri = null;
110
111 @Basic
112 @Column(name = "console_url")
113 private String consoleUrl = null;
114
115 @Basic
116 @Column(name = "error_code")
117 private String errorCode = null;
118
119 @Column(name = "error_message")
120 @Lob
121 private String errorMessage = null;
122
123 public JsonWorkflowAction() {
124 }
125
126 @SuppressWarnings("unchecked")
127 public JSONObject toJSONObject() {
128 JSONObject json = new JSONObject();
129 json.put(JsonTags.WORKFLOW_ACTION_ID, id);
130 json.put(JsonTags.WORKFLOW_ACTION_NAME, name);
131 json.put(JsonTags.WORKFLOW_ACTION_AUTH, cred);
132 json.put(JsonTags.WORKFLOW_ACTION_TYPE, type);
133 json.put(JsonTags.WORKFLOW_ACTION_CONF, conf);
134 json.put(JsonTags.WORKFLOW_ACTION_STATUS, status.toString());
135 json.put(JsonTags.WORKFLOW_ACTION_RETRIES, (long) retries);
136 json.put(JsonTags.WORKFLOW_ACTION_START_TIME, JsonUtils.formatDateRfc822(startTime));
137 json.put(JsonTags.WORKFLOW_ACTION_END_TIME, JsonUtils.formatDateRfc822(endTime));
138 json.put(JsonTags.WORKFLOW_ACTION_TRANSITION, transition);
139 json.put(JsonTags.WORKFLOW_ACTION_DATA, data);
140 json.put(JsonTags.WORKFLOW_ACTION_STATS, stats);
141 json.put(JsonTags.WORKFLOW_ACTION_EXTERNAL_CHILD_IDS, externalChildIDs);
142 json.put(JsonTags.WORKFLOW_ACTION_EXTERNAL_ID, externalId);
143 json.put(JsonTags.WORKFLOW_ACTION_EXTERNAL_STATUS, externalStatus);
144 json.put(JsonTags.WORKFLOW_ACTION_TRACKER_URI, trackerUri);
145 json.put(JsonTags.WORKFLOW_ACTION_CONSOLE_URL, consoleUrl);
146 json.put(JsonTags.WORKFLOW_ACTION_ERROR_CODE, errorCode);
147 json.put(JsonTags.WORKFLOW_ACTION_ERROR_MESSAGE, errorMessage);
148 json.put(JsonTags.TO_STRING, toString());
149 return json;
150 }
151
152 public String getId() {
153 return id;
154 }
155
156 public void setId(String id) {
157 this.id = id;
158 }
159
160 public String getName() {
161 return name;
162 }
163
164 public void setName(String name) {
165 this.name = name;
166 }
167
168 public String getCred() {
169 return cred;
170 }
171
172 public void setCred(String cred) {
173 this.cred = cred;
174 }
175
176 public String getType() {
177 return type;
178 }
179
180 public void setType(String type) {
181 this.type = type;
182 }
183
184 public String getConf() {
185 return conf;
186 }
187
188 public void setConf(String conf) {
189 this.conf = conf;
190 }
191
192 public Status getStatus() {
193 return status;
194 }
195
196 public void setStatus(Status status) {
197 this.status = status;
198 }
199
200 public int getRetries() {
201 return retries;
202 }
203
204 public void setRetries(int retries) {
205 this.retries = retries;
206 }
207
208 public int getUserRetryCount() {
209 return userRetryCount;
210 }
211
212 public void setUserRetryCount(int retryCount) {
213 this.userRetryCount = retryCount;
214 }
215
216 public void incrmentUserRetryCount() {
217 this.userRetryCount++;
218 }
219
220 public int getUserRetryMax() {
221 return userRetryMax;
222 }
223
224 public void setUserRetryMax(int retryMax) {
225 this.userRetryMax = retryMax;
226 }
227
228 public int getUserRetryInterval() {
229 return userRetryInterval;
230 }
231
232 public void setUserRetryInterval(int retryInterval) {
233 this.userRetryInterval = retryInterval;
234 }
235
236 public Date getStartTime() {
237 return startTime;
238 }
239
240 public void setStartTime(Date startTime) {
241 this.startTime = startTime;
242 }
243
244 public Date getEndTime() {
245 return endTime;
246 }
247
248 public void setEndTime(Date endTime) {
249 this.endTime = endTime;
250 }
251
252 public String getTransition() {
253 return transition;
254 }
255
256 public void setTransition(String transition) {
257 this.transition = transition;
258 }
259
260 public String getData() {
261 return data;
262 }
263
264 public void setData(String data) {
265 this.data = data;
266 }
267
268 public String getStats() {
269 return stats;
270 }
271
272 public void setStats(String stats) {
273 this.stats = stats;
274 }
275
276 public String getExternalChildIDs() {
277 return externalChildIDs;
278 }
279
280 public void setExternalChildIDs(String externalChildIDs) {
281 this.externalChildIDs = externalChildIDs;
282 }
283
284 public String getExternalId() {
285 return externalId;
286 }
287
288 public void setExternalId(String externalId) {
289 this.externalId = externalId;
290 }
291
292 public String getExternalStatus() {
293 return externalStatus;
294 }
295
296 public void setExternalStatus(String externalStatus) {
297 this.externalStatus = externalStatus;
298 }
299
300 public String getTrackerUri() {
301 return trackerUri;
302 }
303
304 public void setTrackerUri(String trackerUri) {
305 this.trackerUri = trackerUri;
306 }
307
308 public String getConsoleUrl() {
309 return consoleUrl;
310 }
311
312 public void setConsoleUrl(String consoleUrl) {
313 this.consoleUrl = consoleUrl;
314 }
315
316 public String getErrorCode() {
317 return errorCode;
318 }
319
320 public String getErrorMessage() {
321 return errorMessage;
322 }
323
324 public void setErrorInfo(String errorCode, String errorMessage) {
325 this.errorCode = errorCode;
326 this.errorMessage = errorMessage;
327 }
328
329 @Override
330 public String toString() {
331 return MessageFormat.format("Action name[{0}] status[{1}]", getName(), getStatus());
332 }
333
334 /**
335 * Convert a nodes list into a JSONArray.
336 *
337 * @param nodes nodes list.
338 * @return the corresponding JSON array.
339 */
340 @SuppressWarnings("unchecked")
341 public static JSONArray toJSONArray(List<? extends JsonWorkflowAction> nodes) {
342 JSONArray array = new JSONArray();
343 for (JsonWorkflowAction node : nodes) {
344 array.add(node.toJSONObject());
345 }
346 return array;
347 }
348
349 }