1 // Copyright (C) 2007-2013 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"
33 #include "Launcher_Job_Writer.hxx"
40 #include <sys/types.h>
43 #include <libxml/parser.h>
47 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
49 //=============================================================================
54 //=============================================================================
55 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
57 MESSAGE("SALOME_Launcher constructor");
58 _NS = new SALOME_NamingService(orb);
59 _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
60 _l.SetResourcesManager(_ResManager->GetImpl());
61 _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS);
62 _ResManager->_remove_ref();
63 _ContManager->_remove_ref();
65 _orb = CORBA::ORB::_duplicate(orb) ;
66 _poa = PortableServer::POA::_duplicate(poa) ;
67 PortableServer::ObjectId_var id = _poa->activate_object(this);
68 CORBA::Object_var obj = _poa->id_to_reference(id);
69 Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
71 _NS->Register(refContMan,_LauncherNameInNS);
72 MESSAGE("SALOME_Launcher constructor end");
75 //=============================================================================
79 //=============================================================================
80 SALOME_Launcher::~SALOME_Launcher()
82 MESSAGE("SALOME_Launcher destructor");
84 MESSAGE("SALOME_Launcher destructor end");
89 SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
91 std::string job_type = job_parameters.job_type.in();
93 if (job_type != "command" && job_type != "yacs_file" && job_type != "python_salome")
95 std::string message("SALOME_Launcher::createJob: bad job type: ");
97 THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
100 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
102 if (job_type == "command")
103 new_job = new Launcher::Job_Command();
104 else if (job_type == "yacs_file")
105 new_job = new Launcher::Job_YACSFile();
106 else if (job_type == "python_salome")
107 new_job = new Launcher::Job_PythonSALOME();
110 new_job->setJobName(job_parameters.job_name.in());
113 std::string work_directory = job_parameters.work_directory.in();
114 std::string local_directory = job_parameters.local_directory.in();
115 std::string result_directory = job_parameters.result_directory.in();
116 new_job->setWorkDirectory(work_directory);
117 new_job->setLocalDirectory(local_directory);
118 new_job->setResultDirectory(result_directory);
120 // Parameters for COORM
121 std::string launcher_file = job_parameters.launcher_file.in();
122 std::string launcher_args = job_parameters.launcher_args.in();
123 new_job->setLauncherFile(launcher_file);
124 new_job->setLauncherArgs(launcher_args);
127 std::string job_file = job_parameters.job_file.in();
130 new_job->setJobFile(job_file);
132 catch(const LauncherException &ex)
134 INFOS(ex.msg.c_str());
135 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
139 std::string env_file = job_parameters.env_file.in();
140 new_job->setEnvFile(env_file);
141 for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
142 new_job->add_in_file(job_parameters.in_files[i].in());
143 for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
144 new_job->add_out_file(job_parameters.out_files[i].in());
146 // Expected During Time
149 std::string maximum_duration = job_parameters.maximum_duration.in();
150 new_job->setMaximumDuration(maximum_duration);
152 catch(const LauncherException &ex){
153 INFOS(ex.msg.c_str());
154 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
158 std::string queue = job_parameters.queue.in();
159 new_job->setQueue(queue);
162 new_job->setExclusive(job_parameters.exclusive);
164 // Memory required per CPU
165 new_job->setMemPerCpu(job_parameters.mem_per_cpu);
167 // Resources requirements
171 p.name = job_parameters.resource_required.name;
172 p.hostname = job_parameters.resource_required.hostname;
173 p.OS = job_parameters.resource_required.OS;
174 p.nb_proc = job_parameters.resource_required.nb_proc;
175 p.nb_node = job_parameters.resource_required.nb_node;
176 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
177 p.cpu_clock = job_parameters.resource_required.cpu_clock;
178 p.mem_mb = job_parameters.resource_required.mem_mb;
179 new_job->setResourceRequiredParams(p);
181 catch(const LauncherException &ex){
182 INFOS(ex.msg.c_str());
183 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
186 // Adding specific parameters to the job
187 for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
188 new_job->addSpecificParameter(job_parameters.specific_parameters[i].name.in(),
189 job_parameters.specific_parameters[i].value.in());
192 new_job->checkSpecificParameters();
194 catch(const LauncherException &ex)
196 INFOS(ex.msg.c_str());
197 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
202 _l.createJob(new_job);
203 std::ostringstream job_id;
204 job_id << new_job->getNumber();
205 notifyObservers("NEW_JOB", job_id.str());
207 catch(const LauncherException &ex)
209 INFOS(ex.msg.c_str());
210 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
212 return new_job->getNumber();
216 SALOME_Launcher::launchJob(CORBA::Long job_id)
220 _l.launchJob(job_id);
222 catch(const LauncherException &ex)
224 INFOS(ex.msg.c_str());
225 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
230 SALOME_Launcher::getJobState(CORBA::Long job_id)
235 result = _l.getJobState(job_id);
237 catch(const LauncherException &ex)
239 INFOS(ex.msg.c_str());
240 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
242 return CORBA::string_dup(result.c_str());
245 // Get names or ids of hosts assigned to the job
247 SALOME_Launcher::getAssignedHostnames(CORBA::Long job_id)
252 result = _l.getAssignedHostnames(job_id);
254 catch(const LauncherException &ex)
256 INFOS(ex.msg.c_str());
257 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
259 return CORBA::string_dup(result.c_str());
263 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
267 _l.getJobResults(job_id, directory);
269 catch(const LauncherException &ex)
271 INFOS(ex.msg.c_str());
272 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
277 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
279 CORBA::Boolean rtn = false;
282 rtn = _l.getJobDumpState(job_id, directory);
284 catch(const LauncherException &ex)
286 INFOS(ex.msg.c_str());
287 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
293 SALOME_Launcher::removeJob(CORBA::Long job_id)
297 _l.removeJob(job_id);
298 std::ostringstream job_id_str;
299 job_id_str << job_id;
300 notifyObservers("REMOVE_JOB", job_id_str.str());
302 catch(const LauncherException &ex)
304 INFOS(ex.msg.c_str());
305 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
310 SALOME_Launcher::stopJob(CORBA::Long job_id)
315 std::ostringstream job_id_str;
316 job_id_str << job_id;
317 notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
319 catch(const LauncherException &ex)
321 INFOS(ex.msg.c_str());
322 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
326 //=============================================================================
328 * Create a job in the launcher with a file
329 * \param xmlExecuteFile : .xml to parse that contains job description
330 * \param clusterName : machine choosed
332 //=============================================================================
334 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
335 const char * clusterName)
339 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
341 catch(const LauncherException &ex){
342 INFOS(ex.msg.c_str());
343 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
349 //=============================================================================
351 * the test batch configuration
352 * \param params : The batch cluster
354 //=============================================================================
356 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
358 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
359 CORBA::Boolean rtn = false;
362 // Consider only resources that can run batch jobs
363 Engines::ResourceParameters new_params(params);
364 new_params.can_launch_batch_jobs = true;
366 // find a resource matching the required parameters
367 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(new_params);
368 if (aMachineList->length() == 0)
369 throw SALOME_Exception("No resources have been found with your parameters");
371 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
372 std::string resource_name(p->name);
373 INFOS("Choose resource for test: " << resource_name);
381 catch(const LauncherException &ex){
382 INFOS(ex.msg.c_str());
383 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
388 //=============================================================================
390 * shutdown all the containers, then the ContainerManager servant
392 //=============================================================================
393 void SALOME_Launcher::Shutdown()
396 _NS->Destroy_Name(_LauncherNameInNS);
397 _ContManager->Shutdown();
398 _ResManager->Shutdown();
399 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
400 _poa->deactivate_object(oid);
401 if(!CORBA::is_nil(_orb))
405 //=============================================================================
407 * Returns the PID of the process
409 //=============================================================================
410 CORBA::Long SALOME_Launcher::getPID()
414 (CORBA::Long)getpid();
416 (CORBA::Long)_getpid();
420 //=============================================================================
422 * Returns current launcher jobs list
424 //=============================================================================
426 SALOME_Launcher::getJobsList()
428 Engines::JobsList_var jobs_list = new Engines::JobsList();
429 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
430 std::map<int, Launcher::Job *>::const_iterator it_job;
432 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
434 int number = it_job->first;
437 // Prepare CORBA job description
438 Engines::JobDescription_var job_descr = new Engines::JobDescription();
439 Engines::JobParameters_var job_parameters = getJobParameters(number);
440 job_descr->job_id = number;
441 job_descr->job_parameters = job_parameters;
443 // Add job description to the sequence
444 jobs_list->length(list_id + 1);
445 jobs_list[list_id] = job_descr;
450 return jobs_list._retn();
453 //=============================================================================
455 * Returns the job description
457 //=============================================================================
458 Engines::JobParameters *
459 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
461 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
462 std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
463 if (it_job == cpp_jobs.end())
465 INFOS("Cannot find the job, is it created ? job number: " << job_id);
466 THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
469 Launcher::Job * job = it_job->second;
470 Engines::JobParameters_var job_parameters = new Engines::JobParameters;
471 job_parameters->job_name = CORBA::string_dup(job->getJobName().c_str());
472 job_parameters->job_type = CORBA::string_dup(job->getJobType().c_str());
473 job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
474 job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
475 job_parameters->work_directory = CORBA::string_dup(job->getWorkDirectory().c_str());
476 job_parameters->local_directory = CORBA::string_dup(job->getLocalDirectory().c_str());
477 job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
479 // Parameters for COORM
480 job_parameters->launcher_file = CORBA::string_dup(job->getLauncherFile().c_str());
481 job_parameters->launcher_args = CORBA::string_dup(job->getLauncherArgs().c_str());
485 std::list<std::string> in_files = job->get_in_files();
486 std::list<std::string> out_files = job->get_out_files();
487 job_parameters->in_files.length(in_files.size());
488 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
490 job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
493 job_parameters->out_files.length(out_files.size());
494 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
496 job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
500 job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
501 job_parameters->queue = CORBA::string_dup(job->getQueue().c_str());
502 job_parameters->exclusive = job->getExclusive();
503 job_parameters->mem_per_cpu = job->getMemPerCpu();
505 resourceParams resource_params = job->getResourceRequiredParams();
506 job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str());
507 job_parameters->resource_required.hostname = CORBA::string_dup(resource_params.hostname.c_str());
508 job_parameters->resource_required.OS = CORBA::string_dup(resource_params.OS.c_str());
509 job_parameters->resource_required.nb_proc = resource_params.nb_proc;
510 job_parameters->resource_required.nb_node = resource_params.nb_node;
511 job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
512 job_parameters->resource_required.cpu_clock = resource_params.cpu_clock;
513 job_parameters->resource_required.mem_mb = resource_params.mem_mb;
515 std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
516 if (!specific_parameters.empty())
518 job_parameters->specific_parameters.length(specific_parameters.size());
519 std::map<std::string, std::string>::const_iterator it_specific;
521 for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
523 Engines::Parameter_var new_param = new Engines::Parameter;
524 new_param->name = CORBA::string_dup((it_specific->first).c_str());
525 new_param->value = CORBA::string_dup((it_specific->second).c_str());
526 job_parameters->specific_parameters[i] = new_param;
531 return job_parameters._retn();
534 //=============================================================================
536 * Loads jobs saved in jobs_file
538 //=============================================================================
540 SALOME_Launcher::loadJobs(const char* jobs_file)
542 // Step 1: check jobs_file read access
543 FILE* xml_file = fopen(jobs_file, "r");
544 if (xml_file == NULL)
546 std::string error = "Error opening jobs_file in SALOME_Launcher::loadJobs: " + std::string(jobs_file);
548 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
551 // Step 2: read xml file
552 xmlDocPtr doc = xmlReadFile(jobs_file, NULL, 0);
555 std::string error = "Error in xmlReadFile in SALOME_Launcher::loadJobs, could not parse file: " + std::string(jobs_file);
558 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
562 xmlNodePtr root_node = xmlDocGetRootElement(doc);
563 xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
564 if (!xmlStrcmp(root_node->name, xmlCharStrdup("jobs")))
566 while(xmlCurrentNode != NULL)
568 if (!xmlStrcmp(xmlCurrentNode->name, xmlCharStrdup("job")))
570 INFOS("A job is found");
571 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
572 xmlNodePtr job_node = xmlCurrentNode;
575 if (!xmlHasProp(job_node, xmlCharStrdup("type")) ||
576 !xmlHasProp(job_node, xmlCharStrdup("name")))
578 INFOS("A bad job is found, type or name not found");
581 xmlChar* type = xmlGetProp(job_node, xmlCharStrdup("type"));
582 xmlChar* name = xmlGetProp(job_node, xmlCharStrdup("name"));
583 std::string job_type((const char*) type);
584 if (job_type == "command")
585 new_job = new Launcher::Job_Command();
586 else if (job_type == "yacs_file")
587 new_job = new Launcher::Job_YACSFile();
588 else if (job_type == "python_salome")
589 new_job = new Launcher::Job_PythonSALOME();
590 new_job->setJobName(std::string((const char *)name));
594 xmlNodePtr user_node = xmlFirstElementChild(job_node);
595 xmlNodePtr run_node = xmlNextElementSibling(user_node);
596 if (user_node == NULL || run_node == NULL)
598 INFOS("A bad job is found, user_part or run_part not found");
602 if (xmlStrcmp(user_node->name, xmlCharStrdup("user_part")) ||
603 xmlStrcmp(run_node->name, xmlCharStrdup("run_part")))
605 INFOS("A bad job is found, cannot get a correct user_part or run_part node");
612 // Get job_file env_file work_directory local_directory result_directory
613 xmlNodePtr job_file_node = xmlFirstElementChild(user_node);
614 xmlNodePtr env_file_node = xmlNextElementSibling(job_file_node);
615 xmlNodePtr work_directory_node = xmlNextElementSibling(env_file_node);
616 xmlNodePtr local_directory_node = xmlNextElementSibling(work_directory_node);
617 xmlNodePtr result_directory_node = xmlNextElementSibling(local_directory_node);
619 // Parameters for COORM
620 xmlNodePtr launcher_file_node = xmlNextElementSibling(result_directory_node);
622 if (job_file_node == NULL ||
623 env_file_node == NULL ||
624 work_directory_node == NULL ||
625 local_directory_node == NULL ||
626 result_directory_node == NULL ||
628 launcher_file_node == NULL
631 INFOS("A bad job is found, some user_part are not found");
635 if (xmlStrcmp(job_file_node->name, xmlCharStrdup("job_file")) ||
636 xmlStrcmp(env_file_node->name, xmlCharStrdup("env_file")) ||
637 xmlStrcmp(work_directory_node->name, xmlCharStrdup("work_directory")) ||
638 xmlStrcmp(local_directory_node->name, xmlCharStrdup("local_directory")) ||
639 xmlStrcmp(result_directory_node->name, xmlCharStrdup("result_directory")) ||
641 xmlStrcmp(launcher_file_node->name, xmlCharStrdup("launcher_file"))
644 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
648 xmlChar* job_file = xmlNodeGetContent(job_file_node);
651 new_job->setJobFile(std::string((const char *)job_file));
653 catch(const LauncherException &ex)
655 INFOS("Exception receice for job_file, cannot add the job" << ex.msg.c_str());
660 xmlChar* env_file = xmlNodeGetContent(env_file_node);
661 xmlChar* work_directory = xmlNodeGetContent(work_directory_node);
662 xmlChar* local_directory = xmlNodeGetContent(local_directory_node);
663 xmlChar* result_directory = xmlNodeGetContent(result_directory_node);
665 // Parameters for COORM
666 xmlChar* launcher_file = xmlNodeGetContent(launcher_file_node);
668 new_job->setEnvFile(std::string((const char *)env_file));
669 new_job->setWorkDirectory(std::string((const char *)work_directory));
670 new_job->setLocalDirectory(std::string((const char *)local_directory));
671 new_job->setResultDirectory(std::string((const char *)result_directory));
673 // Parameters for COORM
674 new_job->setLauncherFile(std::string((const char *)launcher_file));
678 xmlFree(work_directory);
679 xmlFree(local_directory);
680 xmlFree(result_directory);
682 // Parameters for COORM
683 xmlFree(launcher_file);
685 // Get in and out files
686 xmlNodePtr files_node = xmlNextElementSibling(launcher_file_node);
687 if (files_node == NULL)
689 INFOS("A bad job is found, user_part files is not found");
693 if (xmlStrcmp(files_node->name, xmlCharStrdup("files")))
695 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");
699 xmlNodePtr file_node = xmlFirstElementChild(files_node);
700 while (file_node != NULL)
702 if (!xmlStrcmp(file_node->name, xmlCharStrdup("in_file")))
704 xmlChar* in_file = xmlNodeGetContent(file_node);
705 new_job->add_in_file(std::string((const char *)in_file));
708 else if (!xmlStrcmp(file_node->name, xmlCharStrdup("out_file")))
710 xmlChar* out_file = xmlNodeGetContent(file_node);
711 new_job->add_out_file(std::string((const char *)out_file));
714 file_node = xmlNextElementSibling(file_node);
718 xmlNodePtr res_node = xmlNextElementSibling(files_node);
719 xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node);
720 xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node);
721 xmlNodePtr exclusive_node = xmlNextElementSibling(queue_node);
722 xmlNodePtr mem_per_cpu_node = xmlNextElementSibling(exclusive_node);
723 xmlNodePtr launcher_args_node = xmlNextElementSibling(mem_per_cpu_node);
724 if (res_node == NULL ||
725 maximum_duration_node == NULL ||
726 queue_node == NULL ||
727 exclusive_node == NULL ||
728 mem_per_cpu_node == NULL ||
730 launcher_args_node == NULL
733 INFOS("A bad job is found, some user_part are not found");
737 if (xmlStrcmp(res_node->name, xmlCharStrdup("resource_params")) ||
738 xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) ||
739 xmlStrcmp(queue_node->name, xmlCharStrdup("queue")) ||
740 xmlStrcmp(exclusive_node->name, xmlCharStrdup("exclusive")) ||
741 xmlStrcmp(mem_per_cpu_node->name, xmlCharStrdup("mem_per_cpu")) ||
743 xmlStrcmp(launcher_args_node->name, xmlCharStrdup("launcher_args"))
746 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
750 xmlChar* maximum_duration = xmlNodeGetContent(maximum_duration_node);
753 new_job->setMaximumDuration(std::string((const char *)maximum_duration));
755 catch(const LauncherException &ex)
757 INFOS("Exception receice for maximum_duration, cannot add the job" << ex.msg.c_str());
759 xmlFree(maximum_duration);
762 xmlChar* queue = xmlNodeGetContent(queue_node);
763 new_job->setQueue(std::string((const char *)queue));
764 xmlFree(maximum_duration);
767 xmlChar* exclusive = xmlNodeGetContent(exclusive_node);
770 new_job->setExclusiveStr(std::string((const char *)exclusive));
772 catch(const LauncherException &ex)
774 INFOS("Exception received for exclusive, cannot add the job. " << ex.msg.c_str());
781 xmlChar* mem_per_cpu_str = xmlNodeGetContent(mem_per_cpu_node);
782 std::istringstream mem_per_cpu_stream((const char *)mem_per_cpu_str);
783 unsigned long mem_per_cpu = 0;
784 if (!(mem_per_cpu_stream >> mem_per_cpu))
786 INFOS("A bad job is found, mem_per_cpu parameter is not correct");
791 new_job->setMemPerCpu(mem_per_cpu);
794 xmlChar* launcher_args = xmlNodeGetContent(launcher_args_node);
795 new_job->setLauncherArgs(std::string((const char *)launcher_args));
796 xmlFree(launcher_args);
798 xmlNodePtr specific_node = xmlNextElementSibling(launcher_args_node);
799 if (specific_node == NULL)
801 INFOS("A bad job is found, specific_parameters part is not found");
805 xmlNodePtr parameter_node = xmlFirstElementChild(specific_node);
806 while (parameter_node != NULL)
808 if (!xmlStrcmp(parameter_node->name, xmlCharStrdup("specific_parameter")))
810 xmlNodePtr name_node = xmlFirstElementChild(parameter_node);
811 xmlNodePtr value_node = xmlNextElementSibling(name_node);
812 if (name_node == NULL ||
815 INFOS("A bad job is found, specific_parameter parts are not found");
819 if (xmlStrcmp(name_node->name, xmlCharStrdup("name")) ||
820 xmlStrcmp(value_node->name, xmlCharStrdup("value")))
822 INFOS("A bad job is found, specific_parameter bad parts are found");
827 xmlChar* name = xmlNodeGetContent(name_node);
828 xmlChar* value = xmlNodeGetContent(value_node);
831 new_job->addSpecificParameter(std::string((const char*)name), std::string((const char*)value));
835 catch(const LauncherException &ex)
837 INFOS("Exception receice for a specific parameter, cannot add the job" << ex.msg.c_str());
846 INFOS("A bad job is found, specific_parameters part is bad, a node that is not a specific parameter is found");
850 parameter_node = xmlNextElementSibling(parameter_node);
853 xmlNodePtr res_name_node = xmlFirstElementChild(res_node);
854 xmlNodePtr res_hostname_node = xmlNextElementSibling(res_name_node);
855 xmlNodePtr res_os_node = xmlNextElementSibling(res_hostname_node);
856 xmlNodePtr res_nb_proc_node = xmlNextElementSibling(res_os_node);
857 xmlNodePtr res_nb_node_node = xmlNextElementSibling(res_nb_proc_node);
858 xmlNodePtr res_nb_proc_per_node_node = xmlNextElementSibling(res_nb_node_node);
859 xmlNodePtr res_cpu_clock_node = xmlNextElementSibling(res_nb_proc_per_node_node);
860 xmlNodePtr res_mem_mb_node = xmlNextElementSibling(res_cpu_clock_node);
861 if (res_name_node == NULL ||
862 res_hostname_node == NULL ||
863 res_os_node == NULL ||
864 res_nb_proc_node == NULL ||
865 res_nb_node_node == NULL ||
866 res_nb_proc_per_node_node == NULL ||
867 res_cpu_clock_node == NULL ||
868 res_mem_mb_node == NULL
871 INFOS("A bad job is found, some resource_params user_part are not found");
875 if (xmlStrcmp(res_name_node->name, xmlCharStrdup("name")) ||
876 xmlStrcmp(res_hostname_node->name, xmlCharStrdup("hostname")) ||
877 xmlStrcmp(res_os_node->name, xmlCharStrdup("OS")) ||
878 xmlStrcmp(res_nb_proc_node->name, xmlCharStrdup("nb_proc")) ||
879 xmlStrcmp(res_nb_node_node->name, xmlCharStrdup("nb_node")) ||
880 xmlStrcmp(res_nb_proc_per_node_node->name, xmlCharStrdup("nb_proc_per_node")) ||
881 xmlStrcmp(res_cpu_clock_node->name, xmlCharStrdup("cpu_clock")) ||
882 xmlStrcmp(res_mem_mb_node->name, xmlCharStrdup("mem_mb"))
885 INFOS("A bad job is found, some resource_params user_part node are not in the rigth or does not have a correct name");
889 xmlChar* res_name = xmlNodeGetContent(res_name_node);
890 xmlChar* res_hostname = xmlNodeGetContent(res_hostname_node);
891 xmlChar* res_os = xmlNodeGetContent(res_os_node);
893 p.name = std::string((const char*) res_name);
894 p.hostname = std::string((const char*) res_hostname);
895 p.OS = std::string((const char*) res_os);
897 xmlFree(res_hostname);
899 xmlChar* res_nb_proc = xmlNodeGetContent(res_nb_proc_node);
900 xmlChar* res_nb_node = xmlNodeGetContent(res_nb_node_node);
901 xmlChar* res_nb_proc_per_node = xmlNodeGetContent(res_nb_proc_per_node_node);
902 xmlChar* res_cpu_clock = xmlNodeGetContent(res_cpu_clock_node);
903 xmlChar* res_mem_mb = xmlNodeGetContent(res_mem_mb_node);
904 bool import_value = true;
905 std::istringstream nb_proc_stream((const char *) res_nb_proc);
906 if (!(nb_proc_stream >> p.nb_proc))
907 import_value = false;
908 std::istringstream nb_node_stream((const char *) res_nb_node);
909 if (!(nb_node_stream >> p.nb_node))
910 import_value = false;
911 std::istringstream nb_proc_per_node_stream((const char *) res_nb_proc_per_node);
912 if (!(nb_proc_per_node_stream >> p.nb_proc_per_node))
913 import_value = false;
914 std::istringstream cpu_clock_stream((const char *) res_cpu_clock);
915 if (!(cpu_clock_stream >> p.cpu_clock))
916 import_value = false;
917 std::istringstream mem_mb_stream((const char *) res_mem_mb);
918 if (!(mem_mb_stream >> p.mem_mb))
919 import_value = false;
920 xmlFree(res_nb_proc);
921 xmlFree(res_nb_node);
922 xmlFree(res_nb_proc_per_node);
923 xmlFree(res_cpu_clock);
927 INFOS("A bad job is found, some resource_params value are not correct");
933 new_job->setResourceRequiredParams(p);
935 catch(const LauncherException &ex)
937 INFOS("A bad job is found, an error when inserting resource_params:" << ex.msg.c_str());
942 // We finally get run part to figure out what to do
943 xmlNodePtr job_state_node = xmlFirstElementChild(run_node);
944 xmlNodePtr resource_choosed_name_node = xmlNextElementSibling(job_state_node);
945 xmlNodePtr job_reference_node = xmlNextElementSibling(resource_choosed_name_node);
946 if (job_state_node == NULL ||
947 resource_choosed_name_node == NULL ||
948 job_reference_node == NULL
951 INFOS("A bad job is found, some run_part are not found");
955 if (xmlStrcmp(job_state_node->name, xmlCharStrdup("job_state")) ||
956 xmlStrcmp(resource_choosed_name_node->name, xmlCharStrdup("resource_choosed_name")) ||
957 xmlStrcmp(job_reference_node->name, xmlCharStrdup("job_reference"))
960 INFOS("A bad job is found, some run_part nodes are not in the rigth or does not have a correct name");
964 xmlChar* job_state_xml = xmlNodeGetContent(job_state_node);
965 xmlChar* resource_choosed_name_xml = xmlNodeGetContent(resource_choosed_name_node);
966 xmlChar* job_reference_xml = xmlNodeGetContent(job_reference_node);
967 std::string job_state((const char *) job_state_xml);
968 std::string resource_choosed_name((const char *) resource_choosed_name_xml);
969 std::string job_reference((const char *) job_reference_xml);
970 xmlFree(job_state_xml);
971 xmlFree(resource_choosed_name_xml);
972 xmlFree(job_reference_xml);
974 if (job_state == "CREATED")
976 // In this case, we ignore run_part informations
979 _l.createJob(new_job);
980 std::ostringstream job_id;
981 job_id << new_job->getNumber();
982 notifyObservers("NEW_JOB", job_id.str());
984 catch(const LauncherException &ex)
986 INFOS("Load failed: " << ex.msg.c_str());
989 else if (job_state == "QUEUED" ||
990 job_state == "RUNNING" ||
991 job_state == "IN_PROCESS" ||
992 job_state == "PAUSED")
996 new_job->setState(job_state);
997 _l.addJobDirectlyToMap(new_job, job_reference);
999 // Step 4: We check that the BatchManager could resume
1001 #ifdef WITH_LIBBATCH
1002 if (new_job->getBatchManagerJobId().getReference() != job_reference)
1004 INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
1005 new_job->setState("ERROR");
1008 std::ostringstream job_id;
1009 job_id << new_job->getNumber();
1010 notifyObservers("NEW_JOB", job_id.str());
1012 catch(const LauncherException &ex)
1014 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
1018 else if (job_state == "FINISHED" ||
1019 job_state == "FAILED" ||
1020 job_state == "ERROR")
1024 // Step 2: We add run_part informations
1025 new_job->setState(job_state);
1026 _l.addJobDirectlyToMap(new_job, job_reference);
1027 std::ostringstream job_id;
1028 job_id << new_job->getNumber();
1029 notifyObservers("NEW_JOB", job_id.str());
1031 catch(const LauncherException &ex)
1033 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
1039 INFOS("A bad job is found, state unknown " << job_state);
1044 xmlCurrentNode = xmlCurrentNode->next;
1051 std::string error = "Error in xml file, could not find root_node named jobs: " + std::string(jobs_file);
1053 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1059 notifyObservers("LOAD_JOBS", jobs_file);
1062 //=============================================================================
1064 * Save jobs of Launcher (in any steps) in file jobs_file
1066 //=============================================================================
1068 SALOME_Launcher::saveJobs(const char* jobs_file)
1071 // Step 1: check jobs_file write access
1072 FILE* xml_file = fopen(jobs_file, "w");
1073 if (xml_file == NULL)
1075 std::string error = "Error opening jobs_file in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1077 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1080 // Step 2: First lines
1081 xmlKeepBlanksDefault(0);
1082 xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
1083 xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
1084 xmlDocSetRootElement(doc, root_node);
1085 xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher save jobs file"));
1086 xmlAddPrevSibling(root_node, doc_comment);
1088 // Step 3: For each job write it on the xml document
1089 // We could put a mutex but are not foing to do that currently
1090 std::map<int, Launcher::Job *> jobs_list = _l.getJobs();
1091 std::map<int, Launcher::Job *>::const_iterator it_job;
1092 for(it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
1094 addToXmlDocument(root_node, it_job->second);
1097 // Final step: write file
1098 int isOk = xmlSaveFormatFile(jobs_file, doc, 1);
1101 std::string error = "Error during xml file saving in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1105 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1111 MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!");
1112 notifyObservers("SAVE_JOBS", jobs_file);
1115 //=============================================================================
1117 * Add a new observer to the launcher
1119 //=============================================================================
1121 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
1123 bool new_observer = true;
1124 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1125 while(iter != _observers.end())
1127 if (std::string(_orb->object_to_string(*iter)) ==
1128 std::string(_orb->object_to_string(observer)))
1130 new_observer = false;
1136 _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
1138 // We notify the new observer with all jobs that are currently in the Launcher
1139 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
1140 std::map<int, Launcher::Job *>::const_iterator it_job;
1141 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
1143 int number = it_job->first;
1144 std::ostringstream job_id;
1148 observer->notify("NEW_JOB", job_id.str().c_str());
1152 MESSAGE("Notify Observer, exception catch");
1158 //=============================================================================
1160 * Add a new observer to the launcher
1162 //=============================================================================
1164 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
1166 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1167 while(iter != _observers.end())
1169 if (std::string(_orb->object_to_string(*iter)) ==
1170 std::string(_orb->object_to_string(observer)))
1173 iter =_observers.erase(iter++);
1182 //=============================================================================
1183 /*! Internal Method:
1184 * Notify observers on a new event
1186 //=============================================================================
1188 SALOME_Launcher::notifyObservers(const std::string & event_name,
1189 const std::string & event_data)
1191 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1192 while(iter != _observers.end())
1196 (*iter)->notify(CORBA::string_dup(event_name.c_str()),
1197 CORBA::string_dup(event_data.c_str()));
1201 MESSAGE("Notify Observer, exception catch");