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 java.io.DataInput;
021    import java.io.DataOutput;
022    import java.io.IOException;
023    import java.sql.Timestamp;
024    import java.text.MessageFormat;
025    import java.util.ArrayList;
026    import java.util.Date;
027    import java.util.List;
028    
029    import javax.persistence.Basic;
030    import javax.persistence.Column;
031    import javax.persistence.Entity;
032    import javax.persistence.Id;
033    import javax.persistence.Lob;
034    import javax.persistence.NamedQueries;
035    import javax.persistence.NamedQuery;
036    import javax.persistence.Table;
037    import javax.persistence.Transient;
038    
039    import org.apache.hadoop.io.Writable;
040    import org.apache.oozie.client.BundleJob;
041    import org.apache.oozie.client.CoordinatorJob;
042    import org.apache.oozie.client.Job;
043    import org.apache.oozie.client.rest.JsonBean;
044    import org.apache.oozie.client.rest.JsonTags;
045    import org.apache.oozie.client.rest.JsonUtils;
046    import org.apache.oozie.util.DateUtils;
047    import org.apache.oozie.util.WritableUtils;
048    import org.apache.openjpa.persistence.jdbc.Index;
049    import org.apache.openjpa.persistence.jdbc.Strategy;
050    import org.json.simple.JSONArray;
051    import org.json.simple.JSONObject;
052    
053    @Entity
054    @NamedQueries( {
055            @NamedQuery(name = "UPDATE_BUNDLE_JOB", query = "update BundleJobBean w set w.appName = :appName, w.appPath = :appPath, w.conf = :conf, w.externalId = :externalId, w.timeOut = :timeOut, w.createdTimestamp = :createdTime, w.endTimestamp = :endTime, w.jobXml = :jobXml, w.lastModifiedTimestamp = :lastModifiedTime, w.origJobXml = :origJobXml, w.startTimestamp = :startTime, w.statusStr = :status, w.timeUnitStr = :timeUnit, w.pending = :pending where w.id = :id"),
056    
057            @NamedQuery(name = "UPDATE_BUNDLE_JOB_STATUS", query = "update BundleJobBean w set w.statusStr = :status, w.lastModifiedTimestamp = :lastModifiedTime, w.pending = :pending where w.id = :id"),
058    
059            @NamedQuery(name = "UPDATE_BUNDLE_JOB_STATUS_PENDING", query = "update BundleJobBean w set w.statusStr = :status, w.pending = :pending where w.id = :id"),
060    
061            @NamedQuery(name = "UPDATE_BUNDLE_JOB_STATUS_PENDING_MODTIME", query = "update BundleJobBean w set w.statusStr = :status, w.lastModifiedTimestamp = :lastModifiedTime, w.pending = :pending where w.id = :id"),
062    
063            @NamedQuery(name = "UPDATE_BUNDLE_JOB_STATUS_PENDING_SUSP_MOD_TIME", query = "update BundleJobBean w set w.statusStr = :status, w.lastModifiedTimestamp = :lastModifiedTime, w.pending = :pending, w.suspendedTimestamp = :suspendedTime where w.id = :id"),
064    
065            @NamedQuery(name = "UPDATE_BUNDLE_JOB_STATUS_PAUSE_ENDTIME", query = "update BundleJobBean w set w.statusStr = :status, w.pauseTimestamp = :pauseTime, w.endTimestamp = :endTime where w.id = :id"),
066    
067            @NamedQuery(name = "UPDATE_BUNDLE_JOB_PAUSE_KICKOFF", query = "update BundleJobBean w set w.kickoffTimestamp = :kickoffTime, w.pauseTimestamp = :pauseTime where w.id = :id"),
068    
069            @NamedQuery(name = "DELETE_BUNDLE_JOB", query = "delete from BundleJobBean w where w.id = :id"),
070    
071            @NamedQuery(name = "GET_BUNDLE_JOBS", query = "select OBJECT(w) from BundleJobBean w"),
072    
073            @NamedQuery(name = "GET_BUNDLE_JOB", query = "select OBJECT(w) from BundleJobBean w where w.id = :id"),
074    
075            @NamedQuery(name = "GET_BUNDLE_JOB_STATUS", query = "select w.statusStr from BundleJobBean w where w.id = :id"),
076    
077            @NamedQuery(name = "GET_BUNDLE_JOB_ID_STATUS_PENDING_MODTIME", query = "select w.id, w.statusStr, w.pending, w.lastModifiedTimestamp from BundleJobBean w where w.id = :id"),
078    
079            @NamedQuery(name = "GET_BUNDLE_JOB_ID_JOBXML_CONF", query = "select w.id, w.jobXml, w.conf from BundleJobBean w where w.id = :id"),
080    
081            @NamedQuery(name = "GET_BUNDLE_JOBS_COUNT", query = "select count(w) from BundleJobBean w"),
082    
083            @NamedQuery(name = "GET_BUNDLE_JOBS_COLUMNS", query = "select w.id, w.appName, w.appPath, w.conf, w.statusStr, w.kickoffTimestamp, w.startTimestamp, w.endTimestamp, w.pauseTimestamp, w.createdTimestamp, w.user, w.group, w.timeUnitStr, w.timeOut from BundleJobBean w order by w.createdTimestamp desc"),
084    
085            @NamedQuery(name = "GET_BUNDLE_JOBS_RUNNING_OR_PENDING", query = "select OBJECT(w) from BundleJobBean w where w.statusStr = 'RUNNING' OR w.statusStr = 'RUNNINGWITHERROR' OR w.pending = 1 order by w.lastModifiedTimestamp"),
086    
087            @NamedQuery(name = "GET_BUNDLE_JOBS_NEED_START", query = "select OBJECT(w) from BundleJobBean w where w.statusStr = 'PREP' AND (w.kickoffTimestamp IS NULL OR (w.kickoffTimestamp IS NOT NULL AND w.kickoffTimestamp <= :currentTime)) order by w.lastModifiedTimestamp"),
088    
089            @NamedQuery(name = "GET_BUNDLE_JOBS_PAUSED", query = "select OBJECT(w) from BundleJobBean w where w.statusStr = 'PAUSED' OR w.statusStr = 'PAUSEDWITHERROR' OR w.statusStr = 'PREPPAUSED' order by w.lastModifiedTimestamp"),
090    
091            @NamedQuery(name = "GET_BUNDLE_JOBS_UNPAUSED", query = "select OBJECT(w) from BundleJobBean w where w.statusStr = 'RUNNING' OR w.statusStr = 'RUNNINGWITHERROR' OR w.statusStr = 'PREP' order by w.lastModifiedTimestamp"),
092    
093            @NamedQuery(name = "GET_BUNDLE_JOBS_OLDER_THAN", query = "select OBJECT(w) from BundleJobBean w where w.startTimestamp <= :matTime AND (w.statusStr = 'PREP' OR w.statusStr = 'RUNNING' or w.statusStr = 'RUNNINGWITHERROR')  order by w.lastModifiedTimestamp"),
094    
095            @NamedQuery(name = "GET_BUNDLE_JOBS_OLDER_THAN_STATUS", query = "select OBJECT(w) from BundleJobBean w where w.statusStr = :status AND w.lastModifiedTimestamp <= :lastModTime order by w.lastModifiedTimestamp"),
096    
097            @NamedQuery(name = "GET_COMPLETED_BUNDLE_JOBS_OLDER_THAN", query = "select w.id from BundleJobBean w where ( w.statusStr = 'SUCCEEDED' OR w.statusStr = 'FAILED' OR w.statusStr = 'KILLED' OR w.statusStr = 'DONEWITHERROR') AND w.lastModifiedTimestamp <= :lastModTime order by w.lastModifiedTimestamp"),
098    
099            @NamedQuery(name = "BULK_MONITOR_BUNDLE_QUERY", query = "SELECT b.id, b.appName, b.statusStr, b.user FROM BundleJobBean b"),
100    
101            // Join query
102            @NamedQuery(name = "BULK_MONITOR_ACTIONS_QUERY", query = "SELECT a.id, a.actionNumber, a.errorCode, a.errorMessage, a.externalId, " +
103                    "a.externalStatus, a.statusStr, a.createdTimestamp, a.nominalTimestamp, a.missingDependencies, " +
104                    "c.id, c.appName, c.statusStr FROM CoordinatorActionBean a, CoordinatorJobBean c " +
105                    "WHERE a.jobId = c.id AND c.bundleId = :bundleId ORDER BY a.jobId, a.createdTimestamp"),
106    
107            @NamedQuery(name = "BULK_MONITOR_COUNT_QUERY", query = "SELECT COUNT(a) FROM CoordinatorActionBean a, CoordinatorJobBean c"),
108    
109            @NamedQuery(name = "GET_BUNDLE_JOB_FOR_USER", query = "select w.user from BundleJobBean w where w.id = :id") })
110    @Table(name = "BUNDLE_JOBS")
111    public class BundleJobBean implements Writable, BundleJob, JsonBean {
112    
113        @Id
114        private String id;
115    
116        @Basic
117        @Column(name = "app_path")
118        private String appPath = null;
119    
120        @Basic
121        @Column(name = "app_name")
122        private String appName = null;
123    
124        @Basic
125        @Column(name = "external_id")
126        private String externalId = null;
127    
128        @Basic
129        @Column(name = "conf")
130        @Lob
131        @Strategy("org.apache.oozie.executor.jpa.StringBlobValueHandler")
132        private StringBlob conf;
133    
134        @Basic
135        @Column(name = "time_out")
136        private int timeOut = 0;
137    
138        @Basic
139        @Column(name = "user_name")
140        private String user = null;
141    
142        @Basic
143        @Column(name = "group_name")
144        private String group = null;
145    
146        @Transient
147        private String consoleUrl;
148    
149        @Basic
150        @Index
151        @Column(name = "status")
152        private String statusStr = Job.Status.PREP.toString();
153    
154        @Basic
155        @Column(name = "kickoff_time")
156        private java.sql.Timestamp kickoffTimestamp = null;
157    
158        @Basic
159        @Column(name = "start_time")
160        private java.sql.Timestamp startTimestamp = null;
161    
162        @Basic
163        @Column(name = "end_time")
164        private java.sql.Timestamp endTimestamp = null;
165    
166        @Basic
167        @Column(name = "pause_time")
168        private java.sql.Timestamp pauseTimestamp = null;
169    
170        @Basic
171        @Index
172        @Column(name = "created_time")
173        private java.sql.Timestamp createdTimestamp = null;
174    
175        @Basic
176        @Column(name = "time_unit")
177        private String timeUnitStr = BundleJob.Timeunit.NONE.toString();
178    
179        @Basic
180        @Column(name = "pending")
181        private int pending = 0;
182    
183        @Basic
184        @Index
185        @Column(name = "last_modified_time")
186        private java.sql.Timestamp lastModifiedTimestamp = null;
187    
188        @Basic
189        @Index
190        @Column(name = "suspended_time")
191        private java.sql.Timestamp suspendedTimestamp = null;
192    
193        @Basic
194        @Column(name = "job_xml")
195        @Lob
196        @Strategy("org.apache.oozie.executor.jpa.StringBlobValueHandler")
197        private StringBlob jobXml;
198    
199        @Basic
200        @Column(name = "orig_job_xml")
201        @Lob
202        @Strategy("org.apache.oozie.executor.jpa.StringBlobValueHandler")
203        private StringBlob origJobXml = null;
204    
205    
206        @Transient
207        private List<CoordinatorJobBean> coordJobs;
208    
209        public BundleJobBean() {
210            coordJobs = new ArrayList<CoordinatorJobBean>();
211        }
212    
213        /**
214         * @return the kickoffTimestamp
215         */
216        public java.sql.Timestamp getKickoffTimestamp() {
217            return kickoffTimestamp;
218        }
219    
220        /**
221         * @return the startTimestamp
222         */
223        public java.sql.Timestamp getstartTimestamp() {
224            return startTimestamp;
225        }
226    
227        /**
228         * @param kickoffTimestamp the kickoffTimestamp to set
229         */
230        public void setKickoffTimestamp(java.sql.Timestamp kickoffTimestamp) {
231            this.kickoffTimestamp = kickoffTimestamp;
232        }
233    
234        /**
235         * @param startTimestamp the startTimestamp to set
236         */
237        public void setStartTimestamp(java.sql.Timestamp startTimestamp) {
238            this.startTimestamp = startTimestamp;
239        }
240    
241        /**
242         * Set startTime
243         *
244         * @param startTime the startTime to set
245         */
246        public void setStartTime(Date startTime) {
247            this.startTimestamp = DateUtils.convertDateToTimestamp(startTime);
248        }
249    
250        /**
251         * @return the endTimestamp
252         */
253        public java.sql.Timestamp getEndTimestamp() {
254            return endTimestamp;
255        }
256    
257        /**
258         * @param endTimestamp the endTimestamp to set
259         */
260        public void setEndTimestamp(java.sql.Timestamp endTimestamp) {
261            this.endTimestamp = endTimestamp;
262        }
263    
264        /**
265         * @return the pauseTimestamp
266         */
267        public java.sql.Timestamp getPauseTimestamp() {
268            return pauseTimestamp;
269        }
270    
271        /**
272         * @param pauseTimestamp the pauseTimestamp to set
273         */
274        public void setPauseTimestamp(java.sql.Timestamp pauseTimestamp) {
275            this.pauseTimestamp = pauseTimestamp;
276        }
277    
278        /**
279         * @return the createdTimestamp
280         */
281        public java.sql.Timestamp getCreatedTimestamp() {
282            return createdTimestamp;
283        }
284    
285        /**
286         * @return the createdTime
287         */
288        @Override
289        public Date getCreatedTime() {
290            return DateUtils.toDate(createdTimestamp);
291        }
292    
293        /**
294         * @return the timeUnitStr
295         */
296        public String getTimeUnitStr() {
297            return timeUnitStr;
298        }
299    
300        /**
301         * @return the pending
302         */
303        public int getPending() {
304            return pending;
305        }
306    
307        /**
308         * Set pending to true
309         *
310         * @param pending set pending to true
311         */
312        @Override
313        public void setPending() {
314            this.pending = 1;
315        }
316    
317        /**
318         * Set pending value
319         *
320         * @param pending set pending value
321         */
322        public void setPending(int i) {
323            this.pending = i;
324        }
325    
326        /**
327         * Set pending to false
328         *
329         * @param pending set pending to false
330         */
331        @Override
332        public void resetPending() {
333            this.pending = 0;
334        }
335    
336        /**
337         * Return if the action is pending.
338         *
339         * @return if the action is pending.
340         */
341        public boolean isPending() {
342            return pending == 1 ? true : false;
343        }
344    
345        /**
346         * @return the lastModifiedTimestamp
347         */
348        public java.sql.Timestamp getLastModifiedTimestamp() {
349            return lastModifiedTimestamp;
350        }
351    
352        /**
353         * @param lastModifiedTimestamp the lastModifiedTimestamp to set
354         */
355        public void setLastModifiedTimestamp(java.sql.Timestamp lastModifiedTimestamp) {
356            this.lastModifiedTimestamp = lastModifiedTimestamp;
357        }
358    
359        /**
360         * @return the suspendedTimestamp
361         */
362        public Timestamp getSuspendedTimestamp() {
363            return suspendedTimestamp;
364        }
365    
366        /**
367         * @param suspendedTimestamp the suspendedTimestamp to set
368         */
369        public void setSuspendedTimestamp(Timestamp suspendedTimestamp) {
370            this.suspendedTimestamp = suspendedTimestamp;
371        }
372    
373        /**
374         * @return the jobXml
375         */
376        public String getJobXml() {
377            return jobXml == null ? null : jobXml.getString();
378        }
379    
380        /**
381         * @param jobXml the jobXml to set
382         */
383        public void setJobXml(String jobXml) {
384            if (this.jobXml == null) {
385                this.jobXml = new StringBlob(jobXml);
386            }
387            else {
388                this.jobXml.setString(jobXml);
389            }
390    
391        }
392    
393        public void setJobXmlBlob (StringBlob jobXmlBlob) {
394            this.jobXml = jobXmlBlob;
395        }
396    
397        public StringBlob getJobXmlBlob() {
398            return jobXml;
399        }
400    
401        /**
402         * @return the origJobXml
403         */
404        public String getOrigJobXml() {
405            return origJobXml == null ? null : origJobXml.getString();
406        }
407    
408        /**
409         * @param origJobXml the origJobXml to set
410         */
411        public void setOrigJobXml(String origJobXml) {
412            if (this.origJobXml == null) {
413                this.origJobXml = new StringBlob(origJobXml);
414            }
415            else {
416                this.origJobXml.setString(origJobXml);
417            }
418        }
419    
420        public void setOrigJobXmlBlob (StringBlob origJobXml) {
421            this.origJobXml = origJobXml;
422        }
423    
424        public StringBlob getOrigJobXmlBlob() {
425            return origJobXml;
426        }
427    
428        /**
429         * @param createTime the createdTime to set
430         */
431        public void setCreatedTime(Date createTime) {
432            this.createdTimestamp = DateUtils.convertDateToTimestamp(createTime);
433        }
434    
435        /**
436         * @param lastModifiedTime
437         */
438        public void setLastModifiedTime(Date lastModifiedTime) {
439            this.lastModifiedTimestamp = DateUtils.convertDateToTimestamp(lastModifiedTime);
440        }
441    
442        /**
443         * Get last modified time
444         *
445         * @return last modified time
446         */
447        public Date getLastModifiedTime() {
448            return DateUtils.toDate(lastModifiedTimestamp);
449        }
450    
451        @Override
452        public void write(DataOutput dataOutput) throws IOException {
453            WritableUtils.writeStr(dataOutput, getAppPath());
454            WritableUtils.writeStr(dataOutput, getAppName());
455            WritableUtils.writeStr(dataOutput, getId());
456            WritableUtils.writeStr(dataOutput, getConf());
457            WritableUtils.writeStr(dataOutput, getStatusStr());
458            WritableUtils.writeStr(dataOutput, getTimeUnit().toString());
459            dataOutput.writeLong((getKickoffTime() != null) ? getKickoffTime().getTime() : -1);
460            dataOutput.writeLong((getStartTime() != null) ? getStartTime().getTime() : -1);
461            dataOutput.writeLong((getEndTime() != null) ? getEndTime().getTime() : -1);
462            WritableUtils.writeStr(dataOutput, getUser());
463            WritableUtils.writeStr(dataOutput, getGroup());
464            WritableUtils.writeStr(dataOutput, getExternalId());
465            dataOutput.writeInt(getTimeout());
466        }
467    
468        @Override
469        public void readFields(DataInput dataInput) throws IOException {
470    
471            setAppPath(WritableUtils.readStr(dataInput));
472            setAppName(WritableUtils.readStr(dataInput));
473            setId(WritableUtils.readStr(dataInput));
474            setConf(WritableUtils.readStr(dataInput));
475            setStatus(BundleJob.Status.valueOf(WritableUtils.readStr(dataInput)));
476            setTimeUnit(BundleJob.Timeunit.valueOf(WritableUtils.readStr(dataInput)));
477    
478            long d = dataInput.readLong();
479            if (d != -1) {
480                setKickoffTime(new Date(d));
481            }
482            d = dataInput.readLong();
483            if (d != -1) {
484                setStartTime(new Date(d));
485            }
486            d = dataInput.readLong();
487            if (d != -1) {
488                setEndTime(new Date(d));
489            }
490            setUser(WritableUtils.readStr(dataInput));
491            setGroup(WritableUtils.readStr(dataInput));
492            setExternalId(WritableUtils.readStr(dataInput));
493            setTimeOut(dataInput.readInt());
494        }
495    
496    
497        public Date getEndTime() {
498            return DateUtils.toDate(endTimestamp);
499        }
500    
501        @Override
502        public Date getKickoffTime() {
503            return DateUtils.toDate(kickoffTimestamp);
504        }
505    
506        @Override
507        public Timeunit getTimeUnit() {
508            return Timeunit.valueOf(this.timeUnitStr);
509        }
510    
511        public void setEndTime(Date endTime) {
512            this.endTimestamp = DateUtils.convertDateToTimestamp(endTime);
513        }
514    
515        public void setKickoffTime(Date kickoffTime) {
516            this.kickoffTimestamp = DateUtils.convertDateToTimestamp(kickoffTime);
517        }
518    
519        @Override
520        public Date getPauseTime() {
521            return DateUtils.toDate(pauseTimestamp);
522        }
523    
524        public void setPauseTime(Date pauseTime) {
525            this.pauseTimestamp = DateUtils.convertDateToTimestamp(pauseTime);
526        }
527    
528        /**
529         * @param return the suspendTime
530         */
531        public void setSuspendedTime(Date suspendTime) {
532            this.suspendedTimestamp = DateUtils.convertDateToTimestamp(suspendTime);
533        }
534    
535        @Override
536        @SuppressWarnings("unchecked")
537        public JSONObject toJSONObject() {
538            return toJSONObject("GMT");
539        }
540    
541        @Override
542        @SuppressWarnings("unchecked")
543        public JSONObject toJSONObject(String timeZoneId) {
544            JSONObject json = new JSONObject();
545            json.put(JsonTags.BUNDLE_JOB_PATH, appPath);
546            json.put(JsonTags.BUNDLE_JOB_NAME, appName);
547            json.put(JsonTags.BUNDLE_JOB_ID, id);
548            json.put(JsonTags.BUNDLE_JOB_EXTERNAL_ID, externalId);
549            json.put(JsonTags.BUNDLE_JOB_CONF, getConf());
550            json.put(JsonTags.BUNDLE_JOB_STATUS, getStatus().toString());
551            json.put(JsonTags.BUNDLE_JOB_TIMEUNIT, getTimeUnit().toString());
552            json.put(JsonTags.BUNDLE_JOB_TIMEOUT, timeOut);
553            json.put(JsonTags.BUNDLE_JOB_KICKOFF_TIME, JsonUtils.formatDateRfc822(getKickoffTime(), timeZoneId));
554            json.put(JsonTags.BUNDLE_JOB_START_TIME, JsonUtils.formatDateRfc822(getStartTime(), timeZoneId));
555            json.put(JsonTags.BUNDLE_JOB_END_TIME, JsonUtils.formatDateRfc822(getEndTime(), timeZoneId));
556            json.put(JsonTags.BUNDLE_JOB_PAUSE_TIME, JsonUtils.formatDateRfc822(getPauseTime(), timeZoneId));
557            json.put(JsonTags.BUNDLE_JOB_CREATED_TIME, JsonUtils.formatDateRfc822(getCreatedTime(), timeZoneId));
558            json.put(JsonTags.BUNDLE_JOB_USER, getUser());
559            json.put(JsonTags.BUNDLE_JOB_GROUP, getGroup());
560            json.put(JsonTags.BUNDLE_JOB_ACL, getAcl());
561            json.put(JsonTags.BUNDLE_JOB_CONSOLE_URL, getConsoleUrl());
562            json.put(JsonTags.BUNDLE_COORDINATOR_JOBS, CoordinatorJobBean.toJSONArray(coordJobs, timeZoneId));
563            json.put(JsonTags.TO_STRING, toString());
564    
565            return json;
566        }
567    
568        @Override
569        public String getAppName() {
570            return appName;
571        }
572    
573        @Override
574        public String getAppPath() {
575            return appPath;
576        }
577    
578        @Override
579        public String getConf() {
580            return conf == null ? null : conf.getString();
581        }
582    
583        @Override
584        public String getConsoleUrl() {
585            return consoleUrl;
586        }
587    
588        @Override
589        @SuppressWarnings("unchecked")
590        public List<CoordinatorJob> getCoordinators() {
591            return (List) coordJobs;
592        }
593    
594        @Override
595        @Deprecated
596        public String getGroup() {
597            return group;
598        }
599    
600        @Override
601        public String getAcl() {
602            return getGroup();
603        }
604    
605        @Override
606        public String getId() {
607            return id;
608        }
609    
610        public int getTimeout() {
611            return timeOut;
612        }
613    
614        public String getUser() {
615            return user;
616        }
617    
618        /**
619         * Set id
620         *
621         * @param id the id to set
622         */
623        public void setId(String id) {
624            this.id = id;
625        }
626    
627        /**
628         * Set bundlePath
629         *
630         * @param bundlePath the bundlePath to set
631         */
632        public void setAppPath(String bundlePath) {
633            this.appPath = bundlePath;
634        }
635    
636        /**
637         * Set bundleName
638         *
639         * @param bundleName the bundleName to set
640         */
641        public void setAppName(String bundleName) {
642            this.appName = bundleName;
643        }
644    
645        /**
646         * Return externalId
647         *
648         * @return externalId
649         */
650        public String getExternalId() {
651            return this.externalId;
652        }
653    
654        /**
655         * Set externalId
656         *
657         * @param externalId the externalId to set
658         */
659        public void setExternalId(String externalId) {
660            this.externalId = externalId;
661        }
662    
663        /**
664         * Set conf
665         *
666         * @param conf the conf to set
667         */
668        public void setConf(String conf) {
669            if (this.conf == null) {
670                this.conf = new StringBlob(conf);
671            }
672            else {
673                this.conf.setString(conf);
674            }
675        }
676    
677        public void setConfBlob(StringBlob conf) {
678            this.conf = conf;
679        }
680    
681        public StringBlob getConfBlob() {
682            return conf;
683        }
684    
685        /**
686         * Set status
687         *
688         * @param status the status to set
689         */
690        public void setStatus(Status status) {
691            this.statusStr = status.toString();
692        }
693    
694    
695        @Override
696        public Status getStatus() {
697            return Status.valueOf(this.statusStr);
698        }
699    
700        /**
701         * Set status
702         *
703         * @param status the status to set
704         */
705        public void setStatus(String statusStr) {
706            this.statusStr = statusStr;
707        }
708    
709    
710        /**
711         * @return status string
712         */
713        public String getStatusStr() {
714            return statusStr;
715        }
716    
717    
718        /**
719         * Set timeUnit
720         *
721         * @param timeUnit the timeUnit to set
722         */
723        public void setTimeUnit(Timeunit timeUnit) {
724            this.timeUnitStr = timeUnit.toString();
725        }
726    
727        /**
728         * Set timeOut
729         *
730         * @param timeOut the timeOut to set
731         */
732        public void setTimeOut(int timeOut) {
733            this.timeOut = timeOut;
734        }
735    
736        /**
737         * Set user
738         *
739         * @param user the user to set
740         */
741        public void setUser(String user) {
742            this.user = user;
743        }
744    
745        /**
746         * Set group
747         *
748         * @param group the group to set
749         */
750        public void setGroup(String group) {
751            this.group = group;
752        }
753    
754        /**
755         * Set consoleUrl
756         *
757         * @param consoleUrl the consoleUrl to set
758         */
759        public void setConsoleUrl(String consoleUrl) {
760            this.consoleUrl = consoleUrl;
761        }
762    
763        /**
764         * Set coordJobs
765         *
766         * @param coordJobs the coordJobs to set
767         */
768        public void setCoordJobs(List<CoordinatorJobBean> coordJobs) {
769            this.coordJobs = (coordJobs != null) ? coordJobs : new ArrayList<CoordinatorJobBean>();
770        }
771    
772        /**
773         * Convert a Bundle job list into a JSONArray.
774         *
775         * @param application list.
776         * @param timeZoneId time zone to use for dates in the JSON array.
777         * @return the corresponding JSON array.
778         */
779        @SuppressWarnings("unchecked")
780        public static JSONArray toJSONArray(List<BundleJobBean> applications, String timeZoneId) {
781            JSONArray array = new JSONArray();
782            if (applications != null) {
783                for (BundleJobBean application : applications) {
784                    array.add(application.toJSONObject(timeZoneId));
785                }
786            }
787            return array;
788        }
789    
790    
791        @Override
792        public String toString() {
793            return MessageFormat.format("Bundle id[{0}] status[{1}]", getId(), getStatus());
794        }
795    
796        @Override
797        public Date getStartTime() {
798            return DateUtils.toDate(startTimestamp);
799        }
800    
801        /**
802         * @return true if in terminal status
803         */
804        public boolean isTerminalStatus() {
805            boolean isTerminal = false;
806            switch (getStatus()) {
807                case SUCCEEDED:
808                case FAILED:
809                case KILLED:
810                case DONEWITHERROR:
811                    isTerminal = true;
812                    break;
813                default:
814                    isTerminal = false;
815                    break;
816            }
817            return isTerminal;
818        }
819    }