Search in sources :

Example 86 with RegistryException

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

the class ExperimentRegistry method addTaskStatus.

public String addTaskStatus(TaskStatus taskStatus, String taskID) throws RegistryException {
    try {
        TaskResource taskResource = new TaskResource();
        taskResource.setTaskId(taskID);
        TaskStatusResource status = taskResource.getTaskStatus();
        TaskState newState = taskStatus.getState();
        if (status == null) {
            status = (TaskStatusResource) taskResource.create(ResourceType.TASK_STATUS);
            status.setStatusId(getStatusID("TASK_STATE"));
        } else {
            String state = status.getState();
            if (newState != null && !state.equals(newState.toString())) {
                status.setStatusId(getStatusID("TASK_STATE"));
            }
        }
        status.setTaskId(taskID);
        status.setTimeOfStateChange(AiravataUtils.getTime(taskStatus.getTimeOfStateChange()));
        if (newState != null) {
            status.setState(newState.toString());
        }
        status.setReason(taskStatus.getReason());
        status.save();
        logger.debug(taskID, "Added task {} status to {}.", taskID, taskStatus.toString());
    } catch (Exception e) {
        logger.error(taskID, "Error while adding task status...", e);
        throw new RegistryException(e);
    }
    return taskID;
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 87 with RegistryException

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

the class ExperimentRegistry method updateProcess.

public void updateProcess(ProcessModel process, String processId) throws RegistryException {
    try {
        ExperimentResource experimentResource = new ExperimentResource();
        ProcessResource processResource = experimentResource.getProcess(processId);
        processResource.setProcessId(process.getProcessId());
        processResource.setExperimentId(process.getExperimentId());
        processResource.setCreationTime(AiravataUtils.getTime(process.getCreationTime()));
        processResource.setLastUpdateTime(AiravataUtils.getTime(process.getLastUpdateTime()));
        processResource.setProcessDetail(process.getProcessDetail());
        processResource.setApplicationInterfaceId(process.getApplicationInterfaceId());
        processResource.setTaskDag(process.getTaskDag());
        processResource.setGatewayExecutionId(process.getGatewayExecutionId());
        processResource.setComputeResourceId(process.getComputeResourceId());
        processResource.setApplicationDeploymentId(process.getApplicationDeploymentId());
        processResource.setStorageResourceId(process.getStorageResourceId());
        processResource.setUserDn(process.getUserDn());
        processResource.setGenerateCert(process.isGenerateCert());
        processResource.setExperimentDataDir(process.getExperimentDataDir());
        processResource.setUserName(process.getUserName());
        processResource.setUseUserCRPref(process.isUseUserCRPref());
        if (process.isEnableEmailNotification()) {
            processResource.setEnableEmailNotification(true);
            if (process.getEmailAddresses() != null) {
                processResource.setEmailAddresses(StringUtils.join(process.getEmailAddresses(), ","));
            }
        } else {
            processResource.setEnableEmailNotification(false);
        }
        processResource.save();
        if (process.getProcessResourceSchedule() != null) {
            updateProcessResourceSchedule(process.getProcessResourceSchedule(), process.getProcessId());
        }
        if (process.getProcessInputs() != null && process.getProcessInputs().size() > 0) {
            updateProcessInputs(process.getProcessInputs(), process.getProcessId());
        }
        if (process.getProcessOutputs() != null && process.getProcessOutputs().size() > 0) {
            updateProcessOutputs(process.getProcessOutputs(), process.getProcessId());
        }
        if (process.getProcessStatuses() != null) {
            updateProcessStatus(process.getProcessStatuses().get(0), process.getProcessId());
        }
        if (process.getProcessErrors() != null) {
            updateProcessError(process.getProcessErrors().get(0), process.getProcessId());
        }
        if (process.getTasks() != null && process.getTasks().size() > 0) {
            for (TaskModel task : process.getTasks()) {
                updateTask(task, task.getTaskId());
            }
        }
    } catch (Exception e) {
        logger.error("Error while updating process...", e);
        throw new RegistryException(e);
    }
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) TaskModel(org.apache.airavata.model.task.TaskModel) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 88 with RegistryException

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

the class ExperimentRegistry method updateTask.

public String updateTask(TaskModel task, String taskID) throws RegistryException {
    try {
        ProcessResource processResource = new ProcessResource();
        TaskResource taskResource = processResource.getTask(taskID);
        taskResource.setTaskId(task.getTaskId());
        taskResource.setParentProcessId(task.getParentProcessId());
        taskResource.setTaskType(task.getTaskType().toString());
        taskResource.setCreationTime(AiravataUtils.getTime(task.getCreationTime()));
        taskResource.setLastUpdateTime(AiravataUtils.getTime(task.getLastUpdateTime()));
        taskResource.setTaskDetail(task.getTaskDetail());
        taskResource.setSubTaskModel(task.getSubTaskModel());
        taskResource.save();
        if (task.getTaskErrors() != null) {
            updateTaskError(task.getTaskErrors().get(0), task.getTaskId());
        }
        if (task.getTaskErrors() != null) {
            updateTaskError(task.getTaskErrors().get(0), task.getTaskId());
        }
    } catch (Exception e) {
        logger.error(taskID, "Error while adding task...", e);
        throw new RegistryException(e);
    }
    return taskID;
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 89 with RegistryException

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

the class GatewayRegistry method addGateway.

public String addGateway(Gateway gateway) throws RegistryException {
    try {
        GatewayResource resource = (GatewayResource) ExpCatResourceUtils.createGateway(gateway.getGatewayId());
        resource.setGatewayApprovalStatus(gateway.getGatewayApprovalStatus().toString());
        resource.setGatewayName(gateway.getGatewayName());
        resource.setEmailAddress(gateway.getEmailAddress());
        resource.setDomain(gateway.getDomain());
        resource.setGatewayAcronym(gateway.getGatewayAcronym());
        resource.setGatewayUrl(gateway.getGatewayURL());
        resource.setGatewayPublicAbstract(gateway.getGatewayPublicAbstract());
        resource.setReviewProposalDescription(gateway.getReviewProposalDescription());
        resource.setGatewayAdminFirstName(gateway.getGatewayAdminFirstName());
        resource.setGetGatewayAdminLastName(gateway.getGatewayAdminLastName());
        resource.setGatewayAdminEmail(gateway.getGatewayAdminEmail());
        resource.setIdentityServerUserName(gateway.getIdentityServerUserName());
        resource.setIdentityServerPasswordToken(gateway.getIdentityServerPasswordToken());
        resource.setDeclinedReason(gateway.getDeclinedReason());
        resource.setOauthClientId(gateway.getOauthClientId());
        resource.setOauthClientSecret(gateway.getOauthClientSecret());
        resource.setRequestCreationTime(new Timestamp(System.currentTimeMillis()));
        resource.setRequesterUsername(gateway.getRequesterUsername());
        resource.save();
        return gateway.getGatewayId();
    } catch (RegistryException e) {
        logger.error("Error while saving gateway to registry", e);
        throw new RegistryException(e);
    }
}
Also used : GatewayResource(org.apache.airavata.registry.core.experiment.catalog.resources.GatewayResource) Timestamp(java.sql.Timestamp) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 90 with RegistryException

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

the class WorkerResource method searchExperiments.

/**
 * To search the experiments of user with the given time period and filter criteria and retrieve the results with
 * pagination support. Results can be ordered based on an identifier (i.e column) either ASC or
 * DESC. But in the current implementation ordering is only supported based on creationTime. Also if
 * time period values i.e fromTime and toTime are null they will be ignored.
 *
 * @param fromTime
 * @param toTime
 * @param filters
 * @param limit
 * @param offset
 * @param orderByIdentifier
 * @param resultOrderType
 * @return
 * @throws org.apache.airavata.registry.cpi.RegistryException
 */
public List<ExperimentSummaryResource> searchExperiments(List<String> accessibleIds, Timestamp fromTime, Timestamp toTime, Map<String, String> filters, int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
    List<ExperimentSummaryResource> result = new ArrayList();
    EntityManager em = null;
    try {
        Map<String, Object> queryParameters = new HashMap<>();
        String query = "SELECT e FROM ExperimentSummary e " + "WHERE ";
        // FIXME There is a performance bottleneck for using IN clause. Try using temporary tables ?
        if (accessibleIds != null && accessibleIds.size() > 0) {
            query += " e.experimentId IN (";
            int accessibleIdIndex = 0;
            for (String id : accessibleIds) {
                String paramName = "accessibleId" + accessibleIdIndex;
                query += (":" + paramName + ",");
                queryParameters.put(paramName, id);
                accessibleIdIndex++;
            }
            query = query.substring(0, query.length() - 1) + ") AND ";
        } else if (ServerSettings.isEnableSharing() && (accessibleIds == null || accessibleIds.size() == 0)) {
            return new ArrayList<>();
        }
        if (filters.get(ExperimentStatusConstants.STATE) != null) {
            String experimentState = ExperimentState.valueOf(filters.get(ExperimentStatusConstants.STATE)).toString();
            query += "e.state='" + experimentState + "' AND ";
        }
        if (toTime != null && fromTime != null && toTime.after(fromTime)) {
            query += "e.creationTime > :fromTime AND e.creationTime < :toTime AND ";
            queryParameters.put("fromTime", fromTime);
            queryParameters.put("toTime", toTime);
        }
        filters.remove(ExperimentStatusConstants.STATE);
        if (filters != null && filters.size() != 0) {
            for (String field : filters.keySet()) {
                String filterVal = filters.get(field);
                if (field.equals(ExperimentConstants.USER_NAME)) {
                    query += "e." + field + "= :username AND ";
                    queryParameters.put("username", filterVal);
                } else if (field.equals(ExperimentConstants.GATEWAY_ID)) {
                    query += "e." + field + "= :gateway_id AND ";
                    queryParameters.put("gateway_id", filterVal);
                } else if (field.equals(ExperimentConstants.PROJECT_ID)) {
                    query += "e." + field + "= :project_id AND ";
                    queryParameters.put("project_id", filterVal);
                } else {
                    if (filterVal.contains("*")) {
                        filterVal = filterVal.replaceAll("\\*", "");
                    }
                    query += "e." + field + " LIKE :" + field + " AND ";
                    queryParameters.put(field, "%" + filterVal + "%");
                }
            }
        }
        query = query.substring(0, query.length() - 5);
        // ordering
        if (orderByIdentifier != null && resultOrderType != null && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)) {
            String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
            query += " ORDER BY e." + ExperimentConstants.CREATION_TIME + " " + order;
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        // pagination
        if (offset >= 0 && limit >= 0) {
            q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit);
        } else {
            q = em.createQuery(query);
        }
        for (String parameterName : queryParameters.keySet()) {
            q.setParameter(parameterName, queryParameters.get(parameterName));
        }
        List resultList = q.getResultList();
        for (Object o : resultList) {
            ExperimentSummary experimentSummary = (ExperimentSummary) o;
            ExperimentSummaryResource experimentSummaryResource = (ExperimentSummaryResource) Utils.getResource(ResourceType.EXPERIMENT_SUMMARY, experimentSummary);
            result.add(experimentSummaryResource);
        }
        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 : Query(javax.persistence.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) List(java.util.List)

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