*
*/
-#include <stdlib.h>
-#include <string.h>
-
-#include <iostream>
+#include <cstdlib>
#include <fstream>
#include <sstream>
-#include <string>
-#include <sys/stat.h>
-
-#include <stdlib.h>
-#include <string.h>
-#ifdef WIN32
-#include <io.h>
-#else
-#include <libgen.h>
-#endif
-
-#include "Batch_Constants.hxx"
+#include <Batch_Constants.hxx>
+#include <Batch_Utils.hxx>
#include "Batch_BatchManager_eLSF.hxx"
#include "Batch_JobInfo_eLSF.hxx"
// Methode pour le controle des jobs : soumet un job au gestionnaire
const JobId BatchManager_eLSF::submitJob(const Job & job)
{
- int status;
Parametre params = job.getParametre();
const std::string workDir = params[WORKDIR];
- const string fileToExecute = params[EXECUTABLE];
- string::size_type p1 = fileToExecute.find_last_of("/");
- string::size_type p2 = fileToExecute.find_last_of(".");
- std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
// export input files on cluster
cerr << "Export des fichiers en entree" << endl;
// build batch script for job
cerr << "Construction du script de batch" << endl;
- buildBatchScript(job);
+ string scriptFile = buildSubmissionScript(job);
cerr << "Script envoye" << endl;
- // define name of log file (local)
- string logFile = generateTemporaryFileName("LSF-submitlog");
-
// define command to submit batch
- string subCommand = string("cd ") + workDir + "; bsub < " + fileNameToExecute + "_Batch.sh";
+ string subCommand = string("cd ") + workDir + "; bsub < " + scriptFile;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- command += " > ";
- command += logFile;
command += " 2>&1";
cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status)
- {
- ifstream error_message(logFile.c_str());
- std::string mess;
- std::string temp;
- while(std::getline(error_message, temp))
- mess += temp;
- error_message.close();
- throw EmulationException("Error of connection on remote host, error was: " + mess);
- }
- // read id of submitted job in log file
- char line[128];
- FILE *fp = fopen(logFile.c_str(),"r");
- fgets( line, 128, fp);
- fclose(fp);
+ string output;
+ int status = Utils::getCommandOutput(command, output);
+ cout << output;
+ if (status != 0) throw EmulationException("Can't submit job, error was: " + output);
- string sline(line);
- int p10 = sline.find("<");
- int p20 = sline.find(">");
- string strjob = sline.substr(p10+1,p20-p10-1);
+ // read id of submitted job in output
+ int p10 = output.find("<");
+ int p20 = output.find(">");
+ string strjob = output.substr(p10+1,p20-p10-1);
JobId id(this, strjob);
return id;
istringstream iss(jobid.getReference());
iss >> id;
- // define name of log file (local)
- string logFile = generateTemporaryFileName(string("LSF-querylog-id") + jobid.getReference());
-
// define command to query batch
string subCommand = string("bjobs ") + iss.str();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- command += " > ";
- command += logFile;
cerr << command.c_str() << endl;
- int status = system(command.c_str());
- if (status)
- throw EmulationException("Error of connection on remote host");
- JobInfo_eLSF ji = JobInfo_eLSF(id,logFile);
+ string output;
+ int status = Utils::getCommandOutput(command, output);
+ if (status) throw EmulationException("Error of connection on remote host");
+
+ JobInfo_eLSF ji = JobInfo_eLSF(id, output);
return ji;
}
throw EmulationException("Not yet implemented");
}
- void BatchManager_eLSF::buildBatchScript(const Job & job)
+ std::string BatchManager_eLSF::buildSubmissionScript(const Job & job)
{
-#ifndef WIN32 //TODO: need for porting on Windows
Parametre params = job.getParametre();
// Job Parameters
std::string TmpFileName = createAndOpenTemporaryFile("LSF-script", tempOutputFile);
tempOutputFile << "#! /bin/sh -f" << endl ;
+ if (params.find(NAME) != params.end())
+ tempOutputFile << "#BSUB -J " << params[NAME] << endl;
if (queue != "")
tempOutputFile << "#BSUB -q " << queue << endl;
if( edt > 0 )
tempOutputFile.flush();
tempOutputFile.close();
- BATCH_CHMOD(TmpFileName.c_str(), 0x1ED);
cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+ string remoteFileName = rootNameToExecute + "_Batch.sh";
int status = _protocol.copyFile(TmpFileName, "", "",
- workDir + "/" + rootNameToExecute + "_Batch.sh",
+ workDir + "/" + remoteFileName,
_hostname, _username);
if (status)
throw EmulationException("Error of connection on remote host");
-
-#endif
-
+ return remoteFileName;
}
std::string BatchManager_eLSF::getWallTime(const long edt)