From: barate Date: Fri, 24 Jun 2011 15:42:30 +0000 (+0000) Subject: First Vishnu integration (not fully functional yet) X-Git-Tag: V1_4_0_VISHNU~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=64400a378bbce7bb1d36625976549643fcdb1796;p=tools%2Flibbatch.git First Vishnu integration (not fully functional yet) --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11e07fb..2148bbf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,6 +57,7 @@ add_subdirectory (SGE) add_subdirectory (SSH) add_subdirectory (LoadLeveler) add_subdirectory (Slurm) +add_subdirectory (Vishnu) # Make a copy of the built value and clear the built value for the next run of cmake SET(SRC_FILES ${SRC_FILES_BUILD} CACHE INTERNAL "") diff --git a/src/Core/Test/batchtest.conf b/src/Core/Test/batchtest.conf index 570ec21..07034c4 100644 --- a/src/Core/Test/batchtest.conf +++ b/src/Core/Test/batchtest.conf @@ -43,3 +43,11 @@ TEST_ESLURM_HOST = "localhost" # Slurm server host TEST_ESLURM_USER = "username" # Login for the Slurm server TEST_ESLURM_HOMEDIR = "/home/username" # Home directory on Slurm server TEST_ESLURM_TIMEOUT = 120 # Execution timeout (in seconds) for Slurm Batch test + +TEST_EVISHNU_HOST = "localhost" # Vishnu server host +TEST_EVISHNU_USER = "username" # Login on the Vishnu server host +TEST_EVISHNU_VISHNU_USERID = "userid" # UserId for connecting to Vishnu +TEST_EVISHNU_VISHNU_PASSWORD = "password" # Password for connecting to Vishnu +TEST_EVISHNU_VISHNU_MACHINEID = "localhost" # ID of the machine where Vishnu will launch the job +TEST_EVISHNU_HOMEDIR = "/home/username" # Home directory on Vishnu server +TEST_EVISHNU_TIMEOUT = 120 # Execution timeout (in seconds) for Vishnu Batch test diff --git a/src/Vishnu/Batch_BatchManager_eVishnu.cxx b/src/Vishnu/Batch_BatchManager_eVishnu.cxx new file mode 100644 index 0000000..5de808b --- /dev/null +++ b/src/Vishnu/Batch_BatchManager_eVishnu.cxx @@ -0,0 +1,262 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_BatchManager_eVishnu.cxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include +#include + +#include +#include + +#include "Batch_FactBatchManager_eVishnu.hxx" +#include "Batch_BatchManager_eVishnu.hxx" +#include "Batch_JobInfo_eVishnu.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_eVishnu::BatchManager_eVishnu(const FactBatchManager * parent, + const char * host, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl, + int nb_proc_per_node) + : BatchManager(parent, host), + BatchManager_eClient(parent, host, username, protocolType, mpiImpl), + _nb_proc_per_node(nb_proc_per_node) + { + } + + BatchManager_eVishnu::~BatchManager_eVishnu() + { + } + + // Method to submit a job to the batch manager + const JobId BatchManager_eVishnu::submitJob(const Job & job) + { + int status; + Parametre params = job.getParametre(); + const string workDir = params[WORKDIR]; + + // export input files on cluster + exportInputFiles(job); + + // build command file to submit the job and copy it on the server + string cmdFile = buildCommandFile(job); + + // define name of log file (local) + string logFile = generateTemporaryFileName("vishnu-submitlog"); + + // define command to submit batch + string subCommand = string("cd ") + workDir + "; "; + subCommand += ". ~/.vishnu/vishnu.env ;"; + subCommand += "vishnu_connect " + params[VISHNU_USERID].str() + + " -w " + params[VISHNU_PASSWORD].str() + "; "; + subCommand += "vishnu_submit_job " + params[VISHNU_MACHINEID].str() + " " + cmdFile; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; + command += logFile; + cerr << command.c_str() << endl; + status = system(command.c_str()); + if (status) + { + ifstream error_message(logFile.c_str()); + string mess; + string temp; + while(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 + string jobref; + ifstream idfile(logFile.c_str()); + string line; + while (idfile && line.compare(0, 13, "Job Id : ") != 0) + getline(idfile, line); + idfile.close(); + if (line.compare(0, 13, "Job Id : ") == 0) + jobref = line.substr(13); + if (jobref.size() == 0) + throw EmulationException("Error in the submission of the job on the remote host"); + + JobId id(this, jobref); + return id; + } + + /** + * Create Vishnu command file and copy it on the server. + * Return the name of the remote file. + */ + string BatchManager_eVishnu::buildCommandFile(const Job & job) + { + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw EmulationException("params[WORKDIR] is not defined. Please define it, cannot submit this job."); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw EmulationException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job."); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + string tmpFileName = createAndOpenTemporaryFile("vishnu-script", tempOutputFile); + + tempOutputFile << "#!/bin/sh" << endl; + tempOutputFile << "%vishnuoutput=" << workDir << "/logs/output.log." << rootNameToExecute << endl; + tempOutputFile << "%vishnuerror=" << workDir << "/logs/error.log." << rootNameToExecute << endl; + + if (params.find(NAME) != params.end()) + tempOutputFile << "%vishnujob_name=\"" << params[NAME] << "\"" << endl; + + // Optional parameters + int nbproc = 1; + if (params.find(NBPROC) != params.end()) + nbproc = params[NBPROC]; + + int nodes_requested = (nbproc + _nb_proc_per_node -1) / _nb_proc_per_node; + //tempOutputFile << "#SBATCH --nodes=" << nodes_requested << endl; + //tempOutputFile << "#SBATCH --ntasks-per-node=" << _nb_proc_per_node << endl; + + if (params.find(MAXWALLTIME) != params.end()) + tempOutputFile << "%vishnuwallclocklimit=" << params[MAXWALLTIME] << endl; + //if (params.find(MAXRAMSIZE) != params.end()) + // tempOutputFile << "#SBATCH --mem=" << params[MAXRAMSIZE] << endl; + if (params.find(QUEUE) != params.end()) + tempOutputFile << "%vishnuqueue=" << params[QUEUE] << endl; + + // Define environment for the job + Environnement env = job.getEnvironnement(); + for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << "export " << iter->first << "=" << iter->second << endl; + } + + // generate nodes file + //tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX`" << endl; + //tempOutputFile << "srun hostname > $LIBBATCH_NODEFILE" << endl; + //tempOutputFile << "export LIBBATCH_NODEFILE" << endl; + + // Launch the executable + tempOutputFile << "cd " << workDir << endl; + tempOutputFile << "./" + fileNameToExecute << endl; + + tempOutputFile.flush(); + tempOutputFile.close(); + + cerr << "Batch script file generated is: " << tmpFileName << endl; + + string remoteFileName = rootNameToExecute + "_vishnu"; + int status = _protocol.copyFile(tmpFileName, "", "", + workDir + "/" + remoteFileName, + _hostname, _username); + if (status) + throw EmulationException("Cannot copy command file on host " + _hostname); + + return remoteFileName; + } + + void BatchManager_eVishnu::deleteJob(const JobId & jobid) + { + // define command to delete job + string subCommand = "vishnu_cancel_job " + jobid.getReference(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + cerr << command.c_str() << endl; + + int status = system(command.c_str()); + if (status) + throw EmulationException("Can't delete job " + jobid.getReference()); + + cerr << "job " << jobid.getReference() << " killed" << endl; + } + + void BatchManager_eVishnu::holdJob(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_eVishnu::holdJob"); + } + + void BatchManager_eVishnu::releaseJob(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_eVishnu::releaseJob"); + } + + void BatchManager_eVishnu::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) + { + throw NotYetImplementedException("BatchManager_eVishnu::alterJob"); + } + + void BatchManager_eVishnu::alterJob(const JobId & jobid, const Parametre & param) + { + throw NotYetImplementedException("BatchManager_eVishnu::alterJob"); + } + + void BatchManager_eVishnu::alterJob(const JobId & jobid, const Environnement & env) + { + throw NotYetImplementedException("BatchManager_eVishnu::alterJob"); + } + + JobInfo BatchManager_eVishnu::queryJob(const JobId & jobid) + { + // define name of log file (local) + string logFile = generateTemporaryFileName("vishnu-querylog-" + jobid.getReference()); + + // define command to query batch + string subCommand = "vishnu_get_job_info " + jobid.getReference(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; + command += logFile; + cerr << command.c_str() << endl; + int status = system(command.c_str()); + if (status != 0) + throw EmulationException("Can't query job " + jobid.getReference()); + + JobInfo_eVishnu jobinfo = JobInfo_eVishnu(jobid.getReference(), logFile); + return jobinfo; + } + + const JobId BatchManager_eVishnu::addJob(const Job & job, const string reference) + { + return JobId(this, reference); + } + +} diff --git a/src/Vishnu/Batch_BatchManager_eVishnu.hxx b/src/Vishnu/Batch_BatchManager_eVishnu.hxx new file mode 100644 index 0000000..b382d2f --- /dev/null +++ b/src/Vishnu/Batch_BatchManager_eVishnu.hxx @@ -0,0 +1,75 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_BatchManager_eVishnu.hxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHMANAGER_EVISHNU_H_ +#define _BATCHMANAGER_EVISHNU_H_ + +#include + +#include +#include +#include +#include +#include + +namespace Batch { + + class BATCH_EXPORT BatchManager_eVishnu : public BatchManager_eClient + { + public: + + BatchManager_eVishnu(const FactBatchManager * parent, + const char * host = "localhost", + const char * username = "", + CommunicationProtocolType protocolType = SSH, + const char * mpiImpl = "nompi", + int nb_proc_per_node = 1); + virtual ~BatchManager_eVishnu(); + + // Methods to control jobs + virtual const JobId submitJob(const Job & job); + virtual void deleteJob(const JobId & jobid); + virtual void holdJob(const JobId & jobid); + virtual void releaseJob(const JobId & jobid); + virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); + virtual void alterJob(const JobId & jobid, const Parametre & param); + virtual void alterJob(const JobId & jobid, const Environnement & env); + virtual JobInfo queryJob(const JobId & jobid); + virtual const JobId addJob(const Job & job, const std::string reference); + + protected: + + std::string buildCommandFile(const Job & job); + + int _nb_proc_per_node; + + }; + +} + +#endif diff --git a/src/Vishnu/Batch_FactBatchManager_eVishnu.cxx b/src/Vishnu/Batch_FactBatchManager_eVishnu.cxx new file mode 100644 index 0000000..bcbe521 --- /dev/null +++ b/src/Vishnu/Batch_FactBatchManager_eVishnu.cxx @@ -0,0 +1,70 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_FactBatchManager_eVishnu.cxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include "Batch_BatchManager_eVishnu.hxx" +#include "Batch_FactBatchManager_eVishnu.hxx" + +namespace Batch { + + def_Constant(VISHNU_USERID); + def_Constant(VISHNU_PASSWORD); + def_Constant(VISHNU_MACHINEID); + + static FactBatchManager_eVishnu sFBM_eVishnu; + + FactBatchManager_eVishnu::FactBatchManager_eVishnu() : FactBatchManager_eClient("eVISHNU") + { + // Add specific parameters + ParameterTypeMap::getInstance().addParameter(VISHNU_USERID, STRING, 1); + ParameterTypeMap::getInstance().addParameter(VISHNU_PASSWORD, STRING, 1); + ParameterTypeMap::getInstance().addParameter(VISHNU_MACHINEID, STRING, 1); + } + + FactBatchManager_eVishnu::~FactBatchManager_eVishnu() + { + } + + BatchManager * FactBatchManager_eVishnu::operator() (const char * hostname) const + { + // MESSAGE("Building new BatchManager_eVishnu on host '" << hostname << "'"); + return new BatchManager_eVishnu(this, hostname); + } + + BatchManager_eClient * FactBatchManager_eVishnu::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl, + int nb_proc_per_node) const + { + // MESSAGE("Building new BatchManager_eVishnu on host '" << hostname << "'"); + return new BatchManager_eVishnu(this, hostname, username, protocolType, mpiImpl, nb_proc_per_node); + } + +} diff --git a/src/Vishnu/Batch_FactBatchManager_eVishnu.hxx b/src/Vishnu/Batch_FactBatchManager_eVishnu.hxx new file mode 100644 index 0000000..9a8bbb7 --- /dev/null +++ b/src/Vishnu/Batch_FactBatchManager_eVishnu.hxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_FactBatchManager_eVishnu.hxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _FACTBATCHMANAGER_EVISHNU_H_ +#define _FACTBATCHMANAGER_EVISHNU_H_ + +#include +#include +#include +#include + +namespace Batch { + + decl_extern_Constant(VISHNU_USERID); + decl_extern_Constant(VISHNU_PASSWORD); + decl_extern_Constant(VISHNU_MACHINEID); + + class BATCH_EXPORT FactBatchManager_eVishnu : public FactBatchManager_eClient + { + public: + + FactBatchManager_eVishnu(); + virtual ~FactBatchManager_eVishnu(); + + virtual BatchManager * operator() (const char * hostname) const; + virtual BatchManager_eClient * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl, + int nb_proc_per_node = 1) const; + + }; + +} + +#endif diff --git a/src/Vishnu/Batch_JobInfo_eVishnu.cxx b/src/Vishnu/Batch_JobInfo_eVishnu.cxx new file mode 100644 index 0000000..b68934c --- /dev/null +++ b/src/Vishnu/Batch_JobInfo_eVishnu.cxx @@ -0,0 +1,93 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_JobInfo_eVishnu.cxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include +#include + +#include +#include + +#include "Batch_JobInfo_eVishnu.hxx" + +using namespace std; + +namespace Batch { + + JobInfo_eVishnu::JobInfo_eVishnu(const std::string & id, const std::string & logFile) + : JobInfo() + { + _param[ID] = id; + + // read log file + ifstream log(logFile.c_str()); + string line; + + // status should be on the second line + for (int i=0 ; i<2 ; i++) + getline(log, line); + log.close(); + string status; + istringstream iss(line); + iss >> status; + + if (status.size() == 0) { + // On some batch managers, the job is deleted as soon as it is finished, + // so we have to consider that an unknown job is a finished one, even if + // it is not always true. + _param[STATE] = FINISHED; + } else if (status == "CA") { // Canceled + _param[STATE] = FAILED; + } else if (status == "CD") { // Completed + _param[STATE] = FINISHED; + } else if (status == "CF") { // Configuring + _param[STATE] = QUEUED; + } else if (status == "CG") { // Completing + _param[STATE] = RUNNING; + } else if (status == "F") { // Failed + _param[STATE] = FAILED; + } else if (status == "NF") { // Node Fail + _param[STATE] = FAILED; + } else if (status == "PD") { // Pending + _param[STATE] = QUEUED; + } else if (status == "R") { // Running + _param[STATE] = RUNNING; + } else if (status == "S") { // Suspended + _param[STATE] = PAUSED; + } else if (status == "TO") { // Timeout + _param[STATE] = FAILED; + } else { + throw RunTimeException("Unknown job state code: \"" + status + "\""); + } + } + + JobInfo_eVishnu::~JobInfo_eVishnu() + { + } + +} diff --git a/src/Vishnu/Batch_JobInfo_eVishnu.hxx b/src/Vishnu/Batch_JobInfo_eVishnu.hxx new file mode 100644 index 0000000..517e797 --- /dev/null +++ b/src/Vishnu/Batch_JobInfo_eVishnu.hxx @@ -0,0 +1,49 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_JobInfo_eVishnu.hxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _JOBINFO_EVISHNU_H_ +#define _JOBINFO_EVISHNU_H_ + +#include + +#include + +namespace Batch { + + class JobInfo_eVishnu : public JobInfo + { + public: + + JobInfo_eVishnu(const std::string & id, const std::string & logFile); + virtual ~JobInfo_eVishnu(); + + }; + +} + +#endif diff --git a/src/Vishnu/CMakeLists.txt b/src/Vishnu/CMakeLists.txt new file mode 100644 index 0000000..02a7b8d --- /dev/null +++ b/src/Vishnu/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(CLASS_LIST Vishnu/Batch_BatchManager_eVishnu + Vishnu/Batch_FactBatchManager_eVishnu + Vishnu/Batch_JobInfo_eVishnu + ) + +APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) + +IF (TEST_ENABLED) + add_subdirectory(Test) +ENDIF (TEST_ENABLED) diff --git a/src/Vishnu/Test/CMakeLists.txt b/src/Vishnu/Test/CMakeLists.txt new file mode 100644 index 0000000..b7606db --- /dev/null +++ b/src/Vishnu/Test/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# Just copy the test scripts to the binary dir +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY) + +# set the include directories +include_directories(${CMAKE_SOURCE_DIR}/src/Core) +include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +# Build the test programs and add the tests +add_executable(Test_eVishnu Test_eVishnu.cxx) +target_link_libraries(Test_eVishnu Batch SimpleParser) + +IF (HAS_SSH) + ADD_TEST(eVishnu_SSH Test_eVishnu SSH) +ENDIF (HAS_SSH) + +#IF (HAS_RSH) +# ADD_TEST(eVishnu_RSH Test_eVishnu RSH) +#ENDIF (HAS_RSH) diff --git a/src/Vishnu/Test/Test_eVishnu.cxx b/src/Vishnu/Test/Test_eVishnu.cxx new file mode 100644 index 0000000..c2d2927 --- /dev/null +++ b/src/Vishnu/Test/Test_eVishnu.cxx @@ -0,0 +1,168 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Test_eVishnu.cxx : + * + * Author : Renaud BARATE - EDF R&D + * Date : June 2011 + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; +using namespace Batch; + +void print_usage() +{ + cout << "usage: Test_eVishnu PROTOCOL" << endl; + cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl; +} + +int main(int argc, char** argv) +{ + // Parse argument + if (argc != 2) { + print_usage(); + return 1; + } + CommunicationProtocolType protocol; + if (strcmp(argv[1], "SSH") == 0) + protocol = SSH; + else if (strcmp(argv[1], "RSH") == 0) + protocol = RSH; + else { + print_usage(); + return 1; + } + + cout << "*******************************************************************************************" << endl; + cout << "This program tests the batch submission based on Vishnu emulation. Passwordless" << endl; + cout << "authentication must be used for this test to pass. For SSH, this can be configured with" << endl; + cout << "ssh-agent for instance. For RSH, this can be configured with the .rhosts file." << endl; + cout << "*******************************************************************************************" << endl; + + // eventually remove any previous result + remove("result.txt"); + + try { + // Parse the test configuration file + SimpleParser parser; + parser.parseTestConfigFile(); + const string & homedir = parser.getValue("TEST_EVISHNU_HOMEDIR"); + const string & host = parser.getValue("TEST_EVISHNU_HOST"); + const string & user = parser.getValue("TEST_EVISHNU_USER"); + const string & vishnu_userid = parser.getValue("TEST_EVISHNU_VISHNU_USERID"); + const string & vishnu_password = parser.getValue("TEST_EVISHNU_VISHNU_PASSWORD"); + const string & vishnu_machineid = parser.getValue("TEST_EVISHNU_VISHNU_MACHINEID"); + int timeout = parser.getValueAsInt("TEST_EVISHNU_TIMEOUT"); + + // Define the job... + Job job; + // ... and its parameters ... + Parametre p; + p[EXECUTABLE] = "./test-script.sh"; + p[NAME] = string("Test eVISHNU ") + argv[1]; + p[WORKDIR] = homedir + "/tmp/Batch"; + p[INFILE] = Couple("seta.sh", "tmp/Batch/seta.sh"); + p[INFILE] += Couple("setb.sh", "tmp/Batch/setb.sh"); + p[OUTFILE] = Couple("result.txt", "tmp/Batch/result.txt"); + p[TMPDIR] = "tmp/Batch/"; + p[NBPROC] = 1; + p[MAXWALLTIME] = 1; + p[MAXRAMSIZE] = 50; + p[HOMEDIR] = homedir; + p["VISHNU_USERID"] = vishnu_userid; + p["VISHNU_PASSWORD"] = vishnu_password; + p["VISHNU_MACHINEID"] = vishnu_machineid; + job.setParametre(p); + // ... and its environment + Environnement e; + e["MYENVVAR"] = "MYVALUE"; + job.setEnvironnement(e); + cout << job << endl; + + // Get the catalog + BatchManagerCatalog& c = BatchManagerCatalog::getInstance(); + + // Create a BatchManager of type ePBS on localhost + FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("eVISHNU")); + BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), protocol); + + // Submit the job to the BatchManager + JobId jobid = bm->submitJob(job); + cout << jobid.__repr__() << endl; + + // Wait for the end of the job + string state = bm->waitForJobEnd(jobid, timeout); + + if (state == FINISHED) { + cout << "Job " << jobid.__repr__() << " is done" << endl; + bm->importOutputFiles(job, "resultdir/seconddirname"); + } else if (state == FAILED) { + cerr << "Job " << jobid.__repr__() << " finished in error" << endl; + bm->importOutputFiles(job, "resultdir/seconddirname"); + return 1; + } else { + cerr << "Timeout while executing job" << endl; + return 1; + } + + } catch (GenericException e) { + cerr << "Error: " << e << endl; + return 1; + } catch (ParserException e) { + cerr << "Parser error: " << e.what() << endl; + return 1; + } + + // test the result file + try { + SimpleParser resultParser; + resultParser.parse("resultdir/seconddirname/result.txt"); + cout << "Result:" << endl << resultParser; + const string & envvar = resultParser.getValue("MYENVVAR"); + int result = resultParser.getValueAsInt("c"); + if (envvar == "MYVALUE" && result == 12) { + cout << "OK, Expected result found." << endl; + return 0; + } else { + cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; + return 1; + } + } catch (ParserException e) { + cerr << "Parser error on result file: " << e.what() << endl; + return 1; + } +} diff --git a/src/Vishnu/Test/seta.sh b/src/Vishnu/Test/seta.sh new file mode 100644 index 0000000..42d1e38 --- /dev/null +++ b/src/Vishnu/Test/seta.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +a=4 diff --git a/src/Vishnu/Test/setb.sh b/src/Vishnu/Test/setb.sh new file mode 100644 index 0000000..8969060 --- /dev/null +++ b/src/Vishnu/Test/setb.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +b=3 diff --git a/src/Vishnu/Test/test-script.sh b/src/Vishnu/Test/test-script.sh new file mode 100755 index 0000000..1d56247 --- /dev/null +++ b/src/Vishnu/Test/test-script.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +. ./seta.sh +. ./setb.sh + +c=`expr $a "*" $b` + +echo "MYENVVAR = $MYENVVAR" > result.txt +echo "c = $c" >> result.txt