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);
}
}
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations