Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
JobLog Class Reference

Put short information into log when every job starts/finishes. And store more detailed information for Reporter. More...

#include <job_log.h>

Collaboration diagram for JobLog:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 JobLog (void)
 JobLog (const char *fname)
 ~JobLog (void)
void SetOutput (const char *fname)
bool start_info (JobDescription &job, const JobUser &user)
bool finish_info (JobDescription &job, const JobUser &user)
bool is_reporting (void)
bool RunReporter (JobUsers &users)
bool SetReporter (const char *destination)
void SetExpiration (time_t period=0)
bool make_file (JobDescription &job, JobUser &user)
void set_credentials (std::string &key_path, std::string &certificate_path, std::string &ca_certificates_dir)
void set_options (std::string &options)

Static Public Member Functions

static bool read_info (std::fstream &i, bool &processed, bool &jobstart, struct tm &t, JobId &jobid, JobLocalDescription &job_desc, std::string &failure)

Private Member Functions

bool open_stream (std::ofstream &o)

Private Attributes

std::string filename
std::list< std::string > urls
std::list< std::string > report_config
std::string certificate_path
std::string ca_certificates_dir
Arc::Runproc
time_t last_run
time_t ex_period

Detailed Description

Put short information into log when every job starts/finishes. And store more detailed information for Reporter.

Definition at line 15 of file job_log.h.


Constructor & Destructor Documentation

JobLog::JobLog ( void  )

Definition at line 34 of file job_log.cpp.

                  :filename(""),proc(NULL),last_run(0),ex_period(0) {
}
JobLog::JobLog ( const char *  fname)

Definition at line 37 of file job_log.cpp.

                               :proc(NULL),last_run(0),ex_period(0) {
  filename=fname;
}
JobLog::~JobLog ( void  )

Definition at line 261 of file job_log.cpp.

                    {
#ifndef NO_GLOBUS_CODE
  if(proc != NULL) {
    if(proc->Running()) proc->Kill(0);
    delete proc;
    proc=NULL;
  };
#endif // NO_GLOBUS_CODE
}

Here is the call graph for this function:


Member Function Documentation

bool JobLog::finish_info ( JobDescription job,
const JobUser user 
)

Definition at line 76 of file job_log.cpp.

                                                                {
  if(filename.length()==0) return true;
    std::ofstream o;
    if(!open_stream(o)) return false;
    o<<"Finished - job id: "<<job.get_id()<<", unix user: "<<job.get_uid()<<":"<<job.get_gid()<<", ";
    std::string tmps;
    if(job.GetLocalDescription(user)) {
      JobLocalDescription *job_desc = job.get_local();
      tmps=job_desc->jobname; make_escaped_string(tmps,'"');
      o<<"name: \""<<tmps<<"\", ";
      tmps=job_desc->DN; make_escaped_string(tmps,'"');
      o<<"owner: \""<<tmps<<"\", ";
      o<<"lrms: "<<job_desc->lrms<<", queue: "<<job_desc->queue;
      if(job_desc->localid.length() >0) o<<", lrmsid: "<<job_desc->localid;
    };
    tmps = job.GetFailure();
    if(tmps.length()) {
      for(std::string::size_type i=0;;) {
        i=tmps.find('\n',i);
        if(i==std::string::npos) break;
        tmps[i]='.';
      };
      make_escaped_string(tmps,'"');
      o<<", failure: \""<<tmps<<"\"";
    };
    o<<std::endl;
    o.close();
    return true;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

bool JobLog::is_reporting ( void  ) [inline]

Definition at line 38 of file job_log.h.

{ return (urls.size() > 0); };
bool JobLog::make_file ( JobDescription job,
JobUser user 
)

Definition at line 223 of file job_log.cpp.

                                                        {
  //if(!is_reporting()) return true;
  if((job.get_state() != JOB_STATE_ACCEPTED) &&
     (job.get_state() != JOB_STATE_FINISHED)) return true;
  bool result = true;
  // for configured loggers
  for(std::list<std::string>::iterator u = urls.begin();u!=urls.end();u++) {
    if(u->length()) result = job_log_make_file(job,user,*u,report_config) && result;
  };
  // for user's logger
  JobLocalDescription* local;
  if(!job.GetLocalDescription(user)) {
    result=false;
  } else if((local=job.get_local()) == NULL) { 
    result=false;
  } else {
    if(!(local->jobreport.empty())) 
    {
      for (std::list<std::string>::iterator v = local->jobreport.begin();
          v!=local->jobreport.end(); v++)
       {
         result = job_log_make_file(job,user,*v,report_config) && result;
       }
    };
  };
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool JobLog::open_stream ( std::ofstream &  o) [private]

Definition at line 49 of file job_log.cpp.

                                       {
    o.open(filename.c_str(),std::ofstream::app);
    if(!o.is_open()) return false;
    o<<" ";
    o<<(Arc::Time().str(Arc::UserTime));
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool JobLog::read_info ( std::fstream &  i,
bool &  processed,
bool &  jobstart,
struct tm &  t,
JobId jobid,
JobLocalDescription job_desc,
std::string &  failure 
) [static]

Definition at line 107 of file job_log.cpp.

                                                                                                                                              {
  processed=false;
  if(!i.is_open()) return false;
  char line[4096];
  std::streampos start_p=i.tellp();
  istream_readline(i,line,sizeof(line));
  std::streampos end_p=i.tellp();
  if((line[0] == 0) || (line[0] == '*')) { processed=true; return true; };
  char* p = line;
  if((*p) == ' ') p++;
  // struct tm t;
  /* read time */
  if(sscanf(p,"%d-%d-%d %d:%d:%d ",
       &t.tm_mday,&t.tm_mon,&t.tm_year,&t.tm_hour,&t.tm_min,&t.tm_sec) != 6) {
    return false;
  };
  t.tm_year-=1900;
  t.tm_mon-=1;
  /* skip time */
  for(;(*p) && ((*p)==' ');p++) {} if(!(*p)) return false;
  for(;(*p) && ((*p)!=' ');p++) {} if(!(*p)) return false;
  for(;(*p) && ((*p)==' ');p++) {} if(!(*p)) return false;
  for(;(*p) && ((*p)!=' ');p++) {} if(!(*p)) return false;
  for(;(*p) && ((*p)==' ');p++) {} if(!(*p)) return false;
  // bool jobstart;
  if(strncmp("Finished - ",p,11) == 0) {
    jobstart=false; p+=11;
  } else if(strncmp("Started - ",p,10) == 0) {
    jobstart=true; p+=10;
  } else {
    return false;
  };
  /* read values */
  char* name;
  char* value;
  char* pp;
  for(;;) {
    for(;(*p) && ((*p)==' ');p++) {} if(!(*p)) break;
    if((pp=strchr(p,':')) == NULL) break;
    name=p; (*pp)=0; pp++;
    for(;(*pp) && ((*pp)==' ');pp++) {}
    value=pp;
    if((*value) == '"') {
      value++;
      pp=make_unescaped_string(value,'"');
      for(;(*pp) && ((*pp) != ',');pp++) {}
      if((*pp)) pp++;
    } else {
      for(;(*pp) && ((*pp) != ',');pp++) {}
      if((*pp)) { (*pp)=0; pp++; };
    };
    p=pp;
    /* use name:value pair */
    if(strcasecmp("job id",name) == 0) {
      jobid=value;
    } else if(strcasecmp("name",name) == 0) {
      job_desc.jobname=value;
    } else if(strcasecmp("unix user",name) == 0) {

    } else if(strcasecmp("owner",name) == 0) {
      job_desc.DN=value;
    } else if(strcasecmp("lrms",name) == 0) {
      job_desc.lrms=value;
    } else if(strcasecmp("queue",name) == 0) {
      job_desc.queue=value;
    } else if(strcasecmp("lrmsid",name) == 0) {
      job_desc.localid=value;
    } else if(strcasecmp("failure",name) == 0) {
      failure=value;
    } else {

    };
  };
  i.seekp(start_p); i<<"*"; i.seekp(end_p);
  return true;
}

Here is the call graph for this function:

bool JobLog::RunReporter ( JobUsers users)

Definition at line 186 of file job_log.cpp.

                                        {
  //if(!is_reporting()) return true;
  if(proc != NULL) {
    if(proc->Running()) return true; /* running */
    delete proc;
    proc=NULL;
  };
  if(time(NULL) < (last_run+3600)) return true; // once per hour
  last_run=time(NULL);
  if(users.size() <= 0) return true; // no users to report
  const char** args = (const char**)malloc(sizeof(char*)*(users.size()+6)); 
  if(args == NULL) return false;
  std::string cmd = nordugrid_libexec_loc()+"/logger";
  int argc=0; args[argc++]=(char*)cmd.c_str();
  std::string ex_str = Arc::tostring(ex_period);
  if(ex_period) {
    args[argc++]="-E";
    args[argc++]=(char*)ex_str.c_str();
  };
  for(JobUsers::iterator i = users.begin();i != users.end();++i) {
    args[argc++]=(char*)(i->ControlDir().c_str());
  };
  args[argc]=NULL;
  JobUser user(getuid());
  user.SetControlDir(users.begin()->ControlDir());
  bool res = RunParallel::run(user,"logger",args,&proc,false,false);
  free(args);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void JobLog::set_credentials ( std::string &  key_path,
std::string &  certificate_path,
std::string &  ca_certificates_dir 
)

Definition at line 251 of file job_log.cpp.

{
  if (!key_path.empty()) 
    report_config.push_back(std::string("key_path=")+key_path);
  if (!certificate_path.empty())
    report_config.push_back(std::string("certificate_path=")+certificate_path);
  if (!ca_certificates_dir.empty())
    report_config.push_back(std::string("ca_certificates_dir=")+ca_certificates_dir);
}

Here is the caller graph for this function:

void JobLog::set_options ( std::string &  options) [inline]

Definition at line 51 of file job_log.h.

{ report_config.push_back(std::string("accounting_options=")+options); }

Here is the caller graph for this function:

void JobLog::SetExpiration ( time_t  period = 0)

Definition at line 45 of file job_log.cpp.

                                        {
  ex_period=period;
}

Here is the caller graph for this function:

void JobLog::SetOutput ( const char *  fname)

Definition at line 41 of file job_log.cpp.

                                        {
  filename=fname;
}

Here is the caller graph for this function:

bool JobLog::SetReporter ( const char *  destination)

Definition at line 218 of file job_log.cpp.

                                                {
  if(destination) urls.push_back(std::string(destination));
  return true;
}

Here is the caller graph for this function:

bool JobLog::start_info ( JobDescription job,
const JobUser user 
)

Definition at line 57 of file job_log.cpp.

                                                               {
  if(filename.length()==0) return true;
    std::ofstream o;
    if(!open_stream(o)) return false;
    o<<"Started - job id: "<<job.get_id()<<", unix user: "<<job.get_uid()<<":"<<job.get_gid()<<", ";
    if(job.GetLocalDescription(user)) {
      JobLocalDescription *job_desc = job.get_local();
      std::string tmps;
      tmps=job_desc->jobname; make_escaped_string(tmps,'"');
      o<<"name: \""<<tmps<<"\", ";
      tmps=job_desc->DN; make_escaped_string(tmps,'"');
      o<<"owner: \""<<tmps<<"\", ";
      o<<"lrms: "<<job_desc->lrms<<", queue: "<<job_desc->queue;
    };
    o<<std::endl;
    o.close();
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

std::string JobLog::ca_certificates_dir [private]

Definition at line 21 of file job_log.h.

std::string JobLog::certificate_path [private]

Definition at line 20 of file job_log.h.

time_t JobLog::ex_period [private]

Definition at line 24 of file job_log.h.

std::string JobLog::filename [private]

Definition at line 17 of file job_log.h.

time_t JobLog::last_run [private]

Definition at line 23 of file job_log.h.

Arc::Run* JobLog::proc [private]

Definition at line 22 of file job_log.h.

std::list<std::string> JobLog::report_config [private]

Definition at line 19 of file job_log.h.

std::list<std::string> JobLog::urls [private]

Definition at line 18 of file job_log.h.


The documentation for this class was generated from the following files: