1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
31 #include <libbatch/BatchManagerCatalog.hxx>
32 #include <libbatch/FactBatchManager.hxx>
33 #include <libbatch/BatchManager.hxx>
36 #include "Basics_Utils.hxx"
37 #include "Basics_DirUtils.hxx"
38 #include "SALOME_Launcher_Handler.hxx"
39 #include "Launcher.hxx"
40 #include "Launcher_Job_Command.hxx"
41 #include "Launcher_Job_YACSFile.hxx"
42 #include "Launcher_Job_PythonSALOME.hxx"
43 #include "Launcher_Job_CommandSALOME.hxx"
44 #include "Launcher_XML_Persistence.hxx"
48 //=============================================================================
52 * Define a CORBA single thread policy for the server, which avoid to deal
53 * with non thread-safe usage like Change_Directory in SALOME naming service
55 //=============================================================================
56 Launcher_cpp::Launcher_cpp()
58 LAUNCHER_MESSAGE("Launcher_cpp constructor");
62 //=============================================================================
66 //=============================================================================
67 Launcher_cpp::~Launcher_cpp()
69 LAUNCHER_MESSAGE("Launcher_cpp destructor");
71 std::map<int, Launcher::Job *>::const_iterator it_job;
72 for(it_job = _launcher_job_map.begin(); it_job != _launcher_job_map.end(); it_job++)
73 delete it_job->second;
74 std::map <int, Batch::BatchManager * >::const_iterator it1;
75 for(it1=_batchmap.begin();it1!=_batchmap.end();it1++)
82 //=============================================================================
84 * Add a job into the launcher - check resource and choose one
86 //=============================================================================
88 Launcher_cpp::createJob(Launcher::Job * new_job)
90 LAUNCHER_MESSAGE("Creating a new job");
91 // Add job to the jobs map
92 new_job->setNumber(_job_cpt);
94 std::map<int, Launcher::Job *>::const_iterator it_job = _launcher_job_map.find(new_job->getNumber());
95 if (it_job == _launcher_job_map.end())
97 _launcher_job_map[new_job->getNumber()] = new_job;
101 LAUNCHER_INFOS("A job has already the same id: " << new_job->getNumber());
102 throw LauncherException("A job has already the same id - job is not created !");
104 LAUNCHER_MESSAGE("New Job created");
107 //=============================================================================
109 * Add a job into the launcher - check resource and choose one
111 //=============================================================================
113 Launcher_cpp::createJob(const JobParameters_cpp& job_parameters)
115 std::string job_type = job_parameters.job_type;
116 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
118 if (job_type == Launcher::Job_Command::TYPE_NAME)
119 new_job = new Launcher::Job_Command();
120 else if (job_type == Launcher::Job_CommandSALOME::TYPE_NAME)
121 new_job = new Launcher::Job_CommandSALOME();
122 else if (job_type == Launcher::Job_YACSFile::TYPE_NAME)
123 new_job = new Launcher::Job_YACSFile();
124 else if (job_type == Launcher::Job_PythonSALOME::TYPE_NAME)
125 new_job = new Launcher::Job_PythonSALOME();
128 std::string message("Launcher_cpp::createJob: bad job type: ");
130 throw LauncherException(message.c_str());
134 new_job->setJobName(job_parameters.job_name);
137 new_job->setWorkDirectory(job_parameters.work_directory);
138 new_job->setLocalDirectory(job_parameters.local_directory);
139 new_job->setResultDirectory(job_parameters.result_directory);
141 // Parameters for COORM
142 new_job->setLauncherFile(job_parameters.launcher_file);
143 new_job->setLauncherArgs(job_parameters.launcher_args);
146 new_job->setJobFile(job_parameters.job_file);
147 new_job->setPreCommand(job_parameters.pre_command);
150 new_job->setEnvFile(job_parameters.env_file);
151 for(const std::string param : job_parameters.in_files)
152 new_job->add_in_file(param);
153 for(const std::string param : job_parameters.out_files)
154 new_job->add_out_file(param);
156 new_job->setMaximumDuration(job_parameters.maximum_duration);
157 new_job->setQueue(job_parameters.queue);
158 new_job->setPartition(job_parameters.partition);
159 new_job->setExclusive(job_parameters.exclusive);
160 new_job->setMemPerCpu(job_parameters.mem_per_cpu);
161 new_job->setWCKey(job_parameters.wckey);
162 new_job->setExtraParams(job_parameters.extra_params);
164 // Resources requirements
165 new_job->setResourceRequiredParams(job_parameters.resource_required);
167 // Adding specific parameters to the job
168 for (const auto& it_specific : job_parameters.specific_parameters)
169 new_job->addSpecificParameter(it_specific.first, it_specific.second);
171 new_job->checkSpecificParameters();
175 return new_job->getNumber();
178 //=============================================================================
182 //=============================================================================
184 Launcher_cpp::launchJob(int job_id)
186 LAUNCHER_MESSAGE("Launch a job");
188 // Check if job exists
189 Launcher::Job * job = findJob(job_id);
191 // Check job state (cannot launch a job already launched...)
192 if (job->getState() != "CREATED")
194 LAUNCHER_INFOS("Bad state of the job: " << job->getState());
195 throw LauncherException("Bad state of the job: " + job->getState());
198 Batch::BatchManager * bm = getBatchManager(job);
201 Batch::JobId batch_manager_job_id = bm->submitJob(*(job->getBatchJob()));
202 job->setBatchManagerJobId(batch_manager_job_id);
203 job->setState("QUEUED");
204 job->setReference(batch_manager_job_id.getReference());
206 catch(const Batch::GenericException &ex)
208 LAUNCHER_INFOS("Job is not launched, exception in submitJob: " << ex.message);
209 throw LauncherException(ex.message.c_str());
211 LAUNCHER_MESSAGE("Job launched");
214 //=============================================================================
218 //=============================================================================
220 Launcher_cpp::getJobState(int job_id)
222 LAUNCHER_MESSAGE("Get job state");
224 // Check if job exist
225 Launcher::Job * job = findJob(job_id);
230 state = job->updateJobState();
232 catch(const Batch::GenericException &ex)
234 LAUNCHER_INFOS("getJobState failed, exception: " << ex.message);
235 throw LauncherException(ex.message.c_str());
241 //=============================================================================
243 * Get job assigned hostnames
245 //=============================================================================
247 Launcher_cpp::getAssignedHostnames(int job_id)
249 LAUNCHER_MESSAGE("Get job assigned hostnames");
251 // Check if job exist
252 Launcher::Job * job = findJob(job_id);
253 std::string assigned_hostnames = job->getAssignedHostnames();
255 return assigned_hostnames;
259 Launcher_cpp::exportInputFiles(int job_id)
261 LAUNCHER_MESSAGE("Copy in files");
262 // Check if job exists
263 Launcher::Job * job = findJob(job_id);
265 // Check job state (cannot launch a job already launched...)
266 if (job->getState() != "CREATED")
268 LAUNCHER_INFOS("Bad state of the job: " << job->getState());
269 throw LauncherException("Bad state of the job: " + job->getState());
272 Batch::BatchManager * bm = getBatchManager(job);
275 bm->exportInputFiles(*(job->getBatchJob()));
277 catch(const Batch::GenericException &ex)
279 LAUNCHER_INFOS("Failed to copy in files: " << ex.message);
280 throw LauncherException(ex.message.c_str());
282 LAUNCHER_MESSAGE("Files copied");
285 //=============================================================================
287 * Get Job result - the result directory could be changed
289 //=============================================================================
291 Launcher_cpp::getJobResults(int job_id, std::string directory)
293 LAUNCHER_MESSAGE("Get Job results");
295 Launcher::Job * job = findJob(job_id);
296 std::string resource_name = job->getResourceDefinition().Name;
300 _batchmap[job_id]->importOutputFiles(*(job->getBatchJob()), directory);
302 _batchmap[job_id]->importOutputFiles(*(job->getBatchJob()), job->getResultDirectory());
304 catch(const Batch::GenericException &ex)
306 LAUNCHER_INFOS("getJobResult is maybe incomplete, exception: " << ex.message);
307 throw LauncherException(ex.message.c_str());
309 LAUNCHER_MESSAGE("getJobResult ended");
312 //=============================================================================
314 * Clear the remote working directory
316 //=============================================================================
318 Launcher_cpp::clearJobWorkingDir(int job_id)
320 LAUNCHER_MESSAGE("Clear the remote working directory");
322 Launcher::Job * job = findJob(job_id);
325 _batchmap[job_id]->clearWorkingDir(*(job->getBatchJob()));
327 catch(const Batch::GenericException &ex)
329 LAUNCHER_INFOS("getJobResult is maybe incomplete, exception: " << ex.message);
330 throw LauncherException(ex.message.c_str());
332 LAUNCHER_MESSAGE("getJobResult ended");
335 //=============================================================================
337 * Get Job dump state - the result directory could be changed
339 //=============================================================================
341 Launcher_cpp::getJobDumpState(int job_id, std::string directory)
344 LAUNCHER_MESSAGE("Get Job dump state");
346 Launcher::Job * job = findJob(job_id);
347 std::string resource_name = job->getResourceDefinition().Name;
351 rtn = _batchmap[job_id]->importDumpStateFile(*(job->getBatchJob()), directory);
353 rtn = _batchmap[job_id]->importDumpStateFile(*(job->getBatchJob()), job->getResultDirectory());
355 catch(const Batch::GenericException &ex)
357 LAUNCHER_INFOS("getJobResult is maybe incomplete, exception: " << ex.message);
358 throw LauncherException(ex.message.c_str());
360 LAUNCHER_MESSAGE("getJobResult ended");
364 //=============================================================================
366 * Get one file from the working directory - the result directory can be changed
368 //=============================================================================
370 Launcher_cpp::getJobWorkFile(int job_id,
371 std::string work_file,
372 std::string directory)
375 LAUNCHER_MESSAGE("Get working file " << work_file);
377 Launcher::Job * job = findJob(job_id);
378 std::string resource_name = job->getResourceDefinition().Name;
382 rtn = _batchmap[job_id]->importWorkFile(*(job->getBatchJob()), work_file, directory);
384 rtn = _batchmap[job_id]->importWorkFile(*(job->getBatchJob()), work_file, job->getResultDirectory());
386 catch(const Batch::GenericException &ex)
388 LAUNCHER_INFOS("getJobWorkFile is maybe incomplete, exception: " << ex.message);
389 throw LauncherException(ex.message.c_str());
391 LAUNCHER_MESSAGE("getJobWorkFile ended");
395 //=============================================================================
397 * Remove the job - into the Launcher and its batch manager
399 //=============================================================================
401 Launcher_cpp::removeJob(int job_id)
403 LAUNCHER_MESSAGE("Remove Job");
405 // Check if job exist
406 std::map<int, Launcher::Job *>::iterator it_job = _launcher_job_map.find(job_id);
407 if (it_job == _launcher_job_map.end())
409 LAUNCHER_INFOS("Cannot find the job, is it created ? job number: " << job_id);
410 throw LauncherException("Cannot find the job, is it created ?");
413 it_job->second->removeJob();
414 delete it_job->second;
415 _launcher_job_map.erase(it_job);
418 //=============================================================================
422 //=============================================================================
424 Launcher_cpp::stopJob(int job_id)
426 LAUNCHER_MESSAGE("Stop Job");
428 Launcher::Job * job = findJob(job_id);
433 Launcher_cpp::dumpJob(int job_id)
435 LAUNCHER_MESSAGE("dump Job");
437 Launcher::Job * job = findJob(job_id);
438 return Launcher::XML_Persistence::dumpJob(*job);
442 Launcher_cpp::restoreJob(const std::string& dumpedJob)
444 LAUNCHER_MESSAGE("restore Job");
445 Launcher::Job* new_job(nullptr);
450 new_job = Launcher::XML_Persistence::createJobFromString(dumpedJob);
454 jobId = addJob(new_job);
457 LAUNCHER_INFOS("Failed to create a new job.");
459 catch(const LauncherException &ex)
461 LAUNCHER_INFOS("Cannot load the job. Exception: " << ex.msg.c_str());
467 Launcher_cpp::getJobParameters(int job_id)
469 Launcher::Job * job = findJob(job_id);
470 JobParameters_cpp job_parameters;
471 job_parameters.job_name = job->getJobName();
472 job_parameters.job_type = job->getJobType();
473 job_parameters.job_file = job->getJobFile();
474 job_parameters.env_file = job->getEnvFile();
475 job_parameters.work_directory = job->getWorkDirectory();
476 job_parameters.local_directory = job->getLocalDirectory();
477 job_parameters.result_directory = job->getResultDirectory();
478 job_parameters.pre_command = job->getPreCommand();
480 // Parameters for COORM
481 job_parameters.launcher_file = job->getLauncherFile();
482 job_parameters.launcher_args = job->getLauncherArgs();
484 job_parameters.in_files = job->get_in_files();
485 job_parameters.out_files = job->get_out_files();
487 job_parameters.maximum_duration = job->getMaximumDuration();
488 job_parameters.queue = job->getQueue();
489 job_parameters.partition = job->getPartition();
490 job_parameters.exclusive = job->getExclusive();
491 job_parameters.mem_per_cpu = job->getMemPerCpu();
492 job_parameters.wckey = job->getWCKey();
493 job_parameters.extra_params = job->getExtraParams();
495 resourceParams resource_params = job->getResourceRequiredParams();
496 job_parameters.resource_required.name = resource_params.name;
497 job_parameters.resource_required.hostname = resource_params.hostname;
498 job_parameters.resource_required.OS = resource_params.OS;
499 job_parameters.resource_required.nb_proc = resource_params.nb_proc;
500 job_parameters.resource_required.nb_node = resource_params.nb_node;
501 job_parameters.resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
502 job_parameters.resource_required.cpu_clock = resource_params.cpu_clock;
503 job_parameters.resource_required.mem_mb = resource_params.mem_mb;
505 job_parameters.specific_parameters = job->getSpecificParameters();
507 return job_parameters;
510 //=============================================================================
512 * create a launcher job based on a file
513 * \param xmlExecuteFile : to define the execution on the batch cluster
515 //=============================================================================
517 Launcher_cpp::createJobWithFile(const std::string xmlExecuteFile,
518 const std::string clusterName)
520 LAUNCHER_MESSAGE("Begin of Launcher_cpp::createJobWithFile");
523 ParserLauncherType job_params = ParseXmlFile(xmlExecuteFile);
525 // Creating a new job
526 std::unique_ptr<Launcher::Job_Command> new_job(new Launcher::Job_Command);
528 std::string cmdFile = Kernel_Utils::GetTmpFileName();
535 os.open(cmdFile.c_str(), std::ofstream::out );
536 os << "#! /bin/sh" << std::endl;
537 os << job_params.Command;
540 new_job->setJobFile(cmdFile);
541 new_job->setLocalDirectory(job_params.RefDirectory);
542 new_job->setWorkDirectory(job_params.MachinesList[clusterName].WorkDirectory);
543 new_job->setEnvFile(job_params.MachinesList[clusterName].EnvFile);
545 for(size_t i=0; i < job_params.InputFile.size(); i++)
546 new_job->add_in_file(job_params.InputFile[i]);
547 for(size_t i=0; i < job_params.OutputFile.size();i++)
548 new_job->add_out_file(job_params.OutputFile[i]);
551 p.hostname = clusterName;
554 p.nb_proc = job_params.NbOfProcesses;
556 p.nb_proc_per_node = 0;
559 new_job->setResourceRequiredParams(p);
561 createJob(new_job.get());
562 return new_job->getNumber();
565 //=============================================================================
567 * Factory to instantiate the good batch manager for chosen cluster.
569 //=============================================================================
570 Batch::BatchManager *
571 Launcher_cpp::FactoryBatchManager(ParserResourcesType& params)
574 Batch::CommunicationProtocolType protocol;
575 Batch::FactBatchManager * fact;
577 std::string hostname = params.HostName;
579 switch(params.Protocol)
582 protocol = Batch::SH;
585 protocol = Batch::RSH;
588 protocol = Batch::SSH;
591 protocol = Batch::RSYNC;
594 throw LauncherException("Unknown protocol for this resource");
626 switch( params.Batch )
659 LAUNCHER_MESSAGE("Bad batch description of the resource: Batch = " << params.Batch);
660 throw LauncherException("No batchmanager for that cluster - Bad batch description of the resource");
662 Batch::BatchManagerCatalog & cata = Batch::BatchManagerCatalog::getInstance();
663 fact = dynamic_cast<Batch::FactBatchManager*>(cata(bmType));
665 LAUNCHER_MESSAGE("Cannot find batch manager factory for " << bmType << ". Check your version of libBatch.");
666 throw LauncherException("Cannot find batch manager factory");
668 LAUNCHER_MESSAGE("Instantiation of batch manager of type: " << bmType);
669 Batch::BatchManager * batch_client = (*fact)(hostname.c_str(), params.UserName.c_str(),
670 protocol, mpi.c_str());
674 //----------------------------------------------------------
675 // Without LIBBATCH - Launcher_cpp do nothing...
676 //----------------------------------------------------------
680 Launcher_cpp::createJob(Launcher::Job * new_job)
682 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot create a job !!!");
683 throw LauncherException("Method Launcher_cpp::createJob is not available "
684 "(libBatch was not present at compilation time)");
688 Launcher_cpp::createJob(const JobParameters_cpp& job_parameters)
690 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot create a job !!!");
691 throw LauncherException("Method Launcher_cpp::createJob is not available "
692 "(libBatch was not present at compilation time)");
696 Launcher_cpp::launchJob(int job_id)
698 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot launch a job !!!");
699 throw LauncherException("Method Launcher_cpp::launchJob is not available "
700 "(libBatch was not present at compilation time)");
704 Launcher_cpp::getJobState(int job_id)
706 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job state!!!");
707 throw LauncherException("Method Launcher_cpp::getJobState is not available "
708 "(libBatch was not present at compilation time)");
712 Launcher_cpp::getAssignedHostnames(int job_id)
714 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job assigned hostnames!!!");
715 throw LauncherException("Method Launcher_cpp::getAssignedHostnames is not available "
716 "(libBatch was not present at compilation time)");
720 Launcher_cpp::exportInputFiles(int job_id)
722 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot copy the files!!!");
723 throw LauncherException("Method Launcher_cpp::exportInputFiles is not available "
724 "(libBatch was not present at compilation time)");
728 Launcher_cpp::getJobResults(int job_id, std::string directory)
730 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job results!!!");
731 throw LauncherException("Method Launcher_cpp::getJobResults is not available "
732 "(libBatch was not present at compilation time)");
736 Launcher_cpp::clearJobWorkingDir(int job_id)
738 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot clear directory!!!");
739 throw LauncherException("Method Launcher_cpp::clearJobWorkingDir is not available "
740 "(libBatch was not present at compilation time)");
744 Launcher_cpp::getJobDumpState(int job_id, std::string directory)
746 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job dump state!!!");
747 throw LauncherException("Method Launcher_cpp::getJobDumpState is not available "
748 "(libBatch was not present at compilation time)");
752 Launcher_cpp::getJobWorkFile(int job_id, std::string work_file, std::string directory)
754 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job dump state!!!");
755 throw LauncherException("Method Launcher_cpp::getJobWorkFile is not available "
756 "(libBatch was not present at compilation time)");
760 Launcher_cpp::removeJob(int job_id)
762 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot remove job!!!");
763 throw LauncherException("Method Launcher_cpp::removeJob is not available "
764 "(libBatch was not present at compilation time)");
768 Launcher_cpp::stopJob(int job_id)
770 throw LauncherException("Method Launcher_cpp::stopJob is not available "
771 "(libBatch was not present at compilation time)");
775 Launcher_cpp::dumpJob(int job_id)
777 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot dump job!!!");
778 throw LauncherException("Method Launcher_cpp::dumpJob is not available "
779 "(libBatch was not present at compilation time)");
784 Launcher_cpp::restoreJob(const std::string& dumpedJob)
786 LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot restore job!!!");
787 throw LauncherException("Method Launcher_cpp::restoreJob is not available "
788 "(libBatch was not present at compilation time)");
793 Launcher_cpp::createJobWithFile( const std::string xmlExecuteFile, std::string clusterName)
795 throw LauncherException("Method Launcher_cpp::createJobWithFile is not available "
796 "(libBatch was not present at compilation time)");
801 Launcher_cpp::getJobParameters(int job_id)
803 throw LauncherException("Method Launcher_cpp::getJobParamaters is not available "
804 "(libBatch was not present at compilation time)");
810 Launcher_cpp::ParseXmlFile(std::string xmlExecuteFile)
812 ParserLauncherType job_params;
813 SALOME_Launcher_Handler * handler = new SALOME_Launcher_Handler(job_params);
815 const char* aFilePath = xmlExecuteFile.c_str();
816 FILE* aFile = fopen(aFilePath, "r");
819 xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
821 handler->ProcessXmlDocument(aDoc);
824 std::string message = "ResourcesManager_cpp: could not parse file: " + xmlExecuteFile;
825 LAUNCHER_MESSAGE(message);
827 throw LauncherException(message);
835 std::string message = "ResourcesManager_cpp: file is not readable: " + xmlExecuteFile;
836 LAUNCHER_MESSAGE(message);
838 throw LauncherException(message);
846 std::map<int, Launcher::Job *>
847 Launcher_cpp::getJobs()
849 return _launcher_job_map;
854 Launcher_cpp::getBatchManager(Launcher::Job * job)
857 throw LauncherException("Resource manager is not set.");
859 Batch::BatchManager* result = nullptr;
860 int job_id = job->getNumber();
862 // Select a resource for the job
863 std::vector<std::string> ResourceList;
864 resourceParams params = job->getResourceRequiredParams();
865 // Consider only resources that can launch batch jobs
866 params.can_launch_batch_jobs = true;
869 ResourceList = _ResManager->GetFittingResources(params);
871 catch(const ResourcesException &ex)
873 throw LauncherException(ex.msg.c_str());
875 if (ResourceList.size() == 0)
877 LAUNCHER_INFOS("No adequate resource found for the job, number " << job->getNumber());
878 job->setState("ERROR");
879 throw LauncherException("No resource found the job");
882 // Configure the job with the resource selected - the first of the list
883 ParserResourcesType resource_definition = _ResManager->GetResourcesDescr(ResourceList[0]);
885 // Set resource definition to the job
886 // The job will check if the definitions needed
889 job->setResourceDefinition(resource_definition);
891 catch(const LauncherException &ex)
893 LAUNCHER_INFOS("Error in the definition of the resource, mess: " << ex.msg);
894 job->setState("ERROR");
898 // Step 2: We can now add a Factory if the resource is correctly define
899 std::map<int, Batch::BatchManager *>::const_iterator it = _batchmap.find(job_id);
900 if(it == _batchmap.end())
904 // Warning cannot write on one line like this, because map object is constructed before
905 // the method is called...
906 //_batchmap[job_id] = FactoryBatchManager(resource_definition);
907 result = FactoryBatchManager(resource_definition);
908 _batchmap[job_id] = result;
910 catch(const LauncherException &ex)
912 LAUNCHER_INFOS("Error during creation of the batch manager of the job, mess: " << ex.msg);
915 catch(const Batch::GenericException &ex)
917 LAUNCHER_INFOS("Error during creation of the batch manager of the job, mess: " << ex.message);
918 throw LauncherException(ex.message);
928 Launcher_cpp::addJobDirectlyToMap(Launcher::Job * new_job)
930 // Step 0: Calculated job_id
931 new_job->setNumber(_job_cpt);
935 // Step 1: check if resource is already in the map
936 Batch::BatchManager * bm = getBatchManager(new_job);
938 // Step 2: add the job to the batch manager
941 Batch::JobId batch_manager_job_id = bm->addJob(*(new_job->getBatchJob()),
942 new_job->getReference());
943 new_job->setBatchManagerJobId(batch_manager_job_id);
945 catch(const Batch::GenericException &ex)
947 LAUNCHER_INFOS("Job cannot be added, exception in addJob: " << ex.message);
948 throw LauncherException(ex.message.c_str());
951 // Step 3: add job to launcher map
952 std::map<int, Launcher::Job *>::const_iterator it_job = _launcher_job_map.find(new_job->getNumber());
953 if (it_job == _launcher_job_map.end())
955 _launcher_job_map[new_job->getNumber()] = new_job;
959 LAUNCHER_INFOS("A job as already the same id: " << new_job->getNumber());
960 throw LauncherException("A job as already the same id - job is not created !");
962 LAUNCHER_MESSAGE("New job added");
967 Launcher_cpp::addJob(Launcher::Job * new_job)
969 string job_state = new_job->getState();
971 if (job_state == "CREATED")
973 // In this case, we ignore run_part information
975 jobId = new_job->getNumber();
977 else if (job_state == "QUEUED" ||
978 job_state == "RUNNING" ||
979 job_state == "IN_PROCESS" ||
980 job_state == "PAUSED")
982 addJobDirectlyToMap(new_job);
983 jobId = new_job->getNumber();
985 // We check that the BatchManager could resume the job
987 if (new_job->getBatchManagerJobId().getReference() != new_job->getReference())
989 LAUNCHER_INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
990 new_job->setState("ERROR");
994 else if (job_state == "FINISHED" ||
995 job_state == "FAILED" ||
996 job_state == "ERROR")
998 // We add run_part information
999 addJobDirectlyToMap(new_job);
1000 jobId = new_job->getNumber();
1004 LAUNCHER_INFOS("A bad job is found, state unknown " << job_state);
1011 Launcher_cpp::loadJobs(const char* jobs_file)
1013 list<int> new_jobs_id_list;
1015 // Load the jobs from XML file
1016 list<Launcher::Job *> jobs_list = Launcher::XML_Persistence::loadJobs(jobs_file);
1018 // Create each job in the launcher
1019 list<Launcher::Job *>::const_iterator it_job;
1020 for (it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
1022 Launcher::Job* new_job(*it_job);
1026 jobId = addJob(new_job);
1028 new_jobs_id_list.push_back(jobId);
1030 catch(const LauncherException &ex)
1032 LAUNCHER_INFOS("Cannot load the job. Exception: " << ex.msg.c_str());
1036 return new_jobs_id_list;
1040 Launcher_cpp::saveJobs(const char* jobs_file)
1042 // Create a sorted list from the internal job map
1043 list<const Launcher::Job *> jobs_list;
1045 for (int i=0; i<_job_cpt; i++)
1047 map<int, Launcher::Job *>::const_iterator it_job = _launcher_job_map.find(i);
1048 if (it_job != _launcher_job_map.end())
1049 jobs_list.push_back(it_job->second);
1052 // Save the jobs in XML file
1053 Launcher::XML_Persistence::saveJobs(jobs_file, jobs_list);
1057 Launcher_cpp::findJob(int job_id)
1059 std::map<int, Launcher::Job *>::const_iterator it_job = _launcher_job_map.find(job_id);
1060 if (it_job == _launcher_job_map.end())
1062 LAUNCHER_INFOS("Cannot find the job, is it created ? job number: " << job_id);
1063 throw LauncherException("Cannot find the job, is it created ?");
1065 Launcher::Job * job = it_job->second;