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