Back to index

nordugrid-arc-nox  1.1.0~rc6
job.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 /*
00006   Filename: states.cc
00007   keeps list of states
00008   acts on states
00009 */
00010 
00011 #include <string>
00012 #include <cstring>
00013 
00014 //# #include "../run/run.h"
00015 #include "../files/info_types.h"
00016 #include "../files/info_files.h"
00017 #include "users.h"
00018 #include "job.h"
00019 
00020 
00021 const char* state_names[JOB_STATE_NUM] = {
00022  "ACCEPTED",
00023  "PREPARING",
00024  "SUBMIT",
00025  "INLRMS",
00026  "FINISHING",
00027  "FINISHED",
00028  "DELETED",
00029  "CANCELING",
00030  "UNDEFINED"
00031 };
00032 
00033 job_state_rec_t states_all[JOB_STATE_UNDEFINED+1] = {
00034  { JOB_STATE_ACCEPTED,   state_names[JOB_STATE_ACCEPTED],   ' ' },
00035  { JOB_STATE_PREPARING,  state_names[JOB_STATE_PREPARING],  'b' },
00036  { JOB_STATE_SUBMITTING, state_names[JOB_STATE_SUBMITTING], ' ' },
00037  { JOB_STATE_INLRMS,     state_names[JOB_STATE_INLRMS],     'q' },
00038  { JOB_STATE_FINISHING,  state_names[JOB_STATE_FINISHING],  'f' },
00039  { JOB_STATE_FINISHED,   state_names[JOB_STATE_FINISHED],   'e' },
00040  { JOB_STATE_DELETED,    state_names[JOB_STATE_DELETED],    'd' },
00041  { JOB_STATE_CANCELING,  state_names[JOB_STATE_CANCELING],  'c' },
00042  { JOB_STATE_UNDEFINED,  NULL,                              ' '}
00043 };
00044 
00045 
00046 const char* JobDescription::get_state_name() const {
00047   if((job_state<0) || (job_state>=JOB_STATE_NUM))
00048                        return state_names[JOB_STATE_UNDEFINED];
00049   return state_names[job_state];
00050 }
00051 
00052 const char* JobDescription::get_state_name(job_state_t st) {
00053   if((st<0) || (st>=JOB_STATE_NUM))
00054                        return state_names[JOB_STATE_UNDEFINED];
00055   return state_names[st];
00056 }
00057 
00058 job_state_t JobDescription::get_state(const char* state) {
00059   for(int i = 0;i<JOB_STATE_NUM;i++) {
00060     if(!strcmp(state_names[i],state)) return (job_state_t)i;
00061   };
00062   return JOB_STATE_UNDEFINED;
00063 }
00064 
00065 void JobDescription::set_share(std::string share) {
00066   transfer_share = share.empty() ? JobLocalDescription::transfersharedefault : share;
00067 }
00068 
00069 JobDescription::JobDescription(void) {
00070   job_state=JOB_STATE_UNDEFINED;
00071   job_pending=false;
00072   child=NULL;
00073   local=NULL;
00074   job_uid=0; job_gid=0;
00075 }
00076 
00077 JobDescription::JobDescription(const JobDescription &job) {
00078   job_state=job.job_state;
00079   job_pending=job.job_pending;
00080   job_id=job.job_id;
00081   session_dir=job.session_dir;
00082   failure_reason=job.failure_reason;
00083   keep_finished=job.keep_finished;
00084   keep_deleted=job.keep_deleted;
00085   child=NULL;
00086   local=job.local;
00087   job_uid=job.job_uid; job_gid=job.job_gid;
00088   retries=job.retries;
00089   next_retry=job.next_retry;
00090   transfer_share=job.transfer_share;
00091 }
00092 
00093 JobDescription::JobDescription(const JobId &id,const std::string &dir,job_state_t state) {
00094   job_state=state;
00095   job_pending=false;
00096   job_id=id;
00097   session_dir=dir;
00098   keep_finished=DEFAULT_KEEP_FINISHED;
00099   keep_deleted=DEFAULT_KEEP_DELETED;
00100   child=NULL;
00101   local=NULL;
00102   job_uid=0; job_gid=0;
00103   retries=0;
00104   next_retry=time(NULL);
00105   transfer_share=JobLocalDescription::transfersharedefault;
00106 }
00107 
00108 JobDescription::~JobDescription(void){
00109  /* child is not destroyed here */
00110 }
00111 
00112 bool JobDescription::GetLocalDescription(const JobUser &user) {
00113   if(local) return true;
00114   JobLocalDescription* job_desc;
00115   job_desc=new JobLocalDescription;
00116   if(!job_local_read_file(job_id,user,*job_desc)) {
00117     delete job_desc;
00118     return false;
00119   };
00120   local=job_desc;
00121   return true;
00122 }
00123