1 // Copyright (C) 2007-2010 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 * Batch_BatchManager_eLL.cxx :
25 * Created on: 25 nov. 2010
26 * Author : Renaud BARATE - EDF R&D
32 #include <Batch_NotYetImplementedException.hxx>
34 #include "Batch_BatchManager_eLL.hxx"
40 BatchManager_eLL::BatchManager_eLL(const FactBatchManager * parent, const char * host,
41 const char * username,
42 CommunicationProtocolType protocolType, const char * mpiImpl,
44 : BatchManager(parent, host),
45 BatchManager_eClient(parent, host, username, protocolType, mpiImpl)
50 BatchManager_eLL::~BatchManager_eLL()
55 // Method to submit a job to the batch manager
56 const JobId BatchManager_eLL::submitJob(const Job & job)
59 Parametre params = job.getParametre();
60 const string workDir = params[WORKDIR];
62 // export input files on cluster
63 exportInputFiles(job);
65 // build command file to submit the job and copy it on the server
66 string cmdFile = buildCommandFile(job);
68 // define name of log file (local)
69 string logFile = generateTemporaryFileName("LL-submitlog");
71 // define command to submit batch
72 string subCommand = string("cd ") + workDir + "; llsubmit " + cmdFile;
73 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
76 cerr << command.c_str() << endl;
77 status = system(command.c_str());
80 ifstream error_message(logFile.c_str());
83 while(std::getline(error_message, temp))
85 error_message.close();
86 throw EmulationException("Error of connection on remote host, error was: " + mess);
89 // read id of submitted job in log file
91 ifstream idfile(logFile.c_str());
92 unsigned int linebufsize = 1024;
93 char linebuf[linebufsize];
94 idfile.getline(linebuf, linebufsize);
95 while (!idfile.eof() && strncmp(linebuf, "llsubmit:", 9) != 0)
96 idfile.getline(linebuf, linebufsize);
98 if (strncmp(linebuf, "llsubmit:", 9) == 0)
100 string line(linebuf);
101 string::size_type p1 = line.find_first_of("\"");
102 string::size_type p2 = line.find_last_of("\"");
104 jobref = line.substr(p1 + 1, p2 - p1 - 1);
106 if (jobref.size() == 0)
107 throw EmulationException("Error in the submission of the job on the remote host");
109 JobId id(this, jobref);
114 * Create LoadLeveler command file and copy it on the server.
115 * Return the name of the remote file.
117 string BatchManager_eLL::buildCommandFile(const Job & job)
119 Parametre params = job.getParametre();
123 string fileToExecute = "";
126 // Mandatory parameters
127 if (params.find(WORKDIR) != params.end())
128 workDir = params[WORKDIR].str();
130 throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job");
131 if (params.find(EXECUTABLE) != params.end())
132 fileToExecute = params[EXECUTABLE].str();
134 throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job");
136 // Optional parameters
137 if (params.find(QUEUE) != params.end())
138 queue = params[QUEUE].str();
140 string::size_type p1 = fileToExecute.find_last_of("/");
141 string::size_type p2 = fileToExecute.find_last_of(".");
142 string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
143 string fileNameToExecute = fileToExecute.substr(p1+1);
145 // Create batch submit file
146 ofstream tempOutputFile;
147 std::string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile);
149 tempOutputFile << "# @ executable = " << fileNameToExecute << endl;
150 tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl;
151 tempOutputFile << "# @ error = " << workDir << "/logs/error.log." << rootNameToExecute << endl;
153 tempOutputFile << "# @ class = " << queue << endl;
154 tempOutputFile << "# @ job_type = bluegene" << endl;
155 tempOutputFile << "# @ queue" << endl;
157 tempOutputFile.flush();
158 tempOutputFile.close();
160 cerr << "Batch script file generated is: " << tmpFileName.c_str() << endl;
162 string remoteFileName = rootNameToExecute + "_LL.cmd";
163 int status = _protocol.copyFile(tmpFileName, "", "",
164 workDir + "/" + remoteFileName,
165 _hostname, _username);
167 throw EmulationException("Error of connection on remote host, cannot copy batch submission file");
169 return remoteFileName;
172 void BatchManager_eLL::deleteJob(const JobId & jobid)
174 throw NotYetImplementedException("BatchManager_eLL::deleteJob");
177 void BatchManager_eLL::holdJob(const JobId & jobid)
179 throw NotYetImplementedException("BatchManager_eLL::holdJob");
182 void BatchManager_eLL::releaseJob(const JobId & jobid)
184 throw NotYetImplementedException("BatchManager_eLL::releaseJob");
187 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
189 throw NotYetImplementedException("BatchManager_eLL::alterJob");
192 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param)
194 throw NotYetImplementedException("BatchManager_eLL::alterJob");
197 void BatchManager_eLL::alterJob(const JobId & jobid, const Environnement & env)
199 throw NotYetImplementedException("BatchManager_eLL::alterJob");
202 JobInfo BatchManager_eLL::queryJob(const JobId & jobid)
204 throw NotYetImplementedException("BatchManager_eLL::queryJob");
207 const JobId BatchManager_eLL::addJob(const Job & job, const string reference)
209 throw NotYetImplementedException("BatchManager_eLL::addJob");