1 // Copyright (C) 2007-2012 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);
173 // Adding specific parameters to the job
174 for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
175 new_job->addSpecificParameter(job_parameters.specific_parameters[i].name.in(),
176 job_parameters.specific_parameters[i].value.in());
179 new_job->checkSpecificParameters();
181 catch(const LauncherException &ex)
183 INFOS(ex.msg.c_str());
184 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
189 _l.createJob(new_job);
190 std::ostringstream job_id;
191 job_id << new_job->getNumber();
192 notifyObservers("NEW_JOB", job_id.str());
194 catch(const LauncherException &ex)
196 INFOS(ex.msg.c_str());
197 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
199 return new_job->getNumber();
203 SALOME_Launcher::launchJob(CORBA::Long job_id)
207 _l.launchJob(job_id);
209 catch(const LauncherException &ex)
211 INFOS(ex.msg.c_str());
212 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
217 SALOME_Launcher::getJobState(CORBA::Long job_id)
222 result = _l.getJobState(job_id);
224 catch(const LauncherException &ex)
226 INFOS(ex.msg.c_str());
227 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
229 return CORBA::string_dup(result.c_str());
233 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
237 _l.getJobResults(job_id, directory);
239 catch(const LauncherException &ex)
241 INFOS(ex.msg.c_str());
242 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
247 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
249 CORBA::Boolean rtn = false;
252 rtn = _l.getJobDumpState(job_id, directory);
254 catch(const LauncherException &ex)
256 INFOS(ex.msg.c_str());
257 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
263 SALOME_Launcher::removeJob(CORBA::Long job_id)
267 _l.removeJob(job_id);
268 std::ostringstream job_id_str;
269 job_id_str << job_id;
270 notifyObservers("REMOVE_JOB", job_id_str.str());
272 catch(const LauncherException &ex)
274 INFOS(ex.msg.c_str());
275 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
280 SALOME_Launcher::stopJob(CORBA::Long job_id)
285 std::ostringstream job_id_str;
286 job_id_str << job_id;
287 notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
289 catch(const LauncherException &ex)
291 INFOS(ex.msg.c_str());
292 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
296 //=============================================================================
298 * Create a job in the launcher with a file
299 * \param xmlExecuteFile : .xml to parse that contains job description
300 * \param clusterName : machine choosed
302 //=============================================================================
304 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
305 const char * clusterName)
309 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
311 catch(const LauncherException &ex){
312 INFOS(ex.msg.c_str());
313 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
319 //=============================================================================
321 * the test batch configuration
322 * \param params : The batch cluster
324 //=============================================================================
326 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
328 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
329 CORBA::Boolean rtn = false;
332 // Consider only resources that can run batch jobs
333 Engines::ResourceParameters new_params(params);
334 new_params.can_launch_batch_jobs = true;
336 // find a resource matching the required parameters
337 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(new_params);
338 if (aMachineList->length() == 0)
339 throw SALOME_Exception("No resources have been found with your parameters");
341 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
342 std::string resource_name(p->name);
343 INFOS("Choose resource for test: " << resource_name);
351 catch(const LauncherException &ex){
352 INFOS(ex.msg.c_str());
353 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
358 //=============================================================================
360 * shutdown all the containers, then the ContainerManager servant
362 //=============================================================================
363 void SALOME_Launcher::Shutdown()
366 _NS->Destroy_Name(_LauncherNameInNS);
367 _ContManager->Shutdown();
368 _ResManager->Shutdown();
369 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
370 _poa->deactivate_object(oid);
371 if(!CORBA::is_nil(_orb))
375 //=============================================================================
377 * Returns the PID of the process
379 //=============================================================================
380 CORBA::Long SALOME_Launcher::getPID()
384 (CORBA::Long)getpid();
386 (CORBA::Long)_getpid();
390 //=============================================================================
392 * Returns current launcher jobs list
394 //=============================================================================
396 SALOME_Launcher::getJobsList()
398 Engines::JobsList_var jobs_list = new Engines::JobsList();
399 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
400 std::map<int, Launcher::Job *>::const_iterator it_job;
402 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
404 int number = it_job->first;
407 // Prepare CORBA job description
408 Engines::JobDescription_var job_descr = new Engines::JobDescription();
409 Engines::JobParameters_var job_parameters = getJobParameters(number);
410 job_descr->job_id = number;
411 job_descr->job_parameters = job_parameters;
413 // Add job description to the sequence
414 jobs_list->length(list_id + 1);
415 jobs_list[list_id] = job_descr;
420 return jobs_list._retn();
423 //=============================================================================
425 * Returns the job description
427 //=============================================================================
428 Engines::JobParameters *
429 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
431 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
432 std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
433 if (it_job == cpp_jobs.end())
435 INFOS("Cannot find the job, is it created ? job number: " << job_id);
436 THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
439 Launcher::Job * job = it_job->second;
440 Engines::JobParameters_var job_parameters = new Engines::JobParameters;
441 job_parameters->job_name = CORBA::string_dup(job->getJobName().c_str());
442 job_parameters->job_type = CORBA::string_dup(job->getJobType().c_str());
443 job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
444 job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
445 job_parameters->work_directory = CORBA::string_dup(job->getWorkDirectory().c_str());
446 job_parameters->local_directory = CORBA::string_dup(job->getLocalDirectory().c_str());
447 job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
451 std::list<std::string> in_files = job->get_in_files();
452 std::list<std::string> out_files = job->get_out_files();
453 job_parameters->in_files.length(in_files.size());
454 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
456 job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
459 job_parameters->out_files.length(out_files.size());
460 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
462 job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
466 job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
467 job_parameters->queue = CORBA::string_dup(job->getQueue().c_str());
469 resourceParams resource_params = job->getResourceRequiredParams();
470 job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str());
471 job_parameters->resource_required.hostname = CORBA::string_dup(resource_params.hostname.c_str());
472 job_parameters->resource_required.OS = CORBA::string_dup(resource_params.OS.c_str());
473 job_parameters->resource_required.nb_proc = resource_params.nb_proc;
474 job_parameters->resource_required.nb_node = resource_params.nb_node;
475 job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
476 job_parameters->resource_required.cpu_clock = resource_params.cpu_clock;
477 job_parameters->resource_required.mem_mb = resource_params.mem_mb;
479 std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
480 if (!specific_parameters.empty())
482 job_parameters->specific_parameters.length(specific_parameters.size());
483 std::map<std::string, std::string>::const_iterator it_specific;
485 for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
487 Engines::Parameter_var new_param = new Engines::Parameter;
488 new_param->name = CORBA::string_dup((it_specific->first).c_str());
489 new_param->value = CORBA::string_dup((it_specific->second).c_str());
490 job_parameters->specific_parameters[i] = new_param;
495 return job_parameters._retn();
498 //=============================================================================
500 * Loads jobs saved in jobs_file
502 //=============================================================================
504 SALOME_Launcher::loadJobs(const char* jobs_file)
506 // Step 1: check jobs_file read access
507 FILE* xml_file = fopen(jobs_file, "r");
508 if (xml_file == NULL)
510 std::string error = "Error opening jobs_file in SALOME_Launcher::loadJobs: " + std::string(jobs_file);
512 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
515 // Step 2: read xml file
516 xmlDocPtr doc = xmlReadFile(jobs_file, NULL, 0);
519 std::string error = "Error in xmlReadFile in SALOME_Launcher::loadJobs, could not parse file: " + std::string(jobs_file);
522 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
526 xmlNodePtr root_node = xmlDocGetRootElement(doc);
527 xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
528 if (!xmlStrcmp(root_node->name, xmlCharStrdup("jobs")))
530 while(xmlCurrentNode != NULL)
532 if (!xmlStrcmp(xmlCurrentNode->name, xmlCharStrdup("job")))
534 INFOS("A job is found");
535 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
536 xmlNodePtr job_node = xmlCurrentNode;
539 if (!xmlHasProp(job_node, xmlCharStrdup("type")) ||
540 !xmlHasProp(job_node, xmlCharStrdup("name")))
542 INFOS("A bad job is found, type or name not found");
545 xmlChar* type = xmlGetProp(job_node, xmlCharStrdup("type"));
546 xmlChar* name = xmlGetProp(job_node, xmlCharStrdup("name"));
547 std::string job_type((const char*) type);
548 if (job_type == "command")
549 new_job = new Launcher::Job_Command();
550 else if (job_type == "yacs_file")
551 new_job = new Launcher::Job_YACSFile();
552 else if (job_type == "python_salome")
553 new_job = new Launcher::Job_PythonSALOME();
554 new_job->setJobName(std::string((const char *)name));
558 xmlNodePtr user_node = xmlFirstElementChild(job_node);
559 xmlNodePtr run_node = xmlNextElementSibling(user_node);
560 if (user_node == NULL || run_node == NULL)
562 INFOS("A bad job is found, user_part or run_part not found");
566 if (xmlStrcmp(user_node->name, xmlCharStrdup("user_part")) ||
567 xmlStrcmp(run_node->name, xmlCharStrdup("run_part")))
569 INFOS("A bad job is found, cannot get a correct user_part or run_part node");
576 // Get job_file env_file work_directory local_directory result_directory
577 xmlNodePtr job_file_node = xmlFirstElementChild(user_node);
578 xmlNodePtr env_file_node = xmlNextElementSibling(job_file_node);
579 xmlNodePtr work_directory_node = xmlNextElementSibling(env_file_node);
580 xmlNodePtr local_directory_node = xmlNextElementSibling(work_directory_node);
581 xmlNodePtr result_directory_node = xmlNextElementSibling(local_directory_node);
582 if (job_file_node == NULL ||
583 env_file_node == NULL ||
584 work_directory_node == NULL ||
585 local_directory_node == NULL ||
586 result_directory_node == NULL
589 INFOS("A bad job is found, some user_part are not found");
593 if (xmlStrcmp(job_file_node->name, xmlCharStrdup("job_file")) ||
594 xmlStrcmp(env_file_node->name, xmlCharStrdup("env_file")) ||
595 xmlStrcmp(work_directory_node->name, xmlCharStrdup("work_directory")) ||
596 xmlStrcmp(local_directory_node->name, xmlCharStrdup("local_directory")) ||
597 xmlStrcmp(result_directory_node->name, xmlCharStrdup("result_directory"))
600 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
604 xmlChar* job_file = xmlNodeGetContent(job_file_node);
607 new_job->setJobFile(std::string((const char *)job_file));
609 catch(const LauncherException &ex)
611 INFOS("Exception receice for job_file, cannot add the job" << ex.msg.c_str());
616 xmlChar* env_file = xmlNodeGetContent(env_file_node);
617 xmlChar* work_directory = xmlNodeGetContent(work_directory_node);
618 xmlChar* local_directory = xmlNodeGetContent(local_directory_node);
619 xmlChar* result_directory = xmlNodeGetContent(result_directory_node);
620 new_job->setEnvFile(std::string((const char *)env_file));
621 new_job->setWorkDirectory(std::string((const char *)work_directory));
622 new_job->setLocalDirectory(std::string((const char *)local_directory));
623 new_job->setResultDirectory(std::string((const char *)result_directory));
626 xmlFree(work_directory);
627 xmlFree(local_directory);
628 xmlFree(result_directory);
630 // Get in and out files
631 xmlNodePtr files_node = xmlNextElementSibling(result_directory_node);
632 if (files_node == NULL)
634 INFOS("A bad job is found, user_part files is not found");
638 if (xmlStrcmp(files_node->name, xmlCharStrdup("files")))
640 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");
644 xmlNodePtr file_node = xmlFirstElementChild(files_node);
645 while (file_node != NULL)
647 if (!xmlStrcmp(file_node->name, xmlCharStrdup("in_file")))
649 xmlChar* in_file = xmlNodeGetContent(file_node);
650 new_job->add_in_file(std::string((const char *)in_file));
653 else if (!xmlStrcmp(file_node->name, xmlCharStrdup("out_file")))
655 xmlChar* out_file = xmlNodeGetContent(file_node);
656 new_job->add_out_file(std::string((const char *)out_file));
659 file_node = xmlNextElementSibling(file_node);
663 xmlNodePtr res_node = xmlNextElementSibling(files_node);
664 xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node);
665 xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node);
666 if (res_node == NULL ||
667 maximum_duration_node == NULL ||
671 INFOS("A bad job is found, some user_part are not found");
675 if (xmlStrcmp(res_node->name, xmlCharStrdup("resource_params")) ||
676 xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) ||
677 xmlStrcmp(queue_node->name, xmlCharStrdup("queue"))
680 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
684 xmlChar* maximum_duration = xmlNodeGetContent(maximum_duration_node);
687 new_job->setMaximumDuration(std::string((const char *)maximum_duration));
689 catch(const LauncherException &ex)
691 INFOS("Exception receice for maximum_duration, cannot add the job" << ex.msg.c_str());
693 xmlFree(maximum_duration);
696 xmlChar* queue = xmlNodeGetContent(queue_node);
697 new_job->setQueue(std::string((const char *)queue));
698 xmlFree(maximum_duration);
701 xmlNodePtr specific_node = xmlNextElementSibling(queue_node);
702 if (specific_node == NULL)
704 INFOS("A bad job is found, specific_parameters part is not found");
708 xmlNodePtr parameter_node = xmlFirstElementChild(specific_node);
709 while (parameter_node != NULL)
711 if (!xmlStrcmp(parameter_node->name, xmlCharStrdup("specific_parameter")))
713 xmlNodePtr name_node = xmlFirstElementChild(parameter_node);
714 xmlNodePtr value_node = xmlNextElementSibling(name_node);
715 if (name_node == NULL ||
718 INFOS("A bad job is found, specific_parameter parts are not found");
722 if (xmlStrcmp(name_node->name, xmlCharStrdup("name")) ||
723 xmlStrcmp(value_node->name, xmlCharStrdup("value")))
725 INFOS("A bad job is found, specific_parameter bad parts are found");
730 xmlChar* name = xmlNodeGetContent(name_node);
731 xmlChar* value = xmlNodeGetContent(value_node);
734 new_job->addSpecificParameter(std::string((const char*)name), std::string((const char*)value));
738 catch(const LauncherException &ex)
740 INFOS("Exception receice for a specific parameter, cannot add the job" << ex.msg.c_str());
749 INFOS("A bad job is found, specific_parameters part is bad, a node that is not a specific parameter is found");
753 parameter_node = xmlNextElementSibling(parameter_node);
756 xmlNodePtr res_name_node = xmlFirstElementChild(res_node);
757 xmlNodePtr res_hostname_node = xmlNextElementSibling(res_name_node);
758 xmlNodePtr res_os_node = xmlNextElementSibling(res_hostname_node);
759 xmlNodePtr res_nb_proc_node = xmlNextElementSibling(res_os_node);
760 xmlNodePtr res_nb_node_node = xmlNextElementSibling(res_nb_proc_node);
761 xmlNodePtr res_nb_proc_per_node_node = xmlNextElementSibling(res_nb_node_node);
762 xmlNodePtr res_cpu_clock_node = xmlNextElementSibling(res_nb_proc_per_node_node);
763 xmlNodePtr res_mem_mb_node = xmlNextElementSibling(res_cpu_clock_node);
764 if (res_name_node == NULL ||
765 res_hostname_node == NULL ||
766 res_os_node == NULL ||
767 res_nb_proc_node == NULL ||
768 res_nb_node_node == NULL ||
769 res_nb_proc_per_node_node == NULL ||
770 res_cpu_clock_node == NULL ||
771 res_mem_mb_node == NULL
774 INFOS("A bad job is found, some resource_params user_part are not found");
778 if (xmlStrcmp(res_name_node->name, xmlCharStrdup("name")) ||
779 xmlStrcmp(res_hostname_node->name, xmlCharStrdup("hostname")) ||
780 xmlStrcmp(res_os_node->name, xmlCharStrdup("OS")) ||
781 xmlStrcmp(res_nb_proc_node->name, xmlCharStrdup("nb_proc")) ||
782 xmlStrcmp(res_nb_node_node->name, xmlCharStrdup("nb_node")) ||
783 xmlStrcmp(res_nb_proc_per_node_node->name, xmlCharStrdup("nb_proc_per_node")) ||
784 xmlStrcmp(res_cpu_clock_node->name, xmlCharStrdup("cpu_clock")) ||
785 xmlStrcmp(res_mem_mb_node->name, xmlCharStrdup("mem_mb"))
788 INFOS("A bad job is found, some resource_params user_part node are not in the rigth or does not have a correct name");
792 xmlChar* res_name = xmlNodeGetContent(res_name_node);
793 xmlChar* res_hostname = xmlNodeGetContent(res_hostname_node);
794 xmlChar* res_os = xmlNodeGetContent(res_os_node);
796 p.name = std::string((const char*) res_name);
797 p.hostname = std::string((const char*) res_hostname);
798 p.OS = std::string((const char*) res_os);
800 xmlFree(res_hostname);
802 xmlChar* res_nb_proc = xmlNodeGetContent(res_nb_proc_node);
803 xmlChar* res_nb_node = xmlNodeGetContent(res_nb_node_node);
804 xmlChar* res_nb_proc_per_node = xmlNodeGetContent(res_nb_proc_per_node_node);
805 xmlChar* res_cpu_clock = xmlNodeGetContent(res_cpu_clock_node);
806 xmlChar* res_mem_mb = xmlNodeGetContent(res_mem_mb_node);
807 bool import_value = true;
808 std::istringstream nb_proc_stream((const char *) res_nb_proc);
809 if (!(nb_proc_stream >> p.nb_proc))
810 import_value = false;
811 std::istringstream nb_node_stream((const char *) res_nb_node);
812 if (!(nb_node_stream >> p.nb_node))
813 import_value = false;
814 std::istringstream nb_proc_per_node_stream((const char *) res_nb_proc_per_node);
815 if (!(nb_proc_per_node_stream >> p.nb_proc_per_node))
816 import_value = false;
817 std::istringstream cpu_clock_stream((const char *) res_cpu_clock);
818 if (!(cpu_clock_stream >> p.cpu_clock))
819 import_value = false;
820 std::istringstream mem_mb_stream((const char *) res_mem_mb);
821 if (!(mem_mb_stream >> p.mem_mb))
822 import_value = false;
823 xmlFree(res_nb_proc);
824 xmlFree(res_nb_node);
825 xmlFree(res_nb_proc_per_node);
826 xmlFree(res_cpu_clock);
830 INFOS("A bad job is found, some resource_params value are not correct");
836 new_job->setResourceRequiredParams(p);
838 catch(const LauncherException &ex)
840 INFOS("A bad job is found, an error when inserting resource_params:" << ex.msg.c_str());
845 // We finally get run part to figure out what to do
846 xmlNodePtr job_state_node = xmlFirstElementChild(run_node);
847 xmlNodePtr resource_choosed_name_node = xmlNextElementSibling(job_state_node);
848 xmlNodePtr job_reference_node = xmlNextElementSibling(resource_choosed_name_node);
849 if (job_state_node == NULL ||
850 resource_choosed_name_node == NULL ||
851 job_reference_node == NULL
854 INFOS("A bad job is found, some run_part are not found");
858 if (xmlStrcmp(job_state_node->name, xmlCharStrdup("job_state")) ||
859 xmlStrcmp(resource_choosed_name_node->name, xmlCharStrdup("resource_choosed_name")) ||
860 xmlStrcmp(job_reference_node->name, xmlCharStrdup("job_reference"))
863 INFOS("A bad job is found, some run_part nodes are not in the rigth or does not have a correct name");
867 xmlChar* job_state_xml = xmlNodeGetContent(job_state_node);
868 xmlChar* resource_choosed_name_xml = xmlNodeGetContent(resource_choosed_name_node);
869 xmlChar* job_reference_xml = xmlNodeGetContent(job_reference_node);
870 std::string job_state((const char *) job_state_xml);
871 std::string resource_choosed_name((const char *) resource_choosed_name_xml);
872 std::string job_reference((const char *) job_reference_xml);
873 xmlFree(job_state_xml);
874 xmlFree(resource_choosed_name_xml);
875 xmlFree(job_reference_xml);
877 if (job_state == "CREATED")
879 // In this case, we ignore run_part informations
882 _l.createJob(new_job);
883 std::ostringstream job_id;
884 job_id << new_job->getNumber();
885 notifyObservers("NEW_JOB", job_id.str());
887 catch(const LauncherException &ex)
889 INFOS("Load failed: " << ex.msg.c_str());
892 else if (job_state == "QUEUED" ||
893 job_state == "RUNNING" ||
894 job_state == "IN_PROCESS" ||
895 job_state == "PAUSED")
899 new_job->setState(job_state);
900 _l.addJobDirectlyToMap(new_job, job_reference);
902 // Step 4: We check that the BatchManager could resume
905 if (new_job->getBatchManagerJobId().getReference() != job_reference)
907 INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
908 new_job->setState("ERROR");
911 std::ostringstream job_id;
912 job_id << new_job->getNumber();
913 notifyObservers("NEW_JOB", job_id.str());
915 catch(const LauncherException &ex)
917 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
921 else if (job_state == "FINISHED" ||
922 job_state == "FAILED" ||
923 job_state == "ERROR")
927 // Step 2: We add run_part informations
928 new_job->setState(job_state);
929 _l.addJobDirectlyToMap(new_job, job_reference);
930 std::ostringstream job_id;
931 job_id << new_job->getNumber();
932 notifyObservers("NEW_JOB", job_id.str());
934 catch(const LauncherException &ex)
936 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
942 INFOS("A bad job is found, state unknown " << job_state);
947 xmlCurrentNode = xmlCurrentNode->next;
954 std::string error = "Error in xml file, could not find root_node named jobs: " + std::string(jobs_file);
956 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
962 notifyObservers("LOAD_JOBS", jobs_file);
965 //=============================================================================
967 * Save jobs of Launcher (in any steps) in file jobs_file
969 //=============================================================================
971 SALOME_Launcher::saveJobs(const char* jobs_file)
974 // Step 1: check jobs_file write access
975 FILE* xml_file = fopen(jobs_file, "w");
976 if (xml_file == NULL)
978 std::string error = "Error opening jobs_file in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
980 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
983 // Step 2: First lines
984 xmlKeepBlanksDefault(0);
985 xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
986 xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
987 xmlDocSetRootElement(doc, root_node);
988 xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher save jobs file"));
989 xmlAddPrevSibling(root_node, doc_comment);
991 // Step 3: For each job write it on the xml document
992 // We could put a mutex but are not foing to do that currently
993 std::map<int, Launcher::Job *> jobs_list = _l.getJobs();
994 std::map<int, Launcher::Job *>::const_iterator it_job;
995 for(it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
997 it_job->second->addToXmlDocument(root_node);
1000 // Final step: write file
1001 int isOk = xmlSaveFormatFile(jobs_file, doc, 1);
1004 std::string error = "Error during xml file saving in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1008 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1014 MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!");
1015 notifyObservers("SAVE_JOBS", jobs_file);
1018 //=============================================================================
1020 * Add a new observer to the launcher
1022 //=============================================================================
1024 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
1026 bool new_observer = true;
1027 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1028 while(iter != _observers.end())
1030 if (std::string(_orb->object_to_string(*iter)) ==
1031 std::string(_orb->object_to_string(observer)))
1033 new_observer = false;
1039 _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
1041 // We notify the new observer with all jobs that are currently in the Launcher
1042 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
1043 std::map<int, Launcher::Job *>::const_iterator it_job;
1044 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
1046 int number = it_job->first;
1047 std::ostringstream job_id;
1051 observer->notify("NEW_JOB", job_id.str().c_str());
1055 MESSAGE("Notify Observer, exception catch");
1061 //=============================================================================
1063 * Add a new observer to the launcher
1065 //=============================================================================
1067 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
1069 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1070 while(iter != _observers.end())
1072 if (std::string(_orb->object_to_string(*iter)) ==
1073 std::string(_orb->object_to_string(observer)))
1076 iter =_observers.erase(iter++);
1085 //=============================================================================
1086 /*! Internal Method:
1087 * Notify observers on a new event
1089 //=============================================================================
1091 SALOME_Launcher::notifyObservers(const std::string & event_name,
1092 const std::string & event_data)
1094 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1095 while(iter != _observers.end())
1099 (*iter)->notify(CORBA::string_dup(event_name.c_str()),
1100 CORBA::string_dup(event_data.c_str()));
1104 MESSAGE("Notify Observer, exception catch");