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"
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);
119 // Parameters for COORM
120 std::string launcher_file = job_parameters.launcher_file.in();
121 std::string launcher_args = job_parameters.launcher_args.in();
122 new_job->setLauncherFile(launcher_file);
123 new_job->setLauncherArgs(launcher_args);
126 std::string job_file = job_parameters.job_file.in();
129 new_job->setJobFile(job_file);
131 catch(const LauncherException &ex)
133 INFOS(ex.msg.c_str());
134 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
138 std::string env_file = job_parameters.env_file.in();
139 new_job->setEnvFile(env_file);
140 for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
141 new_job->add_in_file(job_parameters.in_files[i].in());
142 for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
143 new_job->add_out_file(job_parameters.out_files[i].in());
145 // Expected During Time
148 std::string maximum_duration = job_parameters.maximum_duration.in();
149 new_job->setMaximumDuration(maximum_duration);
151 catch(const LauncherException &ex){
152 INFOS(ex.msg.c_str());
153 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
157 std::string queue = job_parameters.queue.in();
158 new_job->setQueue(queue);
161 new_job->setExclusive(job_parameters.exclusive);
163 // Memory required per CPU
164 new_job->setMemPerCpu(job_parameters.mem_per_cpu);
166 // Resources requirements
170 p.name = job_parameters.resource_required.name;
171 p.hostname = job_parameters.resource_required.hostname;
172 p.OS = job_parameters.resource_required.OS;
173 p.nb_proc = job_parameters.resource_required.nb_proc;
174 p.nb_node = job_parameters.resource_required.nb_node;
175 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
176 p.cpu_clock = job_parameters.resource_required.cpu_clock;
177 p.mem_mb = job_parameters.resource_required.mem_mb;
178 new_job->setResourceRequiredParams(p);
180 catch(const LauncherException &ex){
181 INFOS(ex.msg.c_str());
182 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
185 // Adding specific parameters to the job
186 for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
187 new_job->addSpecificParameter(job_parameters.specific_parameters[i].name.in(),
188 job_parameters.specific_parameters[i].value.in());
191 new_job->checkSpecificParameters();
193 catch(const LauncherException &ex)
195 INFOS(ex.msg.c_str());
196 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
201 _l.createJob(new_job);
202 std::ostringstream job_id;
203 job_id << new_job->getNumber();
204 notifyObservers("NEW_JOB", job_id.str());
206 catch(const LauncherException &ex)
208 INFOS(ex.msg.c_str());
209 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
211 return new_job->getNumber();
215 SALOME_Launcher::launchJob(CORBA::Long job_id)
219 _l.launchJob(job_id);
221 catch(const LauncherException &ex)
223 INFOS(ex.msg.c_str());
224 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
229 SALOME_Launcher::getJobState(CORBA::Long job_id)
234 result = _l.getJobState(job_id);
236 catch(const LauncherException &ex)
238 INFOS(ex.msg.c_str());
239 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
241 return CORBA::string_dup(result.c_str());
244 // Get names or ids of hosts assigned to the job
246 SALOME_Launcher::getAssignedHostnames(CORBA::Long job_id)
251 result = _l.getAssignedHostnames(job_id);
253 catch(const LauncherException &ex)
255 INFOS(ex.msg.c_str());
256 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
258 return CORBA::string_dup(result.c_str());
262 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
266 _l.getJobResults(job_id, directory);
268 catch(const LauncherException &ex)
270 INFOS(ex.msg.c_str());
271 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
276 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
278 CORBA::Boolean rtn = false;
281 rtn = _l.getJobDumpState(job_id, directory);
283 catch(const LauncherException &ex)
285 INFOS(ex.msg.c_str());
286 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
292 SALOME_Launcher::removeJob(CORBA::Long job_id)
296 _l.removeJob(job_id);
297 std::ostringstream job_id_str;
298 job_id_str << job_id;
299 notifyObservers("REMOVE_JOB", job_id_str.str());
301 catch(const LauncherException &ex)
303 INFOS(ex.msg.c_str());
304 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
309 SALOME_Launcher::stopJob(CORBA::Long job_id)
314 std::ostringstream job_id_str;
315 job_id_str << job_id;
316 notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
318 catch(const LauncherException &ex)
320 INFOS(ex.msg.c_str());
321 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
325 //=============================================================================
327 * Create a job in the launcher with a file
328 * \param xmlExecuteFile : .xml to parse that contains job description
329 * \param clusterName : machine choosed
331 //=============================================================================
333 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
334 const char * clusterName)
338 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
340 catch(const LauncherException &ex){
341 INFOS(ex.msg.c_str());
342 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
348 //=============================================================================
350 * the test batch configuration
351 * \param params : The batch cluster
353 //=============================================================================
355 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
357 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
358 CORBA::Boolean rtn = false;
361 // Consider only resources that can run batch jobs
362 Engines::ResourceParameters new_params(params);
363 new_params.can_launch_batch_jobs = true;
365 // find a resource matching the required parameters
366 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(new_params);
367 if (aMachineList->length() == 0)
368 throw SALOME_Exception("No resources have been found with your parameters");
370 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
371 std::string resource_name(p->name);
372 INFOS("Choose resource for test: " << resource_name);
380 catch(const LauncherException &ex){
381 INFOS(ex.msg.c_str());
382 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
387 //=============================================================================
389 * shutdown all the containers, then the ContainerManager servant
391 //=============================================================================
392 void SALOME_Launcher::Shutdown()
395 _NS->Destroy_Name(_LauncherNameInNS);
396 _ContManager->Shutdown();
397 _ResManager->Shutdown();
398 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
399 _poa->deactivate_object(oid);
400 if(!CORBA::is_nil(_orb))
404 //=============================================================================
406 * Returns the PID of the process
408 //=============================================================================
409 CORBA::Long SALOME_Launcher::getPID()
413 (CORBA::Long)getpid();
415 (CORBA::Long)_getpid();
419 //=============================================================================
421 * Returns current launcher jobs list
423 //=============================================================================
425 SALOME_Launcher::getJobsList()
427 Engines::JobsList_var jobs_list = new Engines::JobsList();
428 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
429 std::map<int, Launcher::Job *>::const_iterator it_job;
431 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
433 int number = it_job->first;
436 // Prepare CORBA job description
437 Engines::JobDescription_var job_descr = new Engines::JobDescription();
438 Engines::JobParameters_var job_parameters = getJobParameters(number);
439 job_descr->job_id = number;
440 job_descr->job_parameters = job_parameters;
442 // Add job description to the sequence
443 jobs_list->length(list_id + 1);
444 jobs_list[list_id] = job_descr;
449 return jobs_list._retn();
452 //=============================================================================
454 * Returns the job description
456 //=============================================================================
457 Engines::JobParameters *
458 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
460 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
461 std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
462 if (it_job == cpp_jobs.end())
464 INFOS("Cannot find the job, is it created ? job number: " << job_id);
465 THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
468 Launcher::Job * job = it_job->second;
469 Engines::JobParameters_var job_parameters = new Engines::JobParameters;
470 job_parameters->job_name = CORBA::string_dup(job->getJobName().c_str());
471 job_parameters->job_type = CORBA::string_dup(job->getJobType().c_str());
472 job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
473 job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
474 job_parameters->work_directory = CORBA::string_dup(job->getWorkDirectory().c_str());
475 job_parameters->local_directory = CORBA::string_dup(job->getLocalDirectory().c_str());
476 job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
478 // Parameters for COORM
479 job_parameters->launcher_file = CORBA::string_dup(job->getLauncherFile().c_str());
480 job_parameters->launcher_args = CORBA::string_dup(job->getLauncherArgs().c_str());
484 std::list<std::string> in_files = job->get_in_files();
485 std::list<std::string> out_files = job->get_out_files();
486 job_parameters->in_files.length(in_files.size());
487 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
489 job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
492 job_parameters->out_files.length(out_files.size());
493 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
495 job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
499 job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
500 job_parameters->queue = CORBA::string_dup(job->getQueue().c_str());
501 job_parameters->exclusive = job->getExclusive();
502 job_parameters->mem_per_cpu = job->getMemPerCpu();
504 resourceParams resource_params = job->getResourceRequiredParams();
505 job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str());
506 job_parameters->resource_required.hostname = CORBA::string_dup(resource_params.hostname.c_str());
507 job_parameters->resource_required.OS = CORBA::string_dup(resource_params.OS.c_str());
508 job_parameters->resource_required.nb_proc = resource_params.nb_proc;
509 job_parameters->resource_required.nb_node = resource_params.nb_node;
510 job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
511 job_parameters->resource_required.cpu_clock = resource_params.cpu_clock;
512 job_parameters->resource_required.mem_mb = resource_params.mem_mb;
514 std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
515 if (!specific_parameters.empty())
517 job_parameters->specific_parameters.length(specific_parameters.size());
518 std::map<std::string, std::string>::const_iterator it_specific;
520 for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
522 Engines::Parameter_var new_param = new Engines::Parameter;
523 new_param->name = CORBA::string_dup((it_specific->first).c_str());
524 new_param->value = CORBA::string_dup((it_specific->second).c_str());
525 job_parameters->specific_parameters[i] = new_param;
530 return job_parameters._retn();
533 //=============================================================================
535 * Loads jobs saved in jobs_file
537 //=============================================================================
539 SALOME_Launcher::loadJobs(const char* jobs_file)
541 // Step 1: check jobs_file read access
542 FILE* xml_file = fopen(jobs_file, "r");
543 if (xml_file == NULL)
545 std::string error = "Error opening jobs_file in SALOME_Launcher::loadJobs: " + std::string(jobs_file);
547 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
550 // Step 2: read xml file
551 xmlDocPtr doc = xmlReadFile(jobs_file, NULL, 0);
554 std::string error = "Error in xmlReadFile in SALOME_Launcher::loadJobs, could not parse file: " + std::string(jobs_file);
557 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
561 xmlNodePtr root_node = xmlDocGetRootElement(doc);
562 xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
563 if (!xmlStrcmp(root_node->name, xmlCharStrdup("jobs")))
565 while(xmlCurrentNode != NULL)
567 if (!xmlStrcmp(xmlCurrentNode->name, xmlCharStrdup("job")))
569 INFOS("A job is found");
570 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
571 xmlNodePtr job_node = xmlCurrentNode;
574 if (!xmlHasProp(job_node, xmlCharStrdup("type")) ||
575 !xmlHasProp(job_node, xmlCharStrdup("name")))
577 INFOS("A bad job is found, type or name not found");
580 xmlChar* type = xmlGetProp(job_node, xmlCharStrdup("type"));
581 xmlChar* name = xmlGetProp(job_node, xmlCharStrdup("name"));
582 std::string job_type((const char*) type);
583 if (job_type == "command")
584 new_job = new Launcher::Job_Command();
585 else if (job_type == "yacs_file")
586 new_job = new Launcher::Job_YACSFile();
587 else if (job_type == "python_salome")
588 new_job = new Launcher::Job_PythonSALOME();
589 new_job->setJobName(std::string((const char *)name));
593 xmlNodePtr user_node = xmlFirstElementChild(job_node);
594 xmlNodePtr run_node = xmlNextElementSibling(user_node);
595 if (user_node == NULL || run_node == NULL)
597 INFOS("A bad job is found, user_part or run_part not found");
601 if (xmlStrcmp(user_node->name, xmlCharStrdup("user_part")) ||
602 xmlStrcmp(run_node->name, xmlCharStrdup("run_part")))
604 INFOS("A bad job is found, cannot get a correct user_part or run_part node");
611 // Get job_file env_file work_directory local_directory result_directory
612 xmlNodePtr job_file_node = xmlFirstElementChild(user_node);
613 xmlNodePtr env_file_node = xmlNextElementSibling(job_file_node);
614 xmlNodePtr work_directory_node = xmlNextElementSibling(env_file_node);
615 xmlNodePtr local_directory_node = xmlNextElementSibling(work_directory_node);
616 xmlNodePtr result_directory_node = xmlNextElementSibling(local_directory_node);
618 // Parameters for COORM
619 xmlNodePtr launcher_file_node = xmlNextElementSibling(result_directory_node);
621 if (job_file_node == NULL ||
622 env_file_node == NULL ||
623 work_directory_node == NULL ||
624 local_directory_node == NULL ||
625 result_directory_node == NULL ||
627 launcher_file_node == NULL
630 INFOS("A bad job is found, some user_part are not found");
634 if (xmlStrcmp(job_file_node->name, xmlCharStrdup("job_file")) ||
635 xmlStrcmp(env_file_node->name, xmlCharStrdup("env_file")) ||
636 xmlStrcmp(work_directory_node->name, xmlCharStrdup("work_directory")) ||
637 xmlStrcmp(local_directory_node->name, xmlCharStrdup("local_directory")) ||
638 xmlStrcmp(result_directory_node->name, xmlCharStrdup("result_directory")) ||
640 xmlStrcmp(launcher_file_node->name, xmlCharStrdup("launcher_file"))
643 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
647 xmlChar* job_file = xmlNodeGetContent(job_file_node);
650 new_job->setJobFile(std::string((const char *)job_file));
652 catch(const LauncherException &ex)
654 INFOS("Exception receice for job_file, cannot add the job" << ex.msg.c_str());
659 xmlChar* env_file = xmlNodeGetContent(env_file_node);
660 xmlChar* work_directory = xmlNodeGetContent(work_directory_node);
661 xmlChar* local_directory = xmlNodeGetContent(local_directory_node);
662 xmlChar* result_directory = xmlNodeGetContent(result_directory_node);
664 // Parameters for COORM
665 xmlChar* launcher_file = xmlNodeGetContent(launcher_file_node);
667 new_job->setEnvFile(std::string((const char *)env_file));
668 new_job->setWorkDirectory(std::string((const char *)work_directory));
669 new_job->setLocalDirectory(std::string((const char *)local_directory));
670 new_job->setResultDirectory(std::string((const char *)result_directory));
672 // Parameters for COORM
673 new_job->setLauncherFile(std::string((const char *)launcher_file));
677 xmlFree(work_directory);
678 xmlFree(local_directory);
679 xmlFree(result_directory);
681 // Parameters for COORM
682 xmlFree(launcher_file);
684 // Get in and out files
685 xmlNodePtr files_node = xmlNextElementSibling(launcher_file_node);
686 if (files_node == NULL)
688 INFOS("A bad job is found, user_part files is not found");
692 if (xmlStrcmp(files_node->name, xmlCharStrdup("files")))
694 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");
698 xmlNodePtr file_node = xmlFirstElementChild(files_node);
699 while (file_node != NULL)
701 if (!xmlStrcmp(file_node->name, xmlCharStrdup("in_file")))
703 xmlChar* in_file = xmlNodeGetContent(file_node);
704 new_job->add_in_file(std::string((const char *)in_file));
707 else if (!xmlStrcmp(file_node->name, xmlCharStrdup("out_file")))
709 xmlChar* out_file = xmlNodeGetContent(file_node);
710 new_job->add_out_file(std::string((const char *)out_file));
713 file_node = xmlNextElementSibling(file_node);
717 xmlNodePtr res_node = xmlNextElementSibling(files_node);
718 xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node);
719 xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node);
720 xmlNodePtr exclusive_node = xmlNextElementSibling(queue_node);
721 xmlNodePtr mem_per_cpu_node = xmlNextElementSibling(exclusive_node);
722 xmlNodePtr launcher_args_node = xmlNextElementSibling(mem_per_cpu_node);
723 if (res_node == NULL ||
724 maximum_duration_node == NULL ||
725 queue_node == NULL ||
726 exclusive_node == NULL ||
727 mem_per_cpu_node == NULL ||
729 launcher_args_node == NULL
732 INFOS("A bad job is found, some user_part are not found");
736 if (xmlStrcmp(res_node->name, xmlCharStrdup("resource_params")) ||
737 xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) ||
738 xmlStrcmp(queue_node->name, xmlCharStrdup("queue")) ||
739 xmlStrcmp(exclusive_node->name, xmlCharStrdup("exclusive")) ||
740 xmlStrcmp(mem_per_cpu_node->name, xmlCharStrdup("mem_per_cpu")) ||
742 xmlStrcmp(launcher_args_node->name, xmlCharStrdup("launcher_args"))
745 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
749 xmlChar* maximum_duration = xmlNodeGetContent(maximum_duration_node);
752 new_job->setMaximumDuration(std::string((const char *)maximum_duration));
754 catch(const LauncherException &ex)
756 INFOS("Exception receice for maximum_duration, cannot add the job" << ex.msg.c_str());
758 xmlFree(maximum_duration);
761 xmlChar* queue = xmlNodeGetContent(queue_node);
762 new_job->setQueue(std::string((const char *)queue));
763 xmlFree(maximum_duration);
766 xmlChar* exclusive = xmlNodeGetContent(exclusive_node);
769 new_job->setExclusiveStr(std::string((const char *)exclusive));
771 catch(const LauncherException &ex)
773 INFOS("Exception received for exclusive, cannot add the job. " << ex.msg.c_str());
780 xmlChar* mem_per_cpu_str = xmlNodeGetContent(mem_per_cpu_node);
781 std::istringstream mem_per_cpu_stream((const char *)mem_per_cpu_str);
782 unsigned long mem_per_cpu = 0;
783 if (!(mem_per_cpu_stream >> mem_per_cpu))
785 INFOS("A bad job is found, mem_per_cpu parameter is not correct");
790 new_job->setMemPerCpu(mem_per_cpu);
793 xmlChar* launcher_args = xmlNodeGetContent(launcher_args_node);
794 new_job->setLauncherArgs(std::string((const char *)launcher_args));
795 xmlFree(launcher_args);
797 xmlNodePtr specific_node = xmlNextElementSibling(launcher_args_node);
798 if (specific_node == NULL)
800 INFOS("A bad job is found, specific_parameters part is not found");
804 xmlNodePtr parameter_node = xmlFirstElementChild(specific_node);
805 while (parameter_node != NULL)
807 if (!xmlStrcmp(parameter_node->name, xmlCharStrdup("specific_parameter")))
809 xmlNodePtr name_node = xmlFirstElementChild(parameter_node);
810 xmlNodePtr value_node = xmlNextElementSibling(name_node);
811 if (name_node == NULL ||
814 INFOS("A bad job is found, specific_parameter parts are not found");
818 if (xmlStrcmp(name_node->name, xmlCharStrdup("name")) ||
819 xmlStrcmp(value_node->name, xmlCharStrdup("value")))
821 INFOS("A bad job is found, specific_parameter bad parts are found");
826 xmlChar* name = xmlNodeGetContent(name_node);
827 xmlChar* value = xmlNodeGetContent(value_node);
830 new_job->addSpecificParameter(std::string((const char*)name), std::string((const char*)value));
834 catch(const LauncherException &ex)
836 INFOS("Exception receice for a specific parameter, cannot add the job" << ex.msg.c_str());
845 INFOS("A bad job is found, specific_parameters part is bad, a node that is not a specific parameter is found");
849 parameter_node = xmlNextElementSibling(parameter_node);
852 xmlNodePtr res_name_node = xmlFirstElementChild(res_node);
853 xmlNodePtr res_hostname_node = xmlNextElementSibling(res_name_node);
854 xmlNodePtr res_os_node = xmlNextElementSibling(res_hostname_node);
855 xmlNodePtr res_nb_proc_node = xmlNextElementSibling(res_os_node);
856 xmlNodePtr res_nb_node_node = xmlNextElementSibling(res_nb_proc_node);
857 xmlNodePtr res_nb_proc_per_node_node = xmlNextElementSibling(res_nb_node_node);
858 xmlNodePtr res_cpu_clock_node = xmlNextElementSibling(res_nb_proc_per_node_node);
859 xmlNodePtr res_mem_mb_node = xmlNextElementSibling(res_cpu_clock_node);
860 if (res_name_node == NULL ||
861 res_hostname_node == NULL ||
862 res_os_node == NULL ||
863 res_nb_proc_node == NULL ||
864 res_nb_node_node == NULL ||
865 res_nb_proc_per_node_node == NULL ||
866 res_cpu_clock_node == NULL ||
867 res_mem_mb_node == NULL
870 INFOS("A bad job is found, some resource_params user_part are not found");
874 if (xmlStrcmp(res_name_node->name, xmlCharStrdup("name")) ||
875 xmlStrcmp(res_hostname_node->name, xmlCharStrdup("hostname")) ||
876 xmlStrcmp(res_os_node->name, xmlCharStrdup("OS")) ||
877 xmlStrcmp(res_nb_proc_node->name, xmlCharStrdup("nb_proc")) ||
878 xmlStrcmp(res_nb_node_node->name, xmlCharStrdup("nb_node")) ||
879 xmlStrcmp(res_nb_proc_per_node_node->name, xmlCharStrdup("nb_proc_per_node")) ||
880 xmlStrcmp(res_cpu_clock_node->name, xmlCharStrdup("cpu_clock")) ||
881 xmlStrcmp(res_mem_mb_node->name, xmlCharStrdup("mem_mb"))
884 INFOS("A bad job is found, some resource_params user_part node are not in the rigth or does not have a correct name");
888 xmlChar* res_name = xmlNodeGetContent(res_name_node);
889 xmlChar* res_hostname = xmlNodeGetContent(res_hostname_node);
890 xmlChar* res_os = xmlNodeGetContent(res_os_node);
892 p.name = std::string((const char*) res_name);
893 p.hostname = std::string((const char*) res_hostname);
894 p.OS = std::string((const char*) res_os);
896 xmlFree(res_hostname);
898 xmlChar* res_nb_proc = xmlNodeGetContent(res_nb_proc_node);
899 xmlChar* res_nb_node = xmlNodeGetContent(res_nb_node_node);
900 xmlChar* res_nb_proc_per_node = xmlNodeGetContent(res_nb_proc_per_node_node);
901 xmlChar* res_cpu_clock = xmlNodeGetContent(res_cpu_clock_node);
902 xmlChar* res_mem_mb = xmlNodeGetContent(res_mem_mb_node);
903 bool import_value = true;
904 std::istringstream nb_proc_stream((const char *) res_nb_proc);
905 if (!(nb_proc_stream >> p.nb_proc))
906 import_value = false;
907 std::istringstream nb_node_stream((const char *) res_nb_node);
908 if (!(nb_node_stream >> p.nb_node))
909 import_value = false;
910 std::istringstream nb_proc_per_node_stream((const char *) res_nb_proc_per_node);
911 if (!(nb_proc_per_node_stream >> p.nb_proc_per_node))
912 import_value = false;
913 std::istringstream cpu_clock_stream((const char *) res_cpu_clock);
914 if (!(cpu_clock_stream >> p.cpu_clock))
915 import_value = false;
916 std::istringstream mem_mb_stream((const char *) res_mem_mb);
917 if (!(mem_mb_stream >> p.mem_mb))
918 import_value = false;
919 xmlFree(res_nb_proc);
920 xmlFree(res_nb_node);
921 xmlFree(res_nb_proc_per_node);
922 xmlFree(res_cpu_clock);
926 INFOS("A bad job is found, some resource_params value are not correct");
932 new_job->setResourceRequiredParams(p);
934 catch(const LauncherException &ex)
936 INFOS("A bad job is found, an error when inserting resource_params:" << ex.msg.c_str());
941 // We finally get run part to figure out what to do
942 xmlNodePtr job_state_node = xmlFirstElementChild(run_node);
943 xmlNodePtr resource_choosed_name_node = xmlNextElementSibling(job_state_node);
944 xmlNodePtr job_reference_node = xmlNextElementSibling(resource_choosed_name_node);
945 if (job_state_node == NULL ||
946 resource_choosed_name_node == NULL ||
947 job_reference_node == NULL
950 INFOS("A bad job is found, some run_part are not found");
954 if (xmlStrcmp(job_state_node->name, xmlCharStrdup("job_state")) ||
955 xmlStrcmp(resource_choosed_name_node->name, xmlCharStrdup("resource_choosed_name")) ||
956 xmlStrcmp(job_reference_node->name, xmlCharStrdup("job_reference"))
959 INFOS("A bad job is found, some run_part nodes are not in the rigth or does not have a correct name");
963 xmlChar* job_state_xml = xmlNodeGetContent(job_state_node);
964 xmlChar* resource_choosed_name_xml = xmlNodeGetContent(resource_choosed_name_node);
965 xmlChar* job_reference_xml = xmlNodeGetContent(job_reference_node);
966 std::string job_state((const char *) job_state_xml);
967 std::string resource_choosed_name((const char *) resource_choosed_name_xml);
968 std::string job_reference((const char *) job_reference_xml);
969 xmlFree(job_state_xml);
970 xmlFree(resource_choosed_name_xml);
971 xmlFree(job_reference_xml);
973 if (job_state == "CREATED")
975 // In this case, we ignore run_part informations
978 _l.createJob(new_job);
979 std::ostringstream job_id;
980 job_id << new_job->getNumber();
981 notifyObservers("NEW_JOB", job_id.str());
983 catch(const LauncherException &ex)
985 INFOS("Load failed: " << ex.msg.c_str());
988 else if (job_state == "QUEUED" ||
989 job_state == "RUNNING" ||
990 job_state == "IN_PROCESS" ||
991 job_state == "PAUSED")
995 new_job->setState(job_state);
996 _l.addJobDirectlyToMap(new_job, job_reference);
998 // Step 4: We check that the BatchManager could resume
1000 #ifdef WITH_LIBBATCH
1001 if (new_job->getBatchManagerJobId().getReference() != job_reference)
1003 INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
1004 new_job->setState("ERROR");
1007 std::ostringstream job_id;
1008 job_id << new_job->getNumber();
1009 notifyObservers("NEW_JOB", job_id.str());
1011 catch(const LauncherException &ex)
1013 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
1017 else if (job_state == "FINISHED" ||
1018 job_state == "FAILED" ||
1019 job_state == "ERROR")
1023 // Step 2: We add run_part informations
1024 new_job->setState(job_state);
1025 _l.addJobDirectlyToMap(new_job, job_reference);
1026 std::ostringstream job_id;
1027 job_id << new_job->getNumber();
1028 notifyObservers("NEW_JOB", job_id.str());
1030 catch(const LauncherException &ex)
1032 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
1038 INFOS("A bad job is found, state unknown " << job_state);
1043 xmlCurrentNode = xmlCurrentNode->next;
1050 std::string error = "Error in xml file, could not find root_node named jobs: " + std::string(jobs_file);
1052 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1058 notifyObservers("LOAD_JOBS", jobs_file);
1061 //=============================================================================
1063 * Save jobs of Launcher (in any steps) in file jobs_file
1065 //=============================================================================
1067 SALOME_Launcher::saveJobs(const char* jobs_file)
1070 // Step 1: check jobs_file write access
1071 FILE* xml_file = fopen(jobs_file, "w");
1072 if (xml_file == NULL)
1074 std::string error = "Error opening jobs_file in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1076 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1079 // Step 2: First lines
1080 xmlKeepBlanksDefault(0);
1081 xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
1082 xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
1083 xmlDocSetRootElement(doc, root_node);
1084 xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher save jobs file"));
1085 xmlAddPrevSibling(root_node, doc_comment);
1087 // Step 3: For each job write it on the xml document
1088 // We could put a mutex but are not foing to do that currently
1089 std::map<int, Launcher::Job *> jobs_list = _l.getJobs();
1090 std::map<int, Launcher::Job *>::const_iterator it_job;
1091 for(it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
1093 it_job->second->addToXmlDocument(root_node);
1096 // Final step: write file
1097 int isOk = xmlSaveFormatFile(jobs_file, doc, 1);
1100 std::string error = "Error during xml file saving in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1104 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1110 MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!");
1111 notifyObservers("SAVE_JOBS", jobs_file);
1114 //=============================================================================
1116 * Add a new observer to the launcher
1118 //=============================================================================
1120 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
1122 bool new_observer = true;
1123 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1124 while(iter != _observers.end())
1126 if (std::string(_orb->object_to_string(*iter)) ==
1127 std::string(_orb->object_to_string(observer)))
1129 new_observer = false;
1135 _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
1137 // We notify the new observer with all jobs that are currently in the Launcher
1138 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
1139 std::map<int, Launcher::Job *>::const_iterator it_job;
1140 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
1142 int number = it_job->first;
1143 std::ostringstream job_id;
1147 observer->notify("NEW_JOB", job_id.str().c_str());
1151 MESSAGE("Notify Observer, exception catch");
1157 //=============================================================================
1159 * Add a new observer to the launcher
1161 //=============================================================================
1163 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
1165 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1166 while(iter != _observers.end())
1168 if (std::string(_orb->object_to_string(*iter)) ==
1169 std::string(_orb->object_to_string(observer)))
1172 iter =_observers.erase(iter++);
1181 //=============================================================================
1182 /*! Internal Method:
1183 * Notify observers on a new event
1185 //=============================================================================
1187 SALOME_Launcher::notifyObservers(const std::string & event_name,
1188 const std::string & event_data)
1190 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1191 while(iter != _observers.end())
1195 (*iter)->notify(CORBA::string_dup(event_name.c_str()),
1196 CORBA::string_dup(event_data.c_str()));
1200 MESSAGE("Notify Observer, exception catch");