Search in sources :

Example 6 with ProcessModel

use of org.apache.airavata.model.process.ProcessModel in project airavata by apache.

the class GFacUtils method saveProcessInput.

public static void saveProcessInput(ProcessContext processContext, String inputName, String inputVal) throws GFacException {
    try {
        ExperimentCatalog experimentCatalog = processContext.getExperimentCatalog();
        String processId = processContext.getProcessId();
        ProcessModel processModel = (ProcessModel) experimentCatalog.get(ExperimentCatalogModelType.PROCESS, processId);
        List<InputDataObjectType> processInputs = processModel.getProcessInputs();
        if (processInputs != null && !processInputs.isEmpty()) {
            for (InputDataObjectType processInput : processInputs) {
                if (processInput.getName().equals(inputName)) {
                    processInput.setValue(inputVal);
                }
            }
        }
        experimentCatalog.update(ExperimentCatalogModelType.PROCESS, processModel, processId);
    } catch (RegistryException e) {
        String msg = "expId: " + processContext.getExperimentId() + " processId: " + processContext.getProcessId() + " : - Error while updating experiment inputs";
        throw new GFacException(msg, e);
    }
}
Also used : ProcessModel(org.apache.airavata.model.process.ProcessModel) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType)

Example 7 with ProcessModel

use of org.apache.airavata.model.process.ProcessModel in project airavata by apache.

the class RegistryServerHandler method getJobStatuses.

/**
 * Get Job Statuses for an Experiment
 * This method to be used when need to get the job status of an Experiment. An experiment may have one or many jobs; there for one or many job statuses may turnup
 *
 * @param airavataExperimentId@return JobStatus
 *                                    Job status (string) for all all the existing jobs for the experiment will be returned in the form of a map
 */
@Override
public Map<String, JobStatus> getJobStatuses(String airavataExperimentId) throws RegistryServiceException, TException {
    try {
        experimentCatalog = RegistryFactory.getDefaultExpCatalog();
        if (!experimentCatalog.isExist(ExperimentCatalogModelType.EXPERIMENT, airavataExperimentId)) {
            logger.error(airavataExperimentId, "Error while retrieving job details, experiment {} doesn't exist.", airavataExperimentId);
            throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system..");
        }
        List<Object> processModels = experimentCatalog.get(ExperimentCatalogModelType.PROCESS, Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId);
        Map<String, JobStatus> jobStatus = new HashMap<String, JobStatus>();
        if (processModels != null && !processModels.isEmpty()) {
            for (Object process : processModels) {
                ProcessModel processModel = (ProcessModel) process;
                List<TaskModel> tasks = processModel.getTasks();
                if (tasks != null && !tasks.isEmpty()) {
                    for (TaskModel task : tasks) {
                        String taskId = task.getTaskId();
                        List<Object> jobs = experimentCatalog.get(ExperimentCatalogModelType.JOB, Constants.FieldConstants.JobConstants.TASK_ID, taskId);
                        if (jobs != null && !jobs.isEmpty()) {
                            for (Object jobObject : jobs) {
                                JobModel jobModel = (JobModel) jobObject;
                                String jobID = jobModel.getJobId();
                                List<JobStatus> status = jobModel.getJobStatuses();
                                if (status != null && status.size() > 0) {
                                    jobStatus.put(jobID, status.get(0));
                                }
                            }
                        }
                    }
                }
            }
        }
        logger.debug("Airavata retrieved job statuses for experiment with experiment id : " + airavataExperimentId);
        return jobStatus;
    } catch (Exception e) {
        logger.error(airavataExperimentId, "Error while retrieving the job statuses", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : ProcessModel(org.apache.airavata.model.process.ProcessModel) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) JobStatus(org.apache.airavata.model.status.JobStatus) JobModel(org.apache.airavata.model.job.JobModel) TaskModel(org.apache.airavata.model.task.TaskModel)

Example 8 with ProcessModel

use of org.apache.airavata.model.process.ProcessModel in project airavata by apache.

the class ThriftDataModelConversion method getProcessModel.

public static ProcessModel getProcessModel(ProcessResource processResource) throws RegistryException {
    if (processResource != null) {
        ProcessModel processModel = new ProcessModel();
        processModel.setProcessId(processResource.getProcessId());
        processModel.setExperimentId(processResource.getExperimentId());
        processModel.setCreationTime(processResource.getCreationTime().getTime());
        processModel.setLastUpdateTime(processResource.getLastUpdateTime().getTime());
        processModel.setProcessDetail(processResource.getProcessDetail());
        processModel.setApplicationInterfaceId(processResource.getApplicationInterfaceId());
        processModel.setTaskDag(processResource.getTaskDag());
        processModel.setGatewayExecutionId(processResource.getGatewayExecutionId());
        processModel.setApplicationDeploymentId(processResource.getApplicationDeploymentId());
        processModel.setComputeResourceId(processResource.getComputeResourceId());
        processModel.setEnableEmailNotification(processResource.getEnableEmailNotification());
        processModel.setExperimentDataDir(processResource.getExperimentDataDir());
        processModel.setUseUserCRPref(processResource.isUseUserCRPref());
        if (processModel.isEnableEmailNotification()) {
            String notificationEmails = processResource.getEmailAddresses();
            processModel.setEmailAddresses(getEmailAddresses(notificationEmails.split(",")));
        }
        processModel.setProcessInputs(getProcessInputs(processResource.getProcessInputs()));
        processModel.setProcessOutputs(getProcessOutputs(processResource.getProcessOutputs()));
        ErrorModel errorModel = getErrorModel(processResource.getProcessError());
        if (errorModel != null) {
            List<ErrorModel> errorModels = new ArrayList<>();
            errorModels.add(errorModel);
            processModel.setProcessErrors(errorModels);
        }
        ProcessStatus processStatus = getProcessStatus(processResource.getProcessStatus());
        if (processStatus != null) {
            List<ProcessStatus> statuses = new ArrayList<>();
            statuses.add(processStatus);
            processModel.setProcessStatuses(statuses);
        }
        ComputationalResourceSchedulingModel schedule = getProcessResourceSchedule(processResource.getProcessResourceSchedule());
        if (schedule != null) {
            processModel.setProcessResourceSchedule(schedule);
        }
        processModel.setTasks(getTaskModelList(processResource.getTaskList()));
        processModel.setStorageResourceId(processResource.getStorageResourceId());
        processModel.setUserDn(processResource.getUserDn());
        processModel.setGenerateCert(processResource.isGenerateCert());
        processModel.setUserName(processResource.getUserName());
        return processModel;
    }
    return null;
}
Also used : ProcessModel(org.apache.airavata.model.process.ProcessModel) ArrayList(java.util.ArrayList) ErrorModel(org.apache.airavata.model.commons.ErrorModel) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)

Example 9 with ProcessModel

use of org.apache.airavata.model.process.ProcessModel in project airavata by apache.

the class OrchestratorServerHandler method launchExperiment.

/**
 * * After creating the experiment Data user have the * experimentID as the
 * handler to the experiment, during the launchProcess * We just have to
 * give the experimentID * * @param experimentID * @return sucess/failure *
 * *
 *
 * @param experimentId
 */
public boolean launchExperiment(String experimentId, String gatewayId) throws TException {
    ExperimentModel experiment = null;
    try {
        String experimentNodePath = GFacUtils.getExperimentNodePath(experimentId);
        ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentNodePath);
        String experimentCancelNode = ZKPaths.makePath(experimentNodePath, ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE);
        ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentCancelNode);
        experiment = (ExperimentModel) experimentCatalog.get(ExperimentCatalogModelType.EXPERIMENT, experimentId);
        if (experiment == null) {
            log.error("Error retrieving the Experiment by the given experimentID: {} ", experimentId);
            return false;
        }
        ComputeResourcePreference computeResourcePreference = appCatalog.getGatewayProfile().getComputeResourcePreference(gatewayId, experiment.getUserConfigurationData().getComputationalResourceScheduling().getResourceHostId());
        String token = computeResourcePreference.getResourceSpecificCredentialStoreToken();
        if (token == null || token.isEmpty()) {
            // try with gateway profile level token
            GatewayResourceProfile gatewayProfile = appCatalog.getGatewayProfile().getGatewayProfile(gatewayId);
            token = gatewayProfile.getCredentialStoreToken();
        }
        // still the token is empty, then we fail the experiment
        if (token == null || token.isEmpty()) {
            log.error("You have not configured credential store token at gateway profile or compute resource preference." + " Please provide the correct token at gateway profile or compute resource preference.");
            return false;
        }
        ExperimentType executionType = experiment.getExperimentType();
        if (executionType == ExperimentType.SINGLE_APPLICATION) {
            // its an single application execution experiment
            List<ProcessModel> processes = orchestrator.createProcesses(experimentId, gatewayId);
            for (ProcessModel processModel : processes) {
                // FIXME Resolving replica if available. This is a very crude way of resolving input replicas. A full featured
                // FIXME replica resolving logic should come here
                ReplicaCatalog replicaCatalog = RegistryFactory.getReplicaCatalog();
                processModel.getProcessInputs().stream().forEach(pi -> {
                    if (pi.getType().equals(DataType.URI) && pi.getValue().startsWith("airavata-dp://")) {
                        try {
                            DataProductModel dataProductModel = replicaCatalog.getDataProduct(pi.getValue());
                            Optional<DataReplicaLocationModel> rpLocation = dataProductModel.getReplicaLocations().stream().filter(rpModel -> rpModel.getReplicaLocationCategory().equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)).findFirst();
                            if (rpLocation.isPresent()) {
                                pi.setValue(rpLocation.get().getFilePath());
                                pi.setStorageResourceId(rpLocation.get().getStorageResourceId());
                            } else {
                                log.error("Could not find a replica for the URI " + pi.getValue());
                            }
                        } catch (ReplicaCatalogException e) {
                            log.error(e.getMessage(), e);
                        }
                    } else if (pi.getType().equals(DataType.URI_COLLECTION) && pi.getValue().contains("airavata-dp://")) {
                        try {
                            String[] uriList = pi.getValue().split(",");
                            final ArrayList<String> filePathList = new ArrayList<>();
                            for (String uri : uriList) {
                                if (uri.startsWith("airavata-dp://")) {
                                    DataProductModel dataProductModel = replicaCatalog.getDataProduct(uri);
                                    Optional<DataReplicaLocationModel> rpLocation = dataProductModel.getReplicaLocations().stream().filter(rpModel -> rpModel.getReplicaLocationCategory().equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)).findFirst();
                                    if (rpLocation.isPresent()) {
                                        filePathList.add(rpLocation.get().getFilePath());
                                    } else {
                                        log.error("Could not find a replica for the URI " + pi.getValue());
                                    }
                                } else {
                                    // uri is in file path format
                                    filePathList.add(uri);
                                }
                            }
                            pi.setValue(StringUtils.join(filePathList, ','));
                        } catch (ReplicaCatalogException e) {
                            log.error(e.getMessage(), e);
                        }
                    }
                });
                String taskDag = orchestrator.createAndSaveTasks(gatewayId, processModel, experiment.getUserConfigurationData().isAiravataAutoSchedule());
                processModel.setTaskDag(taskDag);
                experimentCatalog.update(ExperimentCatalogModelType.PROCESS, processModel, processModel.getProcessId());
            }
            if (!validateProcess(experimentId, processes)) {
                log.error("Validating process fails for given experiment Id : {}", experimentId);
                return false;
            }
            log.debug(experimentId, "Launching single application experiment {}.", experimentId);
            ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED);
            status.setReason("submitted all processes");
            status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            OrchestratorUtils.updageAndPublishExperimentStatus(experimentId, status, publisher, gatewayId);
            log.info("expId: {}, Launched experiment ", experimentId);
            OrchestratorServerThreadPoolExecutor.getCachedThreadPool().execute(MDCUtil.wrapWithMDC(new SingleAppExperimentRunner(experimentId, token, gatewayId)));
        } else if (executionType == ExperimentType.WORKFLOW) {
            // its a workflow execution experiment
            log.debug(experimentId, "Launching workflow experiment {}.", experimentId);
            launchWorkflowExperiment(experimentId, token, gatewayId);
        } else {
            log.error(experimentId, "Couldn't identify experiment type, experiment {} is neither single application nor workflow.", experimentId);
            throw new TException("Experiment '" + experimentId + "' launch failed. Unable to figureout execution type for application " + experiment.getExecutionId());
        }
    } catch (LaunchValidationException launchValidationException) {
        ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED);
        status.setReason("Validation failed: " + launchValidationException.getErrorMessage());
        status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        OrchestratorUtils.updageAndPublishExperimentStatus(experimentId, status, publisher, gatewayId);
        throw new TException("Experiment '" + experimentId + "' launch failed. Experiment failed to validate: " + launchValidationException.getErrorMessage(), launchValidationException);
    } catch (Exception e) {
        throw new TException("Experiment '" + experimentId + "' launch failed. Unable to figureout execution type for application " + experiment.getExecutionId(), e);
    }
    return true;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) MDCUtil(org.apache.airavata.common.logging.MDCUtil) LoggerFactory(org.slf4j.LoggerFactory) org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants(org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants) Stat(org.apache.zookeeper.data.Stat) DataReplicaLocationModel(org.apache.airavata.model.data.replica.DataReplicaLocationModel) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) ZKPaths(org.apache.curator.utils.ZKPaths) ServerSettings(org.apache.airavata.common.utils.ServerSettings) TBase(org.apache.thrift.TBase) OrchestratorServerThreadPoolExecutor(org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor) AbstractExpCatResource(org.apache.airavata.registry.core.experiment.catalog.resources.AbstractExpCatResource) ZkConstants(org.apache.airavata.common.utils.ZkConstants) ApplicationInterfaceDescription(org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription) OrchestratorService(org.apache.airavata.orchestrator.cpi.OrchestratorService) DataType(org.apache.airavata.model.application.io.DataType) ValidationResults(org.apache.airavata.model.error.ValidationResults) HostScheduler(org.apache.airavata.gfac.core.scheduler.HostScheduler) AppCatAbstractResource(org.apache.airavata.registry.core.app.catalog.resources.AppCatAbstractResource) CuratorFramework(org.apache.curator.framework.CuratorFramework) ErrorModel(org.apache.airavata.model.commons.ErrorModel) RetryPolicy(org.apache.curator.RetryPolicy) AiravataUtils(org.apache.airavata.common.utils.AiravataUtils) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) java.util(java.util) SimpleOrchestratorImpl(org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl) MDCConstants(org.apache.airavata.common.logging.MDCConstants) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ReplicaLocationCategory(org.apache.airavata.model.data.replica.ReplicaLocationCategory) ExperimentStatus(org.apache.airavata.model.status.ExperimentStatus) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacUtils(org.apache.airavata.gfac.core.GFacUtils) RegistryFactory(org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) Logger(org.slf4j.Logger) org.apache.airavata.messaging.core(org.apache.airavata.messaging.core) ExperimentState(org.apache.airavata.model.status.ExperimentState) TException(org.apache.thrift.TException) ExperimentType(org.apache.airavata.model.experiment.ExperimentType) DataProductModel(org.apache.airavata.model.data.replica.DataProductModel) ThriftUtils(org.apache.airavata.common.utils.ThriftUtils) org.apache.airavata.registry.cpi(org.apache.airavata.registry.cpi) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) MDC(org.slf4j.MDC) org.apache.airavata.model.messaging.event(org.apache.airavata.model.messaging.event) OrchestratorUtils(org.apache.airavata.orchestrator.util.OrchestratorUtils) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) ProcessModel(org.apache.airavata.model.process.ProcessModel) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) TException(org.apache.thrift.TException) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) ProcessModel(org.apache.airavata.model.process.ProcessModel) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) DataReplicaLocationModel(org.apache.airavata.model.data.replica.DataReplicaLocationModel) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) AiravataException(org.apache.airavata.common.exception.AiravataException) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) DataProductModel(org.apache.airavata.model.data.replica.DataProductModel) ExperimentStatus(org.apache.airavata.model.status.ExperimentStatus) ExperimentType(org.apache.airavata.model.experiment.ExperimentType)

Example 10 with ProcessModel

use of org.apache.airavata.model.process.ProcessModel in project airavata by apache.

the class SimpleOrchestratorImpl method createProcesses.

public List<ProcessModel> createProcesses(String experimentId, String gatewayId) throws OrchestratorException {
    List<ProcessModel> processModels = new ArrayList<ProcessModel>();
    try {
        Registry registry = orchestratorContext.getRegistry();
        ExperimentModel experimentModel = (ExperimentModel) registry.getExperimentCatalog().get(ExperimentCatalogModelType.EXPERIMENT, experimentId);
        List<Object> processList = registry.getExperimentCatalog().get(ExperimentCatalogModelType.PROCESS, Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentId);
        if (processList != null && !processList.isEmpty()) {
            for (Object processObject : processList) {
                ProcessModel processModel = (ProcessModel) processObject;
                processModels.add(processModel);
            }
        } else {
            ProcessModel processModel = ExperimentModelUtil.cloneProcessFromExperiment(experimentModel);
            String processId = (String) registry.getExperimentCatalog().add(ExpCatChildDataType.PROCESS, processModel, experimentId);
            processModel.setProcessId(processId);
            processModels.add(processModel);
        }
    } catch (Exception e) {
        throw new OrchestratorException("Error during creating process");
    }
    return processModels;
}
Also used : ProcessModel(org.apache.airavata.model.process.ProcessModel) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) URISyntaxException(java.net.URISyntaxException) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) AiravataException(org.apache.airavata.common.exception.AiravataException) TaskException(org.apache.airavata.gfac.core.task.TaskException) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) TException(org.apache.thrift.TException)

Aggregations

ProcessModel (org.apache.airavata.model.process.ProcessModel)19 TException (org.apache.thrift.TException)7 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)6 JobModel (org.apache.airavata.model.job.JobModel)5 AiravataException (org.apache.airavata.common.exception.AiravataException)4 ComputationalResourceSchedulingModel (org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)4 URISyntaxException (java.net.URISyntaxException)3 ApplicationDeploymentDescription (org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription)3 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)3 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)3 ErrorModel (org.apache.airavata.model.commons.ErrorModel)3 AppCatalog (org.apache.airavata.registry.cpi.AppCatalog)3 java.util (java.util)2 ComputeResourcePreference (org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)2 DataType (org.apache.airavata.model.application.io.DataType)2 LaunchValidationException (org.apache.airavata.model.error.LaunchValidationException)2 ExperimentModel (org.apache.airavata.model.experiment.ExperimentModel)2 org.apache.airavata.model.messaging.event (org.apache.airavata.model.messaging.event)2 OrchestratorException (org.apache.airavata.orchestrator.core.exception.OrchestratorException)2 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)2