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"
38 BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host, const char* protocol, const char* mpiImpl) : BatchManager(parent, host), _protocol(protocol), _username("")
40 // instanciation of mpi implementation needed to launch executable in batch script
41 _mpiImpl = FactoryMpiImpl(mpiImpl);
45 BatchManager_eClient::~BatchManager_eClient()
51 void BatchManager_eClient::exportInputFiles(const Job& job) throw(EmulationException)
54 Parametre params = job.getParametre();
55 Versatile V = params[INFILE];
56 Versatile::iterator Vit;
59 _username = string(params[USER]);
62 if( _protocol == "rsh" )
63 copy_command = "rcp ";
64 else if( _protocol == "ssh" )
65 copy_command = "scp ";
67 throw EmulationException("Unknown protocol : only rsh and ssh are known !");
69 // First step : creating batch tmp files directory
77 command += " \"mkdir -p ";
78 command += string(params[TMPDIR]);
80 cerr << command.c_str() << endl;
81 status = system(command.c_str());
83 std::ostringstream oss;
85 std::string ex_mess("Error of connection on remote host ! status = ");
87 throw EmulationException(ex_mess.c_str());
90 // Second step : copy fileToExecute into
91 // batch tmp files directory
92 command = copy_command;
93 command += string(params[EXECUTABLE]);
101 command += string(params[TMPDIR]);
102 cerr << command.c_str() << endl;
103 status = system(command.c_str());
105 std::ostringstream oss;
107 std::string ex_mess("Error of connection on remote host ! status = ");
108 ex_mess += oss.str();
109 throw EmulationException(ex_mess.c_str());
112 // Third step : copy filesToExportList into
113 // batch tmp files directory
114 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
115 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
116 Couple inputFile = cpt;
117 command = copy_command;
118 command += inputFile.getLocal();
121 command += _username;
124 command += _hostname;
126 command += inputFile.getRemote();
127 cerr << command.c_str() << endl;
128 status = system(command.c_str());
130 std::ostringstream oss;
132 std::string ex_mess("Error of connection on remote host ! status = ");
133 ex_mess += oss.str();
134 throw EmulationException(ex_mess.c_str());
140 void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) throw(EmulationException)
145 Parametre params = job.getParametre();
146 Versatile V = params[OUTFILE];
147 Versatile::iterator Vit;
149 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
150 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
151 Couple outputFile = cpt;
152 if( _protocol == "rsh" )
154 else if( _protocol == "ssh" )
157 throw EmulationException("Unknown protocol");
159 if (_username != ""){
160 command += _username;
163 command += _hostname;
165 command += outputFile.getRemote();
167 command += directory;
168 cerr << command.c_str() << endl;
169 status = system(command.c_str());
172 // Try to get what we can (logs files)
173 // throw BatchException("Error of connection on remote host");
174 std::string mess("Copy command failed ! status is :");
175 ostringstream status_str;
176 status_str << status;
177 mess += status_str.str();
178 cerr << mess << endl;
184 MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl) throw(EmulationException)
187 return new MpiImpl_LAM();
188 else if(mpiImpl == "mpich1")
189 return new MpiImpl_MPICH1();
190 else if(mpiImpl == "mpich2")
191 return new MpiImpl_MPICH2();
192 else if(mpiImpl == "openmpi")
193 return new MpiImpl_OPENMPI();
194 else if(mpiImpl == "slurm")
195 return new MpiImpl_SLURM();
198 oss << mpiImpl << " : not yet implemented";
199 throw EmulationException(oss.str().c_str());
203 string BatchManager_eClient::BuildTemporaryFileName() const
205 //build more complex file name to support multiple salome session
206 char *temp = new char[19];
207 strcpy(temp, "/tmp/command");
208 strcat(temp, "XXXXXX");
213 itoa(getpid(), aPID, 10);
217 string command(temp);
223 void BatchManager_eClient::RmTmpFile(std::string & TemporaryFileName)
225 string command = "rm ";
226 command += TemporaryFileName;
227 char *temp = strdup(command.c_str());
228 int lgthTemp = strlen(temp);
229 temp[lgthTemp - 3] = '*';
230 temp[lgthTemp - 2] = '\0';