// CondorJobCreator.cxx #include "dataset_util/DtdRegistry.h" #include "dataset_util/Environment.h" #include "dataset_util/FileName.h" #include "dataset_util/FileStatus.h" #include "dial_condor/CondorJobCreator.h" #include "dial_condor/CondorJob.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::CondorJobCreator; typedef std::string Name; //********************************************************************** // Local definitions. //********************************************************************** namespace { //********************************************************************** // Creator. const JobCreator* create(const XmlElement& ele) { if ( ele.name() != CondorJobCreator::xml_name() ) return 0; if ( ! ele.has_attribute("submitdesc") ) return 0; string submitdesc = ele.attribute("submitdesc"); return new CondorJobCreator(submitdesc); } //********************************************************************** // Register creator. int STAT_CondorJobCreator = JobCreator:: register_creator(CondorJobCreator::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_CondorJobCreator = DtdRegistry::register_dtd("dial"); } // end unnamed namespace //********************************************************************** // Static member functions. //********************************************************************** // DTD const Text& CondorJobCreator::dtd() { static Text txt; if ( txt.size() == 0 ) { txt.append(""); txt.append(""); } return txt; } //********************************************************************** // Constructor CondorJobCreator::CondorJobCreator(string descfile) { m_validity = true; const Environment* penv = new Environment(Environment::current()); string confdir = find_dir("DIAL_CONDOR_CONF", penv); if ( descfile == "" ) descfile = "default"; string conffile = confdir + DSEP + descfile; if ( ! check_file(conffile) ) { cout << "Warning: condor conf file unreadable." << endl; m_validity = false; } else { m_descfile = conffile; } } //********************************************************************** // Validity. bool CondorJobCreator::is_valid() const { return m_validity; } //********************************************************************** // Create a new local job. Job* CondorJobCreator:: 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 CondorJob(jid, m_descfile, app, tsk, dst, prf, rundir, runfile); } //********************************************************************** // Convert. Job* CondorJobCreator::convert(const Job& job) const { return new CondorJob(job, m_descfile); } //********************************************************************** // Return user or site specific submit description file name string CondorJobCreator::desc_file() const { return m_descfile; } //********************************************************************** // XML. const XmlElement* CondorJobCreator::xml() const { auto_ptr pele(new XmlElement(xml_name())); pele->add_attribute("submitdesc", desc_file()); return pele.release(); } //********************************************************************** // Output stream. ostream& CondorJobCreator::ostr(ostream& lhs) const { lhs << "Creator for CondorJob"; return lhs; }