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 std::string work_directory = job_parameters.work_directory.in();
110 std::string local_directory = job_parameters.local_directory.in();
111 std::string result_directory = job_parameters.result_directory.in();
112 new_job->setWorkDirectory(work_directory);
113 new_job->setLocalDirectory(local_directory);
114 new_job->setResultDirectory(result_directory);
117 std::string job_file = job_parameters.job_file.in();
120 new_job->setJobFile(job_file);
122 catch(const LauncherException &ex)
124 INFOS(ex.msg.c_str());
125 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
129 std::string env_file = job_parameters.env_file.in();
130 new_job->setEnvFile(env_file);
131 for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
132 new_job->add_in_file(job_parameters.in_files[i].in());
133 for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
134 new_job->add_out_file(job_parameters.out_files[i].in());
136 // Expected During Time
139 std::string maximum_duration = job_parameters.maximum_duration.in();
140 new_job->setMaximumDuration(maximum_duration);
142 catch(const LauncherException &ex){
143 INFOS(ex.msg.c_str());
144 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
148 std::string queue = job_parameters.queue.in();
149 new_job->setQueue(queue);
151 // Resources requirements
155 p.name = job_parameters.resource_required.name;
156 p.hostname = job_parameters.resource_required.hostname;
157 p.OS = job_parameters.resource_required.OS;
158 p.nb_proc = job_parameters.resource_required.nb_proc;
159 p.nb_node = job_parameters.resource_required.nb_node;
160 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
161 p.cpu_clock = job_parameters.resource_required.cpu_clock;
162 p.mem_mb = job_parameters.resource_required.mem_mb;
163 new_job->setResourceRequiredParams(p);
165 catch(const LauncherException &ex){
166 INFOS(ex.msg.c_str());
167 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
172 _l.createJob(new_job);
174 catch(const LauncherException &ex)
176 INFOS(ex.msg.c_str());
177 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
179 return new_job->getNumber();
183 SALOME_Launcher::launchJob(CORBA::Long job_id)
187 _l.launchJob(job_id);
189 catch(const LauncherException &ex)
191 INFOS(ex.msg.c_str());
192 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
197 SALOME_Launcher::getJobState(CORBA::Long job_id)
202 result = _l.getJobState(job_id);
204 catch(const LauncherException &ex)
206 INFOS(ex.msg.c_str());
207 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
209 return CORBA::string_dup(result.c_str());
213 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
217 _l.getJobResults(job_id, directory);
219 catch(const LauncherException &ex)
221 INFOS(ex.msg.c_str());
222 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
227 SALOME_Launcher::removeJob(CORBA::Long job_id)
231 _l.removeJob(job_id);
233 catch(const LauncherException &ex)
235 INFOS(ex.msg.c_str());
236 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
240 //=============================================================================
242 * Create a job in the launcher with a file
243 * \param xmlExecuteFile : .xml to parse that contains job description
244 * \param clusterName : machine choosed
246 //=============================================================================
248 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
249 const char * clusterName)
253 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
255 catch(const LauncherException &ex){
256 INFOS(ex.msg.c_str());
257 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
263 //=============================================================================
265 * the test batch configuration
266 * \param params : The batch cluster
268 //=============================================================================
270 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
272 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
273 CORBA::Boolean rtn = false;
276 // find a cluster matching the structure params
277 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(params);
278 if (aMachineList->length() == 0)
279 throw SALOME_Exception("No resources have been found with your parameters");
281 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
282 std::string resource_name(p->name);
283 INFOS("Choose resource for test: " << resource_name);
291 catch(const LauncherException &ex){
292 INFOS(ex.msg.c_str());
293 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
298 //=============================================================================
300 * shutdown all the containers, then the ContainerManager servant
302 //=============================================================================
303 void SALOME_Launcher::Shutdown()
306 _NS->Destroy_Name(_LauncherNameInNS);
307 _ContManager->Shutdown();
308 _ResManager->Shutdown();
309 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
310 _poa->deactivate_object(oid);
311 if(!CORBA::is_nil(_orb))
315 //=============================================================================
317 * Returns the PID of the process
319 //=============================================================================
320 CORBA::Long SALOME_Launcher::getPID()
324 (CORBA::Long)getpid();
326 (CORBA::Long)_getpid();
330 //=============================================================================
332 * Add a new observer to the launcher
334 //=============================================================================
336 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
340 //=============================================================================
342 * Returns current launcher jobs list
344 //=============================================================================
346 SALOME_Launcher::getJobsList()
348 Engines::JobsList_var jobs_list = new Engines::JobsList();
349 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
350 std::map<int, Launcher::Job *>::const_iterator it_job;
352 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
354 int number = it_job->first;
357 // Prepare CORBA job description
358 Engines::JobDescription_var job_descr = new Engines::JobDescription();
359 Engines::JobParameters_var job_parameters = getJobParameters(number);
360 job_descr->job_id = number;
361 job_descr->job_parameters = job_parameters;
363 // Add job description to the sequence
364 jobs_list->length(list_id + 1);
365 jobs_list[list_id] = job_descr;
370 return jobs_list._retn();
373 //=============================================================================
375 * Returns the job description
377 //=============================================================================
378 Engines::JobParameters *
379 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
381 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
382 std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
383 if (it_job == cpp_jobs.end())
385 INFOS("Cannot find the job, is it created ? job number: " << job_id);
386 THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
389 Launcher::Job * job = it_job->second;
390 Engines::JobParameters_var job_parameters = new Engines::JobParameters;
391 job_parameters->job_name = CORBA::string_dup(job->getJobName().c_str());
392 job_parameters->job_type = CORBA::string_dup(job->getJobType().c_str());
393 job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
394 job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
395 job_parameters->work_directory = CORBA::string_dup(job->getWorkDirectory().c_str());
396 job_parameters->local_directory = CORBA::string_dup(job->getLocalDirectory().c_str());
397 job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
401 std::list<std::string> in_files = job->get_in_files();
402 std::list<std::string> out_files = job->get_out_files();
403 job_parameters->in_files.length(in_files.size());
404 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
406 job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
409 job_parameters->out_files.length(out_files.size());
410 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
412 job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
416 job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
417 job_parameters->queue = CORBA::string_dup(job->getQueue().c_str());
419 resourceParams resource_params = job->getResourceRequiredParams();
420 job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str());
421 job_parameters->resource_required.hostname = CORBA::string_dup(resource_params.hostname.c_str());
422 job_parameters->resource_required.OS = CORBA::string_dup(resource_params.OS.c_str());
423 job_parameters->resource_required.nb_proc = resource_params.nb_proc;
424 job_parameters->resource_required.nb_node = resource_params.nb_node;
425 job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
426 job_parameters->resource_required.cpu_clock = resource_params.cpu_clock;
427 job_parameters->resource_required.mem_mb = resource_params.mem_mb;
429 return job_parameters._retn();
432 //=============================================================================
434 * Loads jobs saved in jobs_file
436 //=============================================================================
438 SALOME_Launcher::loadJobs(const char* jobs_file)
440 // Step 1: check jobs_file read access
441 FILE* xml_file = fopen(jobs_file, "r");
442 if (xml_file == NULL)
444 std::string error = "Error opening jobs_file in SALOME_Launcher::loadJobs: " + std::string(jobs_file);
446 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
449 // Step 2: read xml file
450 xmlDocPtr doc = xmlReadFile(jobs_file, NULL, 0);
453 std::string error = "Error in xmlReadFile in SALOME_Launcher::loadJobs, could not parse file: " + std::string(jobs_file);
456 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
460 xmlNodePtr root_node = xmlDocGetRootElement(doc);
461 xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
462 if (!xmlStrcmp(root_node->name, xmlCharStrdup("jobs")))
464 while(xmlCurrentNode != NULL)
466 if (!xmlStrcmp(xmlCurrentNode->name, xmlCharStrdup("job")))
468 INFOS("A job is found");
469 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
470 xmlNodePtr job_node = xmlCurrentNode;
473 if (!xmlHasProp(job_node, xmlCharStrdup("type")) ||
474 !xmlHasProp(job_node, xmlCharStrdup("name")))
476 INFOS("A bad job is found, type or name not found");
479 xmlChar* type = xmlGetProp(job_node, xmlCharStrdup("type"));
480 xmlChar* name = xmlGetProp(job_node, xmlCharStrdup("name"));
481 std::string job_type((const char*) type);
482 if (job_type == "command")
483 new_job = new Launcher::Job_Command();
484 else if (job_type == "yacs_file")
485 new_job = new Launcher::Job_YACSFile();
486 else if (job_type == "python_salome")
487 new_job = new Launcher::Job_PythonSALOME();
488 new_job->setJobName(std::string((const char *)name));
492 xmlNodePtr user_node = xmlFirstElementChild(job_node);
493 xmlNodePtr run_node = xmlNextElementSibling(user_node);
494 if (user_node == NULL || run_node == NULL)
496 INFOS("A bad job is found, user_part or run_part not found");
500 if (xmlStrcmp(user_node->name, xmlCharStrdup("user_part")) ||
501 xmlStrcmp(run_node->name, xmlCharStrdup("run_part")))
503 INFOS("A bad job is found, cannot get a correct user_part or run_part node");
510 // Get job_file env_file work_directory local_directory result_directory
511 xmlNodePtr job_file_node = xmlFirstElementChild(user_node);
512 xmlNodePtr env_file_node = xmlNextElementSibling(job_file_node);
513 xmlNodePtr work_directory_node = xmlNextElementSibling(env_file_node);
514 xmlNodePtr local_directory_node = xmlNextElementSibling(work_directory_node);
515 xmlNodePtr result_directory_node = xmlNextElementSibling(local_directory_node);
516 if (job_file_node == NULL ||
517 env_file_node == NULL ||
518 work_directory_node == NULL ||
519 local_directory_node == NULL ||
520 result_directory_node == NULL
523 INFOS("A bad job is found, some user_part are not found");
527 if (xmlStrcmp(job_file_node->name, xmlCharStrdup("job_file")) ||
528 xmlStrcmp(env_file_node->name, xmlCharStrdup("env_file")) ||
529 xmlStrcmp(work_directory_node->name, xmlCharStrdup("work_directory")) ||
530 xmlStrcmp(local_directory_node->name, xmlCharStrdup("local_directory")) ||
531 xmlStrcmp(result_directory_node->name, xmlCharStrdup("result_directory"))
534 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
538 xmlChar* job_file = xmlNodeGetContent(job_file_node);
541 new_job->setJobFile(std::string((const char *)job_file));
543 catch(const LauncherException &ex)
545 INFOS("Exception receice for job_file, cannot add the job" << ex.msg.c_str());
550 xmlChar* env_file = xmlNodeGetContent(env_file_node);
551 xmlChar* work_directory = xmlNodeGetContent(work_directory_node);
552 xmlChar* local_directory = xmlNodeGetContent(local_directory_node);
553 xmlChar* result_directory = xmlNodeGetContent(result_directory_node);
554 new_job->setEnvFile(std::string((const char *)env_file));
555 new_job->setWorkDirectory(std::string((const char *)work_directory));
556 new_job->setLocalDirectory(std::string((const char *)local_directory));
557 new_job->setResultDirectory(std::string((const char *)result_directory));
560 xmlFree(work_directory);
561 xmlFree(local_directory);
562 xmlFree(result_directory);
564 // Get in and out files
565 xmlNodePtr files_node = xmlNextElementSibling(result_directory_node);
566 if (files_node == NULL)
568 INFOS("A bad job is found, user_part files is not found");
572 if (xmlStrcmp(files_node->name, xmlCharStrdup("files")))
574 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");
578 xmlNodePtr file_node = xmlFirstElementChild(files_node);
579 while (file_node != NULL)
581 if (!xmlStrcmp(file_node->name, xmlCharStrdup("in_file")))
583 xmlChar* in_file = xmlNodeGetContent(file_node);
584 new_job->add_in_file(std::string((const char *)in_file));
587 else if (!xmlStrcmp(file_node->name, xmlCharStrdup("out_file")))
589 xmlChar* out_file = xmlNodeGetContent(file_node);
590 new_job->add_out_file(std::string((const char *)out_file));
593 file_node = xmlNextElementSibling(file_node);
597 xmlNodePtr res_node = xmlNextElementSibling(files_node);
598 xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node);
599 xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node);
600 if (res_node == NULL ||
601 maximum_duration_node == NULL ||
605 INFOS("A bad job is found, some user_part are not found");
609 if (xmlStrcmp(res_node->name, xmlCharStrdup("resource_params")) ||
610 xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) ||
611 xmlStrcmp(queue_node->name, xmlCharStrdup("queue"))
614 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
618 xmlChar* maximum_duration = xmlNodeGetContent(maximum_duration_node);
621 new_job->setMaximumDuration(std::string((const char *)maximum_duration));
623 catch(const LauncherException &ex)
625 INFOS("Exception receice for maximum_duration, cannot add the job" << ex.msg.c_str());
627 xmlFree(maximum_duration);
630 xmlChar* queue = xmlNodeGetContent(queue_node);
631 new_job->setQueue(std::string((const char *)queue));
632 xmlFree(maximum_duration);
635 xmlNodePtr res_name_node = xmlFirstElementChild(res_node);
636 xmlNodePtr res_hostname_node = xmlNextElementSibling(res_name_node);
637 xmlNodePtr res_os_node = xmlNextElementSibling(res_hostname_node);
638 xmlNodePtr res_nb_proc_node = xmlNextElementSibling(res_os_node);
639 xmlNodePtr res_nb_node_node = xmlNextElementSibling(res_nb_proc_node);
640 xmlNodePtr res_nb_proc_per_node_node = xmlNextElementSibling(res_nb_node_node);
641 xmlNodePtr res_cpu_clock_node = xmlNextElementSibling(res_nb_proc_per_node_node);
642 xmlNodePtr res_mem_mb_node = xmlNextElementSibling(res_cpu_clock_node);
643 if (res_name_node == NULL ||
644 res_hostname_node == NULL ||
645 res_os_node == NULL ||
646 res_nb_proc_node == NULL ||
647 res_nb_node_node == NULL ||
648 res_nb_proc_per_node_node == NULL ||
649 res_cpu_clock_node == NULL ||
650 res_mem_mb_node == NULL
653 INFOS("A bad job is found, some resource_params user_part are not found");
657 if (xmlStrcmp(res_name_node->name, xmlCharStrdup("name")) ||
658 xmlStrcmp(res_hostname_node->name, xmlCharStrdup("hostname")) ||
659 xmlStrcmp(res_os_node->name, xmlCharStrdup("OS")) ||
660 xmlStrcmp(res_nb_proc_node->name, xmlCharStrdup("nb_proc")) ||
661 xmlStrcmp(res_nb_node_node->name, xmlCharStrdup("nb_node")) ||
662 xmlStrcmp(res_nb_proc_per_node_node->name, xmlCharStrdup("nb_proc_per_node")) ||
663 xmlStrcmp(res_cpu_clock_node->name, xmlCharStrdup("cpu_clock")) ||
664 xmlStrcmp(res_mem_mb_node->name, xmlCharStrdup("mem_mb"))
667 INFOS("A bad job is found, some resource_params user_part node are not in the rigth or does not have a correct name");
671 xmlChar* res_name = xmlNodeGetContent(res_name_node);
672 xmlChar* res_hostname = xmlNodeGetContent(res_hostname_node);
673 xmlChar* res_os = xmlNodeGetContent(res_os_node);
675 p.name = std::string((const char*) res_name);
676 p.hostname = std::string((const char*) res_hostname);
677 p.OS = std::string((const char*) res_os);
679 xmlFree(res_hostname);
681 xmlChar* res_nb_proc = xmlNodeGetContent(res_nb_proc_node);
682 xmlChar* res_nb_node = xmlNodeGetContent(res_nb_node_node);
683 xmlChar* res_nb_proc_per_node = xmlNodeGetContent(res_nb_proc_per_node_node);
684 xmlChar* res_cpu_clock = xmlNodeGetContent(res_cpu_clock_node);
685 xmlChar* res_mem_mb = xmlNodeGetContent(res_mem_mb_node);
686 bool import_value = true;
687 std::istringstream nb_proc_stream((const char *) res_nb_proc);
688 if (!(nb_proc_stream >> p.nb_proc))
689 import_value = false;
690 std::istringstream nb_node_stream((const char *) res_nb_node);
691 if (!(nb_node_stream >> p.nb_node))
692 import_value = false;
693 std::istringstream nb_proc_per_node_stream((const char *) res_nb_proc_per_node);
694 if (!(nb_proc_per_node_stream >> p.nb_proc_per_node))
695 import_value = false;
696 std::istringstream cpu_clock_stream((const char *) res_cpu_clock);
697 if (!(cpu_clock_stream >> p.cpu_clock))
698 import_value = false;
699 std::istringstream mem_mb_stream((const char *) res_mem_mb);
700 if (!(mem_mb_stream >> p.mem_mb))
701 import_value = false;
702 xmlFree(res_nb_proc);
703 xmlFree(res_nb_node);
704 xmlFree(res_nb_proc_per_node);
705 xmlFree(res_cpu_clock);
709 INFOS("A bad job is found, some resource_params value are not correct");
715 new_job->setResourceRequiredParams(p);
717 catch(const LauncherException &ex)
719 INFOS("A bad job is found, an error when inserting resource_params:" << ex.msg.c_str());
724 // We finally get run part to figure out what to do
725 xmlNodePtr job_state_node = xmlFirstElementChild(run_node);
726 xmlNodePtr resource_choosed_name_node = xmlNextElementSibling(job_state_node);
727 xmlNodePtr job_reference_node = xmlNextElementSibling(resource_choosed_name_node);
728 if (job_state_node == NULL ||
729 resource_choosed_name_node == NULL ||
730 job_reference_node == NULL
733 INFOS("A bad job is found, some run_part are not found");
737 if (xmlStrcmp(job_state_node->name, xmlCharStrdup("job_state")) ||
738 xmlStrcmp(resource_choosed_name_node->name, xmlCharStrdup("resource_choosed_name")) ||
739 xmlStrcmp(job_reference_node->name, xmlCharStrdup("job_reference"))
742 INFOS("A bad job is found, some run_part nodes are not in the rigth or does not have a correct name");
746 xmlChar* job_state_xml = xmlNodeGetContent(job_state_node);
747 xmlChar* resource_choosed_name_xml = xmlNodeGetContent(resource_choosed_name_node);
748 xmlChar* job_reference_xml = xmlNodeGetContent(job_reference_node);
749 std::string job_state((const char *) job_state_xml);
750 std::string resource_choosed_name((const char *) resource_choosed_name_xml);
751 std::string job_reference((const char *) job_reference_xml);
752 xmlFree(job_state_xml);
753 xmlFree(resource_choosed_name_xml);
754 xmlFree(job_reference_xml);
756 // TODO: EVENT for observer !
757 if (job_state == "CREATED")
759 // In this case, we ignore run_part informations
762 _l.createJob(new_job);
764 catch(const LauncherException &ex)
766 INFOS("Load failed: " << ex.msg.c_str());
769 else if (job_state == "QUEUED" ||
770 job_state == "RUNNING" ||
771 job_state == "IN_PROCESS" ||
772 job_state == "PAUSED")
776 // Step 1: Add the resource to the launcher C++ map
777 _l.checkFactoryForResource(resource_choosed_name);
779 // Step 2: We add run_part informations
780 new_job->setState(job_state);
782 // Step 3: We add the job to the launcher
783 ParserResourcesType resource_definition;
784 resource_definition.Name = resource_choosed_name;
785 new_job->setResourceDefinition(resource_definition);
786 _l.addJobDirectlyToMap(new_job, job_reference);
788 // Step 4: We check that the BatchManager could resume
790 if (new_job->getBatchManagerJobId().getReference() != job_reference)
792 INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
793 new_job->setState("ERROR");
796 catch(const LauncherException &ex)
798 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
802 else if (job_state == "FINISHED" ||
803 job_state == "FAILED" ||
804 job_state == "ERROR")
808 // Step 1: Add the resource to the launcher C++ map
809 _l.checkFactoryForResource(resource_choosed_name);
811 // Step 2: We add run_part informations
812 new_job->setState(job_state);
814 // Step 3: We add the job to the launcher
815 ParserResourcesType resource_definition;
816 resource_definition.Name = resource_choosed_name;
817 new_job->setResourceDefinition(resource_definition);
818 _l.addJobDirectlyToMap(new_job, job_reference);
820 catch(const LauncherException &ex)
822 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
828 INFOS("A bad job is found, state unknown " << job_state);
833 xmlCurrentNode = xmlCurrentNode->next;
840 std::string error = "Error in xml file, could not find root_node named jobs: " + std::string(jobs_file);
842 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
850 //=============================================================================
852 * Save jobs of Launcher (in any steps) in file jobs_file
854 //=============================================================================
856 SALOME_Launcher::saveJobs(const char* jobs_file)
859 // Step 1: check jobs_file write access
860 FILE* xml_file = fopen(jobs_file, "w");
861 if (xml_file == NULL)
863 std::string error = "Error opening jobs_file in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
865 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
868 // Step 2: First lines
869 xmlKeepBlanksDefault(0);
870 xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
871 xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
872 xmlDocSetRootElement(doc, root_node);
873 xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher save jobs file"));
874 xmlAddPrevSibling(root_node, doc_comment);
876 // Step 3: For each job write it on the xml document
877 // We could put a mutex but are not foing to do that currently
878 std::map<int, Launcher::Job *> jobs_list = _l.getJobs();
879 std::map<int, Launcher::Job *>::const_iterator it_job;
880 for(it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
882 it_job->second->addToXmlDocument(root_node);
885 // Final step: write file
886 int isOk = xmlSaveFormatFile(jobs_file, doc, 1);
889 std::string error = "Error during xml file saving in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
893 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
899 MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!");
900 //TODO: Generation evenement pour les observeurs