Back to index

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

Class to communicate with Janitor - Dynmaic Runtime Environment handler. More...

#include <janitor.h>

Collaboration diagram for Janitor:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Result { DEPLOYED, REMOVED, NOTENABLED, FAILED }

Public Member Functions

 Janitor (const std::string &id, const std::string &cdir)
 Creates instance representing job entry in Janitor database.
 ~Janitor (void)
bool enabled ()
 Returns true if janitor is enabled in the config file.
 operator bool (void)
 Returns true if instance is valid.
bool operator! (void)
 Returns true if instance is invalid.
bool deploy (void)
 Registers associated job with Janitor and deploys dynamic RTEs.
bool remove (void)
 Removes job from those handled by Janitor and releases associated RTEs.
bool wait (int timeout)
 Wait till operation initiated by deploy() or remove() finished.
Result result (void)
 Returns true if operation initiated by deploy() or remove() succeeded.

Private Member Functions

void cancel (void)
bool readConfig ()

Static Private Member Functions

static void deploy_thread (void *arg)
static void remove_thread (void *arg)

Private Attributes

bool enabled_
std::string path_
std::string id_
std::string cdir_
bool running_
Result result_
Arc::SimpleCondition completed_
Arc::SimpleCondition cancel_

Detailed Description

Class to communicate with Janitor - Dynmaic Runtime Environment handler.

Definition at line 6 of file janitor.h.


Member Enumeration Documentation

Enumerator:
DEPLOYED 
REMOVED 
NOTENABLED 
FAILED 

Definition at line 8 of file janitor.h.


Constructor & Destructor Documentation

Janitor::Janitor ( const std::string &  id,
const std::string &  cdir 
)

Creates instance representing job entry in Janitor database.

Takes id for job identifier and cdir for the control directory of A-Rex. constructor does not register job in the Janitor. It only associates job with this instance.

Definition at line 39 of file janitor.cpp.

                                                         :
         id_(id),cdir_(cdir),running_(false),result_(FAILED),enabled_(false) {
  if(!readConfig()) return;
  if(!enabled()) return;
  if(id_.empty()) return;
  if(cdir_.empty()) return;
  // create path to janitor utility
  path_ = Glib::build_filename(nordugrid_libexec_loc(),"janitor");
  if(path_.empty()) {
    logger.msg(Arc::ERROR, "Failed to create path to janitor at %s",nordugrid_libexec_loc());
    return;
  };
  // check if utility exists
  if(!Glib::file_test(path_,Glib::FILE_TEST_IS_EXECUTABLE)) {
    logger.msg(Arc::ERROR, "Janitor executable not found at %s",path_);
    path_.resize(0);
    return;
  };
}

Here is the call graph for this function:

Janitor::~Janitor ( void  )

Definition at line 59 of file janitor.cpp.

                      {
  cancel();;
}

Here is the call graph for this function:


Member Function Documentation

void Janitor::cancel ( void  ) [private]

Definition at line 103 of file janitor.cpp.

                         {
  if(!running_) return;
  if(completed_.wait(0)) return;
  cancel_.signal();
  completed_.wait();
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Janitor::deploy ( void  )

Registers associated job with Janitor and deploys dynamic RTEs.

This operation is asynchronous. Returned true means Janitor will be contacted and deployemnt will start soon. For obtaining result of operation see methods wait() and result(). During this operation janitor utility is called with command register and optionally deploy.

Definition at line 247 of file janitor.cpp.

                         {
  if(operator!()) return false;
  if(running_) return false;
  running_=true;
  running_=Arc::CreateThreadFunction(&Janitor::deploy_thread,this);
  return running_;
}

Here is the call graph for this function:

void Janitor::deploy_thread ( void *  arg) [static, private]

Definition at line 110 of file janitor.cpp.

                                     {
  Janitor& it = *((Janitor*)arg);
  it.result_=FAILED;
    // Fetch list of REs
  JobUser user;
  user.SetControlDir(it.cdir_);
  std::list<std::string> rtes;
  if(!job_rte_read_file(it.id_,user,rtes)) { it.completed_.signal(); return; };
  if(rtes.size() == 0) {
    it.result_=DEPLOYED;
    it.completed_.signal();
    return;
  };
  std::string cmd;
  // Make command line
  cmd = it.path_ + " register " + it.id_;
  while(rtes.size() > 0) {
    cmd += " " + *rtes.begin();
    rtes.pop_front();
  };
  // Run command
  {
    Arc::Run run(cmd);
    if(!run) {
      logger.msg(Arc::DEBUG, "Can't run %s", cmd);
      it.completed_.signal();
      return;
    };
    run.KeepStdout(true);
    run.KeepStderr(true);
    if(!run.Start()) {
      logger.msg(Arc::DEBUG, "Can't start %s", cmd);
      it.completed_.signal();
      return;
    };
    // Wait for result or cancel request
    for(;;) {
      if(run.Wait(1)) break;
      if(it.cancel_.wait(0)) { it.completed_.signal(); return; };
    };
    if(run.Result() == 0) {
      logger.msg(Arc::DEBUG, "janitor register returned 0 - no RTE needs to be deployed");
      it.result_=DEPLOYED; it.completed_.signal();
      return;
    };
    if(run.Result() == 3) {
      logger.msg(Arc::DEBUG, "janitor register returned 3 - no Janitor enabled in configuration");
      it.result_=NOTENABLED; it.completed_.signal();
      return;
    };
    if(run.Result() != 1) {
      logger.msg(Arc::ERROR, "janitor register failed with exit code %i",run.Result());
      it.completed_.signal();
      return;
    };
    logger.msg(Arc::DEBUG, "janitor register returned 1 - need to run janitor deploy");
  };
  // Make command line
  cmd = it.path_ + " deploy " + it.id_;
  // Run command
  {
    Arc::Run run(cmd);
    if(!run) {
      logger.msg(Arc::DEBUG, "Can't run %s", cmd);
      it.completed_.signal();
      return;
    };
    run.KeepStdout(true);
    run.KeepStderr(true);
    if(!run.Start()) {
      logger.msg(Arc::DEBUG, "Can't start %s", cmd);
      it.completed_.signal();
      return;
    };
    // Wait for result or cancel request
    for(;;) {
      if(run.Wait(1)) break;
      if(it.cancel_.wait(0)) { it.completed_.signal(); return; };
    };
    if(run.Result() == 3) {
      logger.msg(Arc::VERBOSE, "janitor deploy returned 3 - no Janitor enabled in configuration");
      it.result_=NOTENABLED; it.completed_.signal();
      return;
    };
    if(run.Result() != 0) {
      logger.msg(Arc::DEBUG, "janitor deploy failed with exit code %i",run.Result());
      it.completed_.signal();
      return;
    };
  };
  it.result_=DEPLOYED;
  it.completed_.signal();
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Janitor::enabled ( ) [inline]

Returns true if janitor is enabled in the config file.

Definition at line 35 of file janitor.h.

{ return enabled_; };

Here is the caller graph for this function:

Janitor::operator bool ( void  ) [inline]

Returns true if instance is valid.

Definition at line 37 of file janitor.h.

{ return !path_.empty(); };
bool Janitor::operator! ( void  ) [inline]

Returns true if instance is invalid.

Definition at line 39 of file janitor.h.

{ return path_.empty(); };
bool Janitor::readConfig ( ) [private]

Definition at line 63 of file janitor.cpp.

                         {
  // open conf file
  std::ifstream cfile;
  if(nordugrid_config_loc().empty()) read_env_vars(true);
  if(!config_open(cfile)) {
    logger.msg(Arc::ERROR,"Can't open configuration file");
    return false;
  }
  switch(config_detect(cfile)) {
    case config_file_XML: {
      Arc::XMLNode cfg;
      if(!cfg.ReadFromStream(cfile)) {
        config_close(cfile);
        logger.msg(Arc::ERROR,"Can't interpret configuration file as XML");
        return false;
      }
      std::string enabled = cfg["janitor"]["enabled"];
      enabled_ = (enabled == "1");
    }; break;
    case config_file_INI: {
      ConfigSections* cf = new ConfigSections(cfile);
      cf->AddSection("janitor");
      for(;;) {
        std::string rest;
        std::string command;
        cf->ReadNext(command,rest);
        if(command.empty()) break;
        if(command == "enabled") enabled_ = (config_next_arg(rest) == "1");
      }
      delete cf;
    }; break;
    default: {
      logger.msg(Arc::ERROR,"Can't recognize type of configuration file");
      return false;
    }; break;
  };
  config_close(cfile);
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Janitor::remove ( void  )

Removes job from those handled by Janitor and releases associated RTEs.

This operation is asynchronous. Returned true means Janitor will be contacted and removal will start soon. For obtaining result of operation see methods wait() and result(). During this operation janitor utility is called with command remove.

Definition at line 255 of file janitor.cpp.

                         {
  if(operator!()) return false;
  if(running_) return false;
  running_=true;
  running_=Arc::CreateThreadFunction(&Janitor::remove_thread,this);
  return running_;
}

Here is the call graph for this function:

void Janitor::remove_thread ( void *  arg) [static, private]

Definition at line 205 of file janitor.cpp.

                                     {
  Janitor& it = *((Janitor*)arg);
  it.result_=FAILED;
  std::string cmd;
  // Make command line
  cmd = it.path_ + " remove " + it.id_;
  // Run command
  {
    Arc::Run run(cmd);
    if(!run) {
      logger.msg(Arc::DEBUG, "Can't run %s", cmd);
      it.completed_.signal();
      return;
    };
    run.KeepStdout(true);
    run.KeepStderr(true);
    if(!run.Start()) {
      logger.msg(Arc::DEBUG, "Can't start %s", cmd);
      it.completed_.signal();
      return;
    };
    // Wait for result or cancel request
    for(;;) {
      if(run.Wait(1)) break;
      if(it.cancel_.wait(0)) { it.completed_.signal(); return; };
    };
    if(run.Result() == 3) {
      logger.msg(Arc::VERBOSE, "janitor remove returned 3 - no Janitor enabled in configuration");
      it.result_=NOTENABLED; it.completed_.signal();
      return;
    };
    if(run.Result() != 0) {
      logger.msg(Arc::DEBUG, "janitor remove failed with exit code %i",run.Result());
      it.completed_.signal();
      return;
    };
  }
  it.result_=REMOVED;
  it.completed_.signal();
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns true if operation initiated by deploy() or remove() succeeded.

It should be called after wait() returned true.

Definition at line 270 of file janitor.cpp.

                                  {
  return result_;
}
bool Janitor::wait ( int  timeout)

Wait till operation initiated by deploy() or remove() finished.

This operation returns true if operation finished or false if timeout seconds passed. It may be called repeatedly and even after it previously returned true. If no operation is running it returns true immeaditely.

Definition at line 263 of file janitor.cpp.

                              {
  if(!running_) return true;
  if(!completed_.wait(timeout*1000)) return false;
  running_=false;
  return true;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 22 of file janitor.h.

std::string Janitor::cdir_ [private]

Definition at line 18 of file janitor.h.

Definition at line 21 of file janitor.h.

bool Janitor::enabled_ [private]

Definition at line 15 of file janitor.h.

std::string Janitor::id_ [private]

Definition at line 17 of file janitor.h.

std::string Janitor::path_ [private]

Definition at line 16 of file janitor.h.

Definition at line 20 of file janitor.h.

bool Janitor::running_ [private]

Definition at line 19 of file janitor.h.


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