From 0c468a0d5480972b78e31cc27813a43b3e017667 Mon Sep 17 00:00:00 2001 From: ribes Date: Thu, 19 Nov 2009 15:11:23 +0000 Subject: [PATCH] Remove Old Launcher Code Works Fine with ePBS and eSSH --- idl/SALOME_ContainerManager.idl | 55 +- src/Launcher/Launcher.cxx | 1161 +++++------------------- src/Launcher/Launcher.hxx | 57 +- src/Launcher/Launcher_Job.cxx | 8 +- src/Launcher/Launcher_Job_YACSFile.cxx | 4 +- src/Launcher/SALOME_Launcher.cxx | 226 +---- src/Launcher/SALOME_Launcher.hxx | 37 +- 7 files changed, 313 insertions(+), 1235 deletions(-) diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index d94f1ee7a..f886b8c62 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -114,19 +114,6 @@ struct MachineDefinition //! exception thrown if a computer is not found in the catalog exception NotFound {}; -//! Structure used for Salome Batch Job parameters -struct BatchParameters -{ - //! Where batch command will be launched and log files will be created - string batch_directory; - //! Time for the batch (has to be like this : hh:mm) - string expected_during_time; - //! Minimum of memory needed (has to be like : 32gb or 512mb) - string mem; - //! Number of processors requested - long nb_proc; -}; - struct JobParameters { //! Job Type - Could be equal to "command" or "yacs_file" @@ -165,31 +152,23 @@ struct JobParameters This interface is used for interaction with the unique instance of SalomeLauncher */ - interface SalomeLauncher - { - long submitJob( in string xmlExecuteFile, - in string clusterName ) raises (SALOME::SALOME_Exception); - long submitSalomeJob( in string fileToExecute, - in FilesList filesToExport, - in FilesList filesToImport, - in BatchParameters batch_params, - in MachineParameters params ) raises (SALOME::SALOME_Exception); - string queryJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - void deleteJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - void getResultsJob( in string directory, in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - - boolean testBatch(in MachineParameters params) raises (SALOME::SALOME_Exception); - - void Shutdown(); - long getPID(); - - // New Launcher interface - long createJob (in Engines::JobParameters job_parameters) raises (SALOME::SALOME_Exception); - void launchJob (in long job_id) raises (SALOME::SALOME_Exception); - string getJobState (in long job_id) raises (SALOME::SALOME_Exception); - void getJobResults(in long job_id, in string directory) raises (SALOME::SALOME_Exception); - void removeJob (in long job_id) raises (SALOME::SALOME_Exception); - } ; +interface SalomeLauncher +{ + // Main methods + long createJob (in Engines::JobParameters job_parameters) raises (SALOME::SALOME_Exception); + void launchJob (in long job_id) raises (SALOME::SALOME_Exception); + string getJobState (in long job_id) raises (SALOME::SALOME_Exception); + void getJobResults(in long job_id, in string directory) raises (SALOME::SALOME_Exception); + void removeJob (in long job_id) raises (SALOME::SALOME_Exception); + + // Useful methods + long createJobWithFile(in string xmlJobFile, in string clusterName) raises (SALOME::SALOME_Exception); + boolean testBatch (in MachineParameters params) raises (SALOME::SALOME_Exception); + + // SALOME kernel service methods + void Shutdown(); + long getPID(); +}; /*! \brief Interface of the %containerManager This interface is used for interaction with the unique instance diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index 729147f76..fffee68cf 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -31,6 +31,7 @@ #include "SALOME_Launcher_Handler.hxx" #include "Launcher.hxx" +#include "Launcher_Job_Command.hxx" #include #include #include @@ -46,12 +47,9 @@ using namespace std; * with non thread-safe usage like Change_Directory in SALOME naming service */ //============================================================================= - Launcher_cpp::Launcher_cpp() { -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Launcher_cpp constructor" << endl; -#endif + LAUNCHER_MESSAGE("Launcher_cpp constructor"); _job_cpt = 0; _job_cpt_mutex = new pthread_mutex_t(); pthread_mutex_init(_job_cpt_mutex, NULL); @@ -62,7 +60,6 @@ Launcher_cpp::Launcher_cpp() * destructor */ //============================================================================= - Launcher_cpp::~Launcher_cpp() { LAUNCHER_MESSAGE("Launcher_cpp destructor"); @@ -70,924 +67,16 @@ Launcher_cpp::~Launcher_cpp() std::map < string, Batch::BatchManager_eClient * >::const_iterator it1; for(it1=_batchmap.begin();it1!=_batchmap.end();it1++) delete it1->second; - std::map < std::pair , Batch::Job* >::const_iterator it2; - for(it2=_jobmap.begin();it2!=_jobmap.end();it2++) - delete it2->second; - std::map::const_iterator it_job; for(it_job = _launcher_job_map.begin(); it_job != _launcher_job_map.end(); it_job++) delete it_job->second; #endif + pthread_mutex_destroy(_job_cpt_mutex); delete _job_cpt_mutex; } -//============================================================================= -/*! CORBA Method: - * Submit a batch job on a cluster and returns the JobId - * \param xmlExecuteFile : to define the execution on the batch cluster - * \param clusterName : name of the batch cluster - */ -//============================================================================= -long Launcher_cpp::submitJob( const std::string xmlExecuteFile, - const std::string clusterName) throw(LauncherException) -{ -#ifdef WITH_LIBBATCH -#if defined(_DEBUG_) || defined(_DEBUG) - cout << "BEGIN OF Launcher_cpp::submitJob" << endl; -#endif - long jobId; - vector aMachineList; - - if(!_ResManager) - throw LauncherException("You must set Resources Manager to Launcher!!"); - - // verify if cluster is in resources catalog - machineParams params; - params.hostname = clusterName; - try{ - aMachineList = _ResManager->GetFittingResources(params); - } - catch(const ResourcesException &ex){ - throw LauncherException(ex.msg.c_str()); - } - if (aMachineList.size() == 0) - throw LauncherException("This cluster is not in resources catalog"); - - // Parsing xml file - ParseXmlFile(xmlExecuteFile); - - // verify if clustername is in xml file - map::const_iterator it1 = _launch.MachinesList.find(clusterName); - if(it1 == _launch.MachinesList.end()) - throw LauncherException("This cluster is not in xml file"); - - ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); - string cname(p.Alias); -#if defined(_DEBUG_) || defined(_DEBUG) - cout << "Choose cluster: " << cname << endl; -#endif - - // search batch manager for that cluster in map or instanciate one - map < string, Batch::BatchManager_eClient * >::const_iterator it2 = _batchmap.find(cname); - if(it2 == _batchmap.end()) - { - _batchmap[cname] = FactoryBatchManager(p); - // TODO: Add a test for the cluster ! - } - - try{ - - // directory on cluster to put files to execute - string remotedir = _launch.MachinesList[clusterName].WorkDirectory; - // local directory to get files to execute and to put results - string localdir = _launch.RefDirectory; - - int idx1 = xmlExecuteFile.find_last_of("/"); - if(idx1 == string::npos) idx1 = -1; - int idx2 = xmlExecuteFile.find(".xml"); - string logfile = xmlExecuteFile.substr(idx1+1,idx2-idx1-1); - string ologfile = logfile + ".output.log"; - string elogfile = logfile + ".error.log"; - - // create and submit job on cluster - Batch::Parametre param; - param[USER] = p.UserName; - param[EXECUTABLE] = ""; - for(int i=0; i<_launch.InputFile.size();i++) - param[INFILE] += Batch::Couple( localdir + "/" + _launch.InputFile[i], remotedir + "/" + _launch.InputFile[i] ); - for(int i=0; i<_launch.OutputFile.size();i++) - param[OUTFILE] += Batch::Couple( localdir + "/" + _launch.OutputFile[i], remotedir + "/" + _launch.OutputFile[i] ); - param[OUTFILE] += Batch::Couple( localdir + "/" + ologfile, remotedir + "/" + ologfile ); - param[OUTFILE] += Batch::Couple( localdir + "/" + elogfile, remotedir + "/" + elogfile ); - param[NBPROC] = _launch.NbOfProcesses; - param[WORKDIR] = remotedir; - param[TMPDIR] = remotedir; - param[MAXWALLTIME] = getWallTime(""); - param[MAXRAMSIZE] = getRamSize(""); - param[HOMEDIR] = ""; - - Batch::Environnement env; - env["COMMAND"] = _launch.Command; - env["SOURCEFILE"] = _launch.MachinesList[clusterName].EnvFile; - env["LOGFILE"] = logfile; - - Batch::Job* job = new Batch::Job(param,env); - - // submit job on cluster - Batch::JobId jid = _batchmap[cname]->submitJob(*job); - - // get job id in long - istringstream iss(jid.getReference()); - iss >> jobId; - - _jobmap[ pair(cname,jobId) ] = job; - } - catch(const Batch::EmulationException &ex){ - throw LauncherException(ex.message.c_str()); - } - - return jobId; -#else - throw LauncherException("Method Launcher_cpp::submitJob is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -//============================================================================= -/*! CORBA Method: - * Submit a batch job on a cluster and returns the JobId - * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster - * \param filesToExport : to export on the batch cluster - * \param NumberOfProcessors : Number of processors needed on the batch cluster - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -long Launcher_cpp::submitSalomeJob( const string fileToExecute , - const vector& filesToExport , - const vector& filesToImport , - const batchParams& batch_params, - const machineParams& params) throw(LauncherException) -{ -#ifdef WITH_LIBBATCH -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "BEGIN OF Launcher_cpp::submitSalomeJob" << endl; -#endif - long jobId; - vector aMachineList; - - if(!_ResManager) - throw LauncherException("You must set Resources Manager to Launcher!!"); - - // check batch params - if ( !check(batch_params) ) - throw LauncherException("Batch parameters are bad (see informations above)"); - - // find a cluster matching the structure params - try{ - aMachineList = _ResManager->GetFittingResources(params); - } - catch(const ResourcesException &ex){ - throw LauncherException(ex.msg.c_str()); - } - if (aMachineList.size() == 0) - throw LauncherException("No resources have been found with your parameters"); - - std::cerr << "Machine name is : " << aMachineList[0] << std::endl; - ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); - string clustername(p.Alias); - if (clustername == "") - { - throw LauncherException("Alias is not defined in machine configuration, please correct your Resource File"); - } - if (p.Batch == ssh_batch) - { - std::cerr << "p.batch value = " << p.Batch << std::endl; - std::cerr << "ssh_batch machine detected !" << std::endl; - } - else - std::cerr << "p.batch value = " << p.Batch << std::endl; - -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Choose cluster: " << clustername << endl; -#endif - - // search batch manager for that cluster in map or instanciate one - map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()) - { - std::cerr << "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" << std::endl; - _batchmap[clustername] = FactoryBatchManager(p); - std::cerr << "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" << std::endl; - // TODO: Add a test for the cluster ! - } - - try{ - // tmp directory on cluster to put files to execute - string tmpdir = getTmpDirForBatchFiles(); - - // create and submit job on cluster - Batch::Parametre param; - param[USER] = p.UserName; - param[EXECUTABLE] = buildSalomeCouplingScript(fileToExecute,tmpdir,p); - param[INFILE] = Batch::Couple( "/tmp/" + param[EXECUTABLE].str(), getRemoteFile(tmpdir, param[EXECUTABLE].str()) ); - param[INFILE] += Batch::Couple( fileToExecute, getRemoteFile(tmpdir,fileToExecute) ); - for(int i=0;isubmitJob(*job); - - // get job id in long - istringstream iss(jid.getReference()); - iss >> jobId; - - _jobmap[ pair(clustername,jobId) ] = job; - } - catch(const Batch::EmulationException &ex){ - throw LauncherException(ex.message.c_str()); - } - - return jobId; -#else - throw LauncherException("Method Launcher_cpp::submitSalomeJob is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -//============================================================================= -/*! CORBA Method: - * Query a batch job on a cluster and returns the status of job - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -string Launcher_cpp::queryJob( long id, - const machineParams& params) throw(LauncherException) -{ -#ifdef WITH_LIBBATCH - if(!_ResManager) - throw LauncherException("You must set Resources Manager to Launcher!!"); - - // find a cluster matching params structure - vector aMachineList = _ResManager->GetFittingResources( params ) ; - ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); - string clustername(p.Alias); - - // search batch manager for that cluster in map - std::map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()) - throw LauncherException("no batchmanager for that cluster"); - - Batch::Parametre par; - try{ - ostringstream oss; - oss << id; - Batch::JobId jobId( _batchmap[clustername], oss.str() ); - - Batch::JobInfo jinfo = jobId.queryJob(); - par = jinfo.getParametre(); - } - catch(const Batch::EmulationException &ex){ - throw LauncherException(ex.message.c_str()); - } - - return par[STATE]; -#else - throw LauncherException("Method Launcher_cpp::queryJob is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -string Launcher_cpp::queryJob( long id, - const std::string clusterName) throw (LauncherException) -{ - machineParams params; - params.hostname = clusterName; - return queryJob(id,params); -} - -//============================================================================= -/*! CORBA Method: - * Delete a batch job on a cluster - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -void Launcher_cpp::deleteJob( const long id, - const machineParams& params) throw(LauncherException) -{ -#ifdef WITH_LIBBATCH - if(!_ResManager) - throw LauncherException("You must set Resources Manager to Launcher!!"); - - // find a cluster matching params structure - vector aMachineList = _ResManager->GetFittingResources( params ) ; - ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); - string clustername(p.Alias); - - // search batch manager for that cluster in map - map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()) - throw LauncherException("no batchmanager for that cluster"); - - ostringstream oss; - oss << id; - Batch::JobId jobId( _batchmap[clustername], oss.str() ); - - jobId.deleteJob(); -#else - throw LauncherException("Method Launcher_cpp::deleteJob is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -void Launcher_cpp::deleteJob( long id, - const std::string clusterName) throw (LauncherException) -{ - machineParams params; - params.hostname = clusterName; - deleteJob(id,params); -} - -//============================================================================= -/*! CORBA Method: - * Get result files of job on a cluster - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -void Launcher_cpp::getResultsJob( const string directory, - const long id, - const machineParams& params) throw(LauncherException) -{ -#ifdef WITH_LIBBATCH - if(!_ResManager) - throw LauncherException("You must set Resources Manager to Launcher!!"); - - vector aMachineList = _ResManager->GetFittingResources( params ) ; - ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); - string clustername(p.Alias); - - // search batch manager for that cluster in map - map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()) - throw LauncherException("no batchmanager for that cluster"); - - Batch::Job* job = _jobmap[ pair(clustername,id) ]; - - _batchmap[clustername]->importOutputFiles( *job, directory ); -#else - throw LauncherException("Method Launcher_cpp::getResultsJob is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -void Launcher_cpp::getResultsJob( const std::string directory, - long id, - const std::string clusterName) throw (LauncherException) -{ - machineParams params; - params.hostname = clusterName; - getResultsJob(directory,id,params); -} - -//============================================================================= -/*! - * Factory to instanciate the good batch manager for choosen cluster. - */ -//============================================================================= - -Batch::BatchManager_eClient *Launcher_cpp::FactoryBatchManager(ParserResourcesType& params ) throw(LauncherException) -{ -#ifdef WITH_LIBBATCH - std::string hostname, mpi; - Batch::CommunicationProtocolType protocol; - Batch::FactBatchManager_eClient* fact; - - int nb_proc_per_node = params.DataForSort._nbOfProcPerNode; - - hostname = params.Alias; - switch(params.Protocol){ - case rsh: - protocol = Batch::RSH; - break; - case ssh: - protocol = Batch::SSH; - break; - default: - throw LauncherException("unknown protocol"); - break; - } - switch(params.mpi){ - case lam: - mpi = "lam"; - break; - case mpich1: - mpi = "mpich1"; - break; - case mpich2: - mpi = "mpich2"; - break; - case openmpi: - mpi = "openmpi"; - break; - case slurm: - mpi = "slurm"; - break; - case prun: - mpi = "prun"; - break; - default: - mpi = "nompi"; - } - -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Instanciation of batch manager" << endl; -#endif - switch( params.Batch ){ - case pbs: -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Instantiation of PBS batch manager" << endl; -#endif - fact = new Batch::FactBatchManager_ePBS; - break; - case lsf: -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Instantiation of LSF batch manager" << endl; -#endif - fact = new Batch::FactBatchManager_eLSF; - break; - case sge: -#if defined(_DEBUG_) || defined(_DEBUG) - cout << "Instantiation of SGE batch manager" << endl; -#endif - fact = new Batch::FactBatchManager_eSGE; - break; - case ssh_batch: -#if defined(_DEBUG_) || defined(_DEBUG) - cout << "Instantiation of SSH batch manager" << endl; -#endif - fact = new Batch::FactBatchManager_eSSH; - break; - default: -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "BATCH = " << params.Batch << endl; -#endif - throw LauncherException("no batchmanager for that cluster"); - } - return (*fact)(hostname.c_str(), protocol, mpi.c_str(), nb_proc_per_node); -#else - throw LauncherException("Method Launcher_cpp::FactoryBatchManager is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -string Launcher_cpp::buildSalomeCouplingScript(const string fileToExecute, const string dirForTmpFiles, const ParserResourcesType& params) -{ -#ifdef WITH_LIBBATCH -#ifndef WIN32 //TODO: need for porting on Windows - - int idx = dirForTmpFiles.find("Batch/"); - std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); - std::string dfilelogtemp = params.AppliPath + "/" + filelogtemp; - 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); - std::string TmpFileName = "/tmp/runSalome_" + fileNameToExecute + ".sh"; - ofstream tempOutputFile; - tempOutputFile.open(TmpFileName.c_str(), ofstream::out ); - - - if (params.Batch == ssh_batch) - { - tempOutputFile << "#! /bin/sh -f" << endl ; - tempOutputFile << "cd ~/" ; - tempOutputFile << dirForTmpFiles << endl ; - tempOutputFile << params.AppliPath << "/runAppli --terminal --ns-port-log=" << filelogtemp << endl; - tempOutputFile << "current=0\n" - << "stop=20\n" - << "while ! test -f " << dfilelogtemp << "\n" - << "do\n" - << " sleep 2\n" - << " let current=current+1\n" - << " if [ \"$current\" -eq \"$stop\" ] ; then\n" - << " echo Error Naming Service failed ! >&2" - << " exit\n" - << " fi\n" - << "done\n" - << "port=`cat " << dfilelogtemp << "`\n"; - tempOutputFile << params.AppliPath << "/runSession driver " << fileNameToExecute << ".xml" << endl; - tempOutputFile << params.AppliPath << "/runSession killSalomeWithPort.py $port" << endl; - tempOutputFile.flush(); - tempOutputFile.close(); - chmod(TmpFileName.c_str(), 0x1ED); -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << TmpFileName.c_str() << endl; -#endif - return "runSalome_" + fileNameToExecute + ".sh"; - } - else - { - - MpiImpl* mpiImpl = FactoryMpiImpl(params.mpi); - - // Begin - tempOutputFile << "#! /bin/sh -f" << endl ; - tempOutputFile << "cd ~/" ; - tempOutputFile << dirForTmpFiles << endl ; - tempOutputFile << "export SALOME_BATCH=1\n"; - tempOutputFile << "export PYTHONPATH=~/" ; - tempOutputFile << dirForTmpFiles ; - tempOutputFile << ":$PYTHONPATH" << endl ; - - // Adding user script - std::string script = params.userCommands; - if (script != "") - tempOutputFile << script << endl; - // Test node rank - tempOutputFile << "if test \"" ; - tempOutputFile << mpiImpl->rank() ; - tempOutputFile << "\" = \"0\"; then" << endl ; - - // ----------------------------------------------- - // Code for rank 0 : launch runAppli and a container - // RunAppli - if(params.ModulesList.size()>0) - tempOutputFile << " " << params.AppliPath << "/runAppli --terminal --modules=" ; - else - tempOutputFile << " " << params.AppliPath << "/runAppli --terminal "; - for ( int i = 0 ; i < params.ModulesList.size() ; i++ ) { - tempOutputFile << params.ModulesList[i] ; - if ( i != params.ModulesList.size()-1 ) - tempOutputFile << "," ; - } - tempOutputFile << " --standalone=registry,study,moduleCatalog --ns-port-log=" - << filelogtemp - << " &\n"; - - // Wait NamingService - tempOutputFile << " current=0\n" - << " stop=20\n" - << " while ! test -f " << dfilelogtemp << "\n" - << " do\n" - << " sleep 2\n" - << " let current=current+1\n" - << " if [ \"$current\" -eq \"$stop\" ] ; then\n" - << " echo Error Naming Service failed ! >&2" - << " exit\n" - << " fi\n" - << " done\n" - << " port=`cat " << dfilelogtemp << "`\n"; - - // Wait other containers - tempOutputFile << " for ((ip=1; ip < "; - tempOutputFile << mpiImpl->size(); - tempOutputFile << " ; ip++))" << endl; - tempOutputFile << " do" << endl ; - tempOutputFile << " arglist=\"$arglist YACS_Server_\"$ip" << endl ; - tempOutputFile << " done" << endl ; - tempOutputFile << " sleep 5" << endl ; - tempOutputFile << " " << params.AppliPath << "/runSession waitContainers.py $arglist" << endl ; - - // Launch user script - tempOutputFile << " " << params.AppliPath << "/runSession python ~/" << dirForTmpFiles << "/" << fileNameToExecute << ".py" << endl; - - // Stop application - tempOutputFile << " rm " << dfilelogtemp << "\n" - << " " << params.AppliPath << "/runSession shutdownSalome.py" << endl; - - // ------------------------------------- - // Other nodes launch a container - tempOutputFile << "else" << endl ; - - // Wait NamingService - tempOutputFile << " current=0\n" - << " stop=20\n" - << " while ! test -f " << dfilelogtemp << "\n" - << " do\n" - << " sleep 2\n" - << " let current=current+1\n" - << " if [ \"$current\" -eq \"$stop\" ] ; then\n" - << " echo Error Naming Service failed ! >&2" - << " exit\n" - << " fi\n" - << " done\n" - << " port=`cat " << dfilelogtemp << "`\n"; - - // Launching container - tempOutputFile << " " << params.AppliPath << "/runSession SALOME_Container YACS_Server_"; - tempOutputFile << mpiImpl->rank() - << " > ~/" << dirForTmpFiles << "/YACS_Server_" - << mpiImpl->rank() << "_container_log." << filelogtemp - << " 2>&1\n"; - tempOutputFile << "fi" << endl ; - tempOutputFile.flush(); - tempOutputFile.close(); - chmod(TmpFileName.c_str(), 0x1ED); -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << TmpFileName.c_str() << endl; -#endif - - delete mpiImpl; - - return TmpFileName; - } -#else - return ""; -#endif -#else - throw LauncherException("Method Launcher_cpp::buildSalomeCouplingScript is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -MpiImpl *Launcher_cpp::FactoryMpiImpl(MpiImplType mpi) throw(LauncherException) -{ -#ifdef WITH_LIBBATCH - switch(mpi){ - case lam: - return new MpiImpl_LAM(); - case mpich1: - return new MpiImpl_MPICH1(); - case mpich2: - return new MpiImpl_MPICH2(); - case openmpi: - return new MpiImpl_OPENMPI(); - case slurm: - return new MpiImpl_SLURM(); - case prun: - return new MpiImpl_PRUN(); - case nompi: - throw LauncherException("you must specify an mpi implementation for batch manager"); - default: - ostringstream oss; - oss << mpi << " : not yet implemented"; - throw LauncherException(oss.str().c_str()); - } -#else - throw LauncherException("Method Launcher_cpp::FactoryMpiImpl is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -string Launcher_cpp::getTmpDirForBatchFiles() -{ #ifdef WITH_LIBBATCH - string ret; - string thedate; - - // Adding date to the directory name - Batch::Date date = Batch::Date(time(0)); - thedate = date.str(); - int lend = thedate.size() ; - int i = 0 ; - while ( i < lend ) { - if ( thedate[i] == '/' || thedate[i] == '-' || thedate[i] == ':' ) { - thedate[i] = '_' ; - } - i++ ; - } - - ret = string("Batch/"); - ret += thedate; - return ret; -#else - throw LauncherException("Method Launcher_cpp::getTmpDirForBatchFiles is not available " - "(libBatch was not present at compilation time)"); -#endif -} - -string Launcher_cpp::getRemoteFile( std::string remoteDir, std::string localFile ) -{ - string::size_type pos = localFile.find_last_of("/") + 1; - int ln = localFile.length() - pos; - string remoteFile = remoteDir + "/" + localFile.substr(pos,ln); - return remoteFile; -} - -bool Launcher_cpp::check(const batchParams& batch_params) -{ - bool rtn = true; -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Job parameters are :" << endl; - cerr << "Directory : $HOME/Batch/$date" << endl; -#endif - - // check expected_during_time (check the format) - std::string edt_info = batch_params.expected_during_time; - std::string edt_value = batch_params.expected_during_time; - if (edt_value != "") { - std::string begin_edt_value = edt_value.substr(0, 2); - std::string mid_edt_value = edt_value.substr(2, 1); - std::string end_edt_value = edt_value.substr(3); - - long value; - std::istringstream iss(begin_edt_value); - if (!(iss >> value)) { - edt_info = "Error on definition ! : " + edt_value; - rtn = false; - } - else if (value < 0) { - edt_info = "Error on definition time is negative ! : " + value; - rtn = false; - } - std::istringstream iss_2(end_edt_value); - if (!(iss_2 >> value)) { - edt_info = "Error on definition ! : " + edt_value; - rtn = false; - } - else if (value < 0) { - edt_info = "Error on definition time is negative ! : " + value; - rtn = false; - } - if (mid_edt_value != ":") { - edt_info = "Error on definition ! :" + edt_value; - rtn = false; - } - } - else { - edt_info = "No value given"; - } -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Expected during time : " << edt_info << endl;; -#endif - - // check memory (check the format) - std::string mem_info = batch_params.mem; - std::string mem_value = batch_params.mem; - if (mem_value != "") { - std::string begin_mem_value = mem_value.substr(0, mem_value.length()-2); - long re_mem_value; - std::istringstream iss(begin_mem_value); - if (!(iss >> re_mem_value)) { - mem_info = "Error on definition ! : " + mem_value; - rtn = false; - } - else if (re_mem_value <= 0) { - mem_info = "Error on definition memory is negative ! : " + mem_value; - rtn = false; - } - std::string end_mem_value = mem_value.substr(mem_value.length()-2); - if (end_mem_value != "gb" && end_mem_value != "mb") { - mem_info = "Error on definition, type is bad ! " + mem_value; - rtn = false; - } - } - else { - mem_info = "No value given"; - } -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Memory : " << mem_info << endl; -#endif - - // check nb_proc - std::string nb_proc_info; - ostringstream nb_proc_value; - nb_proc_value << batch_params.nb_proc; - if(batch_params.nb_proc <= 0) { - nb_proc_info = "Bad value ! nb_proc = "; - nb_proc_info += nb_proc_value.str(); - rtn = false; - } - else { - nb_proc_info = nb_proc_value.str(); - } -#if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Nb of processors : " << nb_proc_info << endl; -#endif - - return rtn; -} - -long Launcher_cpp::getWallTime(std::string edt) -{ - long hh, mm, ret; - - if( edt.size() == 0 ) - return 0; - - string::size_type pos = edt.find(":"); - string h = edt.substr(0,pos); - string m = edt.substr(pos+1,edt.size()-pos+1); - istringstream issh(h); - issh >> hh; - istringstream issm(m); - issm >> mm; - ret = hh*60 + mm; - return ret; -} - -long Launcher_cpp::getRamSize(std::string mem) -{ - long mv; - - if( mem.size() == 0 ) - return 0; - - string ram = mem.substr(0,mem.size()-2); - istringstream iss(ram); - iss >> mv; - string unity = mem.substr(mem.size()-2,2); - if( (unity.find("gb") != string::npos) || (unity.find("GB") != string::npos) ) - return mv*1024; - else if( (unity.find("mb") != string::npos) || (unity.find("MB") != string::npos) ) - return mv; - else if( (unity.find("kb") != string::npos) || (unity.find("KB") != string::npos) ) - return mv/1024; - else if( (unity.find("b") != string::npos) || (unity.find("B") != string::npos) ) - return mv/(1024*1024); - else - return 0; -} - -void Launcher_cpp::ParseXmlFile(string xmlExecuteFile) -{ - SALOME_Launcher_Handler* handler = new SALOME_Launcher_Handler(_launch); - - const char* aFilePath = xmlExecuteFile.c_str(); - FILE* aFile = fopen(aFilePath, "r"); - - if (aFile != NULL) - { - xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0); - - if (aDoc != NULL) - handler->ProcessXmlDocument(aDoc); - else{ -#if defined(_DEBUG_) || defined(_DEBUG) - cout << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl; -#endif - } - - // Free the document - xmlFreeDoc(aDoc); - - fclose(aFile); - } - else{ -#if defined(_DEBUG_) || defined(_DEBUG) - cout << "Launcher_cpp: file "< instanciate one if does not exist std::string machine_name = machine_definition.Alias; std::map::const_iterator it = _batchmap.find(machine_name); @@ -1083,12 +170,6 @@ Launcher_cpp::createJob(Launcher::Job * new_job) throw LauncherException("A job as already the same id - job is not created !"); } LAUNCHER_MESSAGE("New Job created"); -#else - LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot create a job !!!"); - delete new_job; - throw LauncherException("Method Launcher_cpp::createJob is not available " - "(libBatch was not present at compilation time)"); -#endif } //============================================================================= @@ -1118,9 +199,6 @@ Launcher_cpp::launchJob(int job_id) throw LauncherException("Bad state of the job: " + job->getState()); } - // Part dependent of LIBBATCH - Without it we delete the job and send an exception -#ifdef WITH_LIBBATCH - std::string machine_name = job->getMachineDefinition().Alias; try { Batch::JobId batch_manager_job_id = _batchmap[machine_name]->submitJob(*(job->getBatchJob())); @@ -1133,12 +211,6 @@ Launcher_cpp::launchJob(int job_id) throw LauncherException(ex.message.c_str()); } LAUNCHER_MESSAGE("Job launched"); - -#else - LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot launch a job !!!"); - throw LauncherException("Method Launcher_cpp::launchJob is not available " - "(libBatch was not present at compilation time)"); -#endif } //============================================================================= @@ -1184,12 +256,6 @@ Launcher_cpp::getJobResults(int job_id, std::string directory) } Launcher::Job * job = it_job->second; - - // Part dependent of LIBBATCH - // We may have to check job state and only get files when job is fisnished or in error... - // We may also change default result directory... -#ifdef WITH_LIBBATCH - std::string machine_name = job->getMachineDefinition().Alias; try { @@ -1204,12 +270,6 @@ Launcher_cpp::getJobResults(int job_id, std::string directory) throw LauncherException(ex.message.c_str()); } LAUNCHER_MESSAGE("getJobResult ended"); - -#else - LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job results!!!"); - throw LauncherException("Method Launcher_cpp::getJobResults is not available " - "(libBatch was not present at compilation time)"); -#endif } //============================================================================= @@ -1232,3 +292,218 @@ Launcher_cpp::removeJob(int job_id) _launcher_job_map.erase(it_job); // Erase call delete on it_job->second } + +//============================================================================= +/*! + * create a launcher job based on a file + * \param xmlExecuteFile : to define the execution on the batch cluster + */ +//============================================================================= +long +Launcher_cpp::createJobWithFile(const std::string xmlExecuteFile, + const std::string clusterName) +{ + LAUNCHER_MESSAGE("Begin of Launcher_cpp::createJobWithFile"); + + // Parsing xml file + ParserLauncherType job_params = ParseXmlFile(xmlExecuteFile); + + // Creating a new job + Launcher::Job_Command * new_job = new Launcher::Job_Command(job_params.Command); + new_job->setLocalDirectory(job_params.RefDirectory); + new_job->setWorkDirectory(job_params.MachinesList[clusterName].WorkDirectory); + new_job->setEnvFile(job_params.MachinesList[clusterName].EnvFile); + + for(int i=0; i < job_params.InputFile.size(); i++) + new_job->add_in_file(job_params.InputFile[i]); + for(int i=0; i < job_params.OutputFile.size();i++) + new_job->add_out_file(job_params.OutputFile[i]); + + machineParams p; + p.hostname = clusterName; + p.nb_node = job_params.NbOfProcesses; + new_job->setMachineRequiredParams(p); + + createJob(new_job); + return new_job->getNumber(); +} + +//============================================================================= +/*! + * Factory to instanciate the good batch manager for choosen cluster. + */ +//============================================================================= +Batch::BatchManager_eClient * +Launcher_cpp::FactoryBatchManager(ParserResourcesType& params) +{ + std::string mpi; + Batch::CommunicationProtocolType protocol; + Batch::FactBatchManager_eClient* fact; + + int nb_proc_per_node = params.DataForSort._nbOfProcPerNode; + std::string hostname = params.Alias; + + switch(params.Protocol) + { + case rsh: + protocol = Batch::RSH; + break; + case ssh: + protocol = Batch::SSH; + break; + default: + throw LauncherException("Unknown protocol for this resource"); + break; + } + + switch(params.mpi) + { + case lam: + mpi = "lam"; + break; + case mpich1: + mpi = "mpich1"; + break; + case mpich2: + mpi = "mpich2"; + break; + case openmpi: + mpi = "openmpi"; + break; + case slurm: + mpi = "slurm"; + break; + case prun: + mpi = "prun"; + break; + default: + mpi = "nompi"; + } + + std::string message = "Instanciation of batch manager of type: "; + switch( params.Batch ) + { + case pbs: + message += "ePBS"; + fact = new Batch::FactBatchManager_ePBS; + break; + case lsf: + message += "eLSF"; + fact = new Batch::FactBatchManager_eLSF; + break; + case sge: + message += "eSGE"; + fact = new Batch::FactBatchManager_eSGE; + break; + case ssh_batch: + message += "eSSH"; + fact = new Batch::FactBatchManager_eSSH; + break; + default: + LAUNCHER_MESSAGE("Bad batch description of the resource: Batch = " << params.Batch); + throw LauncherException("No batchmanager for that cluster - Bad batch description of the resource"); + } + LAUNCHER_MESSAGE(message); + return (*fact)(hostname.c_str(), protocol, mpi.c_str(), nb_proc_per_node); +} + +//---------------------------------------------------------- +// Without LIBBATCH - Launcher_cpp do nothing... +//---------------------------------------------------------- +#else + +void +Launcher_cpp::createJob(Launcher::Job * new_job) +{ + LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot create a job !!!"); + delete new_job; + throw LauncherException("Method Launcher_cpp::createJob is not available " + "(libBatch was not present at compilation time)"); +} + +void +Launcher_cpp::launchJob(int job_id) +{ + LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot launch a job !!!"); + throw LauncherException("Method Launcher_cpp::launchJob is not available " + "(libBatch was not present at compilation time)"); +} + +const char * +Launcher_cpp::getJobState(int job_id) +{ + LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job state!!!"); + throw LauncherException("Method Launcher_cpp::getJobState is not available " + "(libBatch was not present at compilation time)"); +} + +void +Launcher_cpp::getJobResults(int job_id, std::string directory) +{ + LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job results!!!"); + throw LauncherException("Method Launcher_cpp::getJobResults is not available " + "(libBatch was not present at compilation time)"); +} + +void +Launcher_cpp::removeJob(int job_id) +{ + LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot remove job!!!"); + throw LauncherException("Method Launcher_cpp::removeJob is not available " + "(libBatch was not present at compilation time)"); +} + +long +Launcher_cpp::createJobWithFile( const std::string xmlExecuteFile) +{ + throw LauncherException("Method Launcher_cpp::createJobWithFile is not available " + "(libBatch was not present at compilation time)"); + return 0; +} + +Batch::BatchManager_eClient * +Launcher_cpp::FactoryBatchManager(ParserResourcesType& params ) throw(LauncherException) +{ + throw LauncherException("Method Launcher_cpp::FactoryBatchManager is not available " + "(libBatch was not present at compilation time)"); + return NULL; +} +#endif + +ParserLauncherType +Launcher_cpp::ParseXmlFile(string xmlExecuteFile) +{ + ParserLauncherType job_params; + SALOME_Launcher_Handler * handler = new SALOME_Launcher_Handler(job_params); + + const char* aFilePath = xmlExecuteFile.c_str(); + FILE* aFile = fopen(aFilePath, "r"); + if (aFile != NULL) + { + xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0); + if (aDoc != NULL) + handler->ProcessXmlDocument(aDoc); + else + { + std::string message = "ResourcesManager_cpp: could not parse file: " + xmlExecuteFile; + LAUNCHER_MESSAGE(message); + delete handler; + throw LauncherException(message); + } + // Free the document + xmlFreeDoc(aDoc); + fclose(aFile); + } + else + { + std::string message = "ResourcesManager_cpp: file is not readable: " + xmlExecuteFile; + LAUNCHER_MESSAGE(message); + delete handler; + throw LauncherException(message); + } + + // Return + delete handler; + return job_params; +} + diff --git a/src/Launcher/Launcher.hxx b/src/Launcher/Launcher.hxx index 916b71cf5..4139a0596 100644 --- a/src/Launcher/Launcher.hxx +++ b/src/Launcher/Launcher.hxx @@ -56,53 +56,28 @@ public: Launcher_cpp(); ~Launcher_cpp(); - long submitJob(const std::string xmlExecuteFile, - const std::string clusterName) throw(LauncherException); - - long submitSalomeJob(const std::string fileToExecute , - const std::vector& filesToExport , - const std::vector& filesToImport , - const batchParams& batch_params, - const machineParams& params) throw(LauncherException); - - std::string queryJob( const long jobId, const machineParams& params) throw(LauncherException); - std::string queryJob( const long jobId, const std::string clusterName) throw(LauncherException); - void deleteJob( const long jobId, const machineParams& params) throw(LauncherException); - void deleteJob( const long jobId, const std::string clusterName) throw(LauncherException); - void getResultsJob( const std::string directory, const long jobId, const machineParams& params ) throw(LauncherException); - void getResultsJob( const std::string directory, const long jobId, const std::string clusterName ) throw (LauncherException); - - void SetResourcesManager( ResourcesManager_cpp* rm ) { _ResManager = rm; } - - // New interface - void createJob(Launcher::Job * new_job); - void launchJob(int job_id); + // Main interface + void createJob(Launcher::Job * new_job); + void launchJob(int job_id); const char * getJobState(int job_id); - void getJobResults(int job_id, std::string directory); - void removeJob(int job_id); + void getJobResults(int job_id, std::string directory); + void removeJob(int job_id); -protected: - - std::string buildSalomeCouplingScript(const std::string fileToExecute, const std::string dirForTmpFiles, const ParserResourcesType& params); - MpiImpl *FactoryMpiImpl(MpiImplType mpiImpl) throw(LauncherException); - Batch::BatchManager_eClient *FactoryBatchManager(ParserResourcesType& params ) throw(LauncherException); - std::string getTmpDirForBatchFiles(); - std::string getRemoteFile( std::string remoteDir, std::string localFile ); - std::string getHomeDir(const ParserResourcesType& p, const std::string & tmpdir); + // Useful methods + long createJobWithFile(std::string xmlExecuteFile, std::string clusterName); - std::map _batchmap; - std::map < std::pair , Batch::Job* > _jobmap; + // Lib methods + void SetResourcesManager( ResourcesManager_cpp* rm ) {_ResManager = rm;} - std::map _launcher_job_map; - ResourcesManager_cpp *_ResManager; - bool check(const batchParams& batch_params); - long getWallTime(std::string edt); - long getRamSize(std::string mem); - void ParseXmlFile(std::string xmlExecuteFile); +protected: - //! will contain the informations on the data type catalog(after parsing) - ParserLauncherType _launch; + // Methods used by user interface methods + Batch::BatchManager_eClient *FactoryBatchManager(ParserResourcesType& params); + ParserLauncherType ParseXmlFile(std::string xmlExecuteFile); + ResourcesManager_cpp *_ResManager; + std::map _batchmap; + std::map _launcher_job_map; int _job_cpt; // job number counter pthread_mutex_t * _job_cpt_mutex; // mutex for job counter }; diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index 9edbb2f4a..6f399b193 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -117,6 +117,8 @@ void Launcher::Job::setEnvFile(std::string & env_file) { _env_file = env_file; + if (_env_file != "") + add_in_file(_env_file); } std::string @@ -282,7 +284,7 @@ Launcher::Job::convertMaximumDuration(const std::string & edt) long hh, mm, ret; if( edt.size() == 0 ) - return 0; + return -1; std::string::size_type pos = edt.find(":"); std::string h = edt.substr(0,pos); @@ -391,10 +393,6 @@ Launcher::Job::common_job_params() if (_result_directory == "") _result_directory = getenv("HOME"); - //Env file - if (_env_file != "") - add_in_file(_env_file); - // _in_files for(std::list::iterator it = _in_files.begin(); it != _in_files.end(); it++) { diff --git a/src/Launcher/Launcher_Job_YACSFile.cxx b/src/Launcher/Launcher_Job_YACSFile.cxx index 6f2366567..8f5347aa7 100644 --- a/src/Launcher/Launcher_Job_YACSFile.cxx +++ b/src/Launcher/Launcher_Job_YACSFile.cxx @@ -111,9 +111,10 @@ Launcher::Job_YACSFile::buildSalomeCouplingScript(Batch::Parametre params) std::string machine_protocol = "ssh"; if (_machine_definition.Protocol == rsh) machine_protocol = "rsh"; + + launch_script_stream << "if [ \"x$LIBBATCH_NODEFILE\" != \"x\" ]; then " << std::endl; launch_script_stream << "CATALOG_FILE=" << work_directory << "/CatalogResources_" << _launch_date << ".xml" << std::endl; launch_script_stream << "export USER_CATALOG_RESOURCES_FILE=" << "$CATALOG_FILE" << std::endl; - launch_script_stream << "echo '' > $CATALOG_FILE" << std::endl; launch_script_stream << "echo '' >> $CATALOG_FILE" << std::endl; launch_script_stream << "cat $LIBBATCH_NODEFILE | sort -u | while read host" << std::endl; @@ -125,6 +126,7 @@ Launcher::Job_YACSFile::buildSalomeCouplingScript(Batch::Parametre params) launch_script_stream << "echo '/>' >> $CATALOG_FILE" << std::endl; launch_script_stream << "done" << std::endl; launch_script_stream << "echo '' >> $CATALOG_FILE" << std::endl; + launch_script_stream << "fi" << std::endl; // Launch SALOME with an appli launch_script_stream << _machine_definition.AppliPath << "/runAppli --terminal --ns-port-log=" << launch_date_port_file << " > logs/salome_" << _launch_date << ".log 2>&1" << std::endl; diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index b6331bd0d..debe56386 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -45,11 +45,8 @@ const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher"; /*! * Constructor * \param orb - * Define a CORBA single thread policy for the server, which avoid to deal - * with non thread-safe usage like Change_Directory in SALOME naming service */ //============================================================================= - SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) : _l() { MESSAGE("SALOME_Launcher constructor"); @@ -67,7 +64,6 @@ SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj); _NS->Register(refContMan,_LauncherNameInNS); - MESSAGE("SALOME_Launcher constructor end"); } @@ -76,118 +72,13 @@ SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa * destructor */ //============================================================================= - SALOME_Launcher::~SALOME_Launcher() { - MESSAGE("destructor"); + MESSAGE("SALOME_Launcher destructor"); delete _NS; + MESSAGE("SALOME_Launcher destructor end"); } -//============================================================================= -/*! CORBA method: - * shutdown all the containers, then the ContainerManager servant - */ -//============================================================================= - -void SALOME_Launcher::Shutdown() -{ - MESSAGE("Shutdown"); - _NS->Destroy_Name(_LauncherNameInNS); - _ContManager->Shutdown(); - _ResManager->Shutdown(); - PortableServer::ObjectId_var oid = _poa->servant_to_id(this); - _poa->deactivate_object(oid); - if(!CORBA::is_nil(_orb)) - _orb->shutdown(0); -} - -//============================================================================= -/*! CORBA Method: - * Returns the PID of the process - */ -//============================================================================= -CORBA::Long SALOME_Launcher::getPID() -{ - return -#ifndef WIN32 - (CORBA::Long)getpid(); -#else - (CORBA::Long)_getpid(); -#endif - -} - -//============================================================================= -/*! CORBA Method: - * Submit a batch job on a cluster and returns the JobId - * \param xmlExecuteFile : .xml to parse to execute on the batch cluster - * \param clusterName : cluster name - */ -//============================================================================= -CORBA::Long SALOME_Launcher::submitJob(const char * xmlExecuteFile, - const char * clusterName) -{ - CORBA::Long jobId; - - try{ - jobId = _l.submitJob(xmlExecuteFile,clusterName); - } - catch(const LauncherException &ex){ - INFOS(ex.msg.c_str()); - THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR); - } - return jobId; -} - -//============================================================================= -/*! CORBA Method: - * Submit a batch job on a cluster and returns the JobId - * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster - * \param filesToExport : to export on the batch cluster - * \param NumberOfProcessors : Number of processors needed on the batch cluster - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -CORBA::Long SALOME_Launcher::submitSalomeJob( const char * fileToExecute , - const Engines::FilesList& filesToExport , - const Engines::FilesList& filesToImport , - const Engines::BatchParameters& batch_params, - const Engines::MachineParameters& params) -{ - MESSAGE("BEGIN OF SALOME_Launcher::submitSalomeJob"); - CORBA::Long jobId; - - machineParams p; - p.hostname = params.hostname; - p.OS = params.OS; - p.nb_node = params.nb_node; - p.nb_proc_per_node = params.nb_proc_per_node; - p.cpu_clock = params.cpu_clock; - p.mem_mb = params.mem_mb; - - batchParams bp; - bp.batch_directory = batch_params.batch_directory; - bp.expected_during_time = batch_params.expected_during_time; - bp.mem = batch_params.mem; - bp.nb_proc = batch_params.nb_proc; - - vector efl; - for(int i=0;i ifl; - for(int i=0;iDestroy_Name(_LauncherNameInNS); + _ContManager->Shutdown(); + _ResManager->Shutdown(); + PortableServer::ObjectId_var oid = _poa->servant_to_id(this); + _poa->deactivate_object(oid); + if(!CORBA::is_nil(_orb)) + _orb->shutdown(0); } //============================================================================= /*! CORBA Method: - * Get result files of job on a cluster - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster + * Returns the PID of the process */ //============================================================================= -void SALOME_Launcher::getResultsJob( const char *directory, - const CORBA::Long jobId, - const Engines::MachineParameters& params) +CORBA::Long SALOME_Launcher::getPID() { - machineParams p; - p.hostname = params.hostname; - p.OS = params.OS; - p.nb_node = params.nb_node; - p.nb_proc_per_node = params.nb_proc_per_node; - p.cpu_clock = params.cpu_clock; - p.mem_mb = params.mem_mb; - - try{ - _l.getResultsJob( directory, jobId, p ); - } - catch(const LauncherException &ex){ - INFOS("Caught exception."); - THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM); - } + return +#ifndef WIN32 + (CORBA::Long)getpid(); +#else + (CORBA::Long)_getpid(); +#endif } diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index 8f463a9f9..6de459767 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -43,32 +43,19 @@ public: SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa); ~SALOME_Launcher(); - CORBA::Long submitJob(const char * xmlExecuteFile, - const char * clusterName); - - CORBA::Long submitSalomeJob(const char * fileToExecute , - const Engines::FilesList& filesToExport , - const Engines::FilesList& filesToImport , - const Engines::BatchParameters& batch_params, - const Engines::MachineParameters& params); - - char* querySalomeJob( CORBA::Long jobId, const Engines::MachineParameters& params); - void deleteSalomeJob( CORBA::Long jobId, const Engines::MachineParameters& params); - void getResultSalomeJob( const char * directory, CORBA::Long jobId, const Engines::MachineParameters& params ); - char* queryJob( CORBA::Long jobId, const Engines::MachineParameters& params); - void deleteJob( CORBA::Long jobId, const Engines::MachineParameters& params); - void getResultsJob( const char * directory, CORBA::Long jobId, const Engines::MachineParameters& params ); - - CORBA::Long createJob(const Engines::JobParameters & job_parameters); - void launchJob(CORBA::Long job_id); - char * getJobState(CORBA::Long job_id); - void getJobResults(CORBA::Long job_id, const char * directory); - void removeJob(CORBA::Long job_id); - - CORBA::Boolean testBatch(const Engines::MachineParameters& params); - + // Main methods + CORBA::Long createJob (const Engines::JobParameters & job_parameters); + void launchJob (CORBA::Long job_id); + char * getJobState (CORBA::Long job_id); + void getJobResults(CORBA::Long job_id, const char * directory); + void removeJob (CORBA::Long job_id); + + // Useful methods + CORBA::Long createJobWithFile(const char * xmlExecuteFile, const char * clusterName); + CORBA::Boolean testBatch (const Engines::MachineParameters& params); + + // SALOME Kernel service methods void Shutdown(); - CORBA::Long getPID(); static const char *_LauncherNameInNS; -- 2.39.2