1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SALOME_Launcher.hxx"
21 #include "BatchTest.hxx"
23 #include "SALOME_ContainerManager.hxx"
24 #include "Utils_CorbaException.hxx"
31 #include <sys/types.h>
36 const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher";
38 //=============================================================================
42 * Define a CORBA single thread policy for the server, which avoid to deal
43 * with non thread-safe usage like Change_Directory in SALOME naming service
45 //=============================================================================
47 SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l()
49 MESSAGE("SALOME_Launcher constructor");
50 _NS = new SALOME_NamingService(orb);
51 _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
52 _l.SetResourcesManager(_ResManager->GetImpl());
53 _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS);
54 _ResManager->_remove_ref();
55 _ContManager->_remove_ref();
57 _orb = CORBA::ORB::_duplicate(orb) ;
58 _poa = PortableServer::POA::_duplicate(poa) ;
59 PortableServer::ObjectId_var id = _poa->activate_object(this);
60 CORBA::Object_var obj = _poa->id_to_reference(id);
61 Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj);
63 _NS->Register(refContMan,_LauncherNameInNS);
64 MESSAGE("SALOME_Launcher constructor end");
67 //=============================================================================
71 //=============================================================================
73 SALOME_Launcher::~SALOME_Launcher()
75 MESSAGE("destructor");
79 //=============================================================================
81 * shutdown all the containers, then the ContainerManager servant
83 //=============================================================================
85 void SALOME_Launcher::Shutdown()
88 _NS->Destroy_Name(_LauncherNameInNS);
89 _ContManager->Shutdown();
90 _ResManager->Shutdown();
91 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
92 _poa->deactivate_object(oid);
94 if(!CORBA::is_nil(_orb))
98 //=============================================================================
100 * Returns the PID of the process
102 //=============================================================================
103 CORBA::Long SALOME_Launcher::getPID()
107 (CORBA::Long)getpid();
109 (CORBA::Long)_getpid();
114 //=============================================================================
116 * Submit a batch job on a cluster and returns the JobId
117 * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster
118 * \param filesToExport : to export on the batch cluster
119 * \param NumberOfProcessors : Number of processors needed on the batch cluster
120 * \param params : Constraints for the choice of the batch cluster
122 //=============================================================================
123 CORBA::Long SALOME_Launcher::submitSalomeJob( const char * fileToExecute ,
124 const Engines::FilesList& filesToExport ,
125 const Engines::FilesList& filesToImport ,
126 const Engines::BatchParameters& batch_params,
127 const Engines::MachineParameters& params)
129 MESSAGE("BEGIN OF SALOME_Launcher::submitSalomeJob");
133 p.hostname = params.hostname;
135 p.nb_node = params.nb_node;
136 p.nb_proc_per_node = params.nb_proc_per_node;
137 p.cpu_clock = params.cpu_clock;
138 p.mem_mb = params.mem_mb;
141 bp.batch_directory = batch_params.batch_directory;
142 bp.expected_during_time = batch_params.expected_during_time;
143 bp.mem = batch_params.mem;
144 bp.nb_proc = batch_params.nb_proc;
147 for(int i=0;i<filesToExport.length();i++)
148 efl.push_back(string(filesToExport[i]));
151 for(int i=0;i<filesToImport.length();i++)
152 ifl.push_back(string(filesToImport[i]));
155 jobId = _l.submitSalomeJob(fileToExecute,efl,ifl,bp,p);
157 catch(const LauncherException &ex){
158 INFOS(ex.msg.c_str());
159 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
164 //=============================================================================
166 * the test batch configuration
167 * \param params : The batch cluster
169 //=============================================================================
171 SALOME_Launcher::testBatch(const Engines::MachineParameters& params)
173 MESSAGE("BEGIN OF SALOME_Launcher::testBatch");
174 CORBA::Boolean rtn = false;
177 // find a cluster matching the structure params
178 Engines::CompoList aCompoList ;
179 Engines::MachineList *aMachineList = _ResManager->GetFittingResources(params, aCompoList);
180 if (aMachineList->length() == 0)
181 throw SALOME_Exception("No resources have been found with your parameters");
183 const Engines::MachineParameters* p = _ResManager->GetMachineParameters((*aMachineList)[0]);
184 string clustername(p->alias);
185 INFOS("Choose cluster" << clustername);
193 catch(const SALOME_Exception &ex){
195 THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::INTERNAL_ERROR);
200 //=============================================================================
202 * Query a batch job on a cluster and returns the status of job
203 * \param jobId : identification of Salome job
204 * \param params : Constraints for the choice of the batch cluster
206 //=============================================================================
207 char* SALOME_Launcher::querySalomeJob( const CORBA::Long jobId,
208 const Engines::MachineParameters& params)
212 p.hostname = params.hostname;
214 p.nb_node = params.nb_node;
215 p.nb_proc_per_node = params.nb_proc_per_node;
216 p.cpu_clock = params.cpu_clock;
217 p.mem_mb = params.mem_mb;
220 status = _l.querySalomeJob(jobId,p);
222 catch(const LauncherException &ex){
223 INFOS("Caught exception.");
224 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
226 return CORBA::string_dup(status.c_str());
229 //=============================================================================
231 * Delete a batch job on a cluster
232 * \param jobId : identification of Salome job
233 * \param params : Constraints for the choice of the batch cluster
235 //=============================================================================
236 void SALOME_Launcher::deleteSalomeJob( const CORBA::Long jobId,
237 const Engines::MachineParameters& params)
240 p.hostname = params.hostname;
242 p.nb_node = params.nb_node;
243 p.nb_proc_per_node = params.nb_proc_per_node;
244 p.cpu_clock = params.cpu_clock;
245 p.mem_mb = params.mem_mb;
248 _l.deleteSalomeJob(jobId,p);
250 catch(const LauncherException &ex){
251 INFOS("Caught exception.");
252 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
256 //=============================================================================
258 * Get result files of job on a cluster
259 * \param jobId : identification of Salome job
260 * \param params : Constraints for the choice of the batch cluster
262 //=============================================================================
263 void SALOME_Launcher::getResultSalomeJob( const char *directory,
264 const CORBA::Long jobId,
265 const Engines::MachineParameters& params)
268 p.hostname = params.hostname;
270 p.nb_node = params.nb_node;
271 p.nb_proc_per_node = params.nb_proc_per_node;
272 p.cpu_clock = params.cpu_clock;
273 p.mem_mb = params.mem_mb;
276 _l.getResultSalomeJob( directory, jobId, p );
278 catch(const LauncherException &ex){
279 INFOS("Caught exception.");
280 THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);