From 540b79ee5dcf65ba448068762445f5663f54110a Mon Sep 17 00:00:00 2001 From: ribes Date: Thu, 12 Nov 2009 13:36:56 +0000 Subject: [PATCH] YACS File job ok --- src/Launcher/Launcher.cxx | 14 +++- src/Launcher/Launcher_Job.cxx | 20 ++++-- src/Launcher/Launcher_Job.hxx | 4 +- src/Launcher/Launcher_Job_YACSFile.cxx | 99 +++++++++++++++++++++++++- src/Launcher/Launcher_Job_YACSFile.hxx | 6 +- 5 files changed, 131 insertions(+), 12 deletions(-) diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index 941374355..56082175e 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -1028,7 +1028,19 @@ Launcher_cpp::createJob(Launcher::Job * new_job) mess += machine_definition.HostName; throw LauncherException(mess); } - new_job->setMachineDefinition(machine_definition); + + // Set machine definition to the job + // The job will check if the definitions needed + try + { + new_job->setMachineDefinition(machine_definition); + } + catch(const LauncherException &ex) + { + LAUNCHER_INFOS("Error in the definition of the resource, mess: " << ex.msg); + delete new_job; + throw ex; + } // Part dependent of LIBBATCH - Without it we delete the job and send an exception #ifdef WITH_LIBBATCH diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index 532d7e844..0f3b5a874 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -94,6 +94,13 @@ Launcher::Job::getNumber() void Launcher::Job::setMachineDefinition(const ParserResourcesType & machine_definition) { + // Check machine_definition + if (machine_definition.UserName == "") + { + std::string mess = "Machine definition must define a user name !, machine name is: " + machine_definition.HostName; + throw LauncherException(mess); + } + _machine_definition = machine_definition; } @@ -331,7 +338,11 @@ Launcher::Job::common_job_params() _work_directory += thedate; } params[WORKDIR] = _work_directory; - params[TMPDIR] = _work_directory; + params[TMPDIR] = _work_directory; // To Compatibility -- remove ??? TODO + + // If result_directory is not defined, we use HOME environnement + if (_result_directory == "") + _result_directory = getenv("HOME"); // _in_files for(std::list::iterator it = _in_files.begin(); it != _in_files.end(); it++) @@ -357,12 +368,9 @@ Launcher::Job::common_job_params() { std::string file = *it; - // local file -> If result_directory is not defined, we use HOME environnement - std::string result_directory = _result_directory; - if (result_directory == "") - result_directory = getenv("HOME"); + // local file size_t found = file.find_last_of("/"); - std::string local_file = result_directory + "/" + file.substr(found+1); + std::string local_file = _result_directory + "/" + file.substr(found+1); // remote file -> If file is not an absolute path, we apply _work_directory std::string remote_file; diff --git a/src/Launcher/Launcher_Job.hxx b/src/Launcher/Launcher_Job.hxx index fb3005463..1f90b75db 100644 --- a/src/Launcher/Launcher_Job.hxx +++ b/src/Launcher/Launcher_Job.hxx @@ -55,7 +55,7 @@ namespace Launcher void setNumber(const int & number); int getNumber(); - void setMachineDefinition(const ParserResourcesType & machine_definition); + virtual void setMachineDefinition(const ParserResourcesType & machine_definition); ParserResourcesType getMachineDefinition(); // Common parameters @@ -87,7 +87,7 @@ namespace Launcher // Abstract class virtual void update_job() = 0; - private: + protected: int _number; std::string _state; diff --git a/src/Launcher/Launcher_Job_YACSFile.cxx b/src/Launcher/Launcher_Job_YACSFile.cxx index c773e6154..53f880b9c 100644 --- a/src/Launcher/Launcher_Job_YACSFile.cxx +++ b/src/Launcher/Launcher_Job_YACSFile.cxx @@ -20,6 +20,9 @@ #include "Launcher_Job_YACSFile.hxx" +#include +#include + Launcher::Job_YACSFile::Job_YACSFile(const std::string & yacs_file) { _yacs_file = yacs_file; @@ -39,18 +42,110 @@ Launcher::Job_YACSFile::getYACSFile() { return _yacs_file; } + +void +Launcher::Job_YACSFile::setMachineDefinition(const ParserResourcesType & machine_definition) +{ + // Check machine_definition + if (machine_definition.AppliPath == "") + { + std::string mess = "Machine definition must define an application path !, machine name is: " + machine_definition.HostName; + throw LauncherException(mess); + } + + Launcher::Job::setMachineDefinition(machine_definition); +} + void Launcher::Job_YACSFile::update_job() { #ifdef WITH_LIBBATCH Batch::Parametre params = common_job_params(); - params[EXECUTABLE] = buildSalomeCouplingScript(); + // Adding New Files for this type of job + // Copy YACS File + // local file -> If file is not an absolute path, we apply _local_directory + // remote file -> get only file name from _in_files + std::string local_file; + if (_yacs_file.substr(0, 1) == std::string("/")) + local_file = _yacs_file; + else + local_file = _local_directory + "/" + _yacs_file; + size_t found = _yacs_file.find_last_of("/"); + std::string remote_file = _work_directory + "/" + _yacs_file.substr(found+1); + params[INFILE] += Batch::Couple(local_file, remote_file); + + // logs + // local file -> If result_directory is not defined, we use HOME environnement + std::string log_directory = "logs"; + std::string log_local_file = _result_directory + "/" + log_directory; + std::string log_remote_file = _work_directory + "/" + log_directory; + params[OUTFILE] += Batch::Couple(log_local_file, log_remote_file); + + params[EXECUTABLE] = buildSalomeCouplingScript(params); + + // Add in files -> yacs_file and launch_script _batch_job->setParametre(params); #endif } std::string -Launcher::Job_YACSFile::buildSalomeCouplingScript() +Launcher::Job_YACSFile::buildSalomeCouplingScript(Batch::Parametre params) { + // parameters + std::string work_directory = params[WORKDIR].str(); + + // File name + std::string::size_type p1 = _yacs_file.find_last_of("/"); + std::string::size_type p2 = _yacs_file.find_last_of("."); + std::string yacs_file_name = _yacs_file.substr(p1+1,p2-p1-1); + + time_t rawtime; + time(&rawtime); + std::string launch_date = ctime(&rawtime); + int i = 0 ; + for (;i < launch_date.size(); i++) + if (launch_date[i] == '/' or + launch_date[i] == '-' or + launch_date[i] == ':' or + launch_date[i] == ' ') + launch_date[i] = '_'; + launch_date.erase(--launch_date.end()); // Last caracter is a \n + + std::string launch_date_port_file = launch_date; + std::string launch_script = "/tmp/runSalome_" + yacs_file_name + "_" + launch_date + ".sh"; + std::ofstream launch_script_stream; + launch_script_stream.open(launch_script.c_str(), std::ofstream::out); + + // Begin of script + launch_script_stream << "#! /bin/sh -f" << std::endl; + launch_script_stream << "cd " << work_directory << std::endl; + launch_script_stream << "mkdir logs" << std::endl; + launch_script_stream << "export SALOME_TMP_DIR=" << work_directory << "/logs" << std::endl; + + // -- Generates Catalog Resources + // TODO + + // Launch SALOME with an appli + launch_script_stream << _machine_definition.AppliPath << "/runAppli --terminal --ns-port-log=" << launch_date_port_file << " > logs/salome.log 2>&1" << std::endl; + launch_script_stream << "current=0\n" + << "stop=20\n" + << "while ! test -f " << _machine_definition.AppliPath << "/" << launch_date_port_file << "\n" + << "do\n" + << " sleep 2\n" + << " let current=current+1\n" + << " if [ \"$current\" -eq \"$stop\" ] ; then\n" + << " echo Error Naming Service failed ! >&2\n" + << " exit\n" + << " fi\n" + << "done\n" + << "port=`cat " << _machine_definition.AppliPath << "/" << launch_date_port_file << "`\n"; + launch_script_stream << _machine_definition.AppliPath << "/runSession driver " << yacs_file_name << ".xml > logs/yacs.log 2>&1" << std::endl; + launch_script_stream << _machine_definition.AppliPath << "/runSession killSalomeWithPort.py $port" << std::endl; + + // Return + launch_script_stream.flush(); + launch_script_stream.close(); + chmod(launch_script.c_str(), 0x1ED); + return launch_script; } diff --git a/src/Launcher/Launcher_Job_YACSFile.hxx b/src/Launcher/Launcher_Job_YACSFile.hxx index bb61e9f4f..229a0b29c 100644 --- a/src/Launcher/Launcher_Job_YACSFile.hxx +++ b/src/Launcher/Launcher_Job_YACSFile.hxx @@ -40,10 +40,14 @@ namespace Launcher void setYACSFile(const std::string & yacs_file); std::string getYACSFile(); + virtual void setMachineDefinition(const ParserResourcesType & machine_definition); + virtual void update_job(); +#ifdef WITH_LIBBATCH protected: - std::string buildSalomeCouplingScript(); + std::string buildSalomeCouplingScript(Batch::Parametre params); +#endif private: std::string _yacs_file; -- 2.39.2