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;
019    
020    import org.apache.oozie.workflow.WorkflowInstance;
021    import org.apache.oozie.workflow.lite.LiteWorkflowInstance;
022    import org.apache.oozie.client.rest.JsonBean;
023    import org.apache.oozie.client.rest.JsonTags;
024    import org.apache.oozie.client.rest.JsonUtils;
025    import org.apache.oozie.client.WorkflowAction;
026    import org.apache.oozie.client.WorkflowJob;
027    import org.apache.oozie.util.DateUtils;
028    import org.apache.oozie.util.WritableUtils;
029    import org.apache.hadoop.io.Writable;
030    
031    import java.io.DataInput;
032    import java.io.IOException;
033    import java.io.DataOutput;
034    import java.text.MessageFormat;
035    import java.util.ArrayList;
036    import java.util.Date;
037    import java.util.List;
038    
039    import javax.persistence.Entity;
040    import javax.persistence.Column;
041    import javax.persistence.Id;
042    import javax.persistence.NamedQueries;
043    import javax.persistence.NamedQuery;
044    import javax.persistence.Basic;
045    import javax.persistence.Lob;
046    import javax.persistence.Table;
047    import javax.persistence.Transient;
048    
049    import java.sql.Timestamp;
050    
051    import org.apache.openjpa.persistence.jdbc.Index;
052    import org.apache.openjpa.persistence.jdbc.Strategy;
053    import org.json.simple.JSONArray;
054    import org.json.simple.JSONObject;
055    
056    @Entity
057    
058    @NamedQueries({
059    
060        @NamedQuery(name = "UPDATE_WORKFLOW", query = "update WorkflowJobBean w set w.appName = :appName, w.appPath = :appPath, w.conf = :conf, w.group = :groupName, w.run = :run, w.user = :user, w.createdTimestamp = :createdTime, w.endTimestamp = :endTime, w.externalId = :externalId, w.lastModifiedTimestamp = :lastModTime,w.logToken = :logToken, w.protoActionConf = :protoActionConf, w.slaXml =:slaXml, w.startTimestamp = :startTime, w.statusStr = :status, w.wfInstance = :wfInstance where w.id = :id"),
061    
062        @NamedQuery(name = "UPDATE_WORKFLOW_MODTIME", query = "update WorkflowJobBean w set w.lastModifiedTimestamp = :lastModTime where w.id = :id"),
063    
064        @NamedQuery(name = "UPDATE_WORKFLOW_STATUS_MODTIME", query = "update WorkflowJobBean w set w.statusStr = :status, w.lastModifiedTimestamp = :lastModTime where w.id = :id"),
065    
066        @NamedQuery(name = "UPDATE_WORKFLOW_PARENT_MODIFIED", query = "update WorkflowJobBean w set w.parentId = :parentId, w.lastModifiedTimestamp = :lastModTime where w.id = :id"),
067    
068        @NamedQuery(name = "UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED", query = "update WorkflowJobBean w set w.statusStr = :status, w.wfInstance = :wfInstance, w.lastModifiedTimestamp = :lastModTime where w.id = :id"),
069    
070        @NamedQuery(name = "UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END", query = "update WorkflowJobBean w set w.statusStr = :status, w.wfInstance = :wfInstance, w.lastModifiedTimestamp = :lastModTime, w.endTimestamp = :endTime where w.id = :id"),
071    
072        @NamedQuery(name = "UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END", query = "update WorkflowJobBean w set w.statusStr = :status, w.wfInstance = :wfInstance, w.lastModifiedTimestamp = :lastModTime, w.startTimestamp = :startTime, w.endTimestamp = :endTime where w.id = :id"),
073    
074        @NamedQuery(name = "UPDATE_WORKFLOW_RERUN", query = "update WorkflowJobBean w set w.appName = :appName, w.protoActionConf = :protoActionConf, w.appPath = :appPath, w.conf = :conf, w.logToken = :logToken, w.user = :user, w.group = :group, w.externalId = :externalId, w.endTimestamp = :endTime, w.run = :run, w.statusStr = :status, w.wfInstance = :wfInstance, w.lastModifiedTimestamp = :lastModTime where w.id = :id"),
075    
076        @NamedQuery(name = "DELETE_WORKFLOW", query = "delete from WorkflowJobBean w where w.id = :id"),
077    
078        @NamedQuery(name = "GET_WORKFLOWS", query = "select OBJECT(w) from WorkflowJobBean w order by w.startTimestamp desc"),
079    
080        @NamedQuery(name = "GET_WORKFLOWS_COLUMNS", query = "select w.id, w.appName, w.statusStr, w.run, w.user, w.group, w.createdTimestamp, w.startTimestamp, w.lastModifiedTimestamp, w.endTimestamp, w.externalId, w.parentId from WorkflowJobBean w order by w.createdTimestamp desc"),
081    
082        @NamedQuery(name = "GET_WORKFLOWS_COUNT", query = "select count(w) from WorkflowJobBean w"),
083    
084        @NamedQuery(name = "GET_COMPLETED_WORKFLOWS_OLDER_THAN", query = "select w from WorkflowJobBean w where w.endTimestamp < :endTime"),
085    
086        @NamedQuery(name = "GET_COMPLETED_WORKFLOWS_WITH_NO_PARENT_OLDER_THAN", query = "select w.id from WorkflowJobBean w where w.endTimestamp < :endTime and w.parentId is null"),
087    
088        @NamedQuery(name = "GET_COMPLETED_COORD_WORKFLOWS_OLDER_THAN", query = "select w.id, w.parentId from WorkflowJobBean w where w.endTimestamp < :endTime and w.parentId like '%C@%'"),
089    
090        @NamedQuery(name = "GET_WORKFLOW", query = "select OBJECT(w) from WorkflowJobBean w where w.id = :id"),
091    
092        @NamedQuery(name = "GET_WORKFLOW_STARTTIME", query = "select w.id, w.startTimestamp from WorkflowJobBean w where w.id = :id"),
093    
094        @NamedQuery(name = "GET_WORKFLOW_START_END_TIME", query = "select w.id, w.startTimestamp, w.endTimestamp from WorkflowJobBean w where w.id = :id"),
095    
096        @NamedQuery(name = "GET_WORKFLOW_USER_GROUP", query = "select w.user, w.group from WorkflowJobBean w where w.id = :id"),
097    
098        @NamedQuery(name = "GET_WORKFLOW_SUSPEND", query = "select w.id, w.user, w.group, w.appName, w.statusStr, w.parentId, w.startTimestamp, w.endTimestamp, w.logToken, w.wfInstance  from WorkflowJobBean w where w.id = :id"),
099    
100        @NamedQuery(name = "GET_WORKFLOW_RERUN", query = "select w.id, w.user, w.group, w.appName, w.statusStr, w.run, w.logToken, w.wfInstance from WorkflowJobBean w where w.id = :id"),
101    
102        @NamedQuery(name = "GET_WORKFLOW_DEFINITION", query = "select w.id, w.user, w.group, w.appName, w.logToken, w.wfInstance from WorkflowJobBean w where w.id = :id"),
103    
104        @NamedQuery(name = "GET_WORKFLOW_ACTION_OP", query = "select w.id, w.user, w.group, w.appName, w.appPath, w.statusStr, w.run, w.parentId, w.logToken, w.wfInstance, w.protoActionConf from WorkflowJobBean w where w.id = :id"),
105    
106        @NamedQuery(name = "GET_WORKFLOW_KILL", query = "select w.id, w.user, w.group, w.appName, w.appPath, w.statusStr, w.parentId, w.startTimestamp, w.endTimestamp, w.logToken, w.wfInstance, w.slaXml from WorkflowJobBean w where w.id = :id"),
107    
108        @NamedQuery(name = "GET_WORKFLOW_RESUME", query = "select w.id, w.user, w.group, w.appName, w.appPath, w.statusStr, w.parentId, w.startTimestamp, w.endTimestamp, w.logToken, w.wfInstance, w.protoActionConf from WorkflowJobBean w where w.id = :id"),
109    
110        @NamedQuery(name = "GET_WORKFLOW_FOR_UPDATE", query = "select OBJECT(w) from WorkflowJobBean w where w.id = :id"),
111    
112        @NamedQuery(name = "GET_WORKFLOW_FOR_SLA", query = "select w.id, w.statusStr, w.startTimestamp, w.endTimestamp from WorkflowJobBean w where w.id = :id"),
113    
114        @NamedQuery(name = "GET_WORKFLOW_ID_FOR_EXTERNAL_ID", query = "select  w.id from WorkflowJobBean w where w.externalId = :externalId"),
115    
116        @NamedQuery(name = "GET_WORKFLOWS_COUNT_WITH_STATUS", query = "select count(w) from WorkflowJobBean w where w.statusStr = :status"),
117    
118        @NamedQuery(name = "GET_WORKFLOWS_COUNT_WITH_STATUS_IN_LAST_N_SECS", query = "select count(w) from WorkflowJobBean w where w.statusStr = :status and w.lastModifiedTimestamp > :lastModTime"),
119    
120        @NamedQuery(name = "GET_WORKFLOWS_WITH_WORKFLOW_PARENT_ID", query = "select w.id from WorkflowJobBean w where w.parentId = :parentId"),
121    
122        @NamedQuery(name = "GET_WORKFLOWS_WITH_COORD_PARENT_ID", query = "select w.id from WorkflowJobBean w where w.parentId like :parentId"), // when setting parentId parameter, make sure to append a '%' (percent symbol) at the end (e.g. 0000004-130709155224435-oozie-rkan-C%")
123    
124        @NamedQuery(name = "GET_WORKFLOWS_COUNT_WITH_WORKFLOW_PARENT_ID_NOT_READY_FOR_PURGE", query = "select count(w) from WorkflowJobBean w where w.parentId = :parentId and (w.statusStr = 'PREP' OR w.statusStr = 'RUNNING' OR w.statusStr = 'SUSPENDED' OR w.endTimestamp >= :endTime)"),
125    
126        @NamedQuery(name = "GET_WORKFLOWS_COUNT_WITH_COORD_PARENT_ID_NOT_READY_FOR_PURGE", query = "select count(w) from WorkflowJobBean w where w.parentId like :parentId and (w.statusStr = 'PREP' OR w.statusStr = 'RUNNING' OR w.statusStr = 'SUSPENDED' OR w.endTimestamp >= :endTime)"), // when setting parentId parameter, make sure to append a '%' (percent symbol) at the end (e.g. 0000004-130709155224435-oozie-rkan-C%")
127    
128        @NamedQuery(name = "GET_WORKFLOW_FOR_USER", query = "select w.user from WorkflowJobBean w where w.id = :id"),
129    
130        @NamedQuery(name = "GET_WORKFLOW_STATUS", query = "select w.statusStr from WorkflowJobBean w where w.id = :id"),
131    
132        @NamedQuery(name = "GET_WORKFLOWS_PARENT_COORD_RERUN", query = "select w.id, w.statusStr, w.startTimestamp, w.endTimestamp "
133                + "from WorkflowJobBean w where w.parentId = :parentId order by w.createdTimestamp")})
134    @Table(name = "WF_JOBS")
135    public class WorkflowJobBean implements Writable, WorkflowJob, JsonBean {
136    
137        @Id
138        private String id;
139    
140        @Basic
141        @Column(name = "proto_action_conf")
142        @Lob
143        @Strategy("org.apache.oozie.executor.jpa.StringBlobValueHandler")
144        private StringBlob protoActionConf;
145    
146        @Basic
147        @Column(name = "log_token")
148        private String logToken = null;
149    
150        @Basic
151        @Index
152        @Column(name = "external_id")
153        private String externalId = null;
154    
155        @Basic
156        @Index
157        @Column(name = "status")
158        private String statusStr = WorkflowJob.Status.PREP.toString();
159    
160        @Basic
161        @Column(name = "created_time")
162        private java.sql.Timestamp createdTimestamp = null;
163    
164        @Basic
165        @Column(name = "start_time")
166        private java.sql.Timestamp startTimestamp = null;
167    
168        @Basic
169        @Index
170        @Column(name = "end_time")
171        private java.sql.Timestamp endTimestamp = null;
172    
173        @Basic
174        @Index
175        @Column(name = "last_modified_time")
176        private java.sql.Timestamp lastModifiedTimestamp = null;
177    
178        @Basic
179        @Column(name = "wf_instance")
180        @Lob
181        @Strategy("org.apache.oozie.executor.jpa.BinaryBlobValueHandler")
182        private BinaryBlob wfInstance ;
183    
184        @Basic
185        @Column(name = "sla_xml")
186        @Lob
187        @Strategy("org.apache.oozie.executor.jpa.StringBlobValueHandler")
188        private StringBlob slaXml;
189    
190    
191        @Basic
192        @Column(name = "app_name")
193        private String appName = null;
194    
195        @Basic
196        @Column(name = "app_path")
197        private String appPath = null;
198    
199        @Basic
200        @Column(name = "conf")
201        @Lob
202        @Strategy("org.apache.oozie.executor.jpa.StringBlobValueHandler")
203        private StringBlob conf;
204    
205        @Basic
206        @Column(name = "user_name")
207        private String user = null;
208    
209        @Basic
210        @Column(name = "group_name")
211        private String group;
212    
213        @Basic
214        @Column(name = "run")
215        private int run = 1;
216    
217        @Basic
218        @Index
219        @Column(name = "parent_id")
220        private String parentId;
221    
222        @Transient
223        private String consoleUrl;
224    
225        @Transient
226        private List<WorkflowActionBean> actions;
227    
228    
229        /**
230         * Default constructor.
231         */
232        public WorkflowJobBean() {
233            actions = new ArrayList<WorkflowActionBean>();
234        }
235    
236        /**
237         * Serialize the workflow bean to a data output.
238         *
239         * @param dataOutput data output.
240         * @throws IOException thrown if the workflow bean could not be serialized.
241         */
242        public void write(DataOutput dataOutput) throws IOException {
243            WritableUtils.writeStr(dataOutput, getAppPath());
244            WritableUtils.writeStr(dataOutput, getAppName());
245            WritableUtils.writeStr(dataOutput, getId());
246            WritableUtils.writeStr(dataOutput, getParentId());
247            WritableUtils.writeStr(dataOutput, getConf());
248            WritableUtils.writeStr(dataOutput, getStatusStr());
249            dataOutput.writeLong((getCreatedTime() != null) ? getCreatedTime().getTime() : -1);
250            dataOutput.writeLong((getStartTime() != null) ? getStartTime().getTime() : -1);
251            dataOutput.writeLong((getLastModifiedTime() != null) ? getLastModifiedTime().getTime() : -1);
252            dataOutput.writeLong((getEndTime() != null) ? getEndTime().getTime() : -1);
253            WritableUtils.writeStr(dataOutput, getUser());
254            WritableUtils.writeStr(dataOutput, getGroup());
255            dataOutput.writeInt(getRun());
256            WritableUtils.writeStr(dataOutput, logToken);
257            WritableUtils.writeStr(dataOutput, getProtoActionConf());
258        }
259    
260        /**
261         * Deserialize a workflow bean from a data input.
262         *
263         * @param dataInput data input.
264         * @throws IOException thrown if the workflow bean could not be deserialized.
265         */
266        public void readFields(DataInput dataInput) throws IOException {
267            setAppPath(WritableUtils.readStr(dataInput));
268            setAppName(WritableUtils.readStr(dataInput));
269            setId(WritableUtils.readStr(dataInput));
270            setParentId(WritableUtils.readStr(dataInput));
271            setConf(WritableUtils.readStr(dataInput));
272            setStatus(WorkflowJob.Status.valueOf(WritableUtils.readStr(dataInput)));
273            // setStatus(WritableUtils.readStr(dataInput));
274            long d = dataInput.readLong();
275            if (d != -1) {
276                setCreatedTime(new Date(d));
277            }
278            d = dataInput.readLong();
279            if (d != -1) {
280            }
281            setStartTime(new Date(d));
282            d = dataInput.readLong();
283            if (d != -1) {
284                setLastModifiedTime(new Date(d));
285            }
286            d = dataInput.readLong();
287            if (d != -1) {
288                setEndTime(new Date(d));
289            }
290            setUser(WritableUtils.readStr(dataInput));
291            setGroup(WritableUtils.readStr(dataInput));
292            setRun(dataInput.readInt());
293            logToken = WritableUtils.readStr(dataInput);
294            setProtoActionConf(WritableUtils.readStr(dataInput));
295            setExternalId(getExternalId());
296        }
297    
298        public boolean inTerminalState() {
299            boolean inTerminalState = false;
300            switch (WorkflowJob.Status.valueOf(statusStr)) {
301                case FAILED:
302                case KILLED:
303                case SUCCEEDED:
304                    inTerminalState = true;
305                    break;
306                default:
307                    break;
308            }
309            return inTerminalState;
310        }
311    
312        public String getLogToken() {
313            return logToken;
314        }
315    
316        public void setLogToken(String logToken) {
317            this.logToken = logToken;
318        }
319    
320        public String getSlaXml() {
321            return slaXml == null ? null : slaXml.getString();
322        }
323    
324        public void setSlaXml(String slaXml) {
325            if (this.slaXml == null) {
326                this.slaXml = new StringBlob(slaXml);
327            }
328            else {
329                this.slaXml.setString(slaXml);
330            }
331        }
332    
333        public void setSlaXmlBlob(StringBlob slaXml) {
334            this.slaXml = slaXml;
335        }
336    
337        public StringBlob getSlaXmlBlob() {
338            return this.slaXml;
339        }
340    
341        public WorkflowInstance getWorkflowInstance() {
342            return wfInstance == null ? null : get(wfInstance.getBytes());
343        }
344    
345        public BinaryBlob getWfInstanceBlob() {
346            return this.wfInstance;
347        }
348    
349        public void setWorkflowInstance(WorkflowInstance workflowInstance) {
350            if (this.wfInstance == null) {
351                this.wfInstance = new BinaryBlob(WritableUtils.toByteArray((LiteWorkflowInstance) workflowInstance), true);
352            }
353            else {
354                this.wfInstance.setBytes(WritableUtils.toByteArray((LiteWorkflowInstance) workflowInstance));
355            }
356        }
357    
358        public void setWfInstanceBlob(BinaryBlob wfInstance) {
359            this.wfInstance = wfInstance;
360        }
361    
362        public String getProtoActionConf() {
363            return protoActionConf == null ? null : protoActionConf.getString();
364        }
365    
366        public void setProtoActionConf(String protoActionConf) {
367            if (this.protoActionConf == null) {
368                this.protoActionConf = new StringBlob(protoActionConf);
369            }
370            else {
371                this.protoActionConf.setString(protoActionConf);
372            }
373        }
374    
375        public void setProtoActionConfBlob (StringBlob protoBytes) {
376            this.protoActionConf = protoBytes;
377        }
378    
379        public StringBlob getProtoActionConfBlob() {
380            return this.protoActionConf;
381        }
382    
383        public String getlogToken() {
384            return logToken;
385        }
386    
387        public Timestamp getLastModifiedTimestamp() {
388            return lastModifiedTimestamp;
389        }
390    
391        public Timestamp getStartTimestamp() {
392            return startTimestamp;
393        }
394    
395        public Timestamp getCreatedTimestamp() {
396            return createdTimestamp;
397        }
398    
399        public Timestamp getEndTimestamp() {
400            return endTimestamp;
401        }
402    
403        public void setStatusStr (String statusStr) {
404            this.statusStr = statusStr;
405        }
406    
407        public void setStatus(Status val) {
408            this.statusStr = val.toString();
409        }
410    
411        @Override
412        public Status getStatus() {
413            return Status.valueOf(statusStr);
414        }
415    
416        public String getStatusStr() {
417            return statusStr;
418        }
419    
420        public void setExternalId(String externalId) {
421            this.externalId = externalId;
422        }
423    
424        @Override
425        public String getExternalId() {
426            return externalId;
427        }
428    
429        public void setLastModifiedTime(Date lastModifiedTime) {
430            this.lastModifiedTimestamp = DateUtils.convertDateToTimestamp(lastModifiedTime);
431        }
432    
433        public Date getLastModifiedTime() {
434            return DateUtils.toDate(lastModifiedTimestamp);
435        }
436    
437        public Date getCreatedTime() {
438            return DateUtils.toDate(createdTimestamp);
439        }
440    
441        public void setCreatedTime(Date createdTime) {
442            this.createdTimestamp = DateUtils.convertDateToTimestamp(createdTime);
443        }
444    
445        @Override
446        public Date getStartTime() {
447            return DateUtils.toDate(startTimestamp);
448        }
449    
450        public void setStartTime(Date startTime) {
451            this.startTimestamp = DateUtils.convertDateToTimestamp(startTime);
452        }
453    
454        public Date getEndTime() {
455            return DateUtils.toDate(endTimestamp);
456        }
457    
458        public void setEndTime(Date endTime) {
459            this.endTimestamp = DateUtils.convertDateToTimestamp(endTime);
460        }
461    
462        private WorkflowInstance get(byte[] array) {
463            LiteWorkflowInstance pInstance = WritableUtils.fromByteArray(array, LiteWorkflowInstance.class);
464            return pInstance;
465        }
466    
467        @SuppressWarnings("unchecked")
468        public JSONObject toJSONObject() {
469            return toJSONObject("GMT");
470        }
471    
472        @SuppressWarnings("unchecked")
473        public JSONObject toJSONObject(String timeZoneId) {
474            JSONObject json = new JSONObject();
475            json.put(JsonTags.WORKFLOW_APP_PATH, getAppPath());
476            json.put(JsonTags.WORKFLOW_APP_NAME, getAppName());
477            json.put(JsonTags.WORKFLOW_ID, getId());
478            json.put(JsonTags.WORKFLOW_EXTERNAL_ID, getExternalId());
479            json.put(JsonTags.WORKFLOW_PARENT_ID, getParentId());
480            json.put(JsonTags.WORKFLOW_CONF, getConf());
481            json.put(JsonTags.WORKFLOW_STATUS, getStatus().toString());
482            json.put(JsonTags.WORKFLOW_LAST_MOD_TIME, JsonUtils.formatDateRfc822(getLastModifiedTime(), timeZoneId));
483            json.put(JsonTags.WORKFLOW_CREATED_TIME, JsonUtils.formatDateRfc822(getCreatedTime(), timeZoneId));
484            json.put(JsonTags.WORKFLOW_START_TIME, JsonUtils.formatDateRfc822(getStartTime(), timeZoneId));
485            json.put(JsonTags.WORKFLOW_END_TIME, JsonUtils.formatDateRfc822(getEndTime(), timeZoneId));
486            json.put(JsonTags.WORKFLOW_USER, getUser());
487            json.put(JsonTags.WORKFLOW_GROUP, getGroup());
488            json.put(JsonTags.WORKFLOW_ACL, getAcl());
489            json.put(JsonTags.WORKFLOW_RUN, (long) getRun());
490            json.put(JsonTags.WORKFLOW_CONSOLE_URL, getConsoleUrl());
491            json.put(JsonTags.WORKFLOW_ACTIONS, WorkflowActionBean.toJSONArray(actions, timeZoneId));
492            json.put(JsonTags.TO_STRING, toString());
493            return json;
494        }
495    
496        public String getAppPath() {
497            return appPath;
498        }
499    
500        public void setAppPath(String appPath) {
501            this.appPath = appPath;
502        }
503    
504        public String getAppName() {
505            return appName;
506        }
507    
508        public void setAppName(String appName) {
509            this.appName = appName;
510        }
511    
512        public String getId() {
513            return id;
514        }
515    
516        public void setId(String id) {
517            this.id = id;
518        }
519    
520        public String getConf() {
521            return conf == null ? null : conf.getString();
522        }
523    
524        public void setConf(String conf) {
525            if (this.conf == null) {
526                this.conf = new StringBlob(conf);
527            }
528            else {
529                this.conf.setString(conf);
530            }
531        }
532    
533        public void setConfBlob(StringBlob conf) {
534            this.conf = conf;
535        }
536    
537        public StringBlob getConfBlob() {
538            return this.conf;
539        }
540    
541        public String getUser() {
542            return user;
543        }
544    
545        public void setUser(String user) {
546            this.user = user;
547        }
548    
549        public String getGroup() {
550            return group;
551        }
552    
553        @Override
554        public String getAcl() {
555            return getGroup();
556        }
557    
558        public void setGroup(String group) {
559            this.group = group;
560        }
561    
562        public int getRun() {
563            return run;
564        }
565    
566        public void setRun(int run) {
567            this.run = run;
568        }
569    
570        /**
571         * Return the workflow job console URL.
572         *
573         * @return the workflow job console URL.
574         */
575        public String getConsoleUrl() {
576            return consoleUrl;
577        }
578    
579        /**
580         * Return the corresponding Action ID, if any.
581         *
582         * @return the coordinator Action Id.
583         */
584        public String getParentId() {
585            return parentId;
586        }
587    
588        /**
589         * Set coordinator action id
590         *
591         * @param parentId : coordinator action id
592         */
593        public void setParentId(String parentId) {
594            this.parentId = parentId;
595        }
596    
597        /**
598         * Set the workflow job console URL.
599         *
600         * @param consoleUrl the workflow job console URL.
601         */
602        public void setConsoleUrl(String consoleUrl) {
603            this.consoleUrl = consoleUrl;
604        }
605    
606        @SuppressWarnings("unchecked")
607        public List<WorkflowAction> getActions() {
608            return (List) actions;
609        }
610    
611        public void setActions(List<WorkflowActionBean> nodes) {
612            this.actions = (nodes != null) ? nodes : new ArrayList<WorkflowActionBean>();
613        }
614    
615        @Override
616        public String toString() {
617            return MessageFormat.format("Workflow id[{0}] status[{1}]", getId(), getStatus());
618        }
619    
620        /**
621         * Convert a workflows list into a JSONArray.
622         *
623         * @param workflows workflows list.
624         * @param timeZoneId time zone to use for dates in the JSON array.
625         * @return the corresponding JSON array.
626         */
627        @SuppressWarnings("unchecked")
628        public static JSONArray toJSONArray(List<WorkflowJobBean> workflows, String timeZoneId) {
629            JSONArray array = new JSONArray();
630            if (workflows != null) {
631                for (WorkflowJobBean node : workflows) {
632                    array.add(node.toJSONObject(timeZoneId));
633                }
634            }
635            return array;
636        }
637    
638    
639    
640    }