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
21 * BatchManager_eLSF.cxx : emulation of LSF client
23 * Auteur : Bernard SECHER - CEA DEN
24 * Mail : mailto:bernard.secher@cea.fr
25 * Date : Thu Apr 24 10:17:22 2008
30 #include "Batch_BatchManager_eClient.hxx"
31 #include "Basics_DirUtils.hxx"
43 BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host, const char* protocol, const char* mpiImpl) : BatchManager(parent, host), _protocol(protocol), _username("")
45 // instanciation of mpi implementation needed to launch executable in batch script
46 _mpiImpl = FactoryMpiImpl(mpiImpl);
50 BatchManager_eClient::~BatchManager_eClient()
56 void BatchManager_eClient::exportInputFiles(const Job& job) throw(EmulationException)
59 Parametre params = job.getParametre();
60 Versatile V = params[INFILE];
61 Versatile::iterator Vit;
64 _username = string(params[USER]);
67 if( _protocol == "rsh" )
68 copy_command = "rcp ";
69 else if( _protocol == "ssh" )
70 copy_command = "scp ";
72 throw EmulationException("Unknown protocol : only rsh and ssh are known !");
74 // First step : creating batch tmp files directory
82 command += " \"mkdir -p ";
83 command += string(params[TMPDIR]);
85 cerr << command.c_str() << endl;
86 status = system(command.c_str());
88 std::ostringstream oss;
90 std::string ex_mess("Error of connection on remote host ! status = ");
92 throw EmulationException(ex_mess.c_str());
95 // Second step : copy fileToExecute into
96 // batch tmp files directory
97 command = copy_command;
98 command += string(params[EXECUTABLE]);
101 command += _username;
104 command += _hostname;
106 command += string(params[TMPDIR]);
107 cerr << command.c_str() << endl;
108 status = system(command.c_str());
110 std::ostringstream oss;
112 std::string ex_mess("Error of connection on remote host ! status = ");
113 ex_mess += oss.str();
114 throw EmulationException(ex_mess.c_str());
117 // Third step : copy filesToExportList into
118 // batch tmp files directory
119 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
120 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
121 Couple inputFile = cpt;
122 command = copy_command;
123 command += inputFile.getLocal();
126 command += _username;
129 command += _hostname;
131 command += inputFile.getRemote();
132 cerr << command.c_str() << endl;
133 status = system(command.c_str());
135 std::ostringstream oss;
137 std::string ex_mess("Error of connection on remote host ! status = ");
138 ex_mess += oss.str();
139 throw EmulationException(ex_mess.c_str());
145 void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) throw(EmulationException)
150 Parametre params = job.getParametre();
151 Versatile V = params[OUTFILE];
152 Versatile::iterator Vit;
154 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
155 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
156 Couple outputFile = cpt;
157 if( _protocol == "rsh" )
159 else if( _protocol == "ssh" )
162 throw EmulationException("Unknown protocol");
164 if (_username != ""){
165 command += _username;
168 command += _hostname;
170 command += outputFile.getRemote();
172 command += directory;
173 cerr << command.c_str() << endl;
174 status = system(command.c_str());
177 // Try to get what we can (logs files)
178 // throw BatchException("Error of connection on remote host");
179 std::string mess("Copy command failed ! status is :");
180 ostringstream status_str;
181 status_str << status;
182 mess += status_str.str();
183 cerr << mess << endl;
189 MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl) throw(EmulationException)
192 return new MpiImpl_LAM();
193 else if(mpiImpl == "mpich1")
194 return new MpiImpl_MPICH1();
195 else if(mpiImpl == "mpich2")
196 return new MpiImpl_MPICH2();
197 else if(mpiImpl == "openmpi")
198 return new MpiImpl_OPENMPI();
199 else if(mpiImpl == "slurm")
200 return new MpiImpl_SLURM();
203 oss << mpiImpl << " : not yet implemented";
204 throw EmulationException(oss.str().c_str());
208 string BatchManager_eClient::BuildTemporaryFileName() const
210 //build more complex file name to support multiple salome session
211 string aFileName = Kernel_Utils::GetTmpFileName();
220 void BatchManager_eClient::RmTmpFile(std::string & TemporaryFileName)
223 string command = "del /F ";
225 string command = "rm ";
227 command += TemporaryFileName;
228 char *temp = strdup(command.c_str());
229 int lgthTemp = strlen(temp);
230 temp[lgthTemp - 3] = '*';
231 temp[lgthTemp - 2] = '\0';