use of org.apache.airavata.model.job.JobModel in project airavata by apache.
the class ProcessContext method getJobModel.
public JobModel getJobModel() {
if (jobModel == null) {
jobModel = new JobModel();
jobModel.setProcessId(processId);
jobModel.setWorkingDir(getWorkingDir());
jobModel.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
}
return jobModel;
}
use of org.apache.airavata.model.job.JobModel 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;
}
}
use of org.apache.airavata.model.job.JobModel 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);
}
}
}
use of org.apache.airavata.model.job.JobModel in project airavata by apache.
the class ExperimentRegistry method getJobList.
public List<JobModel> getJobList(String fieldName, Object value) throws RegistryException {
List<JobModel> jobs = new ArrayList<JobModel>();
try {
if (fieldName.equals(Constants.FieldConstants.JobConstants.PROCESS_ID)) {
ProcessResource processResource = new ProcessResource();
processResource.setProcessId((String) value);
List<JobResource> resources = processResource.getJobList();
for (JobResource jobResource : resources) {
JobModel jobModel = ThriftDataModelConversion.getJobModel(jobResource);
JobStatusResource latestSR = jobResource.getJobStatus();
if (latestSR != null) {
JobStatus jobStatus = new JobStatus(JobState.valueOf(latestSR.getState()));
jobStatus.setReason(latestSR.getReason());
List<JobStatus> statuses = new ArrayList<>();
statuses.add(jobStatus);
jobModel.setJobStatuses(statuses);
}
jobs.add(jobModel);
}
return jobs;
} else if (fieldName.equals(Constants.FieldConstants.JobConstants.TASK_ID)) {
TaskResource taskResource = new TaskResource();
taskResource.setTaskId((String) value);
List<JobResource> resources = taskResource.getJobList();
for (JobResource jobResource : resources) {
JobModel jobModel = ThriftDataModelConversion.getJobModel(jobResource);
JobStatusResource latestSR = jobResource.getJobStatus();
if (latestSR != null) {
JobStatus jobStatus = new JobStatus(JobState.valueOf(latestSR.getState()));
jobStatus.setReason(latestSR.getReason());
List<JobStatus> statuses = new ArrayList<>();
statuses.add(jobStatus);
jobModel.setJobStatuses(statuses);
}
jobs.add(jobModel);
}
return jobs;
} else {
logger.error("Unsupported field name to retrieve job list...");
}
} catch (Exception e) {
logger.error("Error while getting job list...", e);
throw new RegistryException(e);
}
return jobs;
}
use of org.apache.airavata.model.job.JobModel in project airavata by apache.
the class ThriftDataModelConversion method getJobModel.
public static JobModel getJobModel(JobResource jobResource) throws RegistryException {
JobModel model = new JobModel();
model.setJobId(jobResource.getJobId());
model.setProcessId(jobResource.getProcessId());
model.setTaskId(jobResource.getTaskId());
model.setJobDescription(jobResource.getJobDescription());
model.setCreationTime(jobResource.getCreationTime().getTime());
model.setComputeResourceConsumed(jobResource.getComputeResourceConsumed());
model.setJobName(jobResource.getJobName());
model.setWorkingDir(jobResource.getWorkingDir());
JobStatus jobStatus = getJobStatus(jobResource.getJobStatus());
if (jobStatus != null) {
List<JobStatus> jobStatuses = new ArrayList<>();
jobStatuses.add(jobStatus);
model.setJobStatuses(jobStatuses);
}
model.setExitCode(jobResource.getExitCode());
model.setStdOut(jobResource.getStdOut());
model.setStdErr(jobResource.getStdErr());
return model;
}
Aggregations