Salome HOME
Create LICENSE
[modules/jobmanager.git] / src / engine / BL_SALOMEServices.cxx
1 // Copyright (C) 2009-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BL_SALOMEServices.hxx"
21 #include <sstream>
22
23 static std::ostream & 
24 operator<<(std::ostream & os, const CORBA::Exception & e)
25 {
26   CORBA::Any tmp;
27   tmp <<=e ;
28   CORBA::TypeCode_var tc = tmp.type();
29   const char * p = tc->name ();
30   if (*p != '\0')
31     os << p;
32   else
33     os << tc->id();
34   return os;
35 }
36
37 BL::SALOMEServices::SALOMEServices()
38 {
39   int nbargs = 0; char **args = 0;
40   _orb = CORBA::ORB_init (nbargs, args);
41   _salome_naming_service = NULL;
42   _lcc = NULL;
43   _state = false;
44   _manager = NULL;
45 }
46
47 BL::SALOMEServices::~SALOMEServices() {}
48
49 void
50 BL::SALOMEServices::end()
51 {
52   if (!CORBA::is_nil(_salome_launcher))
53     _salome_launcher->removeObserver(_this());
54   if (_salome_naming_service)
55     delete _salome_naming_service;
56   if (_lcc)
57     delete _lcc;
58 }
59
60 bool
61 BL::SALOMEServices::initNS()
62 {
63   bool return_value = true;
64   _salome_naming_service = new BL_SALOME_NamingService_Wrapper(_orb);
65   _lcc = new SALOME_LifeCycleCORBA(_salome_naming_service);
66   CORBA::Object_var obj = _salome_naming_service->Resolve("/SalomeLauncher");
67   _salome_launcher = Engines::SalomeLauncher::_narrow(obj);
68
69   if (CORBA::is_nil(_salome_launcher))
70   {
71     DEBMSG("SALOME Launcher is not reachable!")
72     return_value = false;
73   }
74   _salome_launcher->addObserver(_this());
75   _remove_ref(); // POA will automatically destroy the object
76
77   obj = _salome_naming_service->Resolve("/ResourcesManager");
78   _resources_manager = Engines::ResourcesManager::_narrow(obj);
79   if (CORBA::is_nil(_resources_manager))
80   {
81     DEBMSG("SALOME Resource Manager is not reachable !");
82     return_value = false;
83   }
84
85   _state = return_value;
86   return return_value;
87 }
88
89 std::list<std::string> 
90 BL::SALOMEServices::getResourceList(bool batch_only)
91 {
92   std::list<std::string> resource_list;
93   
94   if (_state)
95   {
96     Engines::ResourceParameters params;
97     _lcc->preSet(params);
98     params.can_launch_batch_jobs = batch_only;
99     Engines::ResourceList * resourceList = NULL;
100     try
101     {
102       resourceList = _resources_manager->GetFittingResources(params);
103     }
104     catch (const SALOME::SALOME_Exception & ex)
105     {
106       DEBMSG("SALOME Exception in addResource ! " << ex.details.text.in());
107     }
108     catch (const CORBA::SystemException& ex)
109     {
110       DEBMSG("Receive SALOME System Exception: " << ex);
111       DEBMSG("Check SALOME servers...");
112     }
113     if (resourceList)
114     {
115       for (int i = 0; i < resourceList->length(); i++)
116       {
117         const char* aResource = (*resourceList)[i];
118         resource_list.push_back(aResource);
119       }
120       delete resourceList;
121     }
122   }
123   return resource_list;
124 }
125
126 BL::ResourceDescr
127 BL::SALOMEServices::getResourceDescr(const std::string& name)
128 {
129   Engines::ResourceDefinition * resource_definition = NULL;
130   BL::ResourceDescr resource_descr;
131
132   try 
133   {
134     resource_definition = _resources_manager-> GetResourceDefinition(name.c_str());
135   }
136   catch (const SALOME::SALOME_Exception & ex)
137   {
138     DEBMSG("SALOME Exception in addResource ! " << ex.details.text.in());
139   }
140   catch (const CORBA::SystemException& ex)
141   {
142     DEBMSG("Receive SALOME System Exception: " << ex);
143     DEBMSG("Check SALOME servers...");
144   }
145
146   if(resource_definition)
147   {
148     resource_descr.name = resource_definition->name.in();
149     resource_descr.hostname = resource_definition->hostname.in();
150     resource_descr.protocol = resource_definition->protocol.in();
151     resource_descr.username = resource_definition->username.in();
152     resource_descr.applipath = resource_definition->applipath.in();
153     for (int i = 0; i < resource_definition->componentList.length(); i++)
154     {
155       resource_descr.componentList.push_back(resource_definition->componentList[i].in());
156     }
157
158     resource_descr.OS = resource_definition->OS.in();
159     resource_descr.mem_mb = resource_definition->mem_mb;
160     resource_descr.cpu_clock = resource_definition->cpu_clock;
161     resource_descr.nb_node = resource_definition->nb_node;
162     resource_descr.nb_proc_per_node = resource_definition->nb_proc_per_node;
163     resource_descr.batch = resource_definition->batch.in();
164     resource_descr.mpiImpl = resource_definition->mpiImpl.in();
165     resource_descr.iprotocol = resource_definition->iprotocol.in();
166     resource_descr.can_launch_batch_jobs = resource_definition->can_launch_batch_jobs;
167     resource_descr.can_run_containers = resource_definition->can_run_containers;
168     resource_descr.working_directory = resource_definition->working_directory.in();
169
170     delete resource_definition;
171   }
172   return resource_descr;
173 }
174
175 void
176 BL::SALOMEServices::addResource(BL::ResourceDescr & new_resource)
177 {
178   Engines::ResourceDefinition_var resource_definition = new Engines::ResourceDefinition;
179
180   resource_definition->name = CORBA::string_dup(new_resource.name.c_str());
181   resource_definition->hostname = CORBA::string_dup(new_resource.hostname.c_str());
182   if (new_resource.batch == "none")
183     resource_definition->type = CORBA::string_dup("single_machine");
184   else
185     resource_definition->type = CORBA::string_dup("cluster");
186   resource_definition->protocol = CORBA::string_dup(new_resource.protocol.c_str());
187   resource_definition->username = CORBA::string_dup(new_resource.username.c_str());
188   resource_definition->applipath = CORBA::string_dup(new_resource.applipath.c_str());
189
190   int i = 0;
191   std::list<std::string>::iterator it = new_resource.componentList.begin();
192   resource_definition->componentList.length(new_resource.componentList.size());
193   for(; it != new_resource.componentList.end(); it++)
194   {
195     resource_definition->componentList[i] = CORBA::string_dup((*it).c_str());
196     i++;
197   }
198
199   resource_definition->OS = CORBA::string_dup(new_resource.OS.c_str());
200   resource_definition->mem_mb = new_resource.mem_mb;
201   resource_definition->cpu_clock = new_resource.cpu_clock;
202   resource_definition->nb_node = new_resource.nb_node;
203   resource_definition->nb_proc_per_node = new_resource.nb_proc_per_node;  
204   resource_definition->batch = CORBA::string_dup(new_resource.batch.c_str());
205   resource_definition->mpiImpl = CORBA::string_dup(new_resource.mpiImpl.c_str());
206   resource_definition->iprotocol = CORBA::string_dup(new_resource.iprotocol.c_str());
207   resource_definition->can_launch_batch_jobs = new_resource.can_launch_batch_jobs;
208   resource_definition->can_run_containers = new_resource.can_run_containers;
209   resource_definition->working_directory = CORBA::string_dup(new_resource.working_directory.c_str());
210
211   try
212   {
213     _resources_manager->AddResource(resource_definition, true, "");
214   }
215   catch (const SALOME::SALOME_Exception & ex)
216   {
217     DEBMSG("SALOME Exception in addResource ! " << ex.details.text.in());
218     throw(BL::Exception(ex.details.text.in()));
219   }
220   catch (const CORBA::SystemException& ex)
221   {
222     DEBMSG("Receive SALOME System Exception: " << ex);
223     DEBMSG("Check SALOME servers...");
224     throw(BL::Exception("SALOME System Exception"));
225   }
226 }
227
228 void 
229 BL::SALOMEServices::removeResource(const std::string & name)
230 {
231   try
232   {
233     _resources_manager->RemoveResource(name.c_str(), true, "");
234   }
235   catch (const SALOME::SALOME_Exception & ex)
236   {
237     DEBMSG("SALOME Exception in removeResource ! " << ex.details.text.in());
238   }
239   catch (const CORBA::SystemException& ex)
240   {
241     DEBMSG("Receive SALOME System Exception: " << ex);
242     DEBMSG("Check SALOME servers...");
243   }
244 }
245
246 std::string
247 BL::SALOMEServices::create_job(BL::Job * job)
248 {
249   DEBMSG("Begin of create_job");
250   std::string ret = "";
251   Engines::JobParameters_var job_parameters = new Engines::JobParameters;
252
253   // Job type
254   if (job->getType() == BL::Job::COMMAND)
255   {
256     job_parameters->job_type = CORBA::string_dup("command");
257   }
258   else if (job->getType() == BL::Job::YACS_SCHEMA)
259   {
260     job_parameters->job_type = CORBA::string_dup("yacs_file");
261   }
262   else if (job->getType() == BL::Job::PYTHON_SALOME)
263   {
264     job_parameters->job_type = CORBA::string_dup("python_salome");
265   }
266   else if (job->getType() == BL::Job::COMMAND_SALOME)
267   {
268     job_parameters->job_type = CORBA::string_dup("command_salome");
269   }
270
271   // Specific parameters
272   if (job->getType() == BL::Job::YACS_SCHEMA)
273   {
274     if (job->getDumpYACSState() > 0)
275     {
276       job_parameters->specific_parameters.length(job_parameters->specific_parameters.length() + 1);
277       std::ostringstream oss;
278       oss << job->getDumpYACSState();
279       Engines::Parameter_var new_parameter = new Engines::Parameter;
280       new_parameter->name = CORBA::string_dup("EnableDumpYACS");
281       new_parameter->value = CORBA::string_dup(oss.str().c_str());
282       job_parameters->specific_parameters[job_parameters->specific_parameters.length() - 1] = new_parameter;
283     }
284     if (!job->getYacsDriverOptions().empty())
285     {
286       job_parameters->specific_parameters.length(job_parameters->specific_parameters.length() + 1);
287       Engines::Parameter_var new_parameter = new Engines::Parameter;
288       new_parameter->name = CORBA::string_dup("YACSDriverOptions");
289       new_parameter->value = CORBA::string_dup(job->getYacsDriverOptions().c_str());
290       job_parameters->specific_parameters[job_parameters->specific_parameters.length() - 1] = new_parameter;
291     }
292   }
293   if (job->getLoadLevelerJobType() != "")
294   {
295     job_parameters->specific_parameters.length(job_parameters->specific_parameters.length() + 1);
296     Engines::Parameter_var new_parameter = new Engines::Parameter;
297     new_parameter->name = CORBA::string_dup("LoalLevelerJobType");
298     new_parameter->value = CORBA::string_dup(job->getLoadLevelerJobType().c_str());
299     job_parameters->specific_parameters[job_parameters->specific_parameters.length() - 1] = new_parameter;
300   }
301
302   // Files
303   job_parameters->job_name = CORBA::string_dup(job->getName().c_str());
304   job_parameters->job_file = CORBA::string_dup(job->getJobFile().c_str());
305   job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str());
306   job_parameters->pre_command = CORBA::string_dup(job->getPreCommand().c_str());
307   BL::Job::FilesParam files = job->getFilesParameters();
308   std::list<std::string>::iterator it;
309   int i = 0;
310   int j = 0;
311
312   job_parameters->in_files.length(files.input_files_list.size());
313   for (it = files.input_files_list.begin() ; it != files.input_files_list.end(); it++)
314   {
315     job_parameters->in_files[i] = CORBA::string_dup((*it).c_str());
316     i++;
317   }
318
319   job_parameters->out_files.length(files.output_files_list.size());
320   for (it = files.output_files_list.begin() ; it != files.output_files_list.end(); it++)
321   {
322     job_parameters->out_files[j] = CORBA::string_dup((*it).c_str());
323     j++;
324   }
325   job_parameters->local_directory = CORBA::string_dup("");
326   job_parameters->result_directory = CORBA::string_dup(files.result_directory.c_str());
327
328   BL::Job::BatchParam cpp_batch_params =  job->getBatchParameters();
329   job_parameters->work_directory = CORBA::string_dup(cpp_batch_params.batch_directory.c_str());
330
331   // Resource
332   job_parameters->maximum_duration = CORBA::string_dup(cpp_batch_params.maximum_duration.c_str());
333   job_parameters->resource_required.name = CORBA::string_dup(job->getResource().c_str());
334   job_parameters->resource_required.nb_proc = cpp_batch_params.nb_proc;
335   job_parameters->resource_required.nb_node = cpp_batch_params.nb_node;
336   job_parameters->queue = CORBA::string_dup(job->getBatchQueue().c_str());
337   job_parameters->partition = CORBA::string_dup(job->getBatchPartition().c_str());
338   job_parameters->exclusive = cpp_batch_params.exclusive;
339   job_parameters->wckey = CORBA::string_dup(job->getWCKey().c_str());
340   job_parameters->extra_params = CORBA::string_dup(job->getExtraParams().c_str());
341
342   // Memory
343   switch (cpp_batch_params.mem_req_type)
344   {
345   case BL::Job::MEM_PER_NODE:
346     job_parameters->resource_required.mem_mb = cpp_batch_params.mem_limit;
347     job_parameters->mem_per_cpu = 0;
348     break;
349   case BL::Job::MEM_PER_CPU:
350     job_parameters->resource_required.mem_mb = 0;
351     job_parameters->mem_per_cpu = cpp_batch_params.mem_limit;
352     break;
353   default:
354     throw Exception("Unknown memory requirement, unable to create job");
355   }
356
357   // Unused parameters
358   job_parameters->resource_required.nb_proc_per_node = -1;
359   job_parameters->resource_required.cpu_clock = -1;
360
361   // Parameters for COORM
362   job_parameters->launcher_file = CORBA::string_dup(cpp_batch_params.launcher_file.c_str());
363   job_parameters->launcher_args = CORBA::string_dup(cpp_batch_params.launcher_args.c_str());
364
365   // Create Job
366   try
367   {
368     int job_id = _salome_launcher->createJob(job_parameters);
369     job->setSalomeLauncherId(job_id);
370   }
371   catch (const SALOME::SALOME_Exception & ex)
372   {
373     DEBMSG("SALOME Exception in createJob !");
374     ret = ex.details.text.in();
375   }
376   catch (const CORBA::SystemException& ex)
377   {
378     DEBMSG("Receive SALOME System Exception: " << ex);
379     DEBMSG("Check SALOME servers...");
380     ret = "SALOME System Exception - see logs";
381   }
382   return ret;
383 }
384
385 std::string
386 BL::SALOMEServices::start_job(BL::Job * job)
387 {
388   std::string ret = "";
389   // Launch Job !
390   try
391   {
392     _salome_launcher->launchJob(job->getSalomeLauncherId());
393   }
394   catch (const SALOME::SALOME_Exception & ex)
395   {
396     DEBMSG("SALOME Exception in launchJob !");
397     ret = ex.details.text.in();
398   }
399   catch (const CORBA::SystemException& ex)
400   {
401     DEBMSG("Receive SALOME System Exception: " << ex);
402     DEBMSG("Check SALOME servers...");
403     ret = "SALOME System Exception - see logs";
404   }
405   return ret;
406 }
407
408 std::string
409 BL::SALOMEServices::refresh_job(BL::Job * job)
410 {
411   std::string ret = "";
412
413   // Refresh Job !
414   try
415   {
416     CORBA::String_var result = _salome_launcher->getJobState(job->getSalomeLauncherId());
417     ret = result.in();
418   }
419   catch (const SALOME::SALOME_Exception & ex)
420   {
421     DEBMSG("SALOME Exception in getJobState !");
422     ret = ex.details.text.in();
423   }
424   catch (const CORBA::SystemException& ex)
425   {
426     DEBMSG("Receive SALOME System Exception: " << ex);
427     DEBMSG("Check SALOME servers...");
428     ret = "SALOME System Exception - see logs";
429   }
430   return ret;
431 }
432
433 std::string
434 BL::SALOMEServices::delete_job(BL::Job * job)
435 {
436   std::string ret = "";
437   // Delete Job !
438   try
439   {
440     _salome_launcher->removeJob(job->getSalomeLauncherId());
441   }
442   catch (const SALOME::SALOME_Exception & ex)
443   {
444     DEBMSG("SALOME Exception in removeJob !");
445     ret = ex.details.text.in();
446   }
447   catch (const CORBA::SystemException& ex)
448   {
449     DEBMSG("Receive SALOME System Exception: " << ex);
450     DEBMSG("Check SALOME servers...");
451     ret = "SALOME System Exception - see logs";
452   }
453   return ret;
454 }
455
456 std::string
457 BL::SALOMEServices::stop_job(BL::Job * job)
458 {
459   std::string ret = "";
460   try
461   {
462     _salome_launcher->stopJob(job->getSalomeLauncherId());
463   }
464   catch (const SALOME::SALOME_Exception & ex)
465   {
466     DEBMSG("SALOME Exception in stopJob !");
467     ret = ex.details.text.in();
468   }
469   catch (const CORBA::SystemException& ex)
470   {
471     DEBMSG("Receive SALOME System Exception: " << ex);
472     DEBMSG("Check SALOME servers...");
473     ret = "SALOME System Exception - see logs";
474   }
475   return ret;
476 }
477
478 std::string
479 BL::SALOMEServices::get_results_job(BL::Job * job)
480 {
481   std::string ret = "";
482
483   BL::Job::FilesParam files = job->getFilesParameters();
484   CORBA::String_var directory = CORBA::string_dup(files.result_directory.c_str());
485
486   // get job results !
487   try
488   {
489     _salome_launcher->getJobResults(job->getSalomeLauncherId(), directory);
490   }
491   catch (const SALOME::SALOME_Exception & ex)
492   {
493     DEBMSG("SALOME Exception in refresh_job !");
494     ret = ex.details.text.in();
495   }
496   catch (const CORBA::SystemException& ex)
497   {
498     DEBMSG("Receive SALOME System Exception: " << ex);
499     DEBMSG("Check SALOME servers...");
500     ret = "SALOME System Exception - see logs";
501   }
502   return ret;
503 }
504
505 // Get names or ids of hosts assigned to the job
506 std::string
507 BL::SALOMEServices::get_assigned_hostnames(BL::Job * job)
508 {
509   std::string ret = "";
510
511   try
512   {
513     CORBA::String_var result = _salome_launcher->getAssignedHostnames(job->getSalomeLauncherId());
514     ret = result.in();
515   }
516   catch (const SALOME::SALOME_Exception & ex)
517   {
518     DEBMSG("SALOME Exception in get_assigned_hostnames !");
519     ret = ex.details.text.in();
520   }
521   catch (const CORBA::SystemException& ex)
522   {
523     DEBMSG("Receive SALOME System Exception: " << ex);
524     DEBMSG("Check SALOME servers...");
525     ret = "SALOME System Exception - see logs";
526   }
527   return ret;
528 }
529
530 std::string
531 BL::SALOMEServices::save_jobs(const std::string & file_name)
532 {
533   CORBA::String_var file = CORBA::string_dup(file_name.c_str());
534   std::string ret = "";
535   try
536   {
537     _salome_launcher->saveJobs(file);
538   }
539   catch (const SALOME::SALOME_Exception & ex)
540   {
541     DEBMSG("SALOME Exception in saveJobs !");
542     ret = ex.details.text.in();
543   }
544   catch (const CORBA::SystemException& ex)
545   {
546     DEBMSG("Receive CORBA System Exception: " << ex);
547     DEBMSG("Check SALOME servers...");
548     ret = "CORBA System Exception - see SALOME logs";
549   }
550   return ret;
551 }
552
553 std::string
554 BL::SALOMEServices::load_jobs(const std::string & file_name)
555 {
556   CORBA::String_var file = CORBA::string_dup(file_name.c_str());
557   std::string ret = "";
558   try
559   {
560     _salome_launcher->loadJobs(file);
561   }
562   catch (const SALOME::SALOME_Exception & ex)
563   {
564     DEBMSG("SALOME Exception in loadJobs !");
565     ret = ex.details.text.in();
566   }
567   catch (const CORBA::SystemException& ex)
568   {
569     DEBMSG("Receive CORBA System Exception: " << ex);
570     DEBMSG("Check SALOME servers...");
571     ret = "CORBA System Exception - see SALOME logs";
572   }
573   return ret;
574 }
575
576 void
577 BL::SALOMEServices::notify(const char* event_name, const char * event_data)
578 {
579   DEBMSG("Launcher event received " << event_name << " " << event_data);
580
581   std::string event(event_name);
582   std::string data(event_data);
583
584   if (event == "SAVE_JOBS")
585   {
586     _manager->launcher_event_save_jobs(data);
587   }
588   else if (event == "LOAD_JOBS")
589   {
590     _manager->launcher_event_load_jobs(data);
591   }
592   else if (event == "NEW_JOB")
593   {
594     _manager->launcher_event_new_job(data);
595   }
596   else if (event == "REMOVE_JOB")
597   {
598     _manager->launcher_event_remove_job(data);
599   }
600   else if (event == "UPDATE_JOB_STATE")
601   {
602     _manager->launcher_event_update_job_state(data);
603   }
604   else
605   {
606     DEBMSG("Unkown launcher event received");
607   }
608 }
609
610 BL::Job * 
611 BL::SALOMEServices::get_new_job(int job_number)
612 {
613   DEBMSG("Start of BL::SALOMEServices::get_new_job");
614   BL::Job * job_return = NULL;
615   Engines::JobParameters * job_parameters = NULL;
616   try
617   {
618     job_parameters = _salome_launcher->getJobParameters(job_number);
619   }
620   catch (const SALOME::SALOME_Exception & ex)
621   {
622     DEBMSG("SALOME Exception in saveJobs !");
623   }
624   catch (const CORBA::SystemException& ex)
625   {
626     DEBMSG("Receive CORBA System Exception: " << ex);
627     DEBMSG("Check SALOME servers...");
628   }
629
630   if (job_parameters)
631   {
632     job_return = new BL::Job();
633     job_return->setSalomeLauncherId(job_number);
634
635     job_return->setName(job_parameters->job_name.in());
636     job_return->setType(job_parameters->job_type.in());
637     job_return->setJobFile(job_parameters->job_file.in());
638     job_return->setEnvFile(job_parameters->env_file.in());
639     job_return->setPreCommand(job_parameters->pre_command.in());
640     job_return->setBatchQueue(job_parameters->queue.in());
641     job_return->setBatchPartition(job_parameters->partition.in());
642     job_return->setWCKey(job_parameters->wckey.in());
643     job_return->setExtraParams(job_parameters->extra_params.in());
644
645     BL::Job::FilesParam param;
646     param.result_directory = job_parameters->result_directory.in();
647     for (CORBA::ULong i = 0; i < job_parameters->in_files.length(); i++)
648       param.input_files_list.push_back(job_parameters->in_files[i].in());
649     for (CORBA::ULong i = 0; i < job_parameters->out_files.length(); i++)
650       param.output_files_list.push_back(job_parameters->out_files[i].in());
651     job_return->setFilesParameters(param);
652
653     BL::Job::BatchParam batch_param;
654     batch_param.batch_directory = job_parameters->work_directory.in();
655     batch_param.maximum_duration = job_parameters->maximum_duration.in();
656     batch_param.nb_proc = job_parameters->resource_required.nb_proc;
657     batch_param.nb_node = job_parameters->resource_required.nb_node;
658     batch_param.exclusive = job_parameters->exclusive;
659
660     if (job_parameters->mem_per_cpu != 0)
661     {
662       batch_param.mem_limit = job_parameters->mem_per_cpu;
663       batch_param.mem_req_type = BL::Job::MEM_PER_CPU;
664     }
665     else
666     {
667       batch_param.mem_limit = job_parameters->resource_required.mem_mb;
668       batch_param.mem_req_type = BL::Job::MEM_PER_NODE;
669     }
670
671     // Parameters for COORM
672     batch_param.launcher_file = job_parameters->launcher_file.in();
673     batch_param.launcher_args = job_parameters->launcher_args.in();
674
675     job_return->setBatchParameters(batch_param);
676
677     job_return->setResource(job_parameters->resource_required.name.in());
678
679     // Specific parameters
680     for (CORBA::ULong i = 0; i < job_parameters->specific_parameters.length(); i++)
681     {
682       if (std::string(job_parameters->specific_parameters[i].name.in()) == "EnableDumpYACS")
683       {
684         std::string user_value = job_parameters->specific_parameters[i].value.in();
685         std::istringstream iss(user_value);
686         int value;
687         iss >> value;
688         job_return->setDumpYACSState(value);
689       }
690       if (std::string(job_parameters->specific_parameters[i].name.in()) == "YACSDriverOptions")
691       {
692         std::string user_value = job_parameters->specific_parameters[i].value.in();
693         job_return->setYacsDriverOptions(user_value);
694       }
695       if (std::string(job_parameters->specific_parameters[i].name.in()) == "LoalLevelerJobType")
696       {
697         std::string user_value = job_parameters->specific_parameters[i].value.in();
698         job_return->setLoadLevelerJobType(user_value);
699       }
700     }
701
702     // Get current state
703     std::string result_job = job_return->setStringState(refresh_job(job_return));
704     if (result_job != "RefreshError") {}
705     else
706     {
707       // Error in getting state
708       DEBMSG("Error in getting state of the new job!");
709       delete job_return;
710       job_return = NULL;
711     }
712     delete job_parameters;
713   }
714
715   return job_return;
716 }