1 // Copyright (C) 2007-2010 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.
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
23 #include "SALOME_Launcher.hxx"
24 #include "BatchTest.hxx"
26 #include "SALOME_ContainerManager.hxx"
27 #include "Utils_CorbaException.hxx"
30 #include "Launcher_Job_Command.hxx"
31 #include "Launcher_Job_YACSFile.hxx"
32 #include "Launcher_Job_PythonSALOME.hxx"
39 #include <sys/types.h>
42 #include <libxml/parser.h>
46 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
48 //=============================================================================
53 //=============================================================================
54 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
56 MESSAGE("SALOME_Launcher constructor");
57 _NS = new SALOME_NamingService(orb);
58 _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
59 _l.SetResourcesManager(_ResManager->GetImpl());
60 _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS);
61 _ResManager->_remove_ref();
62 _ContManager->_remove_ref();
64 _orb = CORBA::ORB::_duplicate(orb) ;
65 _poa = PortableServer::POA::_duplicate(poa) ;
66 PortableServer::ObjectId_var id = _poa->activate_object(this);
67 CORBA::Object_var obj = _poa->id_to_reference(id);
68 Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
70 _NS->Register(refContMan,_LauncherNameInNS);
71 MESSAGE("SALOME_Launcher constructor end");
74 //=============================================================================
78 //=============================================================================
79 SALOME_Launcher::~SALOME_Launcher()
81 MESSAGE("SALOME_Launcher destructor");
83 MESSAGE("SALOME_Launcher destructor end");
88 SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
90 std::string job_type = job_parameters.job_type.in();
92 if (job_type != "command" && job_type != "yacs_file" && job_type != "python_salome")
94 std::string message("SALOME_Launcher::createJob: bad job type: ");
96 THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
99 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
101 if (job_type == "command")
102 new_job = new Launcher::Job_Command();
103 else if (job_type == "yacs_file")
104 new_job = new Launcher::Job_YACSFile();
105 else if (job_type == "python_salome")
106 new_job = new Launcher::Job_PythonSALOME();
109 new_job->setJobName(job_parameters.job_name.in());
112 std::string work_directory = job_parameters.work_directory.in();
113 std::string local_directory = job_parameters.local_directory.in();
114 std::string result_directory = job_parameters.result_directory.in();
115 new_job->setWorkDirectory(work_directory);
116 new_job->setLocalDirectory(local_directory);
117 new_job->setResultDirectory(result_directory);
120 std::string job_file = job_parameters.job_file.in();
123 new_job->setJobFile(job_file);
125 catch(const LauncherException &ex)
127 INFOS(ex.msg.c_str());
128 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
132 std::string env_file = job_parameters.env_file.in();
133 new_job->setEnvFile(env_file);
134 for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
135 new_job->add_in_file(job_parameters.in_files[i].in());
136 for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
137 new_job->add_out_file(job_parameters.out_files[i].in());
139 // Expected During Time
142 std::string maximum_duration = job_parameters.maximum_duration.in();
143 new_job->setMaximumDuration(maximum_duration);
145 catch(const LauncherException &ex){
146 INFOS(ex.msg.c_str());
147 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
151 std::string queue = job_parameters.queue.in();
152 new_job->setQueue(queue);
154 // Resources requirements
158 p.name = job_parameters.resource_required.name;
159 p.hostname = job_parameters.resource_required.hostname;
160 p.OS = job_parameters.resource_required.OS;
161 p.nb_proc = job_parameters.resource_required.nb_proc;
162 p.nb_node = job_parameters.resource_required.nb_node;
163 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
164 p.cpu_clock = job_parameters.resource_required.cpu_clock;
165 p.mem_mb = job_parameters.resource_required.mem_mb;
166 new_job->setResourceRequiredParams(p);
168 catch(const LauncherException &ex){
169 INFOS(ex.msg.c_str());
170 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
175 _l.createJob(new_job);
176 std::ostringstream job_id;
177 job_id << new_job->getNumber();
178 notifyObservers("NEW_JOB", job_id.str());
180 catch(const LauncherException &ex)
182 INFOS(ex.msg.c_str());
183 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
185 return new_job->getNumber();
189 SALOME_Launcher::launchJob(CORBA::Long job_id)
193 _l.launchJob(job_id);
195 catch(const LauncherException &ex)
197 INFOS(ex.msg.c_str());
198 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
203 SALOME_Launcher::getJobState(CORBA::Long job_id)
208 result = _l.getJobState(job_id);
210 catch(const LauncherException &ex)
212 INFOS(ex.msg.c_str());
213 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
215 return CORBA::string_dup(result.c_str());
219 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
223 _l.getJobResults(job_id, directory);
225 catch(const LauncherException &ex)
227 INFOS(ex.msg.c_str());
228 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
233 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
235 CORBA::Boolean rtn = false;
238 rtn = _l.getJobDumpState(job_id, directory);
240 catch(const LauncherException &ex)
242 INFOS(ex.msg.c_str());
243 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
249 SALOME_Launcher::removeJob(CORBA::Long job_id)
253 _l.removeJob(job_id);
254 std::ostringstream job_id_str;
255 job_id_str << job_id;
256 notifyObservers("REMOVE_JOB", job_id_str.str());
258 catch(const LauncherException &ex)
260 INFOS(ex.msg.c_str());
261 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
265 //=============================================================================
267 * Create a job in the launcher with a file
268 * \param xmlExecuteFile : .xml to parse that contains job description
269 * \param clusterName : machine choosed
271 //=============================================================================
273 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
274 const char * clusterName)
278 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
280 catch(const LauncherException &ex){
281 INFOS(ex.msg.c_str());
282 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
288 //=============================================================================
290 * the test batch configuration
291 * \param params : The batch cluster
293 //=============================================================================
295 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
297 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
298 CORBA::Boolean rtn = false;
301 // find a cluster matching the structure params
302 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(params);
303 if (aMachineList->length() == 0)
304 throw SALOME_Exception("No resources have been found with your parameters");
306 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
307 std::string resource_name(p->name);
308 INFOS("Choose resource for test: " << resource_name);
316 catch(const LauncherException &ex){
317 INFOS(ex.msg.c_str());
318 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
323 //=============================================================================
325 * shutdown all the containers, then the ContainerManager servant
327 //=============================================================================
328 void SALOME_Launcher::Shutdown()
331 _NS->Destroy_Name(_LauncherNameInNS);
332 _ContManager->Shutdown();
333 _ResManager->Shutdown();
334 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
335 _poa->deactivate_object(oid);
336 if(!CORBA::is_nil(_orb))
340 //=============================================================================
342 * Returns the PID of the process
344 //=============================================================================
345 CORBA::Long SALOME_Launcher::getPID()
349 (CORBA::Long)getpid();
351 (CORBA::Long)_getpid();
355 //=============================================================================
357 * Returns current launcher jobs list
359 //=============================================================================
361 SALOME_Launcher::getJobsList()
363 Engines::JobsList_var jobs_list = new Engines::JobsList();
364 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
365 std::map<int, Launcher::Job *>::const_iterator it_job;
367 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
369 int number = it_job->first;
372 // Prepare CORBA job description
373 Engines::JobDescription_var job_descr = new Engines::JobDescription();
374 Engines::JobParameters_var job_parameters = getJobParameters(number);
375 job_descr->job_id = number;
376 job_descr->job_parameters = job_parameters;
378 // Add job description to the sequence
379 jobs_list->length(list_id + 1);
380 jobs_list[list_id] = job_descr;
385 return jobs_list._retn();
388 //=============================================================================
390 * Returns the job description
392 //=============================================================================
393 Engines::JobParameters *
394 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
396 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
397 std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
398 if (it_job == cpp_jobs.end())
400 INFOS("Cannot find the job, is it created ? job number: " << job_id);
401 THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
404 Launcher::Job * job = it_job->second;
405 Engines::JobParameters_var job_parameters = new Engines::JobParameters;
406 job_parameters->job_name = CORBA::string_dup(job->getJobName().c_str());
407 job_parameters->job_type = CORBA::string_dup(job->getJobType().c_str());
408 job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
409 job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
410 job_parameters->work_directory = CORBA::string_dup(job->getWorkDirectory().c_str());
411 job_parameters->local_directory = CORBA::string_dup(job->getLocalDirectory().c_str());
412 job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
416 std::list<std::string> in_files = job->get_in_files();
417 std::list<std::string> out_files = job->get_out_files();
418 job_parameters->in_files.length(in_files.size());
419 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
421 job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
424 job_parameters->out_files.length(out_files.size());
425 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
427 job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
431 job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
432 job_parameters->queue = CORBA::string_dup(job->getQueue().c_str());
434 resourceParams resource_params = job->getResourceRequiredParams();
435 job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str());
436 job_parameters->resource_required.hostname = CORBA::string_dup(resource_params.hostname.c_str());
437 job_parameters->resource_required.OS = CORBA::string_dup(resource_params.OS.c_str());
438 job_parameters->resource_required.nb_proc = resource_params.nb_proc;
439 job_parameters->resource_required.nb_node = resource_params.nb_node;
440 job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
441 job_parameters->resource_required.cpu_clock = resource_params.cpu_clock;
442 job_parameters->resource_required.mem_mb = resource_params.mem_mb;
444 return job_parameters._retn();
447 //=============================================================================
449 * Loads jobs saved in jobs_file
451 //=============================================================================
453 SALOME_Launcher::loadJobs(const char* jobs_file)
455 // Step 1: check jobs_file read access
456 FILE* xml_file = fopen(jobs_file, "r");
457 if (xml_file == NULL)
459 std::string error = "Error opening jobs_file in SALOME_Launcher::loadJobs: " + std::string(jobs_file);
461 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
464 // Step 2: read xml file
465 xmlDocPtr doc = xmlReadFile(jobs_file, NULL, 0);
468 std::string error = "Error in xmlReadFile in SALOME_Launcher::loadJobs, could not parse file: " + std::string(jobs_file);
471 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
475 xmlNodePtr root_node = xmlDocGetRootElement(doc);
476 xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
477 if (!xmlStrcmp(root_node->name, xmlCharStrdup("jobs")))
479 while(xmlCurrentNode != NULL)
481 if (!xmlStrcmp(xmlCurrentNode->name, xmlCharStrdup("job")))
483 INFOS("A job is found");
484 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
485 xmlNodePtr job_node = xmlCurrentNode;
488 if (!xmlHasProp(job_node, xmlCharStrdup("type")) ||
489 !xmlHasProp(job_node, xmlCharStrdup("name")))
491 INFOS("A bad job is found, type or name not found");
494 xmlChar* type = xmlGetProp(job_node, xmlCharStrdup("type"));
495 xmlChar* name = xmlGetProp(job_node, xmlCharStrdup("name"));
496 std::string job_type((const char*) type);
497 if (job_type == "command")
498 new_job = new Launcher::Job_Command();
499 else if (job_type == "yacs_file")
500 new_job = new Launcher::Job_YACSFile();
501 else if (job_type == "python_salome")
502 new_job = new Launcher::Job_PythonSALOME();
503 new_job->setJobName(std::string((const char *)name));
507 xmlNodePtr user_node = xmlFirstElementChild(job_node);
508 xmlNodePtr run_node = xmlNextElementSibling(user_node);
509 if (user_node == NULL || run_node == NULL)
511 INFOS("A bad job is found, user_part or run_part not found");
515 if (xmlStrcmp(user_node->name, xmlCharStrdup("user_part")) ||
516 xmlStrcmp(run_node->name, xmlCharStrdup("run_part")))
518 INFOS("A bad job is found, cannot get a correct user_part or run_part node");
525 // Get job_file env_file work_directory local_directory result_directory
526 xmlNodePtr job_file_node = xmlFirstElementChild(user_node);
527 xmlNodePtr env_file_node = xmlNextElementSibling(job_file_node);
528 xmlNodePtr work_directory_node = xmlNextElementSibling(env_file_node);
529 xmlNodePtr local_directory_node = xmlNextElementSibling(work_directory_node);
530 xmlNodePtr result_directory_node = xmlNextElementSibling(local_directory_node);
531 if (job_file_node == NULL ||
532 env_file_node == NULL ||
533 work_directory_node == NULL ||
534 local_directory_node == NULL ||
535 result_directory_node == NULL
538 INFOS("A bad job is found, some user_part are not found");
542 if (xmlStrcmp(job_file_node->name, xmlCharStrdup("job_file")) ||
543 xmlStrcmp(env_file_node->name, xmlCharStrdup("env_file")) ||
544 xmlStrcmp(work_directory_node->name, xmlCharStrdup("work_directory")) ||
545 xmlStrcmp(local_directory_node->name, xmlCharStrdup("local_directory")) ||
546 xmlStrcmp(result_directory_node->name, xmlCharStrdup("result_directory"))
549 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
553 xmlChar* job_file = xmlNodeGetContent(job_file_node);
556 new_job->setJobFile(std::string((const char *)job_file));
558 catch(const LauncherException &ex)
560 INFOS("Exception receice for job_file, cannot add the job" << ex.msg.c_str());
565 xmlChar* env_file = xmlNodeGetContent(env_file_node);
566 xmlChar* work_directory = xmlNodeGetContent(work_directory_node);
567 xmlChar* local_directory = xmlNodeGetContent(local_directory_node);
568 xmlChar* result_directory = xmlNodeGetContent(result_directory_node);
569 new_job->setEnvFile(std::string((const char *)env_file));
570 new_job->setWorkDirectory(std::string((const char *)work_directory));
571 new_job->setLocalDirectory(std::string((const char *)local_directory));
572 new_job->setResultDirectory(std::string((const char *)result_directory));
575 xmlFree(work_directory);
576 xmlFree(local_directory);
577 xmlFree(result_directory);
579 // Get in and out files
580 xmlNodePtr files_node = xmlNextElementSibling(result_directory_node);
581 if (files_node == NULL)
583 INFOS("A bad job is found, user_part files is not found");
587 if (xmlStrcmp(files_node->name, xmlCharStrdup("files")))
589 INFOS("A bad job is found, files node are not in the rigth place or does not have a correct name or does not exist");
593 xmlNodePtr file_node = xmlFirstElementChild(files_node);
594 while (file_node != NULL)
596 if (!xmlStrcmp(file_node->name, xmlCharStrdup("in_file")))
598 xmlChar* in_file = xmlNodeGetContent(file_node);
599 new_job->add_in_file(std::string((const char *)in_file));
602 else if (!xmlStrcmp(file_node->name, xmlCharStrdup("out_file")))
604 xmlChar* out_file = xmlNodeGetContent(file_node);
605 new_job->add_out_file(std::string((const char *)out_file));
608 file_node = xmlNextElementSibling(file_node);
612 xmlNodePtr res_node = xmlNextElementSibling(files_node);
613 xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node);
614 xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node);
615 if (res_node == NULL ||
616 maximum_duration_node == NULL ||
620 INFOS("A bad job is found, some user_part are not found");
624 if (xmlStrcmp(res_node->name, xmlCharStrdup("resource_params")) ||
625 xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) ||
626 xmlStrcmp(queue_node->name, xmlCharStrdup("queue"))
629 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
633 xmlChar* maximum_duration = xmlNodeGetContent(maximum_duration_node);
636 new_job->setMaximumDuration(std::string((const char *)maximum_duration));
638 catch(const LauncherException &ex)
640 INFOS("Exception receice for maximum_duration, cannot add the job" << ex.msg.c_str());
642 xmlFree(maximum_duration);
645 xmlChar* queue = xmlNodeGetContent(queue_node);
646 new_job->setQueue(std::string((const char *)queue));
647 xmlFree(maximum_duration);
650 xmlNodePtr res_name_node = xmlFirstElementChild(res_node);
651 xmlNodePtr res_hostname_node = xmlNextElementSibling(res_name_node);
652 xmlNodePtr res_os_node = xmlNextElementSibling(res_hostname_node);
653 xmlNodePtr res_nb_proc_node = xmlNextElementSibling(res_os_node);
654 xmlNodePtr res_nb_node_node = xmlNextElementSibling(res_nb_proc_node);
655 xmlNodePtr res_nb_proc_per_node_node = xmlNextElementSibling(res_nb_node_node);
656 xmlNodePtr res_cpu_clock_node = xmlNextElementSibling(res_nb_proc_per_node_node);
657 xmlNodePtr res_mem_mb_node = xmlNextElementSibling(res_cpu_clock_node);
658 if (res_name_node == NULL ||
659 res_hostname_node == NULL ||
660 res_os_node == NULL ||
661 res_nb_proc_node == NULL ||
662 res_nb_node_node == NULL ||
663 res_nb_proc_per_node_node == NULL ||
664 res_cpu_clock_node == NULL ||
665 res_mem_mb_node == NULL
668 INFOS("A bad job is found, some resource_params user_part are not found");
672 if (xmlStrcmp(res_name_node->name, xmlCharStrdup("name")) ||
673 xmlStrcmp(res_hostname_node->name, xmlCharStrdup("hostname")) ||
674 xmlStrcmp(res_os_node->name, xmlCharStrdup("OS")) ||
675 xmlStrcmp(res_nb_proc_node->name, xmlCharStrdup("nb_proc")) ||
676 xmlStrcmp(res_nb_node_node->name, xmlCharStrdup("nb_node")) ||
677 xmlStrcmp(res_nb_proc_per_node_node->name, xmlCharStrdup("nb_proc_per_node")) ||
678 xmlStrcmp(res_cpu_clock_node->name, xmlCharStrdup("cpu_clock")) ||
679 xmlStrcmp(res_mem_mb_node->name, xmlCharStrdup("mem_mb"))
682 INFOS("A bad job is found, some resource_params user_part node are not in the rigth or does not have a correct name");
686 xmlChar* res_name = xmlNodeGetContent(res_name_node);
687 xmlChar* res_hostname = xmlNodeGetContent(res_hostname_node);
688 xmlChar* res_os = xmlNodeGetContent(res_os_node);
690 p.name = std::string((const char*) res_name);
691 p.hostname = std::string((const char*) res_hostname);
692 p.OS = std::string((const char*) res_os);
694 xmlFree(res_hostname);
696 xmlChar* res_nb_proc = xmlNodeGetContent(res_nb_proc_node);
697 xmlChar* res_nb_node = xmlNodeGetContent(res_nb_node_node);
698 xmlChar* res_nb_proc_per_node = xmlNodeGetContent(res_nb_proc_per_node_node);
699 xmlChar* res_cpu_clock = xmlNodeGetContent(res_cpu_clock_node);
700 xmlChar* res_mem_mb = xmlNodeGetContent(res_mem_mb_node);
701 bool import_value = true;
702 std::istringstream nb_proc_stream((const char *) res_nb_proc);
703 if (!(nb_proc_stream >> p.nb_proc))
704 import_value = false;
705 std::istringstream nb_node_stream((const char *) res_nb_node);
706 if (!(nb_node_stream >> p.nb_node))
707 import_value = false;
708 std::istringstream nb_proc_per_node_stream((const char *) res_nb_proc_per_node);
709 if (!(nb_proc_per_node_stream >> p.nb_proc_per_node))
710 import_value = false;
711 std::istringstream cpu_clock_stream((const char *) res_cpu_clock);
712 if (!(cpu_clock_stream >> p.cpu_clock))
713 import_value = false;
714 std::istringstream mem_mb_stream((const char *) res_mem_mb);
715 if (!(mem_mb_stream >> p.mem_mb))
716 import_value = false;
717 xmlFree(res_nb_proc);
718 xmlFree(res_nb_node);
719 xmlFree(res_nb_proc_per_node);
720 xmlFree(res_cpu_clock);
724 INFOS("A bad job is found, some resource_params value are not correct");
730 new_job->setResourceRequiredParams(p);
732 catch(const LauncherException &ex)
734 INFOS("A bad job is found, an error when inserting resource_params:" << ex.msg.c_str());
739 // We finally get run part to figure out what to do
740 xmlNodePtr job_state_node = xmlFirstElementChild(run_node);
741 xmlNodePtr resource_choosed_name_node = xmlNextElementSibling(job_state_node);
742 xmlNodePtr job_reference_node = xmlNextElementSibling(resource_choosed_name_node);
743 if (job_state_node == NULL ||
744 resource_choosed_name_node == NULL ||
745 job_reference_node == NULL
748 INFOS("A bad job is found, some run_part are not found");
752 if (xmlStrcmp(job_state_node->name, xmlCharStrdup("job_state")) ||
753 xmlStrcmp(resource_choosed_name_node->name, xmlCharStrdup("resource_choosed_name")) ||
754 xmlStrcmp(job_reference_node->name, xmlCharStrdup("job_reference"))
757 INFOS("A bad job is found, some run_part nodes are not in the rigth or does not have a correct name");
761 xmlChar* job_state_xml = xmlNodeGetContent(job_state_node);
762 xmlChar* resource_choosed_name_xml = xmlNodeGetContent(resource_choosed_name_node);
763 xmlChar* job_reference_xml = xmlNodeGetContent(job_reference_node);
764 std::string job_state((const char *) job_state_xml);
765 std::string resource_choosed_name((const char *) resource_choosed_name_xml);
766 std::string job_reference((const char *) job_reference_xml);
767 xmlFree(job_state_xml);
768 xmlFree(resource_choosed_name_xml);
769 xmlFree(job_reference_xml);
771 if (job_state == "CREATED")
773 // In this case, we ignore run_part informations
776 _l.createJob(new_job);
778 std::ostringstream job_id;
779 job_id << new_job->getNumber();
780 notifyObservers("NEW_JOB", job_id.str());
782 catch(const LauncherException &ex)
784 INFOS("Load failed: " << ex.msg.c_str());
787 else if (job_state == "QUEUED" ||
788 job_state == "RUNNING" ||
789 job_state == "IN_PROCESS" ||
790 job_state == "PAUSED")
794 // Step 1: Add the resource to the launcher C++ map
795 _l.checkFactoryForResource(resource_choosed_name);
797 // Step 2: We add run_part informations
798 new_job->setState(job_state);
800 // Step 3: We add the job to the launcher
801 ParserResourcesType resource_definition = _l._ResManager->GetResourcesDescr(resource_choosed_name);
802 new_job->setResourceDefinition(resource_definition);
803 _l.addJobDirectlyToMap(new_job, job_reference);
805 // Step 4: We check that the BatchManager could resume
808 if (new_job->getBatchManagerJobId().getReference() != job_reference)
810 INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
811 new_job->setState("ERROR");
814 std::ostringstream job_id;
815 job_id << new_job->getNumber();
816 notifyObservers("NEW_JOB", job_id.str());
818 catch(const LauncherException &ex)
820 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
824 else if (job_state == "FINISHED" ||
825 job_state == "FAILED" ||
826 job_state == "ERROR")
830 // Step 1: Add the resource to the launcher C++ map
831 _l.checkFactoryForResource(resource_choosed_name);
833 // Step 2: We add run_part informations
834 new_job->setState(job_state);
836 // Step 3: We add the job to the launcher
837 ParserResourcesType resource_definition = _l._ResManager->GetResourcesDescr(resource_choosed_name);
838 new_job->setResourceDefinition(resource_definition);
839 _l.addJobDirectlyToMap(new_job, job_reference);
841 std::ostringstream job_id;
842 job_id << new_job->getNumber();
843 notifyObservers("NEW_JOB", job_id.str());
845 catch(const LauncherException &ex)
847 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
853 INFOS("A bad job is found, state unknown " << job_state);
858 xmlCurrentNode = xmlCurrentNode->next;
865 std::string error = "Error in xml file, could not find root_node named jobs: " + std::string(jobs_file);
867 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
873 notifyObservers("LOAD_JOBS", jobs_file);
876 //=============================================================================
878 * Save jobs of Launcher (in any steps) in file jobs_file
880 //=============================================================================
882 SALOME_Launcher::saveJobs(const char* jobs_file)
885 // Step 1: check jobs_file write access
886 FILE* xml_file = fopen(jobs_file, "w");
887 if (xml_file == NULL)
889 std::string error = "Error opening jobs_file in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
891 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
894 // Step 2: First lines
895 xmlKeepBlanksDefault(0);
896 xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
897 xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
898 xmlDocSetRootElement(doc, root_node);
899 xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher save jobs file"));
900 xmlAddPrevSibling(root_node, doc_comment);
902 // Step 3: For each job write it on the xml document
903 // We could put a mutex but are not foing to do that currently
904 std::map<int, Launcher::Job *> jobs_list = _l.getJobs();
905 std::map<int, Launcher::Job *>::const_iterator it_job;
906 for(it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
908 it_job->second->addToXmlDocument(root_node);
911 // Final step: write file
912 int isOk = xmlSaveFormatFile(jobs_file, doc, 1);
915 std::string error = "Error during xml file saving in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
919 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
925 MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!");
926 notifyObservers("SAVE_JOBS", jobs_file);
929 //=============================================================================
931 * Add a new observer to the launcher
933 //=============================================================================
935 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
937 bool new_observer = true;
938 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
939 while(iter != _observers.end())
941 if (std::string(_orb->object_to_string(*iter)) ==
942 std::string(_orb->object_to_string(observer)))
944 new_observer = false;
950 _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
952 // We notify the new observer with all jobs that are currently in the Launcher
953 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
954 std::map<int, Launcher::Job *>::const_iterator it_job;
955 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
957 int number = it_job->first;
958 std::ostringstream job_id;
962 observer->notify("NEW_JOB", job_id.str().c_str());
966 MESSAGE("Notify Observer, exception catch");
972 //=============================================================================
974 * Add a new observer to the launcher
976 //=============================================================================
978 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
980 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
981 while(iter != _observers.end())
983 if (std::string(_orb->object_to_string(*iter)) ==
984 std::string(_orb->object_to_string(observer)))
987 iter =_observers.erase(iter++);
996 //=============================================================================
998 * Notify observers on a new event
1000 //=============================================================================
1002 SALOME_Launcher::notifyObservers(const std::string & event_name,
1003 const std::string & event_data)
1005 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1006 while(iter != _observers.end())
1010 (*iter)->notify(CORBA::string_dup(event_name.c_str()),
1011 CORBA::string_dup(event_data.c_str()));
1015 MESSAGE("Notify Observer, exception catch");