Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
Arc::UsageReporter Class Reference

The class for main JURA functionality. More...

#include <UsageReporter.h>

Collaboration diagram for Arc::UsageReporter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UsageReporter (std::string job_log_dir_, time_t expiration_time_=0, std::list< std::string > urls_=std::list< std::string >())
 Constructor.
int report ()
 Processes job log files in '<control_dir>/logs'.
 ~UsageReporter ()

Private Attributes

Arc::Logger logger
Arc::Destinationsdests
std::string job_log_dir
 Directory where A-REX puts job logs.
time_t expiration_time
std::list< std::string > urls

Detailed Description

The class for main JURA functionality.

Traverses the 'logs' dir of the given control directory, and reports usage data extracted from job log files within.

Definition at line 23 of file UsageReporter.h.


Constructor & Destructor Documentation

Arc::UsageReporter::UsageReporter ( std::string  job_log_dir_,
time_t  expiration_time_ = 0,
std::list< std::string >  urls_ = std::list<std::string>() 
)

Constructor.

Gets the job log dir and the expiration time in seconds. Default expiration time is infinity (represented by zero value).

Pass name of directory containing job log files, expiration time of files in seconds, list of URLs in case of interactive mode.

Definition at line 21 of file UsageReporter.cpp.

                                                     :
    logger(Arc::Logger::rootLogger, "JURA.UsageReporter"),
    job_log_dir(job_log_dir_),
    expiration_time(expiration_time_),
    urls(urls_)
  {
    logger.msg(Arc::INFO, "Initialised, job log dir: %s",
              job_log_dir.c_str());
    logger.msg(Arc::VERBOSE, "Expiration time: %d seconds",
              expiration_time);
    if (!urls.empty())
      logger.msg(Arc::VERBOSE, "Interactive mode.",
               expiration_time);
    //Collection of logging destinations:
    dests=new Arc::Destinations();
  }

Here is the call graph for this function:

Definition at line 153 of file UsageReporter.cpp.

  {
    delete dests;
    logger.msg(Arc::INFO, "Finished, job log dir: %s",
              job_log_dir.c_str());
  }

Here is the call graph for this function:


Member Function Documentation

Processes job log files in '<control_dir>/logs'.

Parse usage data and publish it via the appropriate destination adapter.

Definition at line 42 of file UsageReporter.cpp.

  {
    //ngjobid->url mapping to keep track of which loggerurl is replaced
    //by the '-u' options
    std::map<std::string,std::string> dest_to_duplicate;
    //Collect job log file names from job log dir
    //(to know where to get usage data from)
    DIR *dirp;
    dirent *entp;
    errno=0;
    if ( (dirp=opendir(job_log_dir.c_str()))==NULL )
      {
       logger.msg(Arc::ERROR, 
                 "Could not open log directory \"%s\": %s",
                 job_log_dir.c_str(),
                 strerror(errno)
                 );
       return -1;
      }

    // Seek "<jobnumber>.<randomstring>" files.
    Arc::RegularExpression logfilepattern("^[0-9]+\\.[^.]+$");
    errno = 0;
    while ((entp = readdir(dirp)) != NULL)
      {
       if (logfilepattern.match(entp->d_name))
         {
           //Parse log file
           Arc::JobLogFile *logfile;
           //TODO handle DOS-style path separator!
           std::string fname=job_log_dir+"/"+entp->d_name;
           logfile=new Arc::JobLogFile(fname);

           //A. Non-interactive mode: each jlf is parsed, and if valid, 
           //   submitted to the destination given  by "loggerurl=..."
           if (urls.empty())
             {
              // Check creation time and remove it if really too old
              if( expiration_time>0 && logfile->olderThan(expiration_time) )
                {
                  logger.msg(Arc::INFO,
                            "Removing outdated job log file %s",
                            logfile->getFilename().c_str()
                            );
                  logfile->remove();
                } 
              else
                {
                  //Pass job log file content to the appropriate 
                  //logging destination
                  dests->report(*logfile);
                  //(deep copy performed)
                }
             }

           //B. Interactive mode: submit only to services specified by
           //   command line option '-u'. Avoid repetition if several jlfs
           //   are created with same content and different destination.
           //   Keep all jlfs on disk.
           else
             {
              if ( dest_to_duplicate.find( (*logfile)["ngjobid"] ) ==
                   dest_to_duplicate.end() )
                {
                  dest_to_duplicate[ (*logfile)["ngjobid"] ]=
                    (*logfile)["loggerurl"];
                }

              //submit only 1x to each!
              if ( dest_to_duplicate[ (*logfile)["ngjobid"] ] ==
                   (*logfile)["loggerurl"] )
                {
                  //Duplicate content of log file, overwriting URL with
                  //each '-u' command line option, disabling file deletion
                  Arc::JobLogFile *dupl_logfile=
                    new Arc::JobLogFile(*logfile);
                  dupl_logfile->allowRemove(false);

                  for (std::list<std::string>::iterator it=urls.begin();
                      it!=urls.end();
                      ++it)
                    {
                     (*dupl_logfile)["loggerurl"] = *it;

                     //Pass duplicated job log content to the appropriate 
                     //logging destination
                     dests->report(*dupl_logfile);
                     //(deep copy performed)

                    }
                  delete dupl_logfile;
                }
             }

           delete logfile;
         }
       errno = 0;
      }

    if (errno!=0)
      {
       logger.msg(Arc::ERROR, 
                 "Error reading log directory \"%s\": %s",
                 job_log_dir.c_str(),
                 strerror(errno)
                 );
       return -2;
      }
    return 0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 27 of file UsageReporter.h.

Definition at line 30 of file UsageReporter.h.

std::string Arc::UsageReporter::job_log_dir [private]

Directory where A-REX puts job logs.

Definition at line 29 of file UsageReporter.h.

Definition at line 26 of file UsageReporter.h.

std::list<std::string> Arc::UsageReporter::urls [private]

Definition at line 31 of file UsageReporter.h.


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