1 // Copyright (C) 2007-2010 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 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
44 //=============================================================================
49 //=============================================================================
50 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
52 MESSAGE("SALOME_Launcher constructor");
53 _NS = new SALOME_NamingService(orb);
54 _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
55 _l.SetResourcesManager(_ResManager->GetImpl());
56 _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS);
57 _ResManager->_remove_ref();
58 _ContManager->_remove_ref();
60 _orb = CORBA::ORB::_duplicate(orb) ;
61 _poa = PortableServer::POA::_duplicate(poa) ;
62 PortableServer::ObjectId_var id = _poa->activate_object(this);
63 CORBA::Object_var obj = _poa->id_to_reference(id);
64 Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
66 _NS->Register(refContMan,_LauncherNameInNS);
67 MESSAGE("SALOME_Launcher constructor end");
70 //=============================================================================
74 //=============================================================================
75 SALOME_Launcher::~SALOME_Launcher()
77 MESSAGE("SALOME_Launcher destructor");
79 MESSAGE("SALOME_Launcher destructor end");
84 SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
86 std::string job_type = job_parameters.job_type.in();
88 if (job_type != "command" && job_type != "yacs_file" && job_type != "python_salome")
90 std::string message("SALOME_Launcher::createJob: bad job type: ");
92 THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
95 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
97 if (job_type == "command")
98 new_job = new Launcher::Job_Command();
99 else if (job_type == "yacs_file")
100 new_job = new Launcher::Job_YACSFile();
101 else if (job_type == "python_salome")
102 new_job = new Launcher::Job_PythonSALOME();
105 std::string work_directory = job_parameters.work_directory.in();
106 std::string local_directory = job_parameters.local_directory.in();
107 std::string result_directory = job_parameters.result_directory.in();
108 new_job->setWorkDirectory(work_directory);
109 new_job->setLocalDirectory(local_directory);
110 new_job->setResultDirectory(result_directory);
113 std::string job_file = job_parameters.job_file.in();
116 new_job->setJobFile(job_file);
118 catch(const LauncherException &ex)
120 INFOS(ex.msg.c_str());
121 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
125 std::string env_file = job_parameters.env_file.in();
126 new_job->setEnvFile(env_file);
127 for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
128 new_job->add_in_file(job_parameters.in_files[i].in());
129 for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
130 new_job->add_out_file(job_parameters.out_files[i].in());
132 // Expected During Time
135 std::string maximum_duration = job_parameters.maximum_duration.in();
136 new_job->setMaximumDuration(maximum_duration);
138 catch(const LauncherException &ex){
139 INFOS(ex.msg.c_str());
140 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
144 std::string queue = job_parameters.queue.in();
146 new_job->setQueue(queue);
148 // Resources requirements
152 p.name = job_parameters.resource_required.name;
153 p.hostname = job_parameters.resource_required.hostname;
154 p.OS = job_parameters.resource_required.OS;
155 p.nb_proc = job_parameters.resource_required.nb_proc;
156 p.nb_node = job_parameters.resource_required.nb_node;
157 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
158 p.cpu_clock = job_parameters.resource_required.cpu_clock;
159 p.mem_mb = job_parameters.resource_required.mem_mb;
160 new_job->setResourceRequiredParams(p);
162 catch(const LauncherException &ex){
163 INFOS(ex.msg.c_str());
164 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
169 _l.createJob(new_job);
171 catch(const LauncherException &ex)
173 INFOS(ex.msg.c_str());
174 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
176 return new_job->getNumber();
180 SALOME_Launcher::launchJob(CORBA::Long job_id)
184 _l.launchJob(job_id);
186 catch(const LauncherException &ex)
188 INFOS(ex.msg.c_str());
189 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
194 SALOME_Launcher::getJobState(CORBA::Long job_id)
199 result = _l.getJobState(job_id);
201 catch(const LauncherException &ex)
203 INFOS(ex.msg.c_str());
204 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
206 return CORBA::string_dup(result.c_str());
210 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
214 _l.getJobResults(job_id, directory);
216 catch(const LauncherException &ex)
218 INFOS(ex.msg.c_str());
219 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
224 SALOME_Launcher::removeJob(CORBA::Long job_id)
228 _l.removeJob(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);
237 //=============================================================================
239 * Create a job in the launcher with a file
240 * \param xmlExecuteFile : .xml to parse that contains job description
241 * \param clusterName : machine choosed
243 //=============================================================================
245 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
246 const char * clusterName)
250 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
252 catch(const LauncherException &ex){
253 INFOS(ex.msg.c_str());
254 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
260 //=============================================================================
262 * the test batch configuration
263 * \param params : The batch cluster
265 //=============================================================================
267 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
269 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
270 CORBA::Boolean rtn = false;
273 // find a cluster matching the structure params
274 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(params);
275 if (aMachineList->length() == 0)
276 throw SALOME_Exception("No resources have been found with your parameters");
278 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
279 std::string resource_name(p->name);
280 INFOS("Choose resource for test: " << resource_name);
288 catch(const LauncherException &ex){
289 INFOS(ex.msg.c_str());
290 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
295 //=============================================================================
297 * shutdown all the containers, then the ContainerManager servant
299 //=============================================================================
300 void SALOME_Launcher::Shutdown()
303 _NS->Destroy_Name(_LauncherNameInNS);
304 _ContManager->Shutdown();
305 _ResManager->Shutdown();
306 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
307 _poa->deactivate_object(oid);
308 if(!CORBA::is_nil(_orb))
312 //=============================================================================
314 * Returns the PID of the process
316 //=============================================================================
317 CORBA::Long SALOME_Launcher::getPID()
321 (CORBA::Long)getpid();
323 (CORBA::Long)_getpid();