Skip to content

Commit

Permalink
Merged in AD-745-JobQueues-Decoupled-Events (pull request #1)
Browse files Browse the repository at this point in the history
JOBS


Former-commit-id: c9efffe
  • Loading branch information
richcar58 committed Dec 9, 2016
2 parents 47d779a + 020cbe4 commit 4dfd89b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.iplantc.service.common.util.TimeUtils;
import org.iplantc.service.jobs.Settings;
import org.iplantc.service.jobs.dao.JobDao;
import org.iplantc.service.jobs.dao.JobEventDao;
import org.iplantc.service.jobs.exceptions.JobDependencyException;
import org.iplantc.service.jobs.exceptions.JobException;
import org.iplantc.service.jobs.exceptions.JobFinishedException;
Expand Down Expand Up @@ -1080,19 +1081,20 @@ else if (!input.isVisible())
/**
* Determines whether the job has completed archiving and can thus
* refer to the archive location for requests for its output data.
*
* TODO: fix this shit
* @param job
* @return
* @throws JobException
*/
public static boolean isJobDataFullyArchived(Job job)
public static boolean isJobDataFullyArchived(Job job) throws JobException
{
if (job.isArchiveOutput())
{
if (job.getStatus() == JobStatusType.ARCHIVING_FINISHED) {
return true;
}
else if (job.getStatus() == JobStatusType.FINISHED) {
for (JobEvent event: job.getEvents()) {
for (JobEvent event: JobEventDao.getByJobId(job.getId())) {
if (StringUtils.equalsIgnoreCase(event.getStatus(), JobStatusType.ARCHIVING_FINISHED.name())) {
return true;
}
Expand All @@ -1104,6 +1106,36 @@ else if (job.getStatus() == JobStatusType.FINISHED) {
// archiving, is in process, or something happened.
return false;
}

/**
* Determines whether the job ever began archiving
* @param job
* @return
* @throws JobException
*/
public static boolean isJobDataPartiallyArchived(Job job) throws JobException
{
if (job.isArchiveOutput())
{
if (job.getStatus() == JobStatusType.ARCHIVING ||
job.getStatus() == JobStatusType.ARCHIVING_FINISHED ||
job.getStatus() == JobStatusType.ARCHIVING_FAILED) {
return true;
}
else if (job.getStatus() == JobStatusType.FINISHED ||
job.getStatus() == JobStatusType.FAILED) {
for (JobEvent event: JobEventDao.getByJobId(job.getId())) {
if (StringUtils.equalsIgnoreCase(event.getStatus(), JobStatusType.ARCHIVING.name())) {
return true;
}
}
}
}

// anything else means the job failed, hasn't reached a point of
// archiving, is in process, or something happened.
return false;
}

/**
* Rolls a {@link Job} back to the previously active state based on its current {@link JobStatusType}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.iplantc.service.common.uuid.AgaveUUID;
import org.iplantc.service.common.uuid.UUIDType;
import org.iplantc.service.jobs.Settings;
import org.iplantc.service.jobs.dao.JobEventDao;
import org.iplantc.service.jobs.exceptions.JobEventProcessingException;
import org.iplantc.service.jobs.exceptions.JobException;
import org.iplantc.service.jobs.managers.JobEventProcessor;
Expand Down Expand Up @@ -130,7 +131,7 @@ public class Job {
private boolean visible; // Can a user see the job?
private Integer version = 0; // Entity version used for optimistic locking
private String tenantId; // current api tenant
private List<JobEvent> events = new ArrayList<JobEvent>(); // complete history of events for this job
// private List<JobEvent> events = new ArrayList<JobEvent>(); // complete history of events for this job

// private Set<Notification> notifications = new HashSet<Notification>(); // all notifications registered to this job

Expand Down Expand Up @@ -546,28 +547,24 @@ public void setStatusChecks(Integer statusChecks) {
* Returns a list of job events in the history of this job.
*
* @return
* @throws JobException
*/
@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "job", fetch=FetchType.EAGER, orphanRemoval=true)
public List<JobEvent> getEvents() {
return events;
}

/**
* @param events
*/
public void setEvents(List<JobEvent> events) {
this.events = events;
@Transient
public List<JobEvent> getEvents() throws JobException {
return JobEventDao.getByJobId(getId());
}

/**
* Adds an event to the history of this job. This will automatically
* be saved with the job when the job is persisted.
*
* @param event
* @throws JobException
*/
public void addEvent(JobEvent event) {
public void addEvent(JobEvent event) throws JobException {
event.setJob(this);
this.events.add(event);
JobEventDao.persist(event);

JobEventProcessor jep;
try {
jep = new JobEventProcessor(event);
Expand Down Expand Up @@ -659,7 +656,7 @@ public void setStatus(JobStatusType status, JobEvent event) throws JobException
}
else {
event.setDescription(event.getDescription() + " Event will be ignored because job has been deleted.");
this.events.add(event);
this.addEvent(event);
}
} else {
// log.debug("Ignoring status update to " + status + " with same message");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.UnresolvableObjectException;
import org.iplantc.service.common.persistence.TenancyHelper;
import org.iplantc.service.jobs.dao.JobDao;
import org.iplantc.service.jobs.dao.JobEventDao;
import org.iplantc.service.jobs.exceptions.JobDependencyException;
import org.iplantc.service.jobs.exceptions.JobException;
import org.iplantc.service.jobs.managers.JobManager;
Expand Down Expand Up @@ -275,11 +276,12 @@ else if (rollbackJobStatus == PENDING)
*
* @param job the job for which to cancel transfers
* @param callingUsername the principal canceling transfers for the job
* @throws JobException
*/
private void cancelCurrentTransfers(Job job, String callingUsername)
private void cancelCurrentTransfers(Job job, String callingUsername) throws JobException
{
// iterate over all job events
for (JobEvent event: job.getEvents())
for (JobEvent event: JobEventDao.getByJobId(job.getId()))
{
// wherever a transfer task is found for an event, cancel it. This will
// issue a single SQL update query to set {@link TransferTask#status} to
Expand Down

0 comments on commit 4dfd89b

Please sign in to comment.