1 // Copyright (C) 2007-2008 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
22 #include "SALOME_Launcher.hxx"
23 #include "BatchTest.hxx"
25 #include "SALOME_ContainerManager.hxx"
26 #include "Utils_CorbaException.hxx"
29 #include "Launcher_Job_Command.hxx"
30 #include "Launcher_Job_YACSFile.hxx"
31 #include "Launcher_Job_PythonSALOME.hxx"
38 #include <sys/types.h>
43 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
45 //=============================================================================
50 //=============================================================================
51 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
53 MESSAGE("SALOME_Launcher constructor");
54 _NS = new SALOME_NamingService(orb);
55 _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
56 _l.SetResourcesManager(_ResManager->GetImpl());
57 _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS);
58 _ResManager->_remove_ref();
59 _ContManager->_remove_ref();
61 _orb = CORBA::ORB::_duplicate(orb) ;
62 _poa = PortableServer::POA::_duplicate(poa) ;
63 PortableServer::ObjectId_var id = _poa->activate_object(this);
64 CORBA::Object_var obj = _poa->id_to_reference(id);
65 Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
67 _NS->Register(refContMan,_LauncherNameInNS);
68 MESSAGE("SALOME_Launcher constructor end");
71 //=============================================================================
75 //=============================================================================
76 SALOME_Launcher::~SALOME_Launcher()
78 MESSAGE("SALOME_Launcher destructor");
80 MESSAGE("SALOME_Launcher destructor end");
85 SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
87 std::string job_type = job_parameters.job_type.in();
89 if (job_type != "command" and job_type != "yacs_file" and job_type != "python_salome")
91 std::string message("SALOME_Launcher::createJob: bad job type: ");
93 THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
96 Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
98 if (job_type == "command")
99 new_job = new Launcher::Job_Command();
100 else if (job_type == "yacs_file")
101 new_job = new Launcher::Job_YACSFile();
102 else if (job_type == "python_salome")
103 new_job = new Launcher::Job_PythonSALOME();
106 std::string work_directory = job_parameters.work_directory.in();
107 std::string local_directory = job_parameters.local_directory.in();
108 std::string result_directory = job_parameters.result_directory.in();
109 new_job->setWorkDirectory(work_directory);
110 new_job->setLocalDirectory(local_directory);
111 new_job->setResultDirectory(result_directory);
114 std::string job_file = job_parameters.job_file.in();
117 new_job->setJobFile(job_file);
119 catch(const LauncherException &ex)
121 INFOS(ex.msg.c_str());
122 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
126 std::string env_file = job_parameters.env_file.in();
127 new_job->setEnvFile(env_file);
128 for (CORBA::ULong i = 0; i < job_parameters.in_files.length(); i++)
129 new_job->add_in_file(job_parameters.in_files[i].in());
130 for (CORBA::ULong i = 0; i < job_parameters.out_files.length(); i++)
131 new_job->add_out_file(job_parameters.out_files[i].in());
133 // Expected During Time
136 std::string maximum_duration = job_parameters.maximum_duration.in();
137 new_job->setMaximumDuration(maximum_duration);
139 catch(const LauncherException &ex){
140 INFOS(ex.msg.c_str());
141 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
145 std::string queue = job_parameters.queue.in();
147 new_job->setQueue(queue);
149 // Resources requirements
153 p.name = job_parameters.resource_required.name;
154 p.hostname = job_parameters.resource_required.hostname;
155 p.OS = job_parameters.resource_required.OS;
156 p.nb_proc = job_parameters.resource_required.nb_proc;
157 p.nb_node = job_parameters.resource_required.nb_node;
158 p.nb_proc_per_node = job_parameters.resource_required.nb_proc_per_node;
159 p.cpu_clock = job_parameters.resource_required.cpu_clock;
160 p.mem_mb = job_parameters.resource_required.mem_mb;
161 new_job->setResourceRequiredParams(p);
163 catch(const LauncherException &ex){
164 INFOS(ex.msg.c_str());
165 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
170 _l.createJob(new_job);
172 catch(const LauncherException &ex)
174 INFOS(ex.msg.c_str());
175 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
177 return new_job->getNumber();
181 SALOME_Launcher::launchJob(CORBA::Long job_id)
185 _l.launchJob(job_id);
187 catch(const LauncherException &ex)
189 INFOS(ex.msg.c_str());
190 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
195 SALOME_Launcher::getJobState(CORBA::Long job_id)
200 result = _l.getJobState(job_id);
202 catch(const LauncherException &ex)
204 INFOS(ex.msg.c_str());
205 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
207 return CORBA::string_dup(result.c_str());
211 SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
215 _l.getJobResults(job_id, directory);
217 catch(const LauncherException &ex)
219 INFOS(ex.msg.c_str());
220 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
225 SALOME_Launcher::removeJob(CORBA::Long job_id)
229 _l.removeJob(job_id);
231 catch(const LauncherException &ex)
233 INFOS(ex.msg.c_str());
234 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
238 //=============================================================================
240 * Create a job in the launcher with a file
241 * \param xmlExecuteFile : .xml to parse that contains job description
242 * \param clusterName : machine choosed
244 //=============================================================================
246 SALOME_Launcher::createJobWithFile(const char * xmlExecuteFile,
247 const char * clusterName)
251 jobId = _l.createJobWithFile(xmlExecuteFile, clusterName);
253 catch(const LauncherException &ex){
254 INFOS(ex.msg.c_str());
255 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
261 //=============================================================================
263 * the test batch configuration
264 * \param params : The batch cluster
266 //=============================================================================
268 SALOME_Launcher::testBatch(const Engines::ResourceParameters& params)
270 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
271 CORBA::Boolean rtn = false;
274 // find a cluster matching the structure params
275 Engines::ResourceList *aMachineList = _ResManager->GetFittingResources(params);
276 if (aMachineList->length() == 0)
277 throw SALOME_Exception("No resources have been found with your parameters");
279 const Engines::ResourceDefinition* p = _ResManager->GetResourceDefinition((*aMachineList)[0]);
280 string resource_name(p->name);
281 INFOS("Choose resource for test: " << resource_name);
289 catch(const LauncherException &ex){
290 INFOS(ex.msg.c_str());
291 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
296 //=============================================================================
298 * shutdown all the containers, then the ContainerManager servant
300 //=============================================================================
301 void SALOME_Launcher::Shutdown()
304 _NS->Destroy_Name(_LauncherNameInNS);
305 _ContManager->Shutdown();
306 _ResManager->Shutdown();
307 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
308 _poa->deactivate_object(oid);
309 if(!CORBA::is_nil(_orb))
313 //=============================================================================
315 * Returns the PID of the process
317 //=============================================================================
318 CORBA::Long SALOME_Launcher::getPID()
322 (CORBA::Long)getpid();
324 (CORBA::Long)_getpid();