Back to index

nordugrid-arc-nox  1.1.0~rc6
job_queue.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 #include <fstream>
00007 #include <ios>
00008 #include "job_queue.h"
00009 
00010 namespace Paul
00011 {
00012 
00013 JobQueue::JobQueue()
00014 {
00015     // NOP
00016 }
00017 
00018 #if 0
00019 bool JobQueue::reload(const std::string &db_path) 
00020 {
00021     // XXX make it more c++ 
00022     db = db_path;
00023     char buf[1000];
00024     char id[100];
00025 
00026     std::string  fname = db + "/" + "/ids.sched";
00027     std::ifstream f(fname.c_str());
00028 
00029     if (!f.is_open()) {
00030         return false;
00031     }
00032     for (;!f.eof();) {
00033         f.getline(buf, 1000);
00034         if (sscanf (buf, "%s", id) != 1) {
00035             continue;
00036         }
00037         std::cout << "Job recovered:  " << id << std::endl;
00038         std::string job_id(id);
00039         Job j(job_id, db);
00040         j.load();
00041         jobs.insert (make_pair(j.getID(), j));
00042     }
00043     f.close();
00044     return true;
00045 }
00046 #endif
00047 
00048 JobQueue::~JobQueue(void) 
00049 {
00050     // NOP
00051 }
00052 
00053 void JobQueue::addJob(Job &job) 
00054 {
00055     // Insert job to the map
00056     jobs.insert(make_pair(job.getID(), job));
00057 #if 0
00058     // create id file
00059     std::string fname = db + "/" + "/ids.sched";
00060     std::ofstream f(fname.c_str(), std::ios_base::app);
00061     f << job.getID() << std::endl;
00062     f.close();
00063 #endif
00064     // save job
00065     // job.save();
00066 }
00067 
00068 void JobQueue::removeJob(Job &job) 
00069 {
00070     std::string s = job.getID();
00071     removeJob(s);
00072 }
00073 
00074 void JobQueue::removeJob(const std::string &job_id) 
00075 {
00076     // jobs[job_id].remove();
00077     jobs.erase(job_id);
00078 #if 0
00079     std::string fname = db + "/" + "/ids.sched";
00080     std::ofstream f(fname.c_str());
00081 
00082     std::map<std::string,Job>::iterator iter;
00083     for (iter = jobs.begin(); iter != jobs.end(); iter++) {
00084         f << (iter->second).getID() << std::endl;
00085     }
00086     f.close();
00087 #endif
00088 }
00089 
00090 bool JobQueue::checkJob(const std::string &job_id) 
00091 {
00092     std::cout << "jobs.size() is " << (int) jobs.size() << std::endl;
00093     if (jobs.find(job_id) == jobs.end()) {
00094         std::cout << std::endl << "This job is NOT IN the queue: " <<job_id.c_str() << std::endl;
00095         return false;
00096     } else {
00097         std::cout << std::endl << "This job is IN the queue: " <<job_id.c_str() << std::endl;
00098         return true;
00099     }
00100 }
00101 
00102 #if 0
00103 std::map<const std::string, Job *> JobQueue::getJobsWithState(const SchedStatus &s) 
00104 {   
00105     std::map<const std::string, Job *> job_list;
00106     std::map<std::string, Job>::iterator iter;
00107     for (iter = jobs.begin(); iter != jobs.end(); iter++ ) {
00108         const std::string &key = iter->first;
00109         Job *j = &(iter->second);
00110         if (s == j->getStatus()) {
00111             job_list[key] = j;
00112         }
00113     }
00114     return job_list;
00115 }
00116 #endif
00117 
00118 std::map<const std::string, Job *> JobQueue::getAllJobs(void)
00119 {
00120     std::map<const std::string, Job *> job_list;
00121     std::map<std::string, Job>::iterator iter;
00122     for (iter = jobs.begin(); iter != jobs.end(); iter++ ) {
00123         const std::string &key = iter->first;
00124         Job *j = &(iter->second);
00125         job_list[key] = j;
00126     }
00127     return job_list;
00128 }
00129 
00130 Job &JobQueue::operator[](const std::string &job_id)
00131 {
00132     // lets the runtime environment to make excpetion 
00133     // if the job_id does not exsists
00134     return jobs[job_id];
00135 }
00136 
00137 }