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);
160 // Resources requirements
164 p.name = job_parameters.resource_required.name;
165 p.hostname = job_parameters.resource_required.hostname;
166 p.OS = job_parameters.resource_required.OS;
167 p.nb_proc = job_parameters.resource_required.nb_proc;
168 p.nb_node = job_parameters.resource_required.nb_node;
169 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
170 p.cpu_clock = job_parameters.resource_required.cpu_clock;
171 p.mem_mb = job_parameters.resource_required.mem_mb;
172 new_job->setResourceRequiredParams(p);
174 catch(const LauncherException &ex){
175 INFOS(ex.msg.c_str());
176 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
179 // Adding specific parameters to the job
180 for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
181 new_job->addSpecificParameter(job_parameters.specific_parameters[i].name.in(),
182 job_parameters.specific_parameters[i].value.in());
185 new_job->checkSpecificParameters();
187 catch(const LauncherException &ex)
189 INFOS(ex.msg.c_str());
190 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
195 _l.createJob(new_job);
196 std::ostringstream job_id;
197 job_id << new_job->getNumber();
198 notifyObservers("NEW_JOB", job_id.str());
200 catch(const LauncherException &ex)
202 INFOS(ex.msg.c_str());
203 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
205 return new_job->getNumber();
209 SALOME_Launcher::launchJob(CORBA::Long job_id)
213 _l.launchJob(job_id);
215 catch(const LauncherException &ex)
217 INFOS(ex.msg.c_str());
218 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
223 SALOME_Launcher::getJobState(CORBA::Long job_id)
228 result = _l.getJobState(job_id);
230 catch(const LauncherException &ex)
232 INFOS(ex.msg.c_str());
233 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
235 return CORBA::string_dup(result.c_str());
238 // Get names or ids of hosts assigned to the job
240 SALOME_Launcher::getAssignedHostnames(CORBA::Long job_id)
245 result = _l.getAssignedHostnames(job_id);
247 catch(const LauncherException &ex)
249 INFOS(ex.msg.c_str());
250 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
252 return CORBA::string_dup(result.c_str());
256 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
260 _l.getJobResults(job_id, directory);
262 catch(const LauncherException &ex)
264 INFOS(ex.msg.c_str());
265 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
270 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
272 CORBA::Boolean rtn = false;
275 rtn = _l.getJobDumpState(job_id, directory);
277 catch(const LauncherException &ex)
279 INFOS(ex.msg.c_str());
280 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
286 SALOME_Launcher::removeJob(CORBA::Long job_id)
290 _l.removeJob(job_id);
291 std::ostringstream job_id_str;
292 job_id_str << job_id;
293 notifyObservers("REMOVE_JOB", job_id_str.str());
295 catch(const LauncherException &ex)
297 INFOS(ex.msg.c_str());
298 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
303 SALOME_Launcher::stopJob(CORBA::Long job_id)
308 std::ostringstream job_id_str;
309 job_id_str << job_id;
310 notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
312 catch(const LauncherException &ex)
314 INFOS(ex.msg.c_str());
315 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
319 //=============================================================================
321 * Create a job in the launcher with a file
322 * \param xmlExecuteFile : .xml to parse that contains job description
323 * \param clusterName : machine choosed
325 //=============================================================================
327 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
328 const char * clusterName)
332 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
334 catch(const LauncherException &ex){
335 INFOS(ex.msg.c_str());
336 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
342 //=============================================================================
344 * the test batch configuration
345 * \param params : The batch cluster
347 //=============================================================================
349 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
351 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
352 CORBA::Boolean rtn = false;
355 // Consider only resources that can run batch jobs
356 Engines::ResourceParameters new_params(params);
357 new_params.can_launch_batch_jobs = true;
359 // find a resource matching the required parameters
360 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(new_params);
361 if (aMachineList->length() == 0)
362 throw SALOME_Exception("No resources have been found with your parameters");
364 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
365 std::string resource_name(p->name);
366 INFOS("Choose resource for test: " << resource_name);
374 catch(const LauncherException &ex){
375 INFOS(ex.msg.c_str());
376 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
381 //=============================================================================
383 * shutdown all the containers, then the ContainerManager servant
385 //=============================================================================
386 void SALOME_Launcher::Shutdown()
389 _NS->Destroy_Name(_LauncherNameInNS);
390 _ContManager->Shutdown();
391 _ResManager->Shutdown();
392 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
393 _poa->deactivate_object(oid);
394 if(!CORBA::is_nil(_orb))
398 //=============================================================================
400 * Returns the PID of the process
402 //=============================================================================
403 CORBA::Long SALOME_Launcher::getPID()
407 (CORBA::Long)getpid();
409 (CORBA::Long)_getpid();
413 //=============================================================================
415 * Returns current launcher jobs list
417 //=============================================================================
419 SALOME_Launcher::getJobsList()
421 Engines::JobsList_var jobs_list = new Engines::JobsList();
422 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
423 std::map<int, Launcher::Job *>::const_iterator it_job;
425 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
427 int number = it_job->first;
430 // Prepare CORBA job description
431 Engines::JobDescription_var job_descr = new Engines::JobDescription();
432 Engines::JobParameters_var job_parameters = getJobParameters(number);
433 job_descr->job_id = number;
434 job_descr->job_parameters = job_parameters;
436 // Add job description to the sequence
437 jobs_list->length(list_id + 1);
438 jobs_list[list_id] = job_descr;
443 return jobs_list._retn();
446 //=============================================================================
448 * Returns the job description
450 //=============================================================================
451 Engines::JobParameters *
452 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
454 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
455 std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
456 if (it_job == cpp_jobs.end())
458 INFOS("Cannot find the job, is it created ? job number: " << job_id);
459 THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
462 Launcher::Job * job = it_job->second;
463 Engines::JobParameters_var job_parameters = new Engines::JobParameters;
464 job_parameters->job_name = CORBA::string_dup(job->getJobName().c_str());
465 job_parameters->job_type = CORBA::string_dup(job->getJobType().c_str());
466 job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
467 job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
468 job_parameters->work_directory = CORBA::string_dup(job->getWorkDirectory().c_str());
469 job_parameters->local_directory = CORBA::string_dup(job->getLocalDirectory().c_str());
470 job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
472 // Parameters for COORM
473 job_parameters->launcher_file = CORBA::string_dup(job->getLauncherFile().c_str());
474 job_parameters->launcher_args = CORBA::string_dup(job->getLauncherArgs().c_str());
478 std::list<std::string> in_files = job->get_in_files();
479 std::list<std::string> out_files = job->get_out_files();
480 job_parameters->in_files.length(in_files.size());
481 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
483 job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
486 job_parameters->out_files.length(out_files.size());
487 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
489 job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
493 job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
494 job_parameters->queue = CORBA::string_dup(job->getQueue().c_str());
496 resourceParams resource_params = job->getResourceRequiredParams();
497 job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str());
498 job_parameters->resource_required.hostname = CORBA::string_dup(resource_params.hostname.c_str());
499 job_parameters->resource_required.OS = CORBA::string_dup(resource_params.OS.c_str());
500 job_parameters->resource_required.nb_proc = resource_params.nb_proc;
501 job_parameters->resource_required.nb_node = resource_params.nb_node;
502 job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
503 job_parameters->resource_required.cpu_clock = resource_params.cpu_clock;
504 job_parameters->resource_required.mem_mb = resource_params.mem_mb;
506 std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
507 if (!specific_parameters.empty())
509 job_parameters->specific_parameters.length(specific_parameters.size());
510 std::map<std::string, std::string>::const_iterator it_specific;
512 for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
514 Engines::Parameter_var new_param = new Engines::Parameter;
515 new_param->name = CORBA::string_dup((it_specific->first).c_str());
516 new_param->value = CORBA::string_dup((it_specific->second).c_str());
517 job_parameters->specific_parameters[i] = new_param;
522 return job_parameters._retn();
525 //=============================================================================
527 * Loads jobs saved in jobs_file
529 //=============================================================================
531 SALOME_Launcher::loadJobs(const char* jobs_file)
533 // Step 1: check jobs_file read access
534 FILE* xml_file = fopen(jobs_file, "r");
535 if (xml_file == NULL)
537 std::string error = "Error opening jobs_file in SALOME_Launcher::loadJobs: " + std::string(jobs_file);
539 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
542 // Step 2: read xml file
543 xmlDocPtr doc = xmlReadFile(jobs_file, NULL, 0);
546 std::string error = "Error in xmlReadFile in SALOME_Launcher::loadJobs, could not parse file: " + std::string(jobs_file);
549 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
553 xmlNodePtr root_node = xmlDocGetRootElement(doc);
554 xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
555 if (!xmlStrcmp(root_node->name, xmlCharStrdup("jobs")))
557 while(xmlCurrentNode != NULL)
559 if (!xmlStrcmp(xmlCurrentNode->name, xmlCharStrdup("job")))
561 INFOS("A job is found");
562 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
563 xmlNodePtr job_node = xmlCurrentNode;
566 if (!xmlHasProp(job_node, xmlCharStrdup("type")) ||
567 !xmlHasProp(job_node, xmlCharStrdup("name")))
569 INFOS("A bad job is found, type or name not found");
572 xmlChar* type = xmlGetProp(job_node, xmlCharStrdup("type"));
573 xmlChar* name = xmlGetProp(job_node, xmlCharStrdup("name"));
574 std::string job_type((const char*) type);
575 if (job_type == "command")
576 new_job = new Launcher::Job_Command();
577 else if (job_type == "yacs_file")
578 new_job = new Launcher::Job_YACSFile();
579 else if (job_type == "python_salome")
580 new_job = new Launcher::Job_PythonSALOME();
581 new_job->setJobName(std::string((const char *)name));
585 xmlNodePtr user_node = xmlFirstElementChild(job_node);
586 xmlNodePtr run_node = xmlNextElementSibling(user_node);
587 if (user_node == NULL || run_node == NULL)
589 INFOS("A bad job is found, user_part or run_part not found");
593 if (xmlStrcmp(user_node->name, xmlCharStrdup("user_part")) ||
594 xmlStrcmp(run_node->name, xmlCharStrdup("run_part")))
596 INFOS("A bad job is found, cannot get a correct user_part or run_part node");
603 // Get job_file env_file work_directory local_directory result_directory
604 xmlNodePtr job_file_node = xmlFirstElementChild(user_node);
605 xmlNodePtr env_file_node = xmlNextElementSibling(job_file_node);
606 xmlNodePtr work_directory_node = xmlNextElementSibling(env_file_node);
607 xmlNodePtr local_directory_node = xmlNextElementSibling(work_directory_node);
608 xmlNodePtr result_directory_node = xmlNextElementSibling(local_directory_node);
610 // Parameters for COORM
611 xmlNodePtr launcher_file_node = xmlNextElementSibling(result_directory_node);
613 if (job_file_node == NULL ||
614 env_file_node == NULL ||
615 work_directory_node == NULL ||
616 local_directory_node == NULL ||
617 result_directory_node == NULL ||
619 launcher_file_node == NULL
622 INFOS("A bad job is found, some user_part are not found");
626 if (xmlStrcmp(job_file_node->name, xmlCharStrdup("job_file")) ||
627 xmlStrcmp(env_file_node->name, xmlCharStrdup("env_file")) ||
628 xmlStrcmp(work_directory_node->name, xmlCharStrdup("work_directory")) ||
629 xmlStrcmp(local_directory_node->name, xmlCharStrdup("local_directory")) ||
630 xmlStrcmp(result_directory_node->name, xmlCharStrdup("result_directory")) ||
632 xmlStrcmp(launcher_file_node->name, xmlCharStrdup("launcher_file"))
635 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
639 xmlChar* job_file = xmlNodeGetContent(job_file_node);
642 new_job->setJobFile(std::string((const char *)job_file));
644 catch(const LauncherException &ex)
646 INFOS("Exception receice for job_file, cannot add the job" << ex.msg.c_str());
651 xmlChar* env_file = xmlNodeGetContent(env_file_node);
652 xmlChar* work_directory = xmlNodeGetContent(work_directory_node);
653 xmlChar* local_directory = xmlNodeGetContent(local_directory_node);
654 xmlChar* result_directory = xmlNodeGetContent(result_directory_node);
656 // Parameters for COORM
657 xmlChar* launcher_file = xmlNodeGetContent(launcher_file_node);
659 new_job->setEnvFile(std::string((const char *)env_file));
660 new_job->setWorkDirectory(std::string((const char *)work_directory));
661 new_job->setLocalDirectory(std::string((const char *)local_directory));
662 new_job->setResultDirectory(std::string((const char *)result_directory));
664 // Parameters for COORM
665 new_job->setLauncherFile(std::string((const char *)launcher_file));
669 xmlFree(work_directory);
670 xmlFree(local_directory);
671 xmlFree(result_directory);
673 // Parameters for COORM
674 xmlFree(launcher_file);
676 // Get in and out files
677 xmlNodePtr files_node = xmlNextElementSibling(launcher_file_node);
678 if (files_node == NULL)
680 INFOS("A bad job is found, user_part files is not found");
684 if (xmlStrcmp(files_node->name, xmlCharStrdup("files")))
686 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");
690 xmlNodePtr file_node = xmlFirstElementChild(files_node);
691 while (file_node != NULL)
693 if (!xmlStrcmp(file_node->name, xmlCharStrdup("in_file")))
695 xmlChar* in_file = xmlNodeGetContent(file_node);
696 new_job->add_in_file(std::string((const char *)in_file));
699 else if (!xmlStrcmp(file_node->name, xmlCharStrdup("out_file")))
701 xmlChar* out_file = xmlNodeGetContent(file_node);
702 new_job->add_out_file(std::string((const char *)out_file));
705 file_node = xmlNextElementSibling(file_node);
709 xmlNodePtr res_node = xmlNextElementSibling(files_node);
710 xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node);
711 xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node);
712 xmlNodePtr launcher_args_node = xmlNextElementSibling(queue_node);
713 if (res_node == NULL ||
714 maximum_duration_node == NULL ||
715 queue_node == NULL ||
717 launcher_args_node == NULL
720 INFOS("A bad job is found, some user_part are not found");
724 if (xmlStrcmp(res_node->name, xmlCharStrdup("resource_params")) ||
725 xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) ||
726 xmlStrcmp(queue_node->name, xmlCharStrdup("queue")) ||
728 xmlStrcmp(launcher_args_node->name, xmlCharStrdup("launcher_args"))
731 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
735 xmlChar* maximum_duration = xmlNodeGetContent(maximum_duration_node);
738 new_job->setMaximumDuration(std::string((const char *)maximum_duration));
740 catch(const LauncherException &ex)
742 INFOS("Exception receice for maximum_duration, cannot add the job" << ex.msg.c_str());
744 xmlFree(maximum_duration);
747 xmlChar* queue = xmlNodeGetContent(queue_node);
748 new_job->setQueue(std::string((const char *)queue));
749 xmlFree(maximum_duration);
753 xmlChar* launcher_args = xmlNodeGetContent(launcher_args_node);
754 new_job->setLauncherArgs(std::string((const char *)launcher_args));
755 xmlFree(launcher_args);
757 xmlNodePtr specific_node = xmlNextElementSibling(launcher_args_node);
758 if (specific_node == NULL)
760 INFOS("A bad job is found, specific_parameters part is not found");
764 xmlNodePtr parameter_node = xmlFirstElementChild(specific_node);
765 while (parameter_node != NULL)
767 if (!xmlStrcmp(parameter_node->name, xmlCharStrdup("specific_parameter")))
769 xmlNodePtr name_node = xmlFirstElementChild(parameter_node);
770 xmlNodePtr value_node = xmlNextElementSibling(name_node);
771 if (name_node == NULL ||
774 INFOS("A bad job is found, specific_parameter parts are not found");
778 if (xmlStrcmp(name_node->name, xmlCharStrdup("name")) ||
779 xmlStrcmp(value_node->name, xmlCharStrdup("value")))
781 INFOS("A bad job is found, specific_parameter bad parts are found");
786 xmlChar* name = xmlNodeGetContent(name_node);
787 xmlChar* value = xmlNodeGetContent(value_node);
790 new_job->addSpecificParameter(std::string((const char*)name), std::string((const char*)value));
794 catch(const LauncherException &ex)
796 INFOS("Exception receice for a specific parameter, cannot add the job" << ex.msg.c_str());
805 INFOS("A bad job is found, specific_parameters part is bad, a node that is not a specific parameter is found");
809 parameter_node = xmlNextElementSibling(parameter_node);
812 xmlNodePtr res_name_node = xmlFirstElementChild(res_node);
813 xmlNodePtr res_hostname_node = xmlNextElementSibling(res_name_node);
814 xmlNodePtr res_os_node = xmlNextElementSibling(res_hostname_node);
815 xmlNodePtr res_nb_proc_node = xmlNextElementSibling(res_os_node);
816 xmlNodePtr res_nb_node_node = xmlNextElementSibling(res_nb_proc_node);
817 xmlNodePtr res_nb_proc_per_node_node = xmlNextElementSibling(res_nb_node_node);
818 xmlNodePtr res_cpu_clock_node = xmlNextElementSibling(res_nb_proc_per_node_node);
819 xmlNodePtr res_mem_mb_node = xmlNextElementSibling(res_cpu_clock_node);
820 if (res_name_node == NULL ||
821 res_hostname_node == NULL ||
822 res_os_node == NULL ||
823 res_nb_proc_node == NULL ||
824 res_nb_node_node == NULL ||
825 res_nb_proc_per_node_node == NULL ||
826 res_cpu_clock_node == NULL ||
827 res_mem_mb_node == NULL
830 INFOS("A bad job is found, some resource_params user_part are not found");
834 if (xmlStrcmp(res_name_node->name, xmlCharStrdup("name")) ||
835 xmlStrcmp(res_hostname_node->name, xmlCharStrdup("hostname")) ||
836 xmlStrcmp(res_os_node->name, xmlCharStrdup("OS")) ||
837 xmlStrcmp(res_nb_proc_node->name, xmlCharStrdup("nb_proc")) ||
838 xmlStrcmp(res_nb_node_node->name, xmlCharStrdup("nb_node")) ||
839 xmlStrcmp(res_nb_proc_per_node_node->name, xmlCharStrdup("nb_proc_per_node")) ||
840 xmlStrcmp(res_cpu_clock_node->name, xmlCharStrdup("cpu_clock")) ||
841 xmlStrcmp(res_mem_mb_node->name, xmlCharStrdup("mem_mb"))
844 INFOS("A bad job is found, some resource_params user_part node are not in the rigth or does not have a correct name");
848 xmlChar* res_name = xmlNodeGetContent(res_name_node);
849 xmlChar* res_hostname = xmlNodeGetContent(res_hostname_node);
850 xmlChar* res_os = xmlNodeGetContent(res_os_node);
852 p.name = std::string((const char*) res_name);
853 p.hostname = std::string((const char*) res_hostname);
854 p.OS = std::string((const char*) res_os);
856 xmlFree(res_hostname);
858 xmlChar* res_nb_proc = xmlNodeGetContent(res_nb_proc_node);
859 xmlChar* res_nb_node = xmlNodeGetContent(res_nb_node_node);
860 xmlChar* res_nb_proc_per_node = xmlNodeGetContent(res_nb_proc_per_node_node);
861 xmlChar* res_cpu_clock = xmlNodeGetContent(res_cpu_clock_node);
862 xmlChar* res_mem_mb = xmlNodeGetContent(res_mem_mb_node);
863 bool import_value = true;
864 std::istringstream nb_proc_stream((const char *) res_nb_proc);
865 if (!(nb_proc_stream >> p.nb_proc))
866 import_value = false;
867 std::istringstream nb_node_stream((const char *) res_nb_node);
868 if (!(nb_node_stream >> p.nb_node))
869 import_value = false;
870 std::istringstream nb_proc_per_node_stream((const char *) res_nb_proc_per_node);
871 if (!(nb_proc_per_node_stream >> p.nb_proc_per_node))
872 import_value = false;
873 std::istringstream cpu_clock_stream((const char *) res_cpu_clock);
874 if (!(cpu_clock_stream >> p.cpu_clock))
875 import_value = false;
876 std::istringstream mem_mb_stream((const char *) res_mem_mb);
877 if (!(mem_mb_stream >> p.mem_mb))
878 import_value = false;
879 xmlFree(res_nb_proc);
880 xmlFree(res_nb_node);
881 xmlFree(res_nb_proc_per_node);
882 xmlFree(res_cpu_clock);
886 INFOS("A bad job is found, some resource_params value are not correct");
892 new_job->setResourceRequiredParams(p);
894 catch(const LauncherException &ex)
896 INFOS("A bad job is found, an error when inserting resource_params:" << ex.msg.c_str());
901 // We finally get run part to figure out what to do
902 xmlNodePtr job_state_node = xmlFirstElementChild(run_node);
903 xmlNodePtr resource_choosed_name_node = xmlNextElementSibling(job_state_node);
904 xmlNodePtr job_reference_node = xmlNextElementSibling(resource_choosed_name_node);
905 if (job_state_node == NULL ||
906 resource_choosed_name_node == NULL ||
907 job_reference_node == NULL
910 INFOS("A bad job is found, some run_part are not found");
914 if (xmlStrcmp(job_state_node->name, xmlCharStrdup("job_state")) ||
915 xmlStrcmp(resource_choosed_name_node->name, xmlCharStrdup("resource_choosed_name")) ||
916 xmlStrcmp(job_reference_node->name, xmlCharStrdup("job_reference"))
919 INFOS("A bad job is found, some run_part nodes are not in the rigth or does not have a correct name");
923 xmlChar* job_state_xml = xmlNodeGetContent(job_state_node);
924 xmlChar* resource_choosed_name_xml = xmlNodeGetContent(resource_choosed_name_node);
925 xmlChar* job_reference_xml = xmlNodeGetContent(job_reference_node);
926 std::string job_state((const char *) job_state_xml);
927 std::string resource_choosed_name((const char *) resource_choosed_name_xml);
928 std::string job_reference((const char *) job_reference_xml);
929 xmlFree(job_state_xml);
930 xmlFree(resource_choosed_name_xml);
931 xmlFree(job_reference_xml);
933 if (job_state == "CREATED")
935 // In this case, we ignore run_part informations
938 _l.createJob(new_job);
939 std::ostringstream job_id;
940 job_id << new_job->getNumber();
941 notifyObservers("NEW_JOB", job_id.str());
943 catch(const LauncherException &ex)
945 INFOS("Load failed: " << ex.msg.c_str());
948 else if (job_state == "QUEUED" ||
949 job_state == "RUNNING" ||
950 job_state == "IN_PROCESS" ||
951 job_state == "PAUSED")
955 new_job->setState(job_state);
956 _l.addJobDirectlyToMap(new_job, job_reference);
958 // Step 4: We check that the BatchManager could resume
961 if (new_job->getBatchManagerJobId().getReference() != job_reference)
963 INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
964 new_job->setState("ERROR");
967 std::ostringstream job_id;
968 job_id << new_job->getNumber();
969 notifyObservers("NEW_JOB", job_id.str());
971 catch(const LauncherException &ex)
973 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
977 else if (job_state == "FINISHED" ||
978 job_state == "FAILED" ||
979 job_state == "ERROR")
983 // Step 2: We add run_part informations
984 new_job->setState(job_state);
985 _l.addJobDirectlyToMap(new_job, job_reference);
986 std::ostringstream job_id;
987 job_id << new_job->getNumber();
988 notifyObservers("NEW_JOB", job_id.str());
990 catch(const LauncherException &ex)
992 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
998 INFOS("A bad job is found, state unknown " << job_state);
1003 xmlCurrentNode = xmlCurrentNode->next;
1010 std::string error = "Error in xml file, could not find root_node named jobs: " + std::string(jobs_file);
1012 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1018 notifyObservers("LOAD_JOBS", jobs_file);
1021 //=============================================================================
1023 * Save jobs of Launcher (in any steps) in file jobs_file
1025 //=============================================================================
1027 SALOME_Launcher::saveJobs(const char* jobs_file)
1030 // Step 1: check jobs_file write access
1031 FILE* xml_file = fopen(jobs_file, "w");
1032 if (xml_file == NULL)
1034 std::string error = "Error opening jobs_file in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1036 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1039 // Step 2: First lines
1040 xmlKeepBlanksDefault(0);
1041 xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
1042 xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
1043 xmlDocSetRootElement(doc, root_node);
1044 xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher save jobs file"));
1045 xmlAddPrevSibling(root_node, doc_comment);
1047 // Step 3: For each job write it on the xml document
1048 // We could put a mutex but are not foing to do that currently
1049 std::map<int, Launcher::Job *> jobs_list = _l.getJobs();
1050 std::map<int, Launcher::Job *>::const_iterator it_job;
1051 for(it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
1053 it_job->second->addToXmlDocument(root_node);
1056 // Final step: write file
1057 int isOk = xmlSaveFormatFile(jobs_file, doc, 1);
1060 std::string error = "Error during xml file saving in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1064 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1070 MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!");
1071 notifyObservers("SAVE_JOBS", jobs_file);
1074 //=============================================================================
1076 * Add a new observer to the launcher
1078 //=============================================================================
1080 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
1082 bool new_observer = true;
1083 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1084 while(iter != _observers.end())
1086 if (std::string(_orb->object_to_string(*iter)) ==
1087 std::string(_orb->object_to_string(observer)))
1089 new_observer = false;
1095 _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
1097 // We notify the new observer with all jobs that are currently in the Launcher
1098 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
1099 std::map<int, Launcher::Job *>::const_iterator it_job;
1100 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
1102 int number = it_job->first;
1103 std::ostringstream job_id;
1107 observer->notify("NEW_JOB", job_id.str().c_str());
1111 MESSAGE("Notify Observer, exception catch");
1117 //=============================================================================
1119 * Add a new observer to the launcher
1121 //=============================================================================
1123 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
1125 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1126 while(iter != _observers.end())
1128 if (std::string(_orb->object_to_string(*iter)) ==
1129 std::string(_orb->object_to_string(observer)))
1132 iter =_observers.erase(iter++);
1141 //=============================================================================
1142 /*! Internal Method:
1143 * Notify observers on a new event
1145 //=============================================================================
1147 SALOME_Launcher::notifyObservers(const std::string & event_name,
1148 const std::string & event_data)
1150 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1151 while(iter != _observers.end())
1155 (*iter)->notify(CORBA::string_dup(event_name.c_str()),
1156 CORBA::string_dup(event_data.c_str()));
1160 MESSAGE("Notify Observer, exception catch");