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
23 * BatchManager_eLSF.cxx : emulation of LSF client
25 * Auteur : Bernard SECHER - CEA DEN
26 * Mail : mailto:bernard.secher@cea.fr
27 * Date : Thu Apr 24 10:17:22 2008
32 #include "Batch_BatchManager_eClient.hxx"
33 #include "Basics_DirUtils.hxx"
47 BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host, const char* protocol, const char* mpiImpl) : BatchManager(parent, host), _protocol(protocol), _username("")
49 // instanciation of mpi implementation needed to launch executable in batch script
50 _mpiImpl = FactoryMpiImpl(mpiImpl);
54 BatchManager_eClient::~BatchManager_eClient()
60 void BatchManager_eClient::exportInputFiles(const Job& job) throw(EmulationException)
63 Parametre params = job.getParametre();
64 Versatile V = params[INFILE];
65 Versatile::iterator Vit;
68 _username = string(params[USER]);
71 if( _protocol == "rsh" )
72 copy_command = "rcp ";
73 else if( _protocol == "ssh" )
74 copy_command = "scp ";
76 throw EmulationException("Unknown protocol : only rsh and ssh are known !");
78 // First step : creating batch tmp files directory
86 command += " \"mkdir -p ";
87 command += string(params[TMPDIR]);
89 cerr << command.c_str() << endl;
90 status = system(command.c_str());
92 std::ostringstream oss;
94 std::string ex_mess("Error of connection on remote host ! status = ");
96 throw EmulationException(ex_mess.c_str());
99 // Second step : copy fileToExecute into
100 // batch tmp files directory
101 string executeFile = params[EXECUTABLE];
102 if( executeFile.size() > 0 ){
103 command = copy_command;
104 command += string(params[EXECUTABLE]);
107 command += _username;
110 command += _hostname;
112 command += string(params[TMPDIR]);
113 cerr << command.c_str() << endl;
114 status = system(command.c_str());
116 std::ostringstream oss;
118 std::string ex_mess("Error of connection on remote host ! status = ");
119 ex_mess += oss.str();
120 throw EmulationException(ex_mess.c_str());
124 // Third step : copy filesToExportList into
125 // batch tmp files directory
126 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
127 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
128 Couple inputFile = cpt;
129 command = copy_command;
130 command += inputFile.getLocal();
133 command += _username;
136 command += _hostname;
138 command += inputFile.getRemote();
139 cerr << command.c_str() << endl;
140 status = system(command.c_str());
142 std::ostringstream oss;
144 std::string ex_mess("Error of connection on remote host ! status = ");
145 ex_mess += oss.str();
146 throw EmulationException(ex_mess.c_str());
152 void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) throw(EmulationException)
157 Parametre params = job.getParametre();
158 Versatile V = params[OUTFILE];
159 Versatile::iterator Vit;
161 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
162 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
163 Couple outputFile = cpt;
164 if( _protocol == "rsh" )
166 else if( _protocol == "ssh" )
169 throw EmulationException("Unknown protocol");
171 if (_username != ""){
172 command += _username;
175 command += _hostname;
177 command += outputFile.getRemote();
179 command += directory;
180 cerr << command.c_str() << endl;
181 status = system(command.c_str());
184 // Try to get what we can (logs files)
185 // throw BatchException("Error of connection on remote host");
186 std::string mess("Copy command failed ! status is :");
187 ostringstream status_str;
188 status_str << status;
189 mess += status_str.str();
190 cerr << mess << endl;
196 MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl) throw(EmulationException)
199 return new MpiImpl_LAM();
200 else if(mpiImpl == "mpich1")
201 return new MpiImpl_MPICH1();
202 else if(mpiImpl == "mpich2")
203 return new MpiImpl_MPICH2();
204 else if(mpiImpl == "openmpi")
205 return new MpiImpl_OPENMPI();
206 else if(mpiImpl == "slurm")
207 return new MpiImpl_SLURM();
208 else if(mpiImpl == "prun")
209 return new MpiImpl_PRUN();
210 else if(mpiImpl == "nompi")
211 throw EmulationException("you must specified an mpi implementation for batch manager");
214 oss << mpiImpl << " : not yet implemented";
215 throw EmulationException(oss.str().c_str());
219 string BatchManager_eClient::BuildTemporaryFileName() const
221 //build more complex file name to support multiple salome session
222 string aFileName = Kernel_Utils::GetTmpFileName();
231 void BatchManager_eClient::RmTmpFile(std::string & TemporaryFileName)
234 string command = "del /F ";
236 string command = "rm ";
238 command += TemporaryFileName;
239 char *temp = strdup(command.c_str());
240 int lgthTemp = strlen(temp);
241 temp[lgthTemp - 3] = '*';
242 temp[lgthTemp - 2] = '\0';