use of org.apache.airavata.registry.core.experiment.catalog.model.Process in project airavata by apache.
the class ExperimentResource 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 EXPERIMENT_STATUS:
generator = new QueryGenerator(EXPERIMENT_STATUS);
generator.setParameter(ExperimentStatusConstants.STATUS_ID, name);
q = generator.selectQuery(em);
ExperimentStatus status = (ExperimentStatus) q.getSingleResult();
ExperimentStatusResource statusResource = (ExperimentStatusResource) Utils.getResource(ResourceType.EXPERIMENT_STATUS, status);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return statusResource;
case EXPERIMENT_ERROR:
generator = new QueryGenerator(EXPERIMENT_ERROR);
generator.setParameter(ExperimentErrorConstants.ERROR_ID, name);
q = generator.selectQuery(em);
ExperimentError experimentError = (ExperimentError) q.getSingleResult();
ExperimentErrorResource processErrorResource = (ExperimentErrorResource) Utils.getResource(ResourceType.EXPERIMENT_ERROR, experimentError);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return processErrorResource;
case EXPERIMENT_INPUT:
generator = new QueryGenerator(EXPERIMENT_INPUT);
generator.setParameter(ExperimentInputConstants.INPUT_NAME, name);
generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
ExperimentInput experimentInput = (ExperimentInput) q.getSingleResult();
ExperimentInputResource experimentInputResource = (ExperimentInputResource) Utils.getResource(ResourceType.EXPERIMENT_INPUT, experimentInput);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return experimentInputResource;
case EXPERIMENT_OUTPUT:
generator = new QueryGenerator(EXPERIMENT_OUTPUT);
generator.setParameter(ExperimentOutputConstants.OUTPUT_NAME, name);
generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
ExperimentOutput experimentOutput = (ExperimentOutput) q.getSingleResult();
ExperimentOutputResource outputResource = (ExperimentOutputResource) Utils.getResource(ResourceType.EXPERIMENT_OUTPUT, experimentOutput);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return outputResource;
case USER_CONFIGURATION_DATA:
generator = new QueryGenerator(USER_CONFIGURATION_DATA);
generator.setParameter(UserConfigurationDataConstants.EXPERIMENT_ID, name);
q = generator.selectQuery(em);
UserConfigurationData configurationData = (UserConfigurationData) q.getSingleResult();
UserConfigurationDataResource configurationDataResource = (UserConfigurationDataResource) Utils.getResource(ResourceType.USER_CONFIGURATION_DATA, configurationData);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return configurationDataResource;
case PROCESS:
generator = new QueryGenerator(PROCESS);
generator.setParameter(ProcessConstants.PROCESS_ID, name);
q = generator.selectQuery(em);
Process process = (Process) q.getSingleResult();
ProcessResource processResource = (ProcessResource) Utils.getResource(ResourceType.PROCESS, process);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return processResource;
default:
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported resource type for experiment resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for experiment resource.");
}
} catch (Exception 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.Process in project airavata by apache.
the class ProcessResource method save.
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
Process existingProcess = em.find(Process.class, processId);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
Process process;
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingProcess == null) {
process = new Process();
} else {
process = existingProcess;
}
process.setProcessId(processId);
process.setExperimentId(experimentId);
process.setCreationTime(creationTime);
process.setLastUpdateTime(lastUpdateTime);
process.setProcessDetail(processDetail);
process.setTaskDag(taskDag);
process.setComputeResourceId(computeResourceId);
process.setApplicationInterfaceId(applicationInterfaceId);
process.setApplicationDeploymentId(applicationDeploymentId);
process.setGatewayExecutionId(gatewayExecutionId);
process.setEnableEmailNotification(enableEmailNotification);
process.setEmailAddresses(emailAddresses);
process.setStorageId(storageResourceId);
process.setUserDn(userDn);
process.setGenerateCert(generateCert);
process.setExperimentDataDir(experimentDataDir);
process.setUserName(userName);
process.setUseUserCRPref(useUserCRPref);
if (existingProcess == null) {
em.persist(process);
} else {
em.merge(process);
}
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();
}
}
}
use of org.apache.airavata.registry.core.experiment.catalog.model.Process in project airavata by apache.
the class ExperimentResource 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 EXPERIMENT_INPUT:
generator = new QueryGenerator(EXPERIMENT_INPUT);
generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ExperimentInput experimentInput = (ExperimentInput) result;
ExperimentInputResource experimentInputResource = (ExperimentInputResource) Utils.getResource(ResourceType.EXPERIMENT_INPUT, experimentInput);
resourceList.add(experimentInputResource);
}
}
break;
case EXPERIMENT_OUTPUT:
generator = new QueryGenerator(EXPERIMENT_OUTPUT);
generator.setParameter(ExperimentOutputConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ExperimentOutput experimentOutput = (ExperimentOutput) result;
ExperimentOutputResource experimentOutputResource = (ExperimentOutputResource) Utils.getResource(ResourceType.EXPERIMENT_OUTPUT, experimentOutput);
resourceList.add(experimentOutputResource);
}
}
break;
case PROCESS:
generator = new QueryGenerator(PROCESS);
generator.setParameter(ProcessConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
Process process = (Process) result;
ProcessResource processResource = (ProcessResource) Utils.getResource(ResourceType.PROCESS, process);
resourceList.add(processResource);
}
}
break;
case EXPERIMENT_ERROR:
generator = new QueryGenerator(EXPERIMENT_ERROR);
generator.setParameter(ExperimentErrorConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ExperimentError experimentError = (ExperimentError) result;
ExperimentErrorResource experimentErrorResource = (ExperimentErrorResource) Utils.getResource(ResourceType.EXPERIMENT_ERROR, experimentError);
resourceList.add(experimentErrorResource);
}
}
break;
case EXPERIMENT_STATUS:
generator = new QueryGenerator(EXPERIMENT_STATUS);
generator.setParameter(ExperimentStatusConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ExperimentStatus experimentStatus = (ExperimentStatus) result;
ExperimentStatusResource experimentStatusResource = (ExperimentStatusResource) Utils.getResource(ResourceType.EXPERIMENT_STATUS, experimentStatus);
resourceList.add(experimentStatusResource);
}
}
break;
default:
logger.error("Unsupported resource type for experiment 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;
}
Aggregations