Search in sources :

Example 1 with GFacWorker

use of org.apache.airavata.gfac.impl.GFacWorker in project airavata by apache.

the class EmailBasedMonitor method stopMonitor.

@Override
public void stopMonitor(String jobId, boolean runOutflow) {
    TaskContext taskContext = jobMonitorMap.remove(jobId);
    if (taskContext != null && runOutflow) {
        try {
            ProcessContext pc = taskContext.getParentProcessContext();
            if (taskContext.isCancel()) {
                // Moved job status to cancel
                JobModel jobModel = pc.getJobModel();
                JobStatus newJobStatus = new JobStatus(JobState.CANCELED);
                newJobStatus.setReason("Moving job status to cancel, as we didn't see any email from this job " + "for a while after execute job cancel command. This may happen if job was in queued state " + "when we run the cancel command");
                jobModel.setJobStatuses(Arrays.asList(newJobStatus));
                GFacUtils.saveJobStatus(pc, jobModel);
            }
            ProcessStatus pStatus = new ProcessStatus(ProcessState.CANCELLING);
            pStatus.setReason("Job cancelled");
            pc.setProcessStatus(pStatus);
            GFacUtils.saveAndPublishProcessStatus(pc);
            GFacThreadPoolExecutor.getCachedThreadPool().execute(new GFacWorker(pc));
        } catch (GFacException e) {
            log.info("[EJM]: Error while running output tasks", e);
        }
    }
}
Also used : TaskContext(org.apache.airavata.gfac.core.context.TaskContext) 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 2 with GFacWorker

use of org.apache.airavata.gfac.impl.GFacWorker in project airavata by apache.

the class GfacServerHandler method submitProcess.

/**
 * * After creating the experiment Data and Task Data in the orchestrator
 * * Orchestrator has to invoke this operation for each Task per experiment to run
 * * the actual Job related actions.
 * *
 * * @param experimentID
 * * @param taskID
 * * @param gatewayId:
 * *  The GatewayId is inferred from security context and passed onto gfac.
 * * @return sucess/failure
 * *
 * *
 *
 * @param processId - processModel id in registry
 * @param gatewayId - gateway Identification
 */
public boolean submitProcess(String processId, String gatewayId, String tokenId) throws TException {
    MDC.put(MDCConstants.PROCESS_ID, processId);
    MDC.put(MDCConstants.GATEWAY_ID, gatewayId);
    MDC.put(MDCConstants.TOKEN_ID, tokenId);
    try {
        executorService.execute(MDCUtil.wrapWithMDC(new GFacWorker(processId, gatewayId, tokenId)));
    } catch (GFacException e) {
        log.error("Failed to submit process", e);
        throw new TException("Failed to submit process", e);
    } catch (CredentialStoreException e) {
        log.error("Failed to submit process due to credential issue, " + "make sure you are passing a valid credentials");
        throw new TException("Failed to submit process due to credential issue, " + "make sure you are passing a valid credential token", e);
    } catch (Exception e) {
        log.error("Error creating zookeeper nodes", e);
        throw new TException("Error creating zookeeper nodes", e);
    }
    return true;
}
Also used : TException(org.apache.thrift.TException) GFacException(org.apache.airavata.gfac.core.GFacException) GFacWorker(org.apache.airavata.gfac.impl.GFacWorker) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) AiravataStartupException(org.apache.airavata.common.exception.AiravataStartupException) GFacException(org.apache.airavata.gfac.core.GFacException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 3 with GFacWorker

use of org.apache.airavata.gfac.impl.GFacWorker 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)

Aggregations

GFacException (org.apache.airavata.gfac.core.GFacException)3 GFacWorker (org.apache.airavata.gfac.impl.GFacWorker)3 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)2 JobModel (org.apache.airavata.model.job.JobModel)2 AiravataException (org.apache.airavata.common.exception.AiravataException)1 AiravataStartupException (org.apache.airavata.common.exception.AiravataStartupException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)1 TaskContext (org.apache.airavata.gfac.core.context.TaskContext)1 RegistryException (org.apache.airavata.registry.cpi.RegistryException)1 TException (org.apache.thrift.TException)1