#include <libgen.h>
#endif
-#include "Batch_Constants.hxx"
+#include <Batch_Constants.hxx>
+#include <Batch_NotYetImplementedException.hxx>
+#include <Batch_Utils.hxx>
+
#include "Batch_BatchManager_eCCC.hxx"
#include "Batch_JobInfo_eCCC.hxx"
BatchManager_eCCC::BatchManager_eCCC(const FactBatchManager * parent, const char * host,
const char * username,
CommunicationProtocolType protocolType, const char * mpiImpl)
- : BatchManager(parent, host),
- BatchManager_eClient(parent, host, username, protocolType, mpiImpl)
+ : BatchManager(parent, host, username, protocolType, mpiImpl)
{
// Nothing to do
}
// Methode pour le controle des jobs : soumet un job au gestionnaire
const JobId BatchManager_eCCC::submitJob(const Job & job)
{
- int status;
Parametre params = job.getParametre();
const std::string workDir = params[WORKDIR];
const string fileToExecute = params[EXECUTABLE];
buildBatchScript(job);
cerr << "Script envoye" << endl;
- // define name of log file (local)
- string logFile = generateTemporaryFileName("CCC-submitlog");
-
// define command to submit batch
- string subCommand = string("bash -l -c \"cd ") + workDir + "; ccc_msub " + fileNameToExecute + "_Batch.sh\"";
+ string subCommand = string("bash -l -c \\\"cd ") + workDir + "; ccc_msub " + fileNameToExecute + "_Batch.sh\\\"";
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
- ifstream idfile(logFile.c_str());
+ // submit job
+ string output;
+ int status = Utils::getCommandOutput(command, output);
+ cout << output;
+ if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
+
+ // find id of submitted job in output
+ istringstream idfile(output);
string sidj;
idfile >> sidj;
idfile >> sidj;
idfile >> sidj;
idfile >> sidj;
- idfile.close();
if (sidj.size() == 0)
- throw EmulationException("Error in the submission of the job on the remote host");
+ throw RunTimeException("Error in the submission of the job on the remote host");
JobId id(this, sidj);
return id;
iss >> ref;
// define command to delete batch
- string subCommand = string("bash -l -c \"ccc_mdel ") + iss.str() + string("\"");
+ string subCommand = string("bash -l -c \\\"ccc_mdel ") + iss.str() + string("\\\"");
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
status = system(command.c_str());
if (status)
- throw EmulationException("Error of connection on remote host");
+ throw RunTimeException("Error of connection on remote host");
cerr << "jobId = " << ref << "killed" << endl;
}
// Methode pour le controle des jobs : suspend un job en file d'attente
void BatchManager_eCCC::holdJob(const JobId & jobid)
{
- throw EmulationException("Not yet implemented");
+ throw NotYetImplementedException("BatchManager_eCCC::holdJob");
}
// Methode pour le controle des jobs : relache un job suspendu
void BatchManager_eCCC::releaseJob(const JobId & jobid)
{
- throw EmulationException("Not yet implemented");
+ throw NotYetImplementedException("BatchManager_eCCC::releaseJob");
}
// Methode pour le controle des jobs : modifie un job en file d'attente
void BatchManager_eCCC::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
{
- throw EmulationException("Not yet implemented");
+ throw NotYetImplementedException("BatchManager_eCCC::alterJob");
}
// Methode pour le controle des jobs : modifie un job en file d'attente
istringstream iss(jobid.getReference());
iss >> id;
- // define name of log file (local)
- string logFile = generateTemporaryFileName(string("CCC-querylog-id") + jobid.getReference());
-
// define command to query batch
- string subCommand = string("bash -l -c \"bjobs ") + iss.str() + string("\"");
+ string subCommand = string("bash -l -c \\\"bjobs ") + iss.str() + string("\\\"");
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- command += " > ";
- command += logFile;
cerr << command.c_str() << endl;
- int status = system(command.c_str());
+
+ string output;
+ int status = Utils::getCommandOutput(command, output);
if (status)
- throw EmulationException("Error of connection on remote host");
+ throw RunTimeException("Error of connection on remote host");
- JobInfo_eCCC ji = JobInfo_eCCC(id,logFile);
+ JobInfo_eCCC ji = JobInfo_eCCC(id, output);
return ji;
}
// Methode pour le controle des jobs : teste si un job est present en machine
bool BatchManager_eCCC::isRunning(const JobId & jobid)
{
- throw EmulationException("Not yet implemented");
+ throw NotYetImplementedException("BatchManager_eCCC::isRunning");
}
void BatchManager_eCCC::buildBatchScript(const Job & job)
if (params.find(WORKDIR) != params.end())
workDir = params[WORKDIR].str();
else
- throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job");
+ throw RunTimeException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job");
if (params.find(EXECUTABLE) != params.end())
fileToExecute = params[EXECUTABLE].str();
else
- throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job");
+ throw RunTimeException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job");
// Optional parameters
if (params.find(NBPROC) != params.end())
// Create batch submit file
ofstream tempOutputFile;
- std::string TmpFileName = createAndOpenTemporaryFile("LSF-script", tempOutputFile);
+ std::string TmpFileName = Utils::createAndOpenTemporaryFile("LSF-script", tempOutputFile);
tempOutputFile << "#!/bin/bash" << endl ;
if (queue != "")
workDir + "/" + rootNameToExecute + "_Batch.sh",
_hostname, _username);
if (status)
- throw EmulationException("Error of connection on remote host");
+ throw RunTimeException("Error of connection on remote host");
#endif
std::string BatchManager_eCCC::getHomeDir(std::string tmpdir)
{
std::string home;
- std::string filelogtemp = generateTemporaryFileName("gethomedir");
string subCommand = string("echo ");
subCommand += tmpdir;
- string command = _protocol.getExecCommand(subCommand, _hostname, _username) + " > " + filelogtemp;
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
- int status = system(command.c_str());
+
+ string output;
+ int status = Utils::getCommandOutput(command, output);
+
if (status)
- throw EmulationException("Error of launching home command on remote host");
+ throw RunTimeException("Error of launching home command on remote host");
- std::ifstream file_home(filelogtemp.c_str());
+ std::istringstream file_home(output);
std::getline(file_home, home);
- file_home.close();
return home;
}