// MasterScheduler.h #ifndef dial__MasterScheduler_H #define dial__MasterScheduler_H // David Adams // August 2003 // // MsterScheduler implements the Scheduler interface. It processes // jobs by splitting the input dataset with a dataset splitter and // then using a slave scheduler to handle the job for each // sub-dataset. The sub-jobs are used to construct a CompoundJob. // The master scheduler concatenates results when the // slave jobs complete. // // XML // MasterScheduler // auto_update = true // cleanup = true // maxjobs = 40 // maxstart = 10 // jobrep = MYSQL:somedb:someaddress:sometable:someuser:somepass // XyzScheduler // ... // XyzDatasetSpliter // ... #include #include "dial_sched/Scheduler.h" namespace dset { class DatasetSplitter; } class XmlElement; class PThreadMutex; namespace dial { class CompoundJob; class JobUpdater; class MasterScheduler : public Scheduler { public: // embedded clases // Implementation class class Imp; private: // Data. MasterScheduler::Imp* pimp; public: // Static functions. // XML name. static std::string xml_name() { return "MasterScheduler"; } // DTD. static const Text& dtd(); // Job directory. // Taken from DIAL_JOBS if this is not called. static void set_job_directory(std::string jobdir); private: // Functions. // Log a message. void msg(std::string txt) const; public: // Constructors and destructors. // Constructor. // splitter - dataset splitter // slave - scheduler to which sub-jobs are submitted // auto_update - if true, scheduler is continuously updated in a // separate thread // cleanup - if true, job directories are deleted in dtor // maxjobs - max # sub-jobs to run simultaneously // maxstart - max # sub-jobs to start simultaneously // jobrep = Connection string for job repository // Caller is responsible for managing the splitter and slave scheduler // and ensuring they are not deleted before the master. MasterScheduler(const dset::DatasetSplitter& splitter, Scheduler& slave, bool auto_update, bool cleanup, unsigned int maxjobs, unsigned int maxstart, std::string jobrep); // Destructor. ~MasterScheduler(); public: // Inherited functions. // Add a task and build it for an application. // Request is passed to slave scheduler. int add_task(const Application& app, const Task& tsk); // Remove a task. int remove_task(const Application& app, const Task& tsk); // Submit a job. JobId submit(const Application& app, const Task& tsk, const dset::Dataset& dst, const JobPreferences& prf); // Kill a job. // Must be a compound job created by this master. // All sub-jobs are killed. int kill(JobId jid); // Remove a job and any associated data. // The run directory and contents are deleted. int remove(JobId jid); // Is this a valid scheduler? // Slave must be valid. bool is_valid() const; // Is an application available? // Request passed to slave. bool has_application(const Application& app) const; // Is an application available and a task installed for that // application? bool has_task(const Application& app, const Task& tsk) const; // Return the ID of the task job. JobId task_job(const Application& app, const Task& tsk) const; // Return the list of jobs. // These are compound jobs. JobIdList jobs() const; // Does this scheduler have a job. // Sub-jobs return false. bool has_job(JobId jid) const; // Fetch a job. // The compound jobs created here and all their sub-jobs are // available. Job& job(JobId jid) const; // Return the log. Text log() const; // Job repository connection. std::string job_repository_connection() const; // Job repository. JobRepository* job_repository() const; // XML. const XmlElement* xml() const; // Output stream. std::ostream& ostr(std::ostream& lhs) const; public: // Local functions. // Return the dataset splitter. const dset::DatasetSplitter& splitter() const; // Return the slave scheduler. Scheduler& slave(); const Scheduler& slave() const; // Return parameters. bool auto_update() const; bool cleanup() const; int max_jobs() const; int max_start() const; // Return the updater. const dial::JobUpdater* updater() const; // Fetch a local job as a compound job. // Empty job returned if ID is not valid. CompoundJob& compound_job(JobId jid) const; // Return the job directory directory. // Job with ID jid is run in job_directory()/jid std::string job_directory() const; // Lock the mutex. int lock() const; int unlock() const; }; } // end namespace dial #endif