# ---- option to build only launcher, resources manager and batch classes
AC_ARG_WITH(onlylauncher,
- --with-onlylauncher,
- [],[with_onlylauncher="no"])
+ [AC_HELP_STRING([--with-onlylauncher],[Build only launcher, resources manager and batch classes [default=no]])],
+ [],
+ [with_onlylauncher="no"])
AM_CONDITIONAL(WITHONLYLAUNCHER, test x$with_onlylauncher = xyes)
# ----------------------------------------------------------------------------
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
/*
- * BatchManagerCatalog.cxx :
+ * BatchManagerCatalog.cxx :
*
* Auteur : Ivan DUTKA-MALEN - EDF R&D
* Date : Septembre 2004
pthread_mutex_t BatchManagerCatalog::_mutex = PTHREAD_MUTEX_INITIALIZER;
std::map<string, FactBatchManager *> * BatchManagerCatalog::_p_catalog = 0;
- BatchManagerCatalog BatchManagerCatalog::theCatalog;
+// BatchManagerCatalog BatchManagerCatalog::theCatalog;
// Constructeur
BatchManagerCatalog::BatchManagerCatalog()
// Destructeur
BatchManagerCatalog::~BatchManagerCatalog()
{
- delete BatchManagerCatalog::_p_catalog;
+ // Note (RB, 6mar09) : this deletion can cause big memory problems as the pointer
+ // may have been destroyed before this call to delete, and delete can be called
+ // several times. So it's better to remove it for now, even if there is a (small)
+ // memory leak.
+ // TODO: Replace that by a clean singleton implementation
+// delete BatchManagerCatalog::_p_catalog;
}
// Functor
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
-* Projet : PAL Salome
+* Projet : PAL Salome
*
*/
#include "Batch_BatchManager_eClient.hxx"
-#include "Basics_DirUtils.hxx"
+#include "Batch_RunTimeException.hxx"
+#include "Batch_NotYetImplementedException.hxx"
#include <iostream>
#include <fstream>
command += directory;
cerr << command.c_str() << endl;
status = system(command.c_str());
- if(status)
+ if(status)
{
// Try to get what we can (logs files)
- // throw BatchException("Error of connection on remote host");
+ // throw BatchException("Error of connection on remote host");
std::string mess("Copy command failed ! status is :");
ostringstream status_str;
status_str << status;
}
}
- string BatchManager_eClient::BuildTemporaryFileName() const
- {
- //build more complex file name to support multiple salome session
- string aFileName = Kernel_Utils::GetTmpFileName();
-#ifndef WIN32
- aFileName += ".sh";
-#else
- aFileName += ".bat";
-#endif
- return aFileName;
- }
-
- void BatchManager_eClient::RmTmpFile(std::string & TemporaryFileName)
+ /**
+ * This method creates a temporary file and opens an output stream to write into this file.
+ * The file is created with the pattern "/tmp/batch_XXXXXX" where the X's are replaced by random
+ * characters. The caller is responsible for closing and deleting the file when it is no more used.
+ * \param outputStream an output stream that will be opened for writing in the temporary file. If
+ * the stream is already open, it will be closed first.
+ * \return the name of the created file.
+ */
+ string BatchManager_eClient::createAndOpenTemporaryFile(ofstream & outputStream) const
{
+ string fileName;
#ifdef WIN32
- string command = "del /F ";
+ throw NotYetImplementedException("Temporary file creation in Batch library has not been ported to Windows yet");
#else
- string command = "rm ";
+ char * tmpFileName = strdup("/tmp/batch_XXXXXX");
+ int fd = mkstemp(tmpFileName);
+ if (fd == -1)
+ {
+ throw RunTimeException("Can't create temporary file");
+ }
+
+ if (outputStream.is_open())
+ outputStream.close();
+ outputStream.open(tmpFileName);
+ close(fd); // Close the file descriptor so that the file is not opened twice
+
+ fileName = tmpFileName;
+ delete[] tmpFileName;
#endif
- command += TemporaryFileName;
- char *temp = strdup(command.c_str());
- int lgthTemp = strlen(temp);
- temp[lgthTemp - 3] = '*';
- temp[lgthTemp - 2] = '\0';
- system(temp);
- free(temp);
+ return fileName;
}
+
}
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
- * Projet : PAL Salome
+ * Projet : PAL Salome
*
*/
{
public:
const std::string msg;
-
+
EmulationException(const std::string m) : msg(m) {}
};
std::string _username; // username to access _hostname
MpiImpl *_mpiImpl; // Mpi implementation to launch executable in batch script
- std::string BuildTemporaryFileName() const;
- void RmTmpFile(std::string & TemporaryFileName);
+ std::string createAndOpenTemporaryFile(std::ofstream & outputStream) const;
MpiImpl* FactoryMpiImpl(std::string mpiImpl) throw(EmulationException);
void exportInputFiles(const Job & job) throw(EmulationException);
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
- * Projet : PAL Salome
+ * Projet : PAL Salome
*
*/
FILE *fp = fopen(logFile.c_str(),"r");
fgets( line, 128, fp);
fclose(fp);
-
+
string sline(line);
int p10 = sline.find("<");
int p20 = sline.find(">");
int ref;
istringstream iss(jobid.getReference());
iss >> ref;
-
+
// define command to submit batch
string command;
command = _protocol;
cerr << "jobId = " << ref << "killed" << endl;
}
-
+
// Methode pour le controle des jobs : suspend un job en file d'attente
void BatchManager_eLSF::holdJob(const JobId & jobid)
{
throw EmulationException("Not yet implemented");
}
- void BatchManager_eLSF::buildBatchScript(const Job & job) throw(EmulationException)
+ void BatchManager_eLSF::buildBatchScript(const Job & job)
{
#ifndef WIN32 //TODO: need for porting on Windows
int status;
rootNameToExecute = "command";
}
- std::string TmpFileName = BuildTemporaryFileName();
ofstream tempOutputFile;
- tempOutputFile.open(TmpFileName.c_str(), ofstream::out );
+ std::string TmpFileName = createAndOpenTemporaryFile(tempOutputFile);
tempOutputFile << "#! /bin/sh -f" << endl ;
if (queue != "")
tempOutputFile << "source " << env["SOURCEFILE"] << endl ;
tempOutputFile << env["COMMAND"];
}
-
+
tempOutputFile.flush();
tempOutputFile.close();
#ifdef WIN32
cerr << command.c_str() << endl;
status = system(command.c_str());
if(status)
- throw EmulationException("Error of connection on remote host");
+ throw EmulationException("Error of connection on remote host");
- RmTmpFile(TmpFileName);
+ remove(TmpFileName.c_str());
#endif
-
+
}
std::string BatchManager_eLSF::getWallTime(const long edt)
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
- * Projet : PAL Salome
+ * Projet : PAL Salome
*
*/
protected:
- void buildBatchScript(const Job & job) throw(EmulationException);
+ void buildBatchScript(const Job & job);
std::string getWallTime(const long edt);
private:
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
- * Projet : PAL Salome
+ * Projet : PAL Salome
*
*/
FILE *fp = fopen(logFile.c_str(),"r");
fgets( line, 128, fp);
fclose(fp);
-
+
string sline(line);
int pos = sline.find(".");
string strjob;
int ref;
istringstream iss(jobid.getReference());
iss >> ref;
-
+
// define command to submit batch
string command;
command = _protocol;
cerr << "jobId = " << ref << "killed" << endl;
}
-
+
// Methode pour le controle des jobs : suspend un job en file d'attente
void BatchManager_ePBS::holdJob(const JobId & jobid)
{
throw EmulationException("Not yet implemented");
}
- void BatchManager_ePBS::buildBatchScript(const Job & job) throw(EmulationException)
+ void BatchManager_ePBS::buildBatchScript(const Job & job)
{
#ifndef WIN32 //TODO: need for porting on Windows
int status;
rootNameToExecute = "command";
}
- std::string TmpFileName = BuildTemporaryFileName();
ofstream tempOutputFile;
- tempOutputFile.open(TmpFileName.c_str(), ofstream::out );
+ std::string TmpFileName = createAndOpenTemporaryFile(tempOutputFile);
tempOutputFile << "#! /bin/sh -f" << endl;
if (queue != "")
tempOutputFile << "source " << env["SOURCEFILE"] << endl ;
tempOutputFile << env["COMMAND"];
}
-
+
tempOutputFile.flush();
tempOutputFile.close();
#ifdef WIN32
cerr << command.c_str() << endl;
status = system(command.c_str());
if(status)
- throw EmulationException("Error of connection on remote host");
+ throw EmulationException("Error of connection on remote host");
- RmTmpFile(TmpFileName);
-#endif
+ remove(TmpFileName.c_str());
+#endif
}
}
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
- * Projet : PAL Salome
+ * Projet : PAL Salome
*
*/
protected:
- void buildBatchScript(const Job & job) throw(EmulationException);
+ void buildBatchScript(const Job & job);
private:
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
- * Projet : PAL Salome
+ * Projet : PAL Salome
*
*/
FILE *fp = fopen(logFile.c_str(),"r");
fgets( line, 128, fp);
fclose(fp);
-
+
string strjob;
istringstream iss(line);
iss >> strjob >> strjob >> strjob;
int ref;
istringstream iss(jobid.getReference());
iss >> ref;
-
+
// define command to submit batch
string command;
command = _protocol;
cerr << "jobId = " << ref << "killed" << endl;
}
-
+
// Methode pour le controle des jobs : suspend un job en file d'attente
void BatchManager_eSGE::holdJob(const JobId & jobid)
{
throw EmulationException("Not yet implemented");
}
- void BatchManager_eSGE::buildBatchScript(const Job & job) throw(EmulationException)
+ void BatchManager_eSGE::buildBatchScript(const Job & job)
{
#ifndef WIN32
//TODO porting on Win32 platform
rootNameToExecute = "command";
}
- std::string TmpFileName = BuildTemporaryFileName();
ofstream tempOutputFile;
- tempOutputFile.open(TmpFileName.c_str(), ofstream::out );
+ std::string TmpFileName = createAndOpenTemporaryFile(tempOutputFile);
tempOutputFile << "#! /bin/sh -f" << endl;
if (queue != "")
tempOutputFile << "source " << env["SOURCEFILE"] << endl ;
tempOutputFile << env["COMMAND"];
}
-
+
tempOutputFile.flush();
tempOutputFile.close();
chmod(TmpFileName.c_str(), 0x1ED);
cerr << command.c_str() << endl;
status = system(command.c_str());
if(status)
- throw EmulationException("Error of connection on remote host");
+ throw EmulationException("Error of connection on remote host");
- RmTmpFile(TmpFileName);
-#endif //WIN32
+ remove(TmpFileName.c_str());
+#endif //WIN32
}
std::string BatchManager_eSGE::getWallTime(const long edt)
* Auteur : Bernard SECHER - CEA DEN
* Mail : mailto:bernard.secher@cea.fr
* Date : Thu Apr 24 10:17:22 2008
- * Projet : PAL Salome
+ * Projet : PAL Salome
*
*/
protected:
- void buildBatchScript(const Job & job) throw(EmulationException);
+ void buildBatchScript(const Job & job);
std::string getWallTime(const long edt);
private:
MpiImpl.cxx
-LIB_CPPFLAGS = \
- ${PYTHON_INCLUDES}
+LIB_CPPFLAGS = ${PYTHON_INCLUDES}
if !WITHONLYLAUNCHER
- LIB_CPPFLAGS += \
- -I$(srcdir)/../Basics \
- -I$(top_builddir)/salome_adm/unix
+ LIB_CPPFLAGS += -I$(top_builddir)/salome_adm/unix
endif
-LIB_LIBADD =
-if !WITHONLYLAUNCHER
- LIB_LIBADD += \
- ../Basics/libSALOMEBasics.la
-endif
-
-LIB_LIBADD += $(PYTHON_LIBS)
+LIB_LIBADD = $(PYTHON_LIBS)
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libLauncher_la_LIBADD =\
../Batch/libSalomeBatch.la \
- ../ResourcesManager/libSalomeResourcesManager.la \
+ ../ResourcesManager/libResourcesManager.la \
@MPI_LIBS@ \
@LIBXML_LIBS@
libResourcesManager_la_LDFLAGS = -no-undefined -version-info=0:0:0
libResourcesManager_la_LIBADD =\
- ../Utils/libOpUtil.la \
@LIBXML_LIBS@