Search in sources :

Example 61 with RegistryException

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

the class ExperimentStatusResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        ExperimentStatus experimentStatus;
        if (experimentId == null || statusId == null) {
            throw new RegistryException("Does not have the experiment id or status id");
        }
        ExperimentStatusPK experimentStatusPK = new ExperimentStatusPK();
        experimentStatusPK.setStatusId(statusId);
        experimentStatusPK.setExperimentId(experimentId);
        ExperimentStatus existingStatus = em.find(ExperimentStatus.class, experimentStatusPK);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingStatus == null) {
            experimentStatus = new ExperimentStatus();
        } else {
            experimentStatus = existingStatus;
        }
        experimentStatus.setStatusId(statusId);
        experimentStatus.setExperimentId(experimentId);
        experimentStatus.setState(state);
        experimentStatus.setReason(reason);
        experimentStatus.setTimeOfStateChange(timeOfStateChange);
        if (existingStatus == null) {
            em.persist(experimentStatus);
        } else {
            em.merge(experimentStatus);
        }
        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) ExperimentStatusPK(org.apache.airavata.registry.core.experiment.catalog.model.ExperimentStatusPK) ExperimentStatus(org.apache.airavata.registry.core.experiment.catalog.model.ExperimentStatus) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 62 with RegistryException

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

the class OrchestratorUtils method updageAndPublishExperimentStatus.

public static void updageAndPublishExperimentStatus(String experimentId, ExperimentStatus status, Publisher publisher, String gatewayId) {
    try {
        RegistryFactory.getDefaultExpCatalog().update(ExperimentCatalogModelType.EXPERIMENT_STATUS, status, experimentId);
        ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(status.getState(), experimentId, gatewayId);
        String messageId = AiravataUtils.getId("EXPERIMENT");
        MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId);
        messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
        publisher.publish(messageContext);
    } catch (RegistryException e) {
        log.error("expId : " + experimentId + " Error while updating experiment status to " + status.toString(), e);
    } catch (AiravataException e) {
        log.error("expId : " + experimentId + " Error while publishing experiment status to " + status.toString(), e);
    }
}
Also used : ExperimentStatusChangeEvent(org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent) MessageContext(org.apache.airavata.messaging.core.MessageContext) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 63 with RegistryException

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

the class ExperimentRegistry method removeTask.

public void removeTask(String taskId) throws RegistryException {
    try {
        ProcessResource process = new ProcessResource();
        process.remove(ResourceType.TASK, taskId);
    } catch (Exception e) {
        logger.error("Error while removing task details..", e);
        throw new RegistryException(e);
    }
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 64 with RegistryException

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

the class ExperimentRegistry method addExperiment.

// CPI Add Methods
public String addExperiment(ExperimentModel experiment) throws RegistryException {
    String experimentId;
    try {
        if (!ExpCatResourceUtils.isUserExist(experiment.getUserName(), experiment.getGatewayId())) {
            ExpCatResourceUtils.addUser(experiment.getUserName(), null, experiment.getGatewayId());
        }
        if (!workerResource.isProjectExists(experiment.getProjectId())) {
            logger.error("Project does not exist in the system..");
            throw new Exception("Project does not exist in the system, Please create the project first...");
        }
        experimentId = AiravataUtils.getId(experiment.getExperimentName());
        experiment.setExperimentId(experimentId);
        ExperimentResource experimentResource = new ExperimentResource();
        experimentResource.setExperimentId(experimentId);
        experimentResource.setProjectId(experiment.getProjectId());
        experimentResource.setGatewayId(experiment.getGatewayId());
        experimentResource.setExperimentType(experiment.getExperimentType().toString());
        experimentResource.setUserName(experiment.getUserName());
        experimentResource.setExperimentName(experiment.getExperimentName());
        experimentResource.setCreationTime(AiravataUtils.getTime(experiment.getCreationTime()));
        experimentResource.setDescription(experiment.getDescription());
        experimentResource.setExecutionId(experiment.getExecutionId());
        experimentResource.setGatewayExecutionId(experiment.getGatewayExecutionId());
        experimentResource.setGatewayInstanceId(experiment.getGatewayInstanceId());
        if (experiment.isEnableEmailNotification()) {
            experimentResource.setEnableEmailNotification(true);
            if (experiment.getEmailAddresses() != null) {
                experimentResource.setEmailAddresses(StringUtils.join(experiment.getEmailAddresses(), ","));
            }
        } else {
            experimentResource.setEnableEmailNotification(false);
        }
        experimentResource.save();
        if (experiment.getUserConfigurationData() != null) {
            addUserConfigData(experiment.getUserConfigurationData(), experimentId);
        }
        if (experiment.getExperimentInputs() != null && experiment.getExperimentInputs().size() > 0) {
            addExpInputs(experiment.getExperimentInputs(), experimentId);
        }
        if (experiment.getExperimentOutputs() != null && experiment.getExperimentOutputs().size() > 0) {
            addExpOutputs(experiment.getExperimentOutputs(), experimentId);
        }
        ExperimentStatus experimentStatus = new ExperimentStatus();
        experimentStatus.setState(ExperimentState.CREATED);
        experimentStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        addExperimentStatus(experimentStatus, experimentId);
        List<ErrorModel> errors = experiment.getErrors();
        if (errors != null && !errors.isEmpty()) {
            for (ErrorModel errror : errors) {
                addExperimentError(errror, experimentId);
            }
        }
    } catch (Exception e) {
        logger.error("Error while saving experiment to registry", e);
        throw new RegistryException(e);
    }
    return experimentId;
}
Also used : ErrorModel(org.apache.airavata.model.commons.ErrorModel) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 65 with RegistryException

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

the class ExperimentRegistry method getProcess.

public Object getProcess(String processId, String fieldName) throws RegistryException {
    try {
        ExperimentResource experimentResource = new ExperimentResource();
        ProcessResource resource = experimentResource.getProcess(processId);
        if (fieldName == null) {
            return ThriftDataModelConversion.getProcessModel(resource);
        } else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_ERROR)) {
            return ThriftDataModelConversion.getErrorModel(resource.getProcessError());
        } else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_STATUS)) {
            return ThriftDataModelConversion.getProcessStatus(resource.getProcessStatus());
        } else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_INPUTS)) {
            return ThriftDataModelConversion.getProcessInputs(resource.getProcessInputs());
        } else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_OUTPUTS)) {
            return ThriftDataModelConversion.getProcessOutputs(resource.getProcessOutputs());
        } else if (fieldName.equals(Constants.FieldConstants.ProcessConstants.PROCESS_RESOURCE_SCHEDULE)) {
            return ThriftDataModelConversion.getProcessResourceSchedule(resource.getProcessResourceSchedule());
        } else {
            logger.error("Unsupported field name for process data..");
        }
    } catch (Exception e) {
        logger.error("Error while getting process data..", e);
        throw new RegistryException(e);
    }
    return null;
}
Also used : RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

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