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);
96 if(!CORBA::is_nil(_orb))
100 //=============================================================================
102 * Returns the PID of the process
104 //=============================================================================
105 CORBA::Long SALOME_Launcher::getPID()
109 (CORBA::Long)getpid();
111 (CORBA::Long)_getpid();
116 //=============================================================================
118 * Submit a batch job on a cluster and returns the JobId
119 * \param xmlExecuteFile : .xml to parse to execute on the batch cluster
120 * \param clusterName : cluster name
122 //=============================================================================
123 CORBA::Long SALOME_Launcher::submitJob(const char * xmlExecuteFile,
124 const char * clusterName)
129 jobId = _l.submitJob(xmlExecuteFile,clusterName);
131 catch(const LauncherException &ex){
132 INFOS(ex.msg.c_str());
133 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
138 //=============================================================================
140 * Submit a batch job on a cluster and returns the JobId
141 * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster
142 * \param filesToExport : to export on the batch cluster
143 * \param NumberOfProcessors : Number of processors needed on the batch cluster
144 * \param params : Constraints for the choice of the batch cluster
146 //=============================================================================
147 CORBA::Long SALOME_Launcher::submitSalomeJob( const char * fileToExecute ,
148 const Engines::FilesList& filesToExport ,
149 const Engines::FilesList& filesToImport ,
150 const Engines::BatchParameters& batch_params,
151 const Engines::MachineParameters& params)
153 MESSAGE("BEGIN OF SALOME_Launcher::submitSalomeJob");
157 p.hostname = params.hostname;
159 p.nb_node = params.nb_node;
160 p.nb_proc_per_node = params.nb_proc_per_node;
161 p.cpu_clock = params.cpu_clock;
162 p.mem_mb = params.mem_mb;
165 bp.batch_directory = batch_params.batch_directory;
166 bp.expected_during_time = batch_params.expected_during_time;
167 bp.mem = batch_params.mem;
168 bp.nb_proc = batch_params.nb_proc;
171 for(int i=0;i<filesToExport.length();i++)
172 efl.push_back(string(filesToExport[i]));
175 for(int i=0;i<filesToImport.length();i++)
176 ifl.push_back(string(filesToImport[i]));
179 jobId = _l.submitSalomeJob(fileToExecute,efl,ifl,bp,p);
181 catch(const LauncherException &ex){
182 INFOS(ex.msg.c_str());
183 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
188 //=============================================================================
190 * the test batch configuration
191 * \param params : The batch cluster
193 //=============================================================================
195 SALOME_Launcher::testBatch(const Engines::MachineParameters& params)
197 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
198 CORBA::Boolean rtn = false;
201 // find a cluster matching the structure params
202 Engines::CompoList aCompoList ;
203 Engines::MachineList *aMachineList = _ResManager->GetFittingResources(params, aCompoList);
204 if (aMachineList->length() == 0)
205 throw SALOME_Exception("No resources have been found with your parameters");
207 const Engines::MachineParameters* p = _ResManager->GetMachineParameters((*aMachineList)[0]);
208 string clustername(p->alias);
209 INFOS("Choose cluster" << clustername);
217 catch(const LauncherException &ex){
218 INFOS(ex.msg.c_str());
219 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
224 //=============================================================================
226 * Query a batch job on a cluster and returns the status of job
227 * \param jobId : identification of Salome job
228 * \param params : Constraints for the choice of the batch cluster
230 //=============================================================================
231 char* SALOME_Launcher::queryJob( const CORBA::Long jobId,
232 const Engines::MachineParameters& params)
236 p.hostname = params.hostname;
238 p.nb_node = params.nb_node;
239 p.nb_proc_per_node = params.nb_proc_per_node;
240 p.cpu_clock = params.cpu_clock;
241 p.mem_mb = params.mem_mb;
244 status = _l.queryJob(jobId,p);
246 catch(const LauncherException &ex){
247 INFOS(ex.msg.c_str());
248 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
250 return CORBA::string_dup(status.c_str());
253 //=============================================================================
255 * Delete a batch job on a cluster
256 * \param jobId : identification of Salome job
257 * \param params : Constraints for the choice of the batch cluster
259 //=============================================================================
260 void SALOME_Launcher::deleteJob( const CORBA::Long jobId,
261 const Engines::MachineParameters& params)
264 p.hostname = params.hostname;
266 p.nb_node = params.nb_node;
267 p.nb_proc_per_node = params.nb_proc_per_node;
268 p.cpu_clock = params.cpu_clock;
269 p.mem_mb = params.mem_mb;
272 _l.deleteJob(jobId,p);
274 catch(const LauncherException &ex){
275 INFOS("Caught exception.");
276 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
280 //=============================================================================
282 * Get result files of job on a cluster
283 * \param jobId : identification of Salome job
284 * \param params : Constraints for the choice of the batch cluster
286 //=============================================================================
287 void SALOME_Launcher::getResultsJob( const char *directory,
288 const CORBA::Long jobId,
289 const Engines::MachineParameters& params)
292 p.hostname = params.hostname;
294 p.nb_node = params.nb_node;
295 p.nb_proc_per_node = params.nb_proc_per_node;
296 p.cpu_clock = params.cpu_clock;
297 p.mem_mb = params.mem_mb;
300 _l.getResultsJob( directory, jobId, p );
302 catch(const LauncherException &ex){
303 INFOS("Caught exception.");
304 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);