// Scheduler_t.h // Test class for Scheduler. // // Creataes and maintains a list of test jobs. // For now all aaplications and tasks are assumed present. #include "dial_sched/Scheduler.h" #include "dataset_util/ssystem.h" #include "dataset_util/XmlElement.h" #include "dataset_util/DtdRegistry.h" #include "dial_job/Job_t.h" #include "dial_job/JobIdList.h" #include #include #include using dial::JobIdList; namespace { dial::Job& badjob() { static dial::Job job; return job; } } class TestScheduler : public dial::Scheduler { public: // typedefs typedef dial::Task Task; typedef dial::Application Application; typedef dial::Job Job; typedef dial::JobId JobId; typedef std::map JobMap; private: // data JobIdList m_jids; JobMap m_jobs; Text m_log; public: // static functions // XML name. static std::string xml_name() { return "TestScheduler"; } // DTD. static Text& dtd() { static Text txt; if ( txt.size() == 0 ) { txt.append(""); } return txt; } public: // functions // Add a task for an application. int add_task(const Application&, const Task&) { return 0; } // Submit a job. JobId submit(const Application& app, const Task& tsk, const dset::Dataset& dst, const dial::JobPreferences& prf) { std::string jdir = "./myjob"; ssystem("rm -rf " + jdir); static int icount = 0; m_log.append("submitting job"); JobId jid = JobId::generate(); assert( jid.is_valid() ); m_jids.push_back(jid); m_jobs[jid] = TestJob(JobId(401, icount), app, tsk, dst, prf, jdir); assert( m_jids.size() == m_jobs.size() ); return jid; } // Kill a job. int kill(JobId) { return 1; } // Remove a job. int remove(JobId) { return 1; } // Is this a valid scheduler? bool is_valid() const { return true; } // Is an application available? bool has_application(const Application&) const { return true; } // Is a task installed. bool has_task(const Application&, const Task&) const { return true; } // Is a task installed in an application? bool has_application_task(const Application&, const Task&) const { return true; } // Return the list of jobs. JobIdList jobs() const { return m_jids; } // Fetch a job. Job& job(JobId jid) const { JobMap::const_iterator ijob = m_jobs.find(jid); if ( ijob == m_jobs.end() ) return badjob(); return const_cast(ijob->second); } // Return the log. Text log() const { return m_log; } // Write description to XML. const XmlElement* xml() const { std::auto_ptr pele(new XmlElement(xml_name())); return pele.release(); } // Output stream. std::ostream& ostr(std::ostream& str) const { str << "Test Scheduler"; return str; } }; namespace { // Creator. dial::Scheduler* create(const XmlElement& ele) { if ( ele.name() != TestScheduler::xml_name() ) return 0; return new TestScheduler; } // Register creator. int STAT_TestScheduler = dial::Scheduler:: register_creator(TestScheduler::xml_name(), create); // Register DTD. DtdRegistry::Status ISTAT_TestScheduler_DTD = DtdRegistry::register_dtd("dial"); } // end unnamed namespace