use of org.apache.airavata.registry.core.experiment.catalog.model.JobStatusPK in project airavata by apache.
the class JobStatusResource method save.
public void save() throws RegistryException {
EntityManager em = null;
try {
if (jobId == null || statusId == null || taskId == null) {
throw new RegistryException("Does not have the job id or status id or task id");
}
em = ExpCatResourceUtils.getEntityManager();
JobStatus jobStatus;
JobStatusPK jobStatusPK = new JobStatusPK();
jobStatusPK.setJobId(jobId);
jobStatusPK.setStatusId(statusId);
jobStatusPK.setTaskId(taskId);
JobStatus existingJobStatus = em.find(JobStatus.class, jobStatusPK);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingJobStatus == null) {
jobStatus = new JobStatus();
} else {
jobStatus = existingJobStatus;
}
jobStatus.setStatusId(statusId);
jobStatus.setJobId(jobId);
jobStatus.setTaskId(taskId);
jobStatus.setState(state);
jobStatus.setReason(reason);
if (timeOfStateChange == null) {
timeOfStateChange = AiravataUtils.getCurrentTimestamp();
}
jobStatus.setTimeOfStateChange(timeOfStateChange);
if (existingJobStatus == null) {
em.persist(jobStatus);
} else {
em.merge(jobStatus);
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
Aggregations