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
34 #include "Batch_BatchManager_eClient.hxx"
39 BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host, const char* protocol, const char* mpiImpl) : BatchManager(parent, host), _protocol(protocol), _username("")
41 // instanciation of mpi implementation needed to launch executable in batch script
42 _mpiImpl = FactoryMpiImpl(mpiImpl);
46 BatchManager_eClient::~BatchManager_eClient()
52 void BatchManager_eClient::exportInputFiles(const Job& job) throw(EmulationException)
55 Parametre params = job.getParametre();
56 Versatile V = params[INFILE];
57 Versatile::iterator Vit;
60 _username = string(params[USER]);
63 if( _protocol == "rsh" )
64 copy_command = "rcp ";
65 else if( _protocol == "ssh" )
66 copy_command = "scp ";
68 throw EmulationException("Unknown protocol : only rsh and ssh are known !");
70 // First step : creating batch tmp files directory
78 command += " \"mkdir -p ";
79 command += string(params[TMPDIR]);
81 cerr << command.c_str() << endl;
82 status = system(command.c_str());
84 std::ostringstream oss;
86 std::string ex_mess("Error of connection on remote host ! status = ");
88 throw EmulationException(ex_mess.c_str());
91 // Second step : copy fileToExecute into
92 // batch tmp files directory
93 command = copy_command;
94 command += string(params[EXECUTABLE]);
100 command += _hostname;
102 command += string(params[TMPDIR]);
103 cerr << command.c_str() << endl;
104 status = system(command.c_str());
106 std::ostringstream oss;
108 std::string ex_mess("Error of connection on remote host ! status = ");
109 ex_mess += oss.str();
110 throw EmulationException(ex_mess.c_str());
113 // Third step : copy filesToExportList into
114 // batch tmp files directory
115 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
116 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
117 Couple inputFile = cpt;
118 command = copy_command;
119 command += inputFile.getLocal();
122 command += _username;
125 command += _hostname;
127 command += inputFile.getRemote();
128 cerr << command.c_str() << endl;
129 status = system(command.c_str());
131 std::ostringstream oss;
133 std::string ex_mess("Error of connection on remote host ! status = ");
134 ex_mess += oss.str();
135 throw EmulationException(ex_mess.c_str());
141 void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) throw(EmulationException)
146 Parametre params = job.getParametre();
147 Versatile V = params[OUTFILE];
148 Versatile::iterator Vit;
150 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
151 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
152 Couple outputFile = cpt;
153 if( _protocol == "rsh" )
155 else if( _protocol == "ssh" )
158 throw EmulationException("Unknown protocol");
160 if (_username != ""){
161 command += _username;
164 command += _hostname;
166 command += outputFile.getRemote();
168 command += directory;
169 cerr << command.c_str() << endl;
170 status = system(command.c_str());
173 // Try to get what we can (logs files)
174 // throw BatchException("Error of connection on remote host");
175 std::string mess("Copy command failed ! status is :");
176 ostringstream status_str;
177 status_str << status;
178 mess += status_str.str();
179 cerr << mess << endl;
185 MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl) throw(EmulationException)
188 return new MpiImpl_LAM();
189 else if(mpiImpl == "mpich1")
190 return new MpiImpl_MPICH1();
191 else if(mpiImpl == "mpich2")
192 return new MpiImpl_MPICH2();
193 else if(mpiImpl == "openmpi")
194 return new MpiImpl_OPENMPI();
195 else if(mpiImpl == "slurm")
196 return new MpiImpl_SLURM();
199 oss << mpiImpl << " : not yet implemented";
200 throw EmulationException(oss.str().c_str());
204 string BatchManager_eClient::BuildTemporaryFileName() const
206 //build more complex file name to support multiple salome session
207 string aFileName = OpUtil_Dir::GetTmpFileName();
216 void BatchManager_eClient::RmTmpFile(std::string & TemporaryFileName)
219 string command = "del /F ";
221 string command = "rm ";
223 command += TemporaryFileName;
224 char *temp = strdup(command.c_str());
225 int lgthTemp = strlen(temp);
226 temp[lgthTemp - 3] = '*';
227 temp[lgthTemp - 2] = '\0';