use of org.apache.airavata.registry.core.experiment.catalog.model.JobStatus in project airavata by apache.
the class JobResource method get.
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case JOB_STATUS:
generator = new QueryGenerator(JOB_STATUS);
generator.setParameter(JobStatusConstants.STATUS_ID, name);
q = generator.selectQuery(em);
JobStatus status = (JobStatus) q.getSingleResult();
JobStatusResource statusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, status);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return statusResource;
default:
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported resource type for Job resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for Job resource.");
}
} 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();
}
}
}
use of org.apache.airavata.registry.core.experiment.catalog.model.JobStatus in project airavata by apache.
the class JobResource method get.
public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
Query q;
QueryGenerator generator;
List results;
switch(type) {
case JOB_STATUS:
generator = new QueryGenerator(JOB_STATUS);
generator.setParameter(JobStatusConstants.JOB_ID, jobId);
generator.setParameter(JobStatusConstants.TASK_ID, taskId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
JobStatus jobStatus = (JobStatus) result;
JobStatusResource jobStatusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, jobStatus);
resourceList.add(jobStatusResource);
}
}
break;
default:
logger.error("Unsupported resource type for job resource.", new UnsupportedOperationException());
throw new UnsupportedOperationException();
}
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();
}
}
return resourceList;
}
use of org.apache.airavata.registry.core.experiment.catalog.model.JobStatus 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