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"
33 #include <sys/types.h>
38 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
40 //=============================================================================
44 * Define a CORBA single thread policy for the server, which avoid to deal
45 * with non thread-safe usage like Change_Directory in SALOME naming service
47 //=============================================================================
49 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
51 MESSAGE("SALOME_Launcher constructor");
52 _NS = new SALOME_NamingService(orb);
53 _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
54 _l.SetResourcesManager(_ResManager->GetImpl());
55 _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS);
56 _ResManager->_remove_ref();
57 _ContManager->_remove_ref();
59 _orb = CORBA::ORB::_duplicate(orb) ;
60 _poa = PortableServer::POA::_duplicate(poa) ;
61 PortableServer::ObjectId_var id = _poa->activate_object(this);
62 CORBA::Object_var obj = _poa->id_to_reference(id);
63 Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
65 _NS->Register(refContMan,_LauncherNameInNS);
66 MESSAGE("SALOME_Launcher constructor end");
69 //=============================================================================
73 //=============================================================================
75 SALOME_Launcher::~SALOME_Launcher()
77 MESSAGE("destructor");
81 //=============================================================================
83 * shutdown all the containers, then the ContainerManager servant
85 //=============================================================================
87 void SALOME_Launcher::Shutdown()
90 _NS->Destroy_Name(_LauncherNameInNS);
91 _ContManager->Shutdown();
92 _ResManager->Shutdown();
93 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
94 _poa->deactivate_object(oid);
95 if(!CORBA::is_nil(_orb))
99 //=============================================================================
101 * Returns the PID of the process
103 //=============================================================================
104 CORBA::Long SALOME_Launcher::getPID()
108 (CORBA::Long)getpid();
110 (CORBA::Long)_getpid();
115 //=============================================================================
117 * Submit a batch job on a cluster and returns the JobId
118 * \param xmlExecuteFile : .xml to parse to execute on the batch cluster
119 * \param clusterName : cluster name
121 //=============================================================================
122 CORBA::Long SALOME_Launcher::submitJob(const char * xmlExecuteFile,
123 const char * clusterName)
128 jobId = _l.submitJob(xmlExecuteFile,clusterName);
130 catch(const LauncherException &ex){
131 INFOS(ex.msg.c_str());
132 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
137 //=============================================================================
139 * Submit a batch job on a cluster and returns the JobId
140 * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster
141 * \param filesToExport : to export on the batch cluster
142 * \param NumberOfProcessors : Number of processors needed on the batch cluster
143 * \param params : Constraints for the choice of the batch cluster
145 //=============================================================================
146 CORBA::Long SALOME_Launcher::submitSalomeJob( const char * fileToExecute ,
147 const Engines::FilesList& filesToExport ,
148 const Engines::FilesList& filesToImport ,
149 const Engines::BatchParameters& batch_params,
150 const Engines::MachineParameters& params)
152 MESSAGE("BEGIN OF SALOME_Launcher::submitSalomeJob");
156 p.hostname = params.hostname;
158 p.nb_node = params.nb_node;
159 p.nb_proc_per_node = params.nb_proc_per_node;
160 p.cpu_clock = params.cpu_clock;
161 p.mem_mb = params.mem_mb;
164 bp.batch_directory = batch_params.batch_directory;
165 bp.expected_during_time = batch_params.expected_during_time;
166 bp.mem = batch_params.mem;
167 bp.nb_proc = batch_params.nb_proc;
170 for(int i=0;i<filesToExport.length();i++)
171 efl.push_back(string(filesToExport[i]));
174 for(int i=0;i<filesToImport.length();i++)
175 ifl.push_back(string(filesToImport[i]));
178 jobId = _l.submitSalomeJob(fileToExecute,efl,ifl,bp,p);
180 catch(const LauncherException &ex){
181 INFOS(ex.msg.c_str());
182 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
187 //=============================================================================
189 * the test batch configuration
190 * \param params : The batch cluster
192 //=============================================================================
194 SALOME_Launcher::testBatch(const Engines::MachineParameters& params)
196 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
197 CORBA::Boolean rtn = false;
200 // find a cluster matching the structure params
201 Engines::MachineList *aMachineList = _ResManager->GetFittingResources(params);
202 if (aMachineList->length() == 0)
203 throw SALOME_Exception("No resources have been found with your parameters");
205 const Engines::MachineDefinition* p = _ResManager->GetMachineParameters((*aMachineList)[0]);
206 string clustername(p->alias);
207 INFOS("Choose cluster" << clustername);
215 catch(const LauncherException &ex){
216 INFOS(ex.msg.c_str());
217 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
222 //=============================================================================
224 * Query a batch job on a cluster and returns the status of job
225 * \param jobId : identification of Salome job
226 * \param params : Constraints for the choice of the batch cluster
228 //=============================================================================
229 char* SALOME_Launcher::queryJob( const CORBA::Long jobId,
230 const Engines::MachineParameters& params)
234 p.hostname = params.hostname;
236 p.nb_node = params.nb_node;
237 p.nb_proc_per_node = params.nb_proc_per_node;
238 p.cpu_clock = params.cpu_clock;
239 p.mem_mb = params.mem_mb;
242 status = _l.queryJob(jobId,p);
244 catch(const LauncherException &ex){
245 INFOS(ex.msg.c_str());
246 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
248 return CORBA::string_dup(status.c_str());
251 //=============================================================================
253 * Delete a batch job on a cluster
254 * \param jobId : identification of Salome job
255 * \param params : Constraints for the choice of the batch cluster
257 //=============================================================================
258 void SALOME_Launcher::deleteJob( const CORBA::Long jobId,
259 const Engines::MachineParameters& params)
262 p.hostname = params.hostname;
264 p.nb_node = params.nb_node;
265 p.nb_proc_per_node = params.nb_proc_per_node;
266 p.cpu_clock = params.cpu_clock;
267 p.mem_mb = params.mem_mb;
270 _l.deleteJob(jobId,p);
272 catch(const LauncherException &ex){
273 INFOS("Caught exception.");
274 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
278 //=============================================================================
280 * Get result files of job on a cluster
281 * \param jobId : identification of Salome job
282 * \param params : Constraints for the choice of the batch cluster
284 //=============================================================================
285 void SALOME_Launcher::getResultsJob( const char *directory,
286 const CORBA::Long jobId,
287 const Engines::MachineParameters& params)
290 p.hostname = params.hostname;
292 p.nb_node = params.nb_node;
293 p.nb_proc_per_node = params.nb_proc_per_node;
294 p.cpu_clock = params.cpu_clock;
295 p.mem_mb = params.mem_mb;
298 _l.getResultsJob( directory, jobId, p );
300 catch(const LauncherException &ex){
301 INFOS("Caught exception.");
302 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);