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 // Resources requirements
167 p.name = job_parameters.resource_required.name;
168 p.hostname = job_parameters.resource_required.hostname;
169 p.OS = job_parameters.resource_required.OS;
170 p.nb_proc = job_parameters.resource_required.nb_proc;
171 p.nb_node = job_parameters.resource_required.nb_node;
172 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
173 p.cpu_clock = job_parameters.resource_required.cpu_clock;
174 p.mem_mb = job_parameters.resource_required.mem_mb;
175 new_job->setResourceRequiredParams(p);
177 catch(const LauncherException &ex){
178 INFOS(ex.msg.c_str());
179 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
182 // Adding specific parameters to the job
183 for (CORBA::ULong i = 0; i < job_parameters.specific_parameters.length(); i++)
184 new_job->addSpecificParameter(job_parameters.specific_parameters[i].name.in(),
185 job_parameters.specific_parameters[i].value.in());
188 new_job->checkSpecificParameters();
190 catch(const LauncherException &ex)
192 INFOS(ex.msg.c_str());
193 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
198 _l.createJob(new_job);
199 std::ostringstream job_id;
200 job_id << new_job->getNumber();
201 notifyObservers("NEW_JOB", job_id.str());
203 catch(const LauncherException &ex)
205 INFOS(ex.msg.c_str());
206 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
208 return new_job->getNumber();
212 SALOME_Launcher::launchJob(CORBA::Long job_id)
216 _l.launchJob(job_id);
218 catch(const LauncherException &ex)
220 INFOS(ex.msg.c_str());
221 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
226 SALOME_Launcher::getJobState(CORBA::Long job_id)
231 result = _l.getJobState(job_id);
233 catch(const LauncherException &ex)
235 INFOS(ex.msg.c_str());
236 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
238 return CORBA::string_dup(result.c_str());
241 // Get names or ids of hosts assigned to the job
243 SALOME_Launcher::getAssignedHostnames(CORBA::Long job_id)
248 result = _l.getAssignedHostnames(job_id);
250 catch(const LauncherException &ex)
252 INFOS(ex.msg.c_str());
253 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
255 return CORBA::string_dup(result.c_str());
259 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
263 _l.getJobResults(job_id, directory);
265 catch(const LauncherException &ex)
267 INFOS(ex.msg.c_str());
268 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
273 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
275 CORBA::Boolean rtn = false;
278 rtn = _l.getJobDumpState(job_id, directory);
280 catch(const LauncherException &ex)
282 INFOS(ex.msg.c_str());
283 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
289 SALOME_Launcher::removeJob(CORBA::Long job_id)
293 _l.removeJob(job_id);
294 std::ostringstream job_id_str;
295 job_id_str << job_id;
296 notifyObservers("REMOVE_JOB", job_id_str.str());
298 catch(const LauncherException &ex)
300 INFOS(ex.msg.c_str());
301 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
306 SALOME_Launcher::stopJob(CORBA::Long job_id)
311 std::ostringstream job_id_str;
312 job_id_str << job_id;
313 notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
315 catch(const LauncherException &ex)
317 INFOS(ex.msg.c_str());
318 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
322 //=============================================================================
324 * Create a job in the launcher with a file
325 * \param xmlExecuteFile : .xml to parse that contains job description
326 * \param clusterName : machine choosed
328 //=============================================================================
330 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
331 const char * clusterName)
335 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
337 catch(const LauncherException &ex){
338 INFOS(ex.msg.c_str());
339 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
345 //=============================================================================
347 * the test batch configuration
348 * \param params : The batch cluster
350 //=============================================================================
352 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
354 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
355 CORBA::Boolean rtn = false;
358 // Consider only resources that can run batch jobs
359 Engines::ResourceParameters new_params(params);
360 new_params.can_launch_batch_jobs = true;
362 // find a resource matching the required parameters
363 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(new_params);
364 if (aMachineList->length() == 0)
365 throw SALOME_Exception("No resources have been found with your parameters");
367 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
368 std::string resource_name(p->name);
369 INFOS("Choose resource for test: " << resource_name);
377 catch(const LauncherException &ex){
378 INFOS(ex.msg.c_str());
379 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
384 //=============================================================================
386 * shutdown all the containers, then the ContainerManager servant
388 //=============================================================================
389 void SALOME_Launcher::Shutdown()
392 _NS->Destroy_Name(_LauncherNameInNS);
393 _ContManager->Shutdown();
394 _ResManager->Shutdown();
395 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
396 _poa->deactivate_object(oid);
397 if(!CORBA::is_nil(_orb))
401 //=============================================================================
403 * Returns the PID of the process
405 //=============================================================================
406 CORBA::Long SALOME_Launcher::getPID()
410 (CORBA::Long)getpid();
412 (CORBA::Long)_getpid();
416 //=============================================================================
418 * Returns current launcher jobs list
420 //=============================================================================
422 SALOME_Launcher::getJobsList()
424 Engines::JobsList_var jobs_list = new Engines::JobsList();
425 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
426 std::map<int, Launcher::Job *>::const_iterator it_job;
428 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
430 int number = it_job->first;
433 // Prepare CORBA job description
434 Engines::JobDescription_var job_descr = new Engines::JobDescription();
435 Engines::JobParameters_var job_parameters = getJobParameters(number);
436 job_descr->job_id = number;
437 job_descr->job_parameters = job_parameters;
439 // Add job description to the sequence
440 jobs_list->length(list_id + 1);
441 jobs_list[list_id] = job_descr;
446 return jobs_list._retn();
449 //=============================================================================
451 * Returns the job description
453 //=============================================================================
454 Engines::JobParameters *
455 SALOME_Launcher::getJobParameters(CORBA::Long job_id)
457 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
458 std::map<int, Launcher::Job *>::const_iterator it_job = cpp_jobs.find(job_id);
459 if (it_job == cpp_jobs.end())
461 INFOS("Cannot find the job, is it created ? job number: " << job_id);
462 THROW_SALOME_CORBA_EXCEPTION("Job does not exist", SALOME::INTERNAL_ERROR);
465 Launcher::Job * job = it_job->second;
466 Engines::JobParameters_var job_parameters = new Engines::JobParameters;
467 job_parameters->job_name = CORBA::string_dup(job->getJobName().c_str());
468 job_parameters->job_type = CORBA::string_dup(job->getJobType().c_str());
469 job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
470 job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
471 job_parameters->work_directory = CORBA::string_dup(job->getWorkDirectory().c_str());
472 job_parameters->local_directory = CORBA::string_dup(job->getLocalDirectory().c_str());
473 job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
475 // Parameters for COORM
476 job_parameters->launcher_file = CORBA::string_dup(job->getLauncherFile().c_str());
477 job_parameters->launcher_args = CORBA::string_dup(job->getLauncherArgs().c_str());
481 std::list<std::string> in_files = job->get_in_files();
482 std::list<std::string> out_files = job->get_out_files();
483 job_parameters->in_files.length(in_files.size());
484 for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
486 job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
489 job_parameters->out_files.length(out_files.size());
490 for(std::list<std::string>::iterator it = out_files.begin(); it != out_files.end(); it++)
492 job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
496 job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
497 job_parameters->queue = CORBA::string_dup(job->getQueue().c_str());
498 job_parameters->exclusive = job->getExclusive();
500 resourceParams resource_params = job->getResourceRequiredParams();
501 job_parameters->resource_required.name = CORBA::string_dup(resource_params.name.c_str());
502 job_parameters->resource_required.hostname = CORBA::string_dup(resource_params.hostname.c_str());
503 job_parameters->resource_required.OS = CORBA::string_dup(resource_params.OS.c_str());
504 job_parameters->resource_required.nb_proc = resource_params.nb_proc;
505 job_parameters->resource_required.nb_node = resource_params.nb_node;
506 job_parameters->resource_required.nb_proc_per_node = resource_params.nb_proc_per_node;
507 job_parameters->resource_required.cpu_clock = resource_params.cpu_clock;
508 job_parameters->resource_required.mem_mb = resource_params.mem_mb;
510 std::map<std::string, std::string> specific_parameters = job->getSpecificParameters();
511 if (!specific_parameters.empty())
513 job_parameters->specific_parameters.length(specific_parameters.size());
514 std::map<std::string, std::string>::const_iterator it_specific;
516 for (it_specific = specific_parameters.begin() ; it_specific != specific_parameters.end(); it_specific++)
518 Engines::Parameter_var new_param = new Engines::Parameter;
519 new_param->name = CORBA::string_dup((it_specific->first).c_str());
520 new_param->value = CORBA::string_dup((it_specific->second).c_str());
521 job_parameters->specific_parameters[i] = new_param;
526 return job_parameters._retn();
529 //=============================================================================
531 * Loads jobs saved in jobs_file
533 //=============================================================================
535 SALOME_Launcher::loadJobs(const char* jobs_file)
537 // Step 1: check jobs_file read access
538 FILE* xml_file = fopen(jobs_file, "r");
539 if (xml_file == NULL)
541 std::string error = "Error opening jobs_file in SALOME_Launcher::loadJobs: " + std::string(jobs_file);
543 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
546 // Step 2: read xml file
547 xmlDocPtr doc = xmlReadFile(jobs_file, NULL, 0);
550 std::string error = "Error in xmlReadFile in SALOME_Launcher::loadJobs, could not parse file: " + std::string(jobs_file);
553 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
557 xmlNodePtr root_node = xmlDocGetRootElement(doc);
558 xmlNodePtr xmlCurrentNode = root_node->xmlChildrenNode;
559 if (!xmlStrcmp(root_node->name, xmlCharStrdup("jobs")))
561 while(xmlCurrentNode != NULL)
563 if (!xmlStrcmp(xmlCurrentNode->name, xmlCharStrdup("job")))
565 INFOS("A job is found");
566 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
567 xmlNodePtr job_node = xmlCurrentNode;
570 if (!xmlHasProp(job_node, xmlCharStrdup("type")) ||
571 !xmlHasProp(job_node, xmlCharStrdup("name")))
573 INFOS("A bad job is found, type or name not found");
576 xmlChar* type = xmlGetProp(job_node, xmlCharStrdup("type"));
577 xmlChar* name = xmlGetProp(job_node, xmlCharStrdup("name"));
578 std::string job_type((const char*) type);
579 if (job_type == "command")
580 new_job = new Launcher::Job_Command();
581 else if (job_type == "yacs_file")
582 new_job = new Launcher::Job_YACSFile();
583 else if (job_type == "python_salome")
584 new_job = new Launcher::Job_PythonSALOME();
585 new_job->setJobName(std::string((const char *)name));
589 xmlNodePtr user_node = xmlFirstElementChild(job_node);
590 xmlNodePtr run_node = xmlNextElementSibling(user_node);
591 if (user_node == NULL || run_node == NULL)
593 INFOS("A bad job is found, user_part or run_part not found");
597 if (xmlStrcmp(user_node->name, xmlCharStrdup("user_part")) ||
598 xmlStrcmp(run_node->name, xmlCharStrdup("run_part")))
600 INFOS("A bad job is found, cannot get a correct user_part or run_part node");
607 // Get job_file env_file work_directory local_directory result_directory
608 xmlNodePtr job_file_node = xmlFirstElementChild(user_node);
609 xmlNodePtr env_file_node = xmlNextElementSibling(job_file_node);
610 xmlNodePtr work_directory_node = xmlNextElementSibling(env_file_node);
611 xmlNodePtr local_directory_node = xmlNextElementSibling(work_directory_node);
612 xmlNodePtr result_directory_node = xmlNextElementSibling(local_directory_node);
614 // Parameters for COORM
615 xmlNodePtr launcher_file_node = xmlNextElementSibling(result_directory_node);
617 if (job_file_node == NULL ||
618 env_file_node == NULL ||
619 work_directory_node == NULL ||
620 local_directory_node == NULL ||
621 result_directory_node == NULL ||
623 launcher_file_node == NULL
626 INFOS("A bad job is found, some user_part are not found");
630 if (xmlStrcmp(job_file_node->name, xmlCharStrdup("job_file")) ||
631 xmlStrcmp(env_file_node->name, xmlCharStrdup("env_file")) ||
632 xmlStrcmp(work_directory_node->name, xmlCharStrdup("work_directory")) ||
633 xmlStrcmp(local_directory_node->name, xmlCharStrdup("local_directory")) ||
634 xmlStrcmp(result_directory_node->name, xmlCharStrdup("result_directory")) ||
636 xmlStrcmp(launcher_file_node->name, xmlCharStrdup("launcher_file"))
639 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
643 xmlChar* job_file = xmlNodeGetContent(job_file_node);
646 new_job->setJobFile(std::string((const char *)job_file));
648 catch(const LauncherException &ex)
650 INFOS("Exception receice for job_file, cannot add the job" << ex.msg.c_str());
655 xmlChar* env_file = xmlNodeGetContent(env_file_node);
656 xmlChar* work_directory = xmlNodeGetContent(work_directory_node);
657 xmlChar* local_directory = xmlNodeGetContent(local_directory_node);
658 xmlChar* result_directory = xmlNodeGetContent(result_directory_node);
660 // Parameters for COORM
661 xmlChar* launcher_file = xmlNodeGetContent(launcher_file_node);
663 new_job->setEnvFile(std::string((const char *)env_file));
664 new_job->setWorkDirectory(std::string((const char *)work_directory));
665 new_job->setLocalDirectory(std::string((const char *)local_directory));
666 new_job->setResultDirectory(std::string((const char *)result_directory));
668 // Parameters for COORM
669 new_job->setLauncherFile(std::string((const char *)launcher_file));
673 xmlFree(work_directory);
674 xmlFree(local_directory);
675 xmlFree(result_directory);
677 // Parameters for COORM
678 xmlFree(launcher_file);
680 // Get in and out files
681 xmlNodePtr files_node = xmlNextElementSibling(launcher_file_node);
682 if (files_node == NULL)
684 INFOS("A bad job is found, user_part files is not found");
688 if (xmlStrcmp(files_node->name, xmlCharStrdup("files")))
690 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");
694 xmlNodePtr file_node = xmlFirstElementChild(files_node);
695 while (file_node != NULL)
697 if (!xmlStrcmp(file_node->name, xmlCharStrdup("in_file")))
699 xmlChar* in_file = xmlNodeGetContent(file_node);
700 new_job->add_in_file(std::string((const char *)in_file));
703 else if (!xmlStrcmp(file_node->name, xmlCharStrdup("out_file")))
705 xmlChar* out_file = xmlNodeGetContent(file_node);
706 new_job->add_out_file(std::string((const char *)out_file));
709 file_node = xmlNextElementSibling(file_node);
713 xmlNodePtr res_node = xmlNextElementSibling(files_node);
714 xmlNodePtr maximum_duration_node = xmlNextElementSibling(res_node);
715 xmlNodePtr queue_node = xmlNextElementSibling(maximum_duration_node);
716 xmlNodePtr exclusive_node = xmlNextElementSibling(queue_node);
717 xmlNodePtr launcher_args_node = xmlNextElementSibling(exclusive_node);
718 if (res_node == NULL ||
719 maximum_duration_node == NULL ||
720 queue_node == NULL ||
721 exclusive_node == NULL ||
723 launcher_args_node == NULL
726 INFOS("A bad job is found, some user_part are not found");
730 if (xmlStrcmp(res_node->name, xmlCharStrdup("resource_params")) ||
731 xmlStrcmp(maximum_duration_node->name, xmlCharStrdup("maximum_duration")) ||
732 xmlStrcmp(queue_node->name, xmlCharStrdup("queue")) ||
733 xmlStrcmp(exclusive_node->name, xmlCharStrdup("exclusive")) ||
735 xmlStrcmp(launcher_args_node->name, xmlCharStrdup("launcher_args"))
738 INFOS("A bad job is found, some user part node are not in the rigth or does not have a correct name");
742 xmlChar* maximum_duration = xmlNodeGetContent(maximum_duration_node);
745 new_job->setMaximumDuration(std::string((const char *)maximum_duration));
747 catch(const LauncherException &ex)
749 INFOS("Exception receice for maximum_duration, cannot add the job" << ex.msg.c_str());
751 xmlFree(maximum_duration);
754 xmlChar* queue = xmlNodeGetContent(queue_node);
755 new_job->setQueue(std::string((const char *)queue));
756 xmlFree(maximum_duration);
759 xmlChar* exclusive = xmlNodeGetContent(exclusive_node);
762 new_job->setExclusiveStr(std::string((const char *)exclusive));
764 catch(const LauncherException &ex)
766 INFOS("Exception received for exclusive, cannot add the job. " << ex.msg.c_str());
774 xmlChar* launcher_args = xmlNodeGetContent(launcher_args_node);
775 new_job->setLauncherArgs(std::string((const char *)launcher_args));
776 xmlFree(launcher_args);
778 xmlNodePtr specific_node = xmlNextElementSibling(launcher_args_node);
779 if (specific_node == NULL)
781 INFOS("A bad job is found, specific_parameters part is not found");
785 xmlNodePtr parameter_node = xmlFirstElementChild(specific_node);
786 while (parameter_node != NULL)
788 if (!xmlStrcmp(parameter_node->name, xmlCharStrdup("specific_parameter")))
790 xmlNodePtr name_node = xmlFirstElementChild(parameter_node);
791 xmlNodePtr value_node = xmlNextElementSibling(name_node);
792 if (name_node == NULL ||
795 INFOS("A bad job is found, specific_parameter parts are not found");
799 if (xmlStrcmp(name_node->name, xmlCharStrdup("name")) ||
800 xmlStrcmp(value_node->name, xmlCharStrdup("value")))
802 INFOS("A bad job is found, specific_parameter bad parts are found");
807 xmlChar* name = xmlNodeGetContent(name_node);
808 xmlChar* value = xmlNodeGetContent(value_node);
811 new_job->addSpecificParameter(std::string((const char*)name), std::string((const char*)value));
815 catch(const LauncherException &ex)
817 INFOS("Exception receice for a specific parameter, cannot add the job" << ex.msg.c_str());
826 INFOS("A bad job is found, specific_parameters part is bad, a node that is not a specific parameter is found");
830 parameter_node = xmlNextElementSibling(parameter_node);
833 xmlNodePtr res_name_node = xmlFirstElementChild(res_node);
834 xmlNodePtr res_hostname_node = xmlNextElementSibling(res_name_node);
835 xmlNodePtr res_os_node = xmlNextElementSibling(res_hostname_node);
836 xmlNodePtr res_nb_proc_node = xmlNextElementSibling(res_os_node);
837 xmlNodePtr res_nb_node_node = xmlNextElementSibling(res_nb_proc_node);
838 xmlNodePtr res_nb_proc_per_node_node = xmlNextElementSibling(res_nb_node_node);
839 xmlNodePtr res_cpu_clock_node = xmlNextElementSibling(res_nb_proc_per_node_node);
840 xmlNodePtr res_mem_mb_node = xmlNextElementSibling(res_cpu_clock_node);
841 if (res_name_node == NULL ||
842 res_hostname_node == NULL ||
843 res_os_node == NULL ||
844 res_nb_proc_node == NULL ||
845 res_nb_node_node == NULL ||
846 res_nb_proc_per_node_node == NULL ||
847 res_cpu_clock_node == NULL ||
848 res_mem_mb_node == NULL
851 INFOS("A bad job is found, some resource_params user_part are not found");
855 if (xmlStrcmp(res_name_node->name, xmlCharStrdup("name")) ||
856 xmlStrcmp(res_hostname_node->name, xmlCharStrdup("hostname")) ||
857 xmlStrcmp(res_os_node->name, xmlCharStrdup("OS")) ||
858 xmlStrcmp(res_nb_proc_node->name, xmlCharStrdup("nb_proc")) ||
859 xmlStrcmp(res_nb_node_node->name, xmlCharStrdup("nb_node")) ||
860 xmlStrcmp(res_nb_proc_per_node_node->name, xmlCharStrdup("nb_proc_per_node")) ||
861 xmlStrcmp(res_cpu_clock_node->name, xmlCharStrdup("cpu_clock")) ||
862 xmlStrcmp(res_mem_mb_node->name, xmlCharStrdup("mem_mb"))
865 INFOS("A bad job is found, some resource_params user_part node are not in the rigth or does not have a correct name");
869 xmlChar* res_name = xmlNodeGetContent(res_name_node);
870 xmlChar* res_hostname = xmlNodeGetContent(res_hostname_node);
871 xmlChar* res_os = xmlNodeGetContent(res_os_node);
873 p.name = std::string((const char*) res_name);
874 p.hostname = std::string((const char*) res_hostname);
875 p.OS = std::string((const char*) res_os);
877 xmlFree(res_hostname);
879 xmlChar* res_nb_proc = xmlNodeGetContent(res_nb_proc_node);
880 xmlChar* res_nb_node = xmlNodeGetContent(res_nb_node_node);
881 xmlChar* res_nb_proc_per_node = xmlNodeGetContent(res_nb_proc_per_node_node);
882 xmlChar* res_cpu_clock = xmlNodeGetContent(res_cpu_clock_node);
883 xmlChar* res_mem_mb = xmlNodeGetContent(res_mem_mb_node);
884 bool import_value = true;
885 std::istringstream nb_proc_stream((const char *) res_nb_proc);
886 if (!(nb_proc_stream >> p.nb_proc))
887 import_value = false;
888 std::istringstream nb_node_stream((const char *) res_nb_node);
889 if (!(nb_node_stream >> p.nb_node))
890 import_value = false;
891 std::istringstream nb_proc_per_node_stream((const char *) res_nb_proc_per_node);
892 if (!(nb_proc_per_node_stream >> p.nb_proc_per_node))
893 import_value = false;
894 std::istringstream cpu_clock_stream((const char *) res_cpu_clock);
895 if (!(cpu_clock_stream >> p.cpu_clock))
896 import_value = false;
897 std::istringstream mem_mb_stream((const char *) res_mem_mb);
898 if (!(mem_mb_stream >> p.mem_mb))
899 import_value = false;
900 xmlFree(res_nb_proc);
901 xmlFree(res_nb_node);
902 xmlFree(res_nb_proc_per_node);
903 xmlFree(res_cpu_clock);
907 INFOS("A bad job is found, some resource_params value are not correct");
913 new_job->setResourceRequiredParams(p);
915 catch(const LauncherException &ex)
917 INFOS("A bad job is found, an error when inserting resource_params:" << ex.msg.c_str());
922 // We finally get run part to figure out what to do
923 xmlNodePtr job_state_node = xmlFirstElementChild(run_node);
924 xmlNodePtr resource_choosed_name_node = xmlNextElementSibling(job_state_node);
925 xmlNodePtr job_reference_node = xmlNextElementSibling(resource_choosed_name_node);
926 if (job_state_node == NULL ||
927 resource_choosed_name_node == NULL ||
928 job_reference_node == NULL
931 INFOS("A bad job is found, some run_part are not found");
935 if (xmlStrcmp(job_state_node->name, xmlCharStrdup("job_state")) ||
936 xmlStrcmp(resource_choosed_name_node->name, xmlCharStrdup("resource_choosed_name")) ||
937 xmlStrcmp(job_reference_node->name, xmlCharStrdup("job_reference"))
940 INFOS("A bad job is found, some run_part nodes are not in the rigth or does not have a correct name");
944 xmlChar* job_state_xml = xmlNodeGetContent(job_state_node);
945 xmlChar* resource_choosed_name_xml = xmlNodeGetContent(resource_choosed_name_node);
946 xmlChar* job_reference_xml = xmlNodeGetContent(job_reference_node);
947 std::string job_state((const char *) job_state_xml);
948 std::string resource_choosed_name((const char *) resource_choosed_name_xml);
949 std::string job_reference((const char *) job_reference_xml);
950 xmlFree(job_state_xml);
951 xmlFree(resource_choosed_name_xml);
952 xmlFree(job_reference_xml);
954 if (job_state == "CREATED")
956 // In this case, we ignore run_part informations
959 _l.createJob(new_job);
960 std::ostringstream job_id;
961 job_id << new_job->getNumber();
962 notifyObservers("NEW_JOB", job_id.str());
964 catch(const LauncherException &ex)
966 INFOS("Load failed: " << ex.msg.c_str());
969 else if (job_state == "QUEUED" ||
970 job_state == "RUNNING" ||
971 job_state == "IN_PROCESS" ||
972 job_state == "PAUSED")
976 new_job->setState(job_state);
977 _l.addJobDirectlyToMap(new_job, job_reference);
979 // Step 4: We check that the BatchManager could resume
982 if (new_job->getBatchManagerJobId().getReference() != job_reference)
984 INFOS("BatchManager type cannot resume a job - job state is set to ERROR");
985 new_job->setState("ERROR");
988 std::ostringstream job_id;
989 job_id << new_job->getNumber();
990 notifyObservers("NEW_JOB", job_id.str());
992 catch(const LauncherException &ex)
994 INFOS("Cannot load the job! Exception: " << ex.msg.c_str());
998 else if (job_state == "FINISHED" ||
999 job_state == "FAILED" ||
1000 job_state == "ERROR")
1004 // Step 2: We add run_part informations
1005 new_job->setState(job_state);
1006 _l.addJobDirectlyToMap(new_job, job_reference);
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());
1019 INFOS("A bad job is found, state unknown " << job_state);
1024 xmlCurrentNode = xmlCurrentNode->next;
1031 std::string error = "Error in xml file, could not find root_node named jobs: " + std::string(jobs_file);
1033 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1039 notifyObservers("LOAD_JOBS", jobs_file);
1042 //=============================================================================
1044 * Save jobs of Launcher (in any steps) in file jobs_file
1046 //=============================================================================
1048 SALOME_Launcher::saveJobs(const char* jobs_file)
1051 // Step 1: check jobs_file write access
1052 FILE* xml_file = fopen(jobs_file, "w");
1053 if (xml_file == NULL)
1055 std::string error = "Error opening jobs_file in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1057 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1060 // Step 2: First lines
1061 xmlKeepBlanksDefault(0);
1062 xmlDocPtr doc = xmlNewDoc(xmlCharStrdup("1.0"));
1063 xmlNodePtr root_node = xmlNewNode(NULL, xmlCharStrdup("jobs"));
1064 xmlDocSetRootElement(doc, root_node);
1065 xmlNodePtr doc_comment = xmlNewDocComment(doc, xmlCharStrdup("SALOME Launcher save jobs file"));
1066 xmlAddPrevSibling(root_node, doc_comment);
1068 // Step 3: For each job write it on the xml document
1069 // We could put a mutex but are not foing to do that currently
1070 std::map<int, Launcher::Job *> jobs_list = _l.getJobs();
1071 std::map<int, Launcher::Job *>::const_iterator it_job;
1072 for(it_job = jobs_list.begin(); it_job != jobs_list.end(); it_job++)
1074 it_job->second->addToXmlDocument(root_node);
1077 // Final step: write file
1078 int isOk = xmlSaveFormatFile(jobs_file, doc, 1);
1081 std::string error = "Error during xml file saving in SALOME_Launcher::saveJobs: " + std::string(jobs_file);
1085 THROW_SALOME_CORBA_EXCEPTION(error.c_str(), SALOME::INTERNAL_ERROR);
1091 MESSAGE("SALOME_Launcher::saveJobs : WRITING DONE!");
1092 notifyObservers("SAVE_JOBS", jobs_file);
1095 //=============================================================================
1097 * Add a new observer to the launcher
1099 //=============================================================================
1101 SALOME_Launcher::addObserver(Engines::SalomeLauncherObserver_ptr observer)
1103 bool new_observer = true;
1104 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1105 while(iter != _observers.end())
1107 if (std::string(_orb->object_to_string(*iter)) ==
1108 std::string(_orb->object_to_string(observer)))
1110 new_observer = false;
1116 _observers.push_back(Engines::SalomeLauncherObserver::_duplicate(observer));
1118 // We notify the new observer with all jobs that are currently in the Launcher
1119 std::map<int, Launcher::Job *> cpp_jobs = _l.getJobs();
1120 std::map<int, Launcher::Job *>::const_iterator it_job;
1121 for(it_job = cpp_jobs.begin(); it_job != cpp_jobs.end(); it_job++)
1123 int number = it_job->first;
1124 std::ostringstream job_id;
1128 observer->notify("NEW_JOB", job_id.str().c_str());
1132 MESSAGE("Notify Observer, exception catch");
1138 //=============================================================================
1140 * Add a new observer to the launcher
1142 //=============================================================================
1144 SALOME_Launcher::removeObserver(Engines::SalomeLauncherObserver_ptr observer)
1146 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1147 while(iter != _observers.end())
1149 if (std::string(_orb->object_to_string(*iter)) ==
1150 std::string(_orb->object_to_string(observer)))
1153 iter =_observers.erase(iter++);
1162 //=============================================================================
1163 /*! Internal Method:
1164 * Notify observers on a new event
1166 //=============================================================================
1168 SALOME_Launcher::notifyObservers(const std::string & event_name,
1169 const std::string & event_data)
1171 std::list<Engines::SalomeLauncherObserver_var>::iterator iter = _observers.begin();
1172 while(iter != _observers.end())
1176 (*iter)->notify(CORBA::string_dup(event_name.c_str()),
1177 CORBA::string_dup(event_data.c_str()));
1181 MESSAGE("Notify Observer, exception catch");