Search in sources :

Example 46 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class QueueStatusResource method get.

/**
 * This method will list all the child resources for the given resource type
 *
 * @param type child resource type
 * @return list of child resources of the given child resource type
 */
@Override
public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
    List<ExperimentCatResource> result = new ArrayList<>();
    EntityManager em = null;
    try {
        String query = "SELECT q from QueueStatus q WHERE q.time IN (SELECT MAX(q2.time) FROM QueueStatus q2 GROUP BY q2.hostName, q2.queueName)";
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q = em.createQuery(query);
        List resultList = q.getResultList();
        for (Object o : resultList) {
            QueueStatus queueStatus = (QueueStatus) o;
            QueueStatusResource queueStatusResource = new QueueStatusResource();
            queueStatusResource.setHostName(queueStatus.getHostName());
            queueStatusResource.setQueueName(queueStatus.getQueueName());
            queueStatusResource.setTime(queueStatus.getTime());
            queueStatusResource.setQueueUp(queueStatus.getQueueUp());
            queueStatusResource.setQueuedJobs(queueStatus.getQueuedJobs());
            queueStatusResource.setRunningJobs(queueStatus.getRunningJobs());
            result.add(queueStatusResource);
        }
        em.getTransaction().commit();
        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 result;
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) QueueStatus(org.apache.airavata.registry.core.experiment.catalog.model.QueueStatus) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 47 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class TaskResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        Task task;
        Task existingTask = em.find(Task.class, taskId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingTask == null) {
            task = new Task();
        } else {
            task = existingTask;
        }
        task.setTaskId(taskId);
        task.setTaskType(taskType);
        task.setParentProcessId(parentProcessId);
        task.setCreationTime(creationTime);
        task.setLastUpdateTime(lastUpdateTime);
        task.setTaskDetail(taskDetail);
        task.setSetSubTaskModel(subTaskModel);
        if (existingTask == null) {
            em.persist(task);
        } else {
            em.merge(task);
        }
        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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Task(org.apache.airavata.registry.core.experiment.catalog.model.Task) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 48 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class TaskResource method remove.

public void remove(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        QueryGenerator generator;
        switch(type) {
            case TASK_STATUS:
                generator = new QueryGenerator(TASK_STATUS);
                generator.setParameter(TaskStatusConstants.STATUS_ID, name);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            case TASK_ERROR:
                generator = new QueryGenerator(TASK_ERROR);
                generator.setParameter(TaskErrorConstants.ERROR_ID, name);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.JOB_ID, name);
                generator.setParameter(JobConstants.TASK_ID, taskId);
                q = generator.deleteQuery(em);
                q.executeUpdate();
                break;
            default:
                logger.error("Unsupported resource type for job details resource.", new IllegalArgumentException());
                break;
        }
        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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 49 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class TaskResource 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 TASK_STATUS:
                generator = new QueryGenerator(TASK_STATUS);
                generator.setParameter(TaskStatusConstants.STATUS_ID, name);
                q = generator.selectQuery(em);
                TaskStatus status = (TaskStatus) q.getSingleResult();
                TaskStatusResource statusResource = (TaskStatusResource) Utils.getResource(ResourceType.TASK_STATUS, status);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return statusResource;
            case TASK_ERROR:
                generator = new QueryGenerator(TASK_ERROR);
                generator.setParameter(TaskErrorConstants.ERROR_ID, name);
                q = generator.selectQuery(em);
                TaskError error = (TaskError) q.getSingleResult();
                TaskErrorResource errorResource = (TaskErrorResource) Utils.getResource(ResourceType.TASK_ERROR, error);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return errorResource;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.JOB_ID, name);
                generator.setParameter(JobConstants.TASK_ID, taskId);
                q = generator.selectQuery(em);
                Job job = (Job) q.getSingleResult();
                JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return jobResource;
            default:
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                logger.error("Unsupported resource type for Task resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for Task 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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) TaskError(org.apache.airavata.registry.core.experiment.catalog.model.TaskError) TaskStatus(org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus) Job(org.apache.airavata.registry.core.experiment.catalog.model.Job) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 50 with RegistryException

use of org.apache.airavata.registry.cpi.RegistryException in project airavata by apache.

the class UserResource method save.

/**
 * save user to the database
 */
public void save() throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        UserPK userPK = new UserPK();
        userPK.setGatewayId(gatewayId);
        userPK.setUserName(userName);
        Users existingUser = em.find(Users.class, userPK);
        Gateway gateway = em.find(Gateway.class, gatewayId);
        em.close();
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Users user = new Users();
        user.setAiravataInternalUserId(userName + "@" + gatewayId);
        user.setUserName(userName);
        user.setGatewayId(gateway.getGatewayId());
        user.setGateway(gateway);
        if (password != null && !password.equals("")) {
            try {
                user.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method")));
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e);
            } catch (ApplicationSettingsException e) {
                throw new RuntimeException("Error reading hash algorithm from configurations", e);
            }
        }
        if (existingUser != null) {
            if (password != null && !password.equals("")) {
                try {
                    existingUser.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method")));
                    existingUser.setGatewayId(gateway.getGatewayId());
                    existingUser.setGateway(gateway);
                } catch (NoSuchAlgorithmException e) {
                    throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e);
                } catch (ApplicationSettingsException e) {
                    throw new RuntimeException("Error reading hash algorithm from configurations", e);
                }
            }
            user = em.merge(existingUser);
        } else {
            em.persist(user);
        }
        em.getTransaction().commit();
        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();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) UserPK(org.apache.airavata.registry.core.experiment.catalog.model.UserPK) Gateway(org.apache.airavata.registry.core.experiment.catalog.model.Gateway) Users(org.apache.airavata.registry.core.experiment.catalog.model.Users) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

RegistryException (org.apache.airavata.registry.cpi.RegistryException)134 EntityManager (javax.persistence.EntityManager)54 Query (javax.persistence.Query)29 QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)29 ArrayList (java.util.ArrayList)15 List (java.util.List)12 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)12 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)11 ExperimentCatalogException (org.apache.airavata.registry.cpi.ExperimentCatalogException)8 AiravataException (org.apache.airavata.common.exception.AiravataException)6 GFacException (org.apache.airavata.gfac.core.GFacException)6 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)6 Node (org.apache.airavata.workflow.model.graph.Node)6 DynamicNode (org.apache.airavata.workflow.model.graph.dynamic.DynamicNode)6 SubWorkflowNode (org.apache.airavata.workflow.model.graph.subworkflow.SubWorkflowNode)6 WSNode (org.apache.airavata.workflow.model.graph.ws.WSNode)6 Timestamp (java.sql.Timestamp)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 DataPort (org.apache.airavata.workflow.model.graph.DataPort)4 HashMap (java.util.HashMap)3