Search in sources :

Example 51 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class EmailBasedMonitor method process.

private void process(JobStatusResult jobStatusResult, TaskContext taskContext) {
    canceledJobs.remove(jobStatusResult.getJobId());
    JobState resultState = jobStatusResult.getState();
    // TODO : update job state on process context
    boolean runOutflowTasks = false;
    JobStatus jobStatus = new JobStatus();
    ProcessContext parentProcessContext = taskContext.getParentProcessContext();
    JobModel jobModel = parentProcessContext.getJobModel();
    String jobDetails = "JobName : " + jobStatusResult.getJobName() + ", JobId : " + jobStatusResult.getJobId();
    JobState currentState = null;
    List<JobStatus> jobStatusList = jobModel.getJobStatuses();
    if (jobStatusList != null && jobStatusList.size() > 0) {
        JobStatus lastStatus = jobStatusList.get(0);
        for (JobStatus temp : jobStatusList) {
            if (temp.getTimeOfStateChange() >= lastStatus.getTimeOfStateChange()) {
                lastStatus = temp;
            }
        }
        currentState = lastStatus.getJobState();
    }
    // FIXME - What if non-authoritative email comes later (getting accumulated in the email account)
    if (resultState == JobState.COMPLETE) {
        if (jobStatusResult.isAuthoritative()) {
            if (currentState != null && currentState == JobState.COMPLETE) {
                jobMonitorMap.remove(jobStatusResult.getJobId());
                runOutflowTasks = false;
                log.info("[EJM]: Authoritative job Complete email received after early Airavata custom complete email," + " removed job from job monitoring. " + jobDetails);
            } else {
                jobMonitorMap.remove(jobStatusResult.getJobId());
                runOutflowTasks = true;
                jobStatus.setJobState(JobState.COMPLETE);
                jobStatus.setReason("Complete email received");
                jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
                log.info("[EJM]: Authoritative job Complete email received , removed job from job monitoring. " + jobDetails);
            }
        } else {
            runOutflowTasks = true;
            jobStatus.setJobState(JobState.COMPLETE);
            jobStatus.setReason("Complete email received");
            jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            log.info("[EJM]: Non Authoritative Job Complete email received. " + jobDetails);
        }
    } else if (resultState == JobState.QUEUED) {
        // scheduler
        if (currentState != JobState.COMPLETE) {
            // nothing special thing to do, update the status change to rabbit mq at the end of this method.
            jobStatus.setJobState(JobState.QUEUED);
            jobStatus.setReason("Queue email received");
            jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            log.info("[EJM]: Job Queued email received, " + jobDetails);
        }
    } else if (resultState == JobState.ACTIVE) {
        // scheduler
        if (currentState != JobState.COMPLETE) {
            // nothing special thing to do, update the status change to rabbit mq at the end of this method.
            jobStatus.setJobState(JobState.ACTIVE);
            jobStatus.setReason("Active email received");
            jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            log.info("[EJM]: Job Active email received, " + jobDetails);
        }
    } else if (resultState == JobState.FAILED) {
        // scheduler
        if (currentState != JobState.COMPLETE) {
            jobMonitorMap.remove(jobStatusResult.getJobId());
            runOutflowTasks = true;
            jobStatus.setJobState(JobState.FAILED);
            jobStatus.setReason("Failed email received");
            jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            log.info("[EJM]: Job failed email received , removed job from job monitoring. " + jobDetails);
        }
    } else if (resultState == JobState.CANCELED) {
        // scheduler
        if (currentState != JobState.COMPLETE) {
            jobMonitorMap.remove(jobStatusResult.getJobId());
            jobStatus.setJobState(JobState.CANCELED);
            jobStatus.setReason("Canceled email received");
            jobStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            log.info("[EJM]: Job canceled mail received, removed job from job monitoring. " + jobDetails);
            // we run out flow and this will move process to cancel state.
            runOutflowTasks = true;
        }
    }
    if (jobStatus.getJobState() != null) {
        try {
            jobModel.setJobStatuses(Arrays.asList(jobStatus));
            log.info("[EJM]: Publishing status changes to amqp. " + jobDetails);
            GFacUtils.saveJobStatus(parentProcessContext, jobModel);
        } catch (GFacException e) {
            log.error("expId: {}, processId: {}, taskId: {}, jobId: {} :- Error while save and publishing Job " + "status {}", taskContext.getExperimentId(), taskContext.getProcessId(), jobModel.getTaskId(), jobModel.getJobId(), jobStatus.getJobState());
        }
    }
    if (runOutflowTasks) {
        log.info("[EJM]: Calling Out Handler chain of " + jobDetails);
        try {
            TaskStatus taskStatus = new TaskStatus(TaskState.COMPLETED);
            taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            taskStatus.setReason("Job monitoring completed with final state: " + TaskState.COMPLETED.name());
            taskContext.setTaskStatus(taskStatus);
            GFacUtils.saveAndPublishTaskStatus(taskContext);
            if (parentProcessContext.isCancel()) {
                ProcessStatus processStatus = new ProcessStatus(ProcessState.CANCELLING);
                processStatus.setReason("Process has been cancelled");
                parentProcessContext.setProcessStatus(processStatus);
                GFacUtils.saveAndPublishProcessStatus(parentProcessContext);
            }
            GFacThreadPoolExecutor.getCachedThreadPool().execute(new GFacWorker(parentProcessContext));
        } catch (GFacException e) {
            log.info("[EJM]: Error while running output tasks", e);
        }
    }
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) GFacWorker(org.apache.airavata.gfac.impl.GFacWorker) JobModel(org.apache.airavata.model.job.JobModel) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext)

Example 52 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class UNICORESecurityContext method getServerSignedConfiguration.

/**
 * Get server signed credentials. Each time it is invoked new certificate
 * is returned.
 *
 * @param userID
 * @param userDN
 * @param caCertPath
 * @param caKeyPath
 * @param caKeyPwd
 * @return
 * @throws GFacException
 */
public DefaultClientConfiguration getServerSignedConfiguration(String userID, String userDN, String caCertPath, String caKeyPath, String caKeyPwd) throws GFacException {
    try {
        KeyAndCertCredential cred = SecurityUtils.generateShortLivedCertificate(userDN, caCertPath, caKeyPath, caKeyPwd);
        secProperties = new DefaultClientConfiguration(dcValidator, cred);
        setExtraSettings();
    } catch (Exception e) {
        throw new GFacException(e.getMessage(), e);
    }
    return secProperties;
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) DefaultClientConfiguration(eu.unicore.util.httpclient.DefaultClientConfiguration) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) GFacException(org.apache.airavata.gfac.core.GFacException) GFacProviderException(org.apache.airavata.gfac.core.provider.GFacProviderException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 53 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class X509SecurityContext method getX509Credentials.

/**
 * Gets X509Credentials. The process is as follows;
 * If credentials were queried for the first time create credentials.
 *   1. Try creating credentials using certificates stored in the credential store
 *   2. If 1 fails use user name and password to create credentials
 * @return x509credentials (from CANL security API)
 * @throws GFacException If an error occurred while creating credentials.
 * @throws org.apache.airavata.common.exception.ApplicationSettingsException
 */
public X509Credential getX509Credentials() throws GFacException, ApplicationSettingsException {
    if (getCredentialReader() == null) {
        return getDefaultCredentials();
    }
    if (x509Credentials == null) {
        try {
            x509Credentials = getCredentialsFromStore();
        } catch (Exception e) {
            log.error("An exception occurred while retrieving credentials from the credential store. " + "Will continue with my proxy user name and password.", e);
        }
        // If store does not have credentials try to get from user name and password
        if (x509Credentials == null) {
            x509Credentials = getDefaultCredentials();
        }
        // if still null, throw an exception
        if (x509Credentials == null) {
            throw new GFacException("Unable to retrieve my proxy credentials to continue operation.");
        }
    } else {
        try {
            final long remainingTime = x509Credentials.getCertificate().getNotAfter().getTime() - new Date().getTime();
            if (remainingTime < CREDENTIAL_RENEWING_THRESH_HOLD) {
                // return renewCredentials();
                log.warn("Do not support credentials renewal");
            }
            log.info("Fall back to get new default credentials");
            try {
                x509Credentials.getCertificate().checkValidity();
            } catch (Exception e) {
                x509Credentials = getDefaultCredentials();
            }
        } catch (Exception e) {
            throw new GFacException("Unable to retrieve remaining life time from credentials.", e);
        }
    }
    return x509Credentials;
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Date(java.util.Date)

Example 54 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class GFacEngineImpl method saveTaskModel.

/**
 * Persist task model
 */
private void saveTaskModel(TaskContext taskContext) throws GFacException {
    try {
        TaskModel taskModel = taskContext.getTaskModel();
        taskContext.getParentProcessContext().getExperimentCatalog().add(ExpCatChildDataType.TASK, taskModel, taskModel.getParentProcessId());
    } catch (RegistryException e) {
        throw new GFacException("Error while saving task model", e);
    }
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EnvironmentSetupTaskModel(org.apache.airavata.model.task.EnvironmentSetupTaskModel) JobSubmissionTaskModel(org.apache.airavata.model.task.JobSubmissionTaskModel) MonitorTaskModel(org.apache.airavata.model.task.MonitorTaskModel) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) TaskModel(org.apache.airavata.model.task.TaskModel)

Example 55 with GFacException

use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.

the class GFacEngineImpl method executeDataStreaming.

private void executeDataStreaming(TaskContext taskContext, boolean recovery) throws GFacException {
    TaskStatus taskStatus = new TaskStatus(TaskState.EXECUTING);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskContext.setTaskStatus(taskStatus);
    GFacUtils.saveAndPublishTaskStatus(taskContext);
    try {
        DataStreamingTask dataStreamingTask = new DataStreamingTask();
        taskStatus = executeTask(taskContext, dataStreamingTask, recovery);
        taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        taskContext.setTaskStatus(taskStatus);
        GFacUtils.saveAndPublishTaskStatus(taskContext);
    } catch (Exception e) {
        throw new GFacException(e);
    }
}
Also used : DataStreamingTask(org.apache.airavata.gfac.impl.task.DataStreamingTask) GFacException(org.apache.airavata.gfac.core.GFacException) TaskStatus(org.apache.airavata.model.status.TaskStatus) URISyntaxException(java.net.URISyntaxException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) TaskException(org.apache.airavata.gfac.core.task.TaskException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacException(org.apache.airavata.gfac.core.GFacException) TException(org.apache.thrift.TException)

Aggregations

GFacException (org.apache.airavata.gfac.core.GFacException)73 IOException (java.io.IOException)24 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)19 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)16 JSchException (com.jcraft.jsch.JSchException)15 RegistryException (org.apache.airavata.registry.cpi.RegistryException)15 AiravataException (org.apache.airavata.common.exception.AiravataException)14 TaskStatus (org.apache.airavata.model.status.TaskStatus)13 URISyntaxException (java.net.URISyntaxException)12 ErrorModel (org.apache.airavata.model.commons.ErrorModel)11 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)10 TException (org.apache.thrift.TException)9 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)8 DefaultClientConfiguration (eu.unicore.util.httpclient.DefaultClientConfiguration)7 URI (java.net.URI)7 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)7 Session (com.jcraft.jsch.Session)6 InvalidKeyException (java.security.InvalidKeyException)6 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)6 JobModel (org.apache.airavata.model.job.JobModel)6