// CondorCodJobCreator.cxx #include "dataset_util/DtdRegistry.h" #include "dataset_util/Environment.h" #include "dataset_util/FileName.h" #include "dataset_util/FileStatus.h" #include "dial_condor/CondorCodJobCreator.h" #include "dial_condor/CondorCodJob.h" #include using std::string; using std::cout; using std::endl; using std::ostream; using std::auto_ptr; using dset::Dataset; using dial::Application; using dial::Task; using dial::Job; using dial::JobCreator; using dial::CondorCodJobCreator; typedef std::string Name; //********************************************************************** // Local definitions. //********************************************************************** namespace { //********************************************************************** // Creator. const JobCreator* create(const XmlElement& ele) { if ( ele.name() != CondorCodJobCreator::xml_name() ) return 0; if ( ! ele.has_attribute("machinefile") ) return 0; string machinefile = ele.attribute("machinefile"); return new CondorCodJobCreator(machinefile); } //********************************************************************** // Register creator. int STAT_CondorCodJobCreator = JobCreator:: register_creator(CondorCodJobCreator::xml_name(), create); //********************************************************************** // Directory name separator. Name DSEP = "/"; //********************************************************************** // Return if a directory exists and is readable. bool check_dir(Name name) { if ( name == "" ) return false; FileStatus stat(name); return stat.is_directory() && stat.is_readable(); } //********************************************************************** // Return if a file is regular and is readable. bool check_file(Name name) { if ( name == "" ) return false; FileStatus stat(name); return stat.is_regular() && stat.is_readable(); } //********************************************************************** // Find and check the existence and readability of a directory // specified by an environmental variable. If succssful, the // directory name is returned. Name find_dir(Name ename, const Environment* penv) { Name dir; if ( penv!=0 && penv->has(ename) ) { dir = penv->value(ename); } else if ( Environment::initial().has(ename) ) { dir = Environment::initial().value(ename); } // Make the path absolute. FileName fname(dir); if ( fname.is_relative() ) { dir = fname.fullpath().name(); } if ( ! check_dir(dir) ) return ""; return dir; } //********************************************************************** // Register the DTD. DtdRegistry::Status ISTAT_DTD_CondorCodJobCreator = DtdRegistry::register_dtd("dial"); } // end unnamed namespace //********************************************************************** // Static member functions. //********************************************************************** // DTD const Text& CondorCodJobCreator::dtd() { static Text txt; if ( txt.size() == 0 ) { txt.append(""); txt.append(""); } return txt; } //********************************************************************** // Constructor CondorCodJobCreator::CondorCodJobCreator(string machinefile) { m_validity = true; const Environment* penv = new Environment(Environment::current()); string confdir = find_dir("DIAL_CONDOR_COD_CONF", penv); if ( machinefile == "") machinefile = "Machines.dat"; string machine_file = confdir + DSEP + machinefile; cout << "Machine file = " << machine_file << endl; if (! check_file(machine_file) ) { m_validity = false; } else { m_machinefile = machinefile; } } //********************************************************************** // Validity. bool CondorCodJobCreator::is_valid() const { return m_validity; } //********************************************************************** // Create a new local job. Job* CondorCodJobCreator:: create_local_job(JobId jid, const Application& app, const Task& tsk, const Dataset& dst,const JobPreferences& prf, string rundir, string runfile) const { if ( ! is_valid() ) return 0; return new CondorCodJob(jid, app, tsk, dst,prf, rundir, runfile, m_machinefile); } //********************************************************************** // Convert. Job* CondorCodJobCreator::convert(const Job& job) const { return new CondorCodJob(job, m_machinefile); } //********************************************************************** // Return user or site specific submit description file name string CondorCodJobCreator::machine_file() const { return m_machinefile; } //********************************************************************** // XML. const XmlElement* CondorCodJobCreator::xml() const { auto_ptr pele(new XmlElement(xml_name())); pele->add_attribute("machinefile", machine_file()); return pele.release(); } //********************************************************************** // Output stream. ostream& CondorCodJobCreator::ostr(ostream& lhs) const { lhs << "Creator for CondorCodJob"; return lhs; }