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