From: boulant Date: Tue, 13 Dec 2005 16:16:26 +0000 (+0000) Subject: Intégration bibliothèque Batch version 0.3.0 (avec gestionnaire local) X-Git-Tag: BR_auto_V310a2__v_0_3~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=921090e259724a27843432880f5e54846613851f;p=modules%2Fkernel.git Intégration bibliothèque Batch version 0.3.0 (avec gestionnaire local) --- diff --git a/src/Batch/Batch_BatchManager_Local.cxx b/src/Batch/Batch_BatchManager_Local.cxx new file mode 100644 index 000000000..0161ed791 --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local.cxx @@ -0,0 +1,774 @@ +/* + * BatchManager_Local.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Batch_IOMutex.hxx" +#include "Batch_BatchManager_Local.hxx" + +namespace Batch { + + + // Constructeur + BatchManager_Local::BatchManager_Local(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host), _connect(0), _threads_mutex(), _threads(), _thread_id_id_association_mutex(), _thread_id_id_association_cond(), _thread_id_id_association() + { + pthread_mutex_init(&_threads_mutex, NULL); + pthread_mutex_init(&_thread_id_id_association_mutex, NULL); + pthread_cond_init(&_thread_id_id_association_cond, NULL); + } + + // Destructeur + BatchManager_Local::~BatchManager_Local() + { + pthread_mutex_destroy(&_threads_mutex); + pthread_mutex_destroy(&_thread_id_id_association_mutex); + pthread_cond_destroy(&_thread_id_id_association_cond); + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_Local::submitJob(const Job & job) + { + Job_Local jobLocal = job; + + pthread_t thread_id = submit(jobLocal); + + ostringstream oss; + oss << getIdByThread_id(thread_id); + + JobId id(this, oss.str()); + + return id; + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_Local::deleteJob(const JobId & jobid) + { + Id id; + + istringstream iss(jobid.getReference()); + iss >> id; + + // On retrouve le thread_id du thread + pthread_t thread_id; + + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + if (_threads.find(id) != _threads.end()) + thread_id = _threads[id].thread_id; + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + cancel(thread_id); + } + + // Methode pour le controle des jobs : suspend un job en file d'attente + void BatchManager_Local::holdJob(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + UNDER_LOCK( cout << "BatchManager is sending HOLD command to the thread " << id << endl ); + + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + if (_threads.find(id) != _threads.end()) + _threads[id].command_queue.push(HOLD); + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + } + + // Methode pour le controle des jobs : relache un job suspendu + void BatchManager_Local::releaseJob(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + UNDER_LOCK( cout << "BatchManager is sending RELEASE command to the thread " << id << endl ); + + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + if (_threads.find(id) != _threads.end()) + _threads[id].command_queue.push(RELEASE); + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + } + + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_Local::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) + { + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_Local::alterJob(const JobId & jobid, const Parametre & param) + { + alterJob(jobid, param, Environnement()); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_Local::alterJob(const JobId & jobid, const Environnement & env) + { + alterJob(jobid, Parametre(), env); + } + + + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_Local::queryJob(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + Parametre param; + Environnement env; + + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : AVANT section critique" << endl ); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + param = _threads[id].param; + env = _threads[id].env; + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : APRES section critique" << endl ); + + JobInfo_Local ji(param, env); + return ji; + } + + + + // Methode pour le controle des jobs : teste si un job est present en machine + bool BatchManager_Local::isRunning(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + Status status; + + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : AVANT section critique" << endl ); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + status = _threads[id].status; + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : APRES section critique" << endl ); + + return (status == RUNNING); + } + + + // Methode d'execution d'un job + pthread_t BatchManager_Local::submit(const Job_Local & job) + { + // L'id du thread a creer + pthread_t thread_id = 0; + + // Les attributs du thread a sa creation + pthread_attr_t thread_attr; + pthread_attr_init(&thread_attr); + pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); + + ThreadAdapter * p_ta = new ThreadAdapter(*this, job); + + // Creation du thread qui va executer la commande systeme qu'on lui passe + int rc = pthread_create(&thread_id, + &thread_attr, + &ThreadAdapter::run, + static_cast(p_ta)); + if (rc) { + } + + // Liberation des zones memoire maintenant inutiles occupees par les attributs du thread + pthread_attr_destroy(&thread_attr); + + return thread_id; + } + + + // Methode de destruction d'un job + void BatchManager_Local::cancel(pthread_t thread_id) + { + pthread_cancel(thread_id); + } + + + // Fabrique un identifiant unique pour les threads puisque le thread_id n'est pas unique + // au cours du temps (il peut etre reutilise lorsqu'un thread se termine) + // ATTENTION : cette methode est uniquement protegee par la section critique de l'association + // Thread_id / Id (_thread_id_id_association_mutex) + BatchManager_Local::Id BatchManager_Local::nextId() + { + static Id id = 0; + Id nextId = id++; + //UNDER_LOCK( cout << "BatchManager_Local::Id BatchManager_Local::nextId() : Id = " << nextId << endl ); + return nextId; + } + + + // Retourne l'Id enregistre dans l'association Thread_id / Id et le detruit immediatement + BatchManager_Local::Id BatchManager_Local::getIdByThread_id(pthread_t thread_id) + { + Id id = -1; + + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_thread_id_id_association_mutex); + while (_thread_id_id_association.find(thread_id) == _thread_id_id_association.end()) + pthread_cond_wait(&_thread_id_id_association_cond, &_thread_id_id_association_mutex); + + id = _thread_id_id_association[thread_id]; + _thread_id_id_association.erase(thread_id); + + pthread_mutex_unlock(&_thread_id_id_association_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + //UNDER_LOCK( cout << "BatchManager_Local::Id BatchManager_Local::getIdByThread_id(pthread_t thread_id) : Id = " << id << " - thread_id = " << thread_id << endl ); + return id; + } + + + // Associe un Thread_id a un Id nouvellement cree + BatchManager_Local::Id BatchManager_Local::registerThread_id(pthread_t thread_id) + { + Id id = -1; + + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_thread_id_id_association_mutex); + if (_thread_id_id_association.find(thread_id) == _thread_id_id_association.end()) { + id = _thread_id_id_association[thread_id] = nextId(); + pthread_cond_signal(&_thread_id_id_association_cond); + + } else { + UNDER_LOCK( cerr << "ERROR : Pthread Inconstency. Two threads own the same thread_id." << endl ); + } + pthread_mutex_unlock(&_thread_id_id_association_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + //UNDER_LOCK( cout << "BatchManager_Local::Id BatchManager_Local::registerThread_id(pthread_t thread_id) : Id = " << id << " - thread_id = " << thread_id << endl ); + return id; + } + + + // Constructeur de la classe ThreadAdapter + BatchManager_Local::ThreadAdapter::ThreadAdapter(BatchManager_Local & bm, const Job_Local & job) : + _bm(bm), _job(job) + { + // Nothing to do + } + + + + // Methode d'execution du thread + void * BatchManager_Local::ThreadAdapter::run(void * arg) + { + // On bloque tous les signaux pour ce thread + sigset_t setmask; + sigfillset(&setmask); + pthread_sigmask(SIG_BLOCK, &setmask, NULL); + + + // On autorise la terminaison differee du thread + // (ces valeurs sont les valeurs par defaut mais on les force par precaution) + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); + + // On enregistre la fonction de suppression du fils en cas d'arret du thread + // Cette fontion sera automatiquement appelee lorsqu'une demande d'annulation + // sera prise en compte par pthread_testcancel() + pid_t child; + pthread_cleanup_push(BatchManager_Local::kill_child_on_exit, static_cast (&child)); + pthread_cleanup_push(BatchManager_Local::delete_on_exit, arg); + + ThreadAdapter * p_ta = static_cast(arg); + + + + + // Le code retour cumule (ORed) de tous les appels + // Nul en cas de reussite de l'ensemble des operations + int rc = 0; + + // Cette table contient la liste des fichiers a detruire a la fin du processus + std::vector files_to_delete; + + + + // On copie les fichiers d'entree pour le fils + const Parametre param = p_ta->_job.getParametre(); + Parametre::const_iterator it; + + // On initialise la variable workdir a la valeur du Current Working Directory + char * cwd = new char [PATH_MAX]; + getcwd(cwd, PATH_MAX); + string workdir = cwd; + delete [] cwd; + + if ( (it = param.find(WORKDIR)) != param.end() ) { + workdir = static_cast( (*it).second ); + } + + string executionhost = string(param[EXECUTIONHOST]); + + if ( (it = param.find(INFILE)) != param.end() ) { + Versatile V = (*it).second; + Versatile::iterator Vit; + + for(Vit=V.begin(); Vit!=V.end(); Vit++) { + CoupleType cpt = *static_cast< CoupleType * >(*Vit); + Couple cp = cpt; + string local = cp.getLocal(); + string remote = cp.getRemote(); + + string copy_cmd = p_ta->getBatchManager().copy_command("", local, executionhost, workdir + "/" + remote); + UNDER_LOCK( cout << "Copying : " << copy_cmd << endl ); + + if (system(copy_cmd.c_str()) ) { + // Echec de la copie + rc |= 1; + } else { + // On enregistre le fichier comme etant a detruire + files_to_delete.push_back(workdir + "/" + remote); + } + + } + } + + + + + + // On forke/exec un nouveau process pour pouvoir controler le fils + // (plus finement qu'avec un appel system) + // int rc = system(commande.c_str()); + child = fork(); + if (child < 0) { // erreur + UNDER_LOCK( cerr << "Fork impossible (rc=" << child << ")" << endl ); + + } else if (child > 0) { // pere + p_ta->pere(child); + + } else { // fils + p_ta->fils(); + } + + + + + // On copie les fichiers de sortie du fils + if ( (it = param.find(OUTFILE)) != param.end() ) { + Versatile V = (*it).second; + Versatile::iterator Vit; + + for(Vit=V.begin(); Vit!=V.end(); Vit++) { + CoupleType cpt = *static_cast< CoupleType * >(*Vit); + Couple cp = cpt; + string local = cp.getLocal(); + string remote = cp.getRemote(); + + string copy_cmd = p_ta->getBatchManager().copy_command(executionhost, workdir + "/" + remote, "", local); + UNDER_LOCK( cout << "Copying : " << copy_cmd << endl ); + + if (system(copy_cmd.c_str()) ) { + // Echec de la copie + rc |= 1; + } else { + // On enregistre le fichier comme etant a detruire + files_to_delete.push_back(workdir + "/" + remote); + } + + } + } + + + + + // On efface les fichiers d'entree et de sortie du fils si les copies precedentes ont reussi + // ou si la creation du fils n'a pu avoir lieu + if ( (rc == 0) || (child < 0) ) { + std::vector::const_iterator it; + for(it=files_to_delete.begin(); it!=files_to_delete.end(); it++) { + string remove_cmd = p_ta->getBatchManager().remove_command(executionhost, *it); + UNDER_LOCK( cout << "Removing : " << remove_cmd << endl ); + system(remove_cmd.c_str()); + } + } + + + + // On retire la fonction de nettoyage de la memoire + pthread_cleanup_pop(0); + + // On retire la fonction de suppression du fils + pthread_cleanup_pop(0); + + + + // On invoque la fonction de nettoyage de la memoire + delete_on_exit(arg); + + UNDER_LOCK( cout << "Father is leaving" << endl ); + pthread_exit(NULL); + + return NULL; + } + + + + + void BatchManager_Local::ThreadAdapter::pere(pid_t child) + { + time_t child_starttime = time(NULL); + + // On enregistre le fils dans la table des threads + pthread_t thread_id = pthread_self(); + Id id = _bm.registerThread_id(thread_id); + + Parametre param = _job.getParametre(); + Environnement env = _job.getEnvironnement(); + + ostringstream thread_id_sst; + thread_id_sst << id; + param[ID] = thread_id_sst.str(); + param[STATE] = "Running"; + param[PID] = child; + + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + _bm._threads[id].thread_id = thread_id; + _bm._threads[id].pid = child; + _bm._threads[id].status = RUNNING; + _bm._threads[id].param = param; + _bm._threads[id].env = env; + _bm._threads[id].command_queue.push(NOP); + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + + + + + // on boucle en attendant que le fils ait termine + while (1) { + int child_rc = 0; + pid_t child_wait_rc = waitpid(child, &child_rc, WNOHANG /* | WUNTRACED */); + if (child_wait_rc > 0) { + if (WIFSTOPPED(child_rc)) { + // NOTA : pour rentrer dans cette section, il faut que le flag WUNTRACED + // soit positionne dans l'appel a waitpid ci-dessus. Ce flag est couramment + // desactive car s'il est possible de detecter l'arret d'un process, il est + // plus difficile de detecter sa reprise. + + // Le fils est simplement stoppe + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + _bm._threads[id].status = STOPPED; + _bm._threads[id].param[STATE] = "Stopped"; + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + UNDER_LOCK( cout << "Father sees his child is STOPPED : " << child_wait_rc << endl ); + + } + else { + // Le fils est termine, on sort de la boucle et du if englobant + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + _bm._threads[id].status = DONE; + _bm._threads[id].param[STATE] = "Done"; + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + UNDER_LOCK( cout << "Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")" << endl ); + break; + } + } + else if (child_wait_rc == -1) { + // Le fils a disparu ... + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + _bm._threads[id].status = DEAD; + _bm._threads[id].param[STATE] = "Dead"; + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + UNDER_LOCK( cout << "Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")" << endl ); + break; + } + + + + // On teste si le thread doit etre detruit + pthread_testcancel(); + + + + // On regarde si le fils n'a pas depasse son temps (wallclock time) + time_t child_currenttime = time(NULL); + time_t child_elapsedtime = child_currenttime - child_starttime; + if (param.find(MAXWALLTIME) != param.end()) { + int maxwalltime = param[MAXWALLTIME]; + // cout << "child_starttime = " << child_starttime << endl + // << "child_currenttime = " << child_currenttime << endl + // << "child_elapsedtime = " << child_elapsedtime << endl + // << "maxwalltime = " << maxwalltime << endl + // << "int(maxwalltime * 1.1) = " << int(maxwalltime * 1.1) << endl; + if (child_elapsedtime > int(maxwalltime * 1.1) ) { // On se donne 10% de marge avant le KILL + UNDER_LOCK( cout << "Father is sending KILL command to the thread " << id << endl ); + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + if (_bm._threads.find(id) != _bm._threads.end()) + _bm._threads[id].command_queue.push(KILL); + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + + } else if (child_elapsedtime > maxwalltime ) { + UNDER_LOCK( cout << "Father is sending TERM command to the thread " << id << endl ); + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + if (_bm._threads.find(id) != _bm._threads.end()) + _bm._threads[id].command_queue.push(TERM); + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + } + } + + + + // On regarde s'il y a quelque chose a faire dans la queue de commande + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + if (_bm._threads.find(id) != _bm._threads.end()) { + while (_bm._threads[id].command_queue.size() > 0) { + Commande cmd = _bm._threads[id].command_queue.front(); + _bm._threads[id].command_queue.pop(); + + switch (cmd) { + case NOP: + UNDER_LOCK( cout << "Father does nothing to his child" << endl ); + break; + + case HOLD: + UNDER_LOCK( cout << "Father is sending SIGSTOP signal to his child" << endl ); + kill(child, SIGSTOP); + break; + + case RELEASE: + UNDER_LOCK( cout << "Father is sending SIGCONT signal to his child" << endl ); + kill(child, SIGCONT); + break; + + case TERM: + UNDER_LOCK( cout << "Father is sending SIGTERM signal to his child" << endl ); + kill(child, SIGTERM); + break; + + case KILL: + UNDER_LOCK( cout << "Father is sending SIGKILL signal to his child" << endl ); + kill(child, SIGKILL); + break; + + case ALTER: + break; + + default: + break; + } + } + + } + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + // On fait une petite pause pour ne pas surcharger inutilement le processeur + sleep(1); + + } + + + } + + + + + void BatchManager_Local::ThreadAdapter::fils() + { + Parametre param = _job.getParametre(); + Parametre::iterator it; + + try { + + // On se place dans le repertoire de travail + if ( (it = param.find(WORKDIR)) != param.end() ) { + string workdir = static_cast( (*it).second ); + chdir(workdir.c_str()); + } + + + + + // EXECUTABLE is MANDATORY, if missing, we exit with failure notification + char * execpath = NULL; + if (param.find(EXECUTABLE) != param.end()) { + string executable = _bm.exec_command(param); + execpath = new char [executable.size() + 1]; + strncpy(execpath, executable.c_str(), executable.size() + 1); + } else exit(1); + + string debug_command = execpath; + + string name = (param.find(NAME) != param.end()) ? param[NAME] : param[EXECUTABLE]; + + char ** argv = NULL; + if (param.find(ARGUMENTS) != param.end()) { + Versatile V = param[ARGUMENTS]; + + argv = new char * [V.size() + 2]; // 1 pour name et 1 pour le NULL terminal + + argv[0] = new char [name.size() + 1]; + strncpy(argv[0], name.c_str(), name.size() + 1); + + debug_command += string(" # ") + argv[0]; + + int i = 1; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++, i++) { + StringType argt = * static_cast(*it); + string arg = argt; + argv[i] = new char [arg.size() + 1]; + strncpy(argv[i], arg.c_str(), arg.size() + 1); + debug_command += string(" # ") + argv[i]; + } + + // assert (i == V.size() + 1) + argv[i] = NULL; + } + + + UNDER_LOCK( cout << "*** debug_command = " << debug_command << endl ); + + + + Environnement env = _job.getEnvironnement(); + + + char ** envp = NULL; + if(env.size() > 0) { + envp = new char * [env.size() + 1]; // 1 pour le NULL terminal + int i = 0; + for(Environnement::const_iterator it=env.begin(); it!=env.end(); it++, i++) { + const string & key = (*it).first; + const string & value = (*it).second; + ostringstream oss; + oss << key << "=" << value; + envp[i] = new char [oss.str().size() + 1]; + strncpy(envp[i], oss.str().c_str(), oss.str().size() + 1); + } + + // assert (i == env.size()) + envp[i] = NULL; + } + + + + + // On positionne les limites systeme imposees au fils + if (param.find(MAXCPUTIME) != param.end()) { + int maxcputime = param[MAXCPUTIME]; + struct rlimit limit; + limit.rlim_cur = maxcputime; + limit.rlim_max = int(maxcputime * 1.1); + setrlimit(RLIMIT_CPU, &limit); + } + + if (param.find(MAXDISKSIZE) != param.end()) { + int maxdisksize = param[MAXDISKSIZE]; + struct rlimit limit; + limit.rlim_cur = maxdisksize * 1024; + limit.rlim_max = int(maxdisksize * 1.1) * 1024; + setrlimit(RLIMIT_FSIZE, &limit); + } + + if (param.find(MAXRAMSIZE) != param.end()) { + int maxramsize = param[MAXRAMSIZE]; + struct rlimit limit; + limit.rlim_cur = maxramsize * 1024; + limit.rlim_max = int(maxramsize * 1.1) * 1024; + setrlimit(RLIMIT_AS, &limit); + } + + + + // On cree une session pour le fils de facon a ce qu'il ne soit pas + // detruit lorsque le shell se termine (le shell ouvre une session et + // tue tous les process appartenant a la session en quittant) + setsid(); + + + // On ferme les descripteurs de fichiers standards + //close(STDIN_FILENO); + //close(STDOUT_FILENO); + //close(STDERR_FILENO); + + + // On execute la commande du fils + execve(execpath, argv, envp); + + // No need to deallocate since nothing happens after a successful exec + + // Normalement on ne devrait jamais arriver ici + ofstream file_err("error.log"); + UNDER_LOCK( file_err << "Echec de l'appel a execve" << endl ); + + } catch (GenericException & e) { + + std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl; + } + + exit(99); + + } + + + + + void BatchManager_Local::kill_child_on_exit(void * p_pid) + { + pid_t child = * static_cast(p_pid); + + // On tue le fils + kill(child, SIGTERM); + + // Nota : on pourrait aussi faire a la suite un kill(child, SIGKILL) + // mais cette option n'est pas implementee pour le moment, car il est + // preferable de laisser le process fils se terminer normalement et seul. + + } + + void BatchManager_Local::delete_on_exit(void * arg) + { + ThreadAdapter * p_ta = static_cast(arg); + delete p_ta; + } + +} diff --git a/src/Batch/Batch_BatchManager_Local.hxx b/src/Batch/Batch_BatchManager_Local.hxx new file mode 100644 index 000000000..e635fa59a --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local.hxx @@ -0,0 +1,146 @@ +/* + * BatchManager_Local.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#ifndef _BATCHMANAGER_LOCAL_H_ +#define _BATCHMANAGER_LOCAL_H_ + + +#include +#include +#include +#include +#include +#include "Batch_Job.hxx" +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" +#include "Batch_JobInfo_Local.hxx" +#include "Batch_Job_Local.hxx" +#include "Batch_InvalidArgumentException.hxx" +#include "Batch_ConnexionFailureException.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_NotYetImplementedException.hxx" +#include "Batch_BatchManager.hxx" + +namespace Batch { + + class FactBatchManager; + + class BatchManager_Local : public BatchManager + { + private: + friend class ThreadAdapter; + class ThreadAdapter{ + public: + ThreadAdapter(BatchManager_Local & bm, const Job_Local & job); + static void * run(void * arg); + BatchManager_Local & getBatchManager() const { return _bm; }; + + protected: + BatchManager_Local & _bm; + const Job_Local _job; + + private: + void pere(pid_t child); + void fils(); + + }; + + typedef int Id; + + enum Commande { + NOP = 0, + HOLD, + RELEASE, + TERM, + KILL, + ALTER, + }; + + enum Status { + UNKNOWN = 0, + RUNNING, + STOPPED, + DONE, + DEAD, + }; + + struct Child { + pthread_t thread_id; + queue > command_queue; + pid_t pid; + int exit_code; + Status status; + Parametre param; + Environnement env; + }; + + + + public: + // Constructeur et destructeur + BatchManager_Local(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + virtual ~BatchManager_Local(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_Local::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente + virtual void releaseJob(const JobId & jobid); // relache un job suspendu + virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente + virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente + virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine + + virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente + virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente + + + protected: + int _connect; // Local connect id + pthread_mutex_t _threads_mutex; + map _threads; + + // Methode abstraite qui renvoie la commande de copie du fichier source en destination + virtual string copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const = 0; + + // Methode abstraite qui renvoie la commande a executer + virtual string exec_command(Parametre & param) const = 0; + + // Methode abstraite qui renvoie la commande d'effacement du fichier + virtual string remove_command(const string & host_destination, const string & destination) const = 0; + + private: + virtual pthread_t submit(const Job_Local & job); + virtual void cancel(pthread_t thread_id); + static void kill_child_on_exit(void * p_pid); + static void delete_on_exit(void * arg); + Id nextId(); // Retourne un identifiant unique pour un thread (clef de la map) + Id getIdByThread_id(pthread_t thread_id); + Id registerThread_id(pthread_t thread_id); + pthread_mutex_t _thread_id_id_association_mutex; + pthread_cond_t _thread_id_id_association_cond; + map _thread_id_id_association; + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + + }; + +} + +#endif diff --git a/src/Batch/Batch_BatchManager_Local_RSH.cxx b/src/Batch/Batch_BatchManager_Local_RSH.cxx new file mode 100644 index 000000000..f376cf060 --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local_RSH.cxx @@ -0,0 +1,126 @@ +/* + * BatchManager_Local_RSH.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Batch_IOMutex.hxx" +#include "Batch_BatchManager_Local_RSH.hxx" + +#ifndef RM +#error "RM undefined. You must set RM to a valid path to a rm-like command." +#endif + +#ifndef RCP +#error "RCP undefined. You must set RCP to a valid path to a rcp-like command." +#endif + +#ifndef RSH +#error "RSH undefined. You must set RSH to a valid path to a rsh-like command." +#endif + +namespace Batch { + + + // Constructeur + BatchManager_Local_RSH::BatchManager_Local_RSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host) + { + } + + // Destructeur + BatchManager_Local_RSH::~BatchManager_Local_RSH() + { + } + + + // Methode abstraite qui renvoie la commande de copie du fichier source en destination + string BatchManager_Local_RSH::copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const + { + ostringstream fullsource; + if (host_source.size() == 0) { + fullsource << "localhost:"; + } else { + fullsource << host_source << ":"; + } + fullsource << source; + + ostringstream fulldestination; + if (host_destination.size() == 0) { + fulldestination << "localhost:"; + } else { + fulldestination << host_destination << ":"; + } + fulldestination << destination; + + ostringstream copy_cmd; + copy_cmd << RCP << " " << fullsource.str() << " " << fulldestination.str(); + return copy_cmd.str(); + } + + // Methode abstraite qui renvoie la commande a executer + string BatchManager_Local_RSH::exec_command(Parametre & param) const + { + ostringstream exec_sub_cmd; + exec_sub_cmd << param[EXECUTABLE]; + + if (param.find(ARGUMENTS) != param.end()) { + Versatile V = param[ARGUMENTS]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + StringType argt = * static_cast(*it); + string arg = argt; + exec_sub_cmd << " " << arg; + } + } + + + Versatile new_arguments; + new_arguments.setMaxSize(0); + new_arguments = string(param[EXECUTIONHOST]); + + + if (param.find(USER) != param.end()) { + new_arguments += "-l"; + new_arguments += string(param[USER]); + } + + new_arguments += exec_sub_cmd.str(); + + param[ARGUMENTS] = new_arguments; + + // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh + param[EXECUTABLE] = RSH; + param.erase(NAME); + + return RSH; + } + + // Methode qui renvoie la commande d'effacement du fichier + string BatchManager_Local_RSH::remove_command(const string & host_destination, const string & destination) const + { + string host = (host_destination.size()) ? host_destination : "localhost:"; + + ostringstream remove_cmd; + remove_cmd << RSH << " " << host << " \"" << RM << " " << destination << "\""; + return remove_cmd.str(); + } +} diff --git a/src/Batch/Batch_BatchManager_Local_RSH.hxx b/src/Batch/Batch_BatchManager_Local_RSH.hxx new file mode 100644 index 000000000..1ea4fc269 --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local_RSH.hxx @@ -0,0 +1,56 @@ +/* + * BatchManager_Local_RSH.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#ifndef _BATCHMANAGER_LOCAL_RSH_H_ +#define _BATCHMANAGER_LOCAL_RSH_H_ + + +#include +#include +#include +#include +#include +#include "Batch_Job.hxx" +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" +#include "Batch_JobInfo_Local.hxx" +#include "Batch_Job_Local.hxx" +#include "Batch_InvalidArgumentException.hxx" +#include "Batch_ConnexionFailureException.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_NotYetImplementedException.hxx" +#include "Batch_BatchManager_Local.hxx" + +namespace Batch { + + class FactBatchManager; + + class BatchManager_Local_RSH : public BatchManager_Local + { + public: + // Constructeur et destructeur + BatchManager_Local_RSH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + virtual ~BatchManager_Local_RSH(); + + protected: + // Methode abstraite qui renvoie la commande de copie du fichier source en destination + virtual string copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const; + + // Methode abstraite qui renvoie la commande a executer + virtual string exec_command(Parametre & param) const; + + // Methode qui renvoie la commande d'effacement du fichier + virtual string remove_command(const string & host_destination, const string & destination) const; + + }; + +} + +#endif diff --git a/src/Batch/Batch_BatchManager_Local_SH.cxx b/src/Batch/Batch_BatchManager_Local_SH.cxx new file mode 100644 index 000000000..e10e7271a --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local_SH.cxx @@ -0,0 +1,93 @@ +/* + * BatchManager_Local_SH.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Batch_IOMutex.hxx" +#include "Batch_BatchManager_Local_SH.hxx" + +#ifndef RM +#error "RM undefined. You must set RM to a valid path to a rm-like command." +#endif + +#ifndef CP +#error "CP undefined. You must set CP to a valid path to a cp-like command." +#endif + +#ifndef SH +#error "SH undefined. You must set SH to a valid path to a sh-like command." +#endif + +namespace Batch { + + + // Constructeur + BatchManager_Local_SH::BatchManager_Local_SH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host) + { + } + + // Destructeur + BatchManager_Local_SH::~BatchManager_Local_SH() + { + } + + + // Methode qui renvoie la commande de copie du fichier source en destination + string BatchManager_Local_SH::copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const + { + ostringstream copy_cmd; + copy_cmd << CP << " " << source << " " << destination; + return copy_cmd.str(); + } + + // Methode qui renvoie la commande a executer + string BatchManager_Local_SH::exec_command(Parametre & param) const + { + ostringstream exec_sub_cmd; + exec_sub_cmd << param[EXECUTABLE]; + + if (param.find(ARGUMENTS) != param.end()) { + Versatile V = param[ARGUMENTS]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + StringType argt = * static_cast(*it); + string arg = argt; + exec_sub_cmd << " " << arg; + } + } + + param[ARGUMENTS] = "-c"; + param[ARGUMENTS] += exec_sub_cmd.str(); + + return SH; + } + + // Methode qui renvoie la commande d'effacement du fichier + string BatchManager_Local_SH::remove_command(const string & host_destination, const string & destination) const + { + ostringstream remove_cmd; + remove_cmd << RM << " " << destination; + return remove_cmd.str(); + } + +} diff --git a/src/Batch/Batch_BatchManager_Local_SH.hxx b/src/Batch/Batch_BatchManager_Local_SH.hxx new file mode 100644 index 000000000..b72a0873e --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local_SH.hxx @@ -0,0 +1,56 @@ +/* + * BatchManager_Local_SH.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#ifndef _BATCHMANAGER_LOCAL_SH_H_ +#define _BATCHMANAGER_LOCAL_SH_H_ + + +#include +#include +#include +#include +#include +#include "Batch_Job.hxx" +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" +#include "Batch_JobInfo_Local.hxx" +#include "Batch_Job_Local.hxx" +#include "Batch_InvalidArgumentException.hxx" +#include "Batch_ConnexionFailureException.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_NotYetImplementedException.hxx" +#include "Batch_BatchManager_Local.hxx" + +namespace Batch { + + class FactBatchManager; + + class BatchManager_Local_SH : public BatchManager_Local + { + public: + // Constructeur et destructeur + BatchManager_Local_SH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + virtual ~BatchManager_Local_SH(); + + protected: + // Methode qui renvoie la commande de copie du fichier source en destination + virtual string copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const; + + // Methode qui renvoie la commande a executer + virtual string exec_command(Parametre & param) const; + + // Methode qui renvoie la commande d'effacement du fichier + virtual string remove_command(const string & host_destination, const string & destination) const; + + }; + +} + +#endif diff --git a/src/Batch/Batch_BatchManager_Local_SSH.cxx b/src/Batch/Batch_BatchManager_Local_SSH.cxx new file mode 100644 index 000000000..d74b4e1f5 --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local_SSH.cxx @@ -0,0 +1,126 @@ +/* + * BatchManager_Local_SSH.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Batch_IOMutex.hxx" +#include "Batch_BatchManager_Local_SSH.hxx" + +#ifndef RM +#error "RM undefined. You must set RM to a valid path to a rm-like command." +#endif + +#ifndef RCP +#error "RCP undefined. You must set RCP to a valid path to a scp-like command." +#endif + +#ifndef SSH +#error "SSH undefined. You must set SSH to a valid path to a ssh-like command." +#endif + +namespace Batch { + + + // Constructeur + BatchManager_Local_SSH::BatchManager_Local_SSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host) + { + } + + // Destructeur + BatchManager_Local_SSH::~BatchManager_Local_SSH() + { + } + + + // Methode abstraite qui renvoie la commande de copie du fichier source en destination + string BatchManager_Local_SSH::copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const + { + ostringstream fullsource; + if (host_source.size() == 0) { + fullsource << "localhost:"; + } else { + fullsource << host_source << ":"; + } + fullsource << source; + + ostringstream fulldestination; + if (host_destination.size() == 0) { + fulldestination << "localhost:"; + } else { + fulldestination << host_destination << ":"; + } + fulldestination << destination; + + ostringstream copy_cmd; + copy_cmd << RCP << " " << fullsource.str() << " " << fulldestination.str(); + return copy_cmd.str(); + } + + // Methode abstraite qui renvoie la commande a executer + string BatchManager_Local_SSH::exec_command(Parametre & param) const + { + ostringstream exec_sub_cmd; + exec_sub_cmd << param[EXECUTABLE]; + + if (param.find(ARGUMENTS) != param.end()) { + Versatile V = param[ARGUMENTS]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + StringType argt = * static_cast(*it); + string arg = argt; + exec_sub_cmd << " " << arg; + } + } + + + Versatile new_arguments; + new_arguments.setMaxSize(0); + new_arguments = string(param[EXECUTIONHOST]); + + + if (param.find(USER) != param.end()) { + new_arguments += "-l"; + new_arguments += string(param[USER]); + } + + new_arguments += exec_sub_cmd.str(); + + param[ARGUMENTS] = new_arguments; + + // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh + param[EXECUTABLE] = SSH; + param.erase(NAME); + + return SSH; + } + + // Methode qui renvoie la commande d'effacement du fichier + string BatchManager_Local_SSH::remove_command(const string & host_destination, const string & destination) const + { + string host = (host_destination.size()) ? host_destination : "localhost:"; + + ostringstream remove_cmd; + remove_cmd << SSH << " " << host << " \"" << RM << " " << destination << "\""; + return remove_cmd.str(); + } +} diff --git a/src/Batch/Batch_BatchManager_Local_SSH.hxx b/src/Batch/Batch_BatchManager_Local_SSH.hxx new file mode 100644 index 000000000..4d6c2eed9 --- /dev/null +++ b/src/Batch/Batch_BatchManager_Local_SSH.hxx @@ -0,0 +1,56 @@ +/* + * BatchManager_Local_SSH.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:17:22 2003 + * Projet : Salome 2 + * + */ + +#ifndef _BATCHMANAGER_LOCAL_SSH_H_ +#define _BATCHMANAGER_LOCAL_SSH_H_ + + +#include +#include +#include +#include +#include +#include "Batch_Job.hxx" +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" +#include "Batch_JobInfo_Local.hxx" +#include "Batch_Job_Local.hxx" +#include "Batch_InvalidArgumentException.hxx" +#include "Batch_ConnexionFailureException.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_NotYetImplementedException.hxx" +#include "Batch_BatchManager_Local.hxx" + +namespace Batch { + + class FactBatchManager; + + class BatchManager_Local_SSH : public BatchManager_Local + { + public: + // Constructeur et destructeur + BatchManager_Local_SSH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + virtual ~BatchManager_Local_SSH(); + + protected: + // Methode abstraite qui renvoie la commande de copie du fichier source en destination + virtual string copy_command(const string & host_source, const string & source, const string & host_destination, const string & destination) const; + + // Methode abstraite qui renvoie la commande a executer + virtual string exec_command(Parametre & param) const; + + // Methode qui renvoie la commande d'effacement du fichier + virtual string remove_command(const string & host_destination, const string & destination) const; + + }; + +} + +#endif diff --git a/src/Batch/Batch_FactBatchManager_Local.cxx b/src/Batch/Batch_FactBatchManager_Local.cxx new file mode 100644 index 000000000..91eb63ef8 --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local.cxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#include +#include "Batch_BatchManager_Local.hxx" +#include "Batch_FactBatchManager_Local.hxx" +//#include "utilities.h" + +namespace Batch { + +// static FactBatchManager_Local sFBM_Local; + + // Constructeur + FactBatchManager_Local::FactBatchManager_Local() : FactBatchManager("Local") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_Local::~FactBatchManager_Local() + { + // Nothing to do + } + + // Functor +// BatchManager * FactBatchManager_Local::operator() (const char * hostname) const +// { +// // MESSAGE("Building new BatchManager_Local on host '" << hostname << "'"); +// return new BatchManager_Local(this, hostname); +// } + + +} diff --git a/src/Batch/Batch_FactBatchManager_Local.hxx b/src/Batch/Batch_FactBatchManager_Local.hxx new file mode 100644 index 000000000..a74f63332 --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local.hxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#ifndef _FACTBATCHMANAGER_LOCAL_H_ +#define _FACTBATCHMANAGER_LOCAL_H_ + +using namespace std; +#include +#include +#include "Batch_FactBatchManager.hxx" + +namespace Batch { + + class BatchManager_Local; + + class FactBatchManager_Local : public FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager_Local(); + virtual ~FactBatchManager_Local(); + + virtual BatchManager * operator() (const char * hostname) const = 0; + + protected: + + private: + + }; + +} + +#endif diff --git a/src/Batch/Batch_FactBatchManager_Local_RSH.cxx b/src/Batch/Batch_FactBatchManager_Local_RSH.cxx new file mode 100644 index 000000000..176e5f13d --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local_RSH.cxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local_RSH.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#include +#include "Batch_BatchManager_Local_RSH.hxx" +#include "Batch_FactBatchManager_Local_RSH.hxx" +//#include "utilities.h" + +namespace Batch { + + static FactBatchManager_Local_RSH sFBM_Local_RSH; + + // Constructeur + FactBatchManager_Local_RSH::FactBatchManager_Local_RSH() : FactBatchManager("RSH") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_Local_RSH::~FactBatchManager_Local_RSH() + { + // Nothing to do + } + + // Functor + BatchManager * FactBatchManager_Local_RSH::operator() (const char * hostname) const + { + // MESSAGE("Building new BatchManager_Local_RSH on host '" << hostname << "'"); + return new BatchManager_Local_RSH(this, hostname); + } + + +} diff --git a/src/Batch/Batch_FactBatchManager_Local_RSH.hxx b/src/Batch/Batch_FactBatchManager_Local_RSH.hxx new file mode 100644 index 000000000..29ed41a6b --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local_RSH.hxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local_RSH.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#ifndef _FACTBATCHMANAGER_LOCAL_RSH_H_ +#define _FACTBATCHMANAGER_LOCAL_RSH_H_ + +using namespace std; +#include +#include +#include "Batch_FactBatchManager.hxx" + +namespace Batch { + + class BatchManager_Local_RSH; + + class FactBatchManager_Local_RSH : public FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager_Local_RSH(); + virtual ~FactBatchManager_Local_RSH(); + + virtual BatchManager * operator() (const char * hostname) const; + + protected: + + private: + + }; + +} + +#endif diff --git a/src/Batch/Batch_FactBatchManager_Local_SH.cxx b/src/Batch/Batch_FactBatchManager_Local_SH.cxx new file mode 100644 index 000000000..185716a94 --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local_SH.cxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local_SH.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#include +#include "Batch_BatchManager_Local_SH.hxx" +#include "Batch_FactBatchManager_Local_SH.hxx" +//#include "utilities.h" + +namespace Batch { + + static FactBatchManager_Local_SH sFBM_Local_SH; + + // Constructeur + FactBatchManager_Local_SH::FactBatchManager_Local_SH() : FactBatchManager("SH") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_Local_SH::~FactBatchManager_Local_SH() + { + // Nothing to do + } + + // Functor + BatchManager * FactBatchManager_Local_SH::operator() (const char * hostname) const + { + // MESSAGE("Building new BatchManager_Local_SH on host '" << hostname << "'"); + return new BatchManager_Local_SH(this, hostname); + } + + +} diff --git a/src/Batch/Batch_FactBatchManager_Local_SH.hxx b/src/Batch/Batch_FactBatchManager_Local_SH.hxx new file mode 100644 index 000000000..1490436d2 --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local_SH.hxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local_SH.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#ifndef _FACTBATCHMANAGER_LOCAL_SH_H_ +#define _FACTBATCHMANAGER_LOCAL_SH_H_ + +using namespace std; +#include +#include +#include "Batch_FactBatchManager.hxx" + +namespace Batch { + + class BatchManager_Local_SH; + + class FactBatchManager_Local_SH : public FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager_Local_SH(); + virtual ~FactBatchManager_Local_SH(); + + virtual BatchManager * operator() (const char * hostname) const; + + protected: + + private: + + }; + +} + +#endif diff --git a/src/Batch/Batch_FactBatchManager_Local_SSH.cxx b/src/Batch/Batch_FactBatchManager_Local_SSH.cxx new file mode 100644 index 000000000..60a26af30 --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local_SSH.cxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local_SSH.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#include +#include "Batch_BatchManager_Local_SSH.hxx" +#include "Batch_FactBatchManager_Local_SSH.hxx" +//#include "utilities.h" + +namespace Batch { + + static FactBatchManager_Local_SSH sFBM_Local_SSH; + + // Constructeur + FactBatchManager_Local_SSH::FactBatchManager_Local_SSH() : FactBatchManager("SSH") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_Local_SSH::~FactBatchManager_Local_SSH() + { + // Nothing to do + } + + // Functor + BatchManager * FactBatchManager_Local_SSH::operator() (const char * hostname) const + { + // MESSAGE("Building new BatchManager_Local_SSH on host '" << hostname << "'"); + return new BatchManager_Local_SSH(this, hostname); + } + + +} diff --git a/src/Batch/Batch_FactBatchManager_Local_SSH.hxx b/src/Batch/Batch_FactBatchManager_Local_SSH.hxx new file mode 100644 index 000000000..645638bcb --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_Local_SSH.hxx @@ -0,0 +1,39 @@ +/* + * FactBatchManager_Local_SSH.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#ifndef _FACTBATCHMANAGER_LOCAL_SSH_H_ +#define _FACTBATCHMANAGER_LOCAL_SSH_H_ + +using namespace std; +#include +#include +#include "Batch_FactBatchManager.hxx" + +namespace Batch { + + class BatchManager_Local_SSH; + + class FactBatchManager_Local_SSH : public FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager_Local_SSH(); + virtual ~FactBatchManager_Local_SSH(); + + virtual BatchManager * operator() (const char * hostname) const; + + protected: + + private: + + }; + +} + +#endif diff --git a/src/Batch/Batch_IOMutex.cxx b/src/Batch/Batch_IOMutex.cxx new file mode 100644 index 000000000..b56a421fa --- /dev/null +++ b/src/Batch/Batch_IOMutex.cxx @@ -0,0 +1,17 @@ +/* + * IOMutex.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#include "Batch_IOMutex.hxx" + +namespace Batch { + + pthread_mutex_t IOMutex = PTHREAD_MUTEX_INITIALIZER; + +} diff --git a/src/Batch/Batch_IOMutex.hxx b/src/Batch/Batch_IOMutex.hxx new file mode 100644 index 000000000..77b40f85e --- /dev/null +++ b/src/Batch/Batch_IOMutex.hxx @@ -0,0 +1,26 @@ +/* + * IOMutex.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#ifndef _IOMUTEX_H_ +#define _IOMUTEX_H_ + +#include + +#define LOCK_IO { pthread_mutex_lock(&Batch::IOMutex) ; } +#define UNLOCK_IO { pthread_mutex_unlock(&Batch::IOMutex) ; } +#define UNDER_LOCK(statement) { LOCK_IO ; { statement ; } ; UNLOCK_IO ; } + +namespace Batch { + + extern pthread_mutex_t IOMutex; + +} + +#endif diff --git a/src/Batch/Batch_Job.cxx b/src/Batch/Batch_Job.cxx index 77f8126e1..a2ea4998d 100644 --- a/src/Batch/Batch_Job.cxx +++ b/src/Batch/Batch_Job.cxx @@ -49,13 +49,13 @@ namespace Batch { } // Accesseur - Parametre Job::getParametre() const + Batch::Parametre Job::getParametre() const { return _param; } // Accesseur - void Job::setParametre(const Parametre & param) + void Job::setParametre(const Batch::Parametre & param) { _param = param; } diff --git a/src/Batch/Batch_JobInfo.cxx b/src/Batch/Batch_JobInfo.cxx index 87f814322..3192f21d5 100644 --- a/src/Batch/Batch_JobInfo.cxx +++ b/src/Batch/Batch_JobInfo.cxx @@ -13,7 +13,6 @@ #include //#include "MEDMEM_STRING.hxx" #include "Batch_JobInfo.hxx" -using namespace std; namespace Batch { diff --git a/src/Batch/Batch_JobInfo.hxx b/src/Batch/Batch_JobInfo.hxx index e9c251c94..1fc9e1cb2 100644 --- a/src/Batch/Batch_JobInfo.hxx +++ b/src/Batch/Batch_JobInfo.hxx @@ -11,6 +11,7 @@ #ifndef _JOBINFO_H_ #define _JOBINFO_H_ +using namespace std; #include #include #include "Batch_Parametre.hxx" @@ -26,23 +27,26 @@ namespace Batch { virtual ~JobInfo(); // Constructeur par recopie - JobInfo(const Batch::JobInfo & jinfo) : _param(jinfo._param), _env(jinfo._env) {}; + JobInfo(const JobInfo & jinfo) : _param(jinfo._param), _env(jinfo._env) {}; // Operateur pour l'affichage sur un stream - friend std::ostream & operator <<(std::ostream & os, const Batch::JobInfo & ji); + friend ostream & operator <<(ostream & os, const JobInfo & ji); // Accesseurs + // _CS_gbo Ajout explicite du namespace pour les besoins de swig (mauvaise gestion + // des namespace par swig. virtual Batch::Parametre getParametre() const; virtual Batch::Environnement getEnvironnement() const; // Methodes pour l'interfacage avec Python (SWIG) // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python + string __str__() const; // SWIG : affichage en Python + string __repr__() const { return __str__(); }; // SWIG : affichage en Python protected: - Batch::Parametre _param; // parametres du job - Batch::Environnement _env; // variables d'environnement du job + Parametre _param; // parametres du job + Environnement _env; // variables d'environnement du job + JobInfo(const Parametre & param, const Environnement & env) : _param(param), _env(env) {}; private: diff --git a/src/Batch/Batch_JobInfo_Local.cxx b/src/Batch/Batch_JobInfo_Local.cxx new file mode 100644 index 000000000..1874793a9 --- /dev/null +++ b/src/Batch/Batch_JobInfo_Local.cxx @@ -0,0 +1,33 @@ +/* + * JobInfo_Local.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 21 09:42:06 2003 + * Projet : Salome 2 + * + */ + +#include +#include "Batch_Parametre.hxx" +#include "Batch_Environnement.hxx" +#include "Batch_JobInfo_Local.hxx" + +namespace Batch { + + // Constructeurs + JobInfo_Local::JobInfo_Local(const Parametre & param, const Environnement & env) : + JobInfo(param, env) + { + // Nothing to do + } + + + // Destructeur + JobInfo_Local::~JobInfo_Local() + { + // Nothing to do + } + + +} diff --git a/src/Batch/Batch_JobInfo_Local.hxx b/src/Batch/Batch_JobInfo_Local.hxx new file mode 100644 index 000000000..05c570db8 --- /dev/null +++ b/src/Batch/Batch_JobInfo_Local.hxx @@ -0,0 +1,39 @@ +/* + * JobInfo_Local.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 21 09:42:05 2003 + * Projet : Salome 2 + * + */ + +#ifndef _JOBINFO_LOCAL_H_ +#define _JOBINFO_LOCAL_H_ + +#include +#include "Batch_JobInfo.hxx" + +namespace Batch { + + class JobInfo_Local : public JobInfo + { + public: + // Constructeurs et destructeur + JobInfo_Local() {}; + JobInfo_Local(const Parametre & param, const Environnement & env); + virtual ~JobInfo_Local(); + + // Constructeur par recopie + JobInfo_Local(const JobInfo_Local & jinfo) : JobInfo(jinfo) {}; + + + protected: + + private: + + }; + +} + +#endif diff --git a/src/Batch/Batch_Job_Local.cxx b/src/Batch/Batch_Job_Local.cxx new file mode 100644 index 000000000..1c5c593dd --- /dev/null +++ b/src/Batch/Batch_Job_Local.cxx @@ -0,0 +1,81 @@ +/* + * Job_Local.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#include +#include +#include +#include "Batch_Job_Local.hxx" + +namespace Batch { + + // Constructeur + Job_Local::Job_Local(const Job & job) : + _command(), _param(job.getParametre()), _env(job.getEnvironnement()) + { + // On positionne le nom du EXECUTIONHOST a "localhost" s'il n'est pas precise + if ( _param.find(EXECUTIONHOST) == _param.end() ) { + _param[EXECUTIONHOST] = "localhost"; + } + + // On convertit les objets Parametre et Environnement en liste chainee d'attributs + operateur + addEnvironnement( _env ); + addParametre ( _param ); + + } + + + // Destructeur + Job_Local::~Job_Local() + { + } + + + void Job_Local::addParametre(const Parametre & P) + { + // En dernier, on ajoute le chemin complet de la commande + _command += P[EXECUTABLE].str(); + } + + + void Job_Local::addEnvironnement(const Environnement & E) + { + for(Environnement::const_iterator it=E.begin(); it != E.end(); it++) { + string variable = (*it).first; + string value = (*it).second; + + // On remplace toutes les occurences de single-quote par backslash-single-quote + for(int pos=0; pos < value.size(); pos++) { + pos = value.find("'", pos); + if ( (pos < 0) || (pos > value.size()) ) break; + value.replace(pos, 1, "\'"); + } + _command += variable + "='" + value + "' "; + } + } + + string Job_Local::getCommand(void) const { + return _command; + } + + + // Retourne l'objet Parametre + Parametre Job_Local::getParametre() const + { + return _param; + } + + // Retourne l'objet Environnement + Environnement Job_Local::getEnvironnement() const + { + return _env; + } + + +} diff --git a/src/Batch/Batch_Job_Local.hxx b/src/Batch/Batch_Job_Local.hxx new file mode 100644 index 000000000..0115c5cec --- /dev/null +++ b/src/Batch/Batch_Job_Local.hxx @@ -0,0 +1,50 @@ +/* + * Job_Local.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#ifndef _JOB_LOCAL_H_ +#define _JOB_LOCAL_H_ + +#include "Batch_Parametre.hxx" +#include "Batch_Environnement.hxx" +#include "Batch_Job.hxx" + +namespace Batch { + + class Job_Local + { + public: + // Constructeur et destructeur + Job_Local(const Job & job); + virtual ~Job_Local(); + + // Retourne la commande _command + virtual std::string getCommand(void) const; + + // Retourne l'objet Parametre + virtual Parametre getParametre() const; + + // Retourne l'objet Environnement + virtual Environnement getEnvironnement() const; + + + protected: + std::string _command; + Parametre _param; + Environnement _env; + + private: + void addParametre(const Parametre & P); + void addEnvironnement(const Environnement & E); + + }; + +} + +#endif diff --git a/src/Batch/Batch_Parametre.cxx b/src/Batch/Batch_Parametre.cxx index 1738d12b3..316e3f034 100644 --- a/src/Batch/Batch_Parametre.cxx +++ b/src/Batch/Batch_Parametre.cxx @@ -11,7 +11,6 @@ #include "Batch_Versatile.hxx" #include "Batch_InvalidKeyException.hxx" #include "Batch_Parametre.hxx" -using namespace std; // Definition des membres constants statiques // Definition des noms globaux pour les clefs en tant que references @@ -53,14 +52,15 @@ def_static_MapKey(USEDDISKSIZE); def_static_MapKey(USEDRAMSIZE); def_static_MapKey(USEDWALLTIME); def_static_MapKey(USER); +def_static_MapKey(WORKDIR); namespace Batch { - // Constructeur standard - // La map interne TypeMap possede les memes clefs que la map principale, mais les - // valeurs associees contiennent le type des clefs de la map principale ainsi que - // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque, - // sinon valeur precisee) + // Constructeur standard + // La map interne TypeMap possede les memes clefs que la map principale, mais les + // valeurs associees contiennent le type des clefs de la map principale ainsi que + // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque, + // sinon valeur precisee) Parametre::Parametre() : map< string, Versatile >() { TypeMap[ACCOUNT].type = STRING; @@ -173,23 +173,26 @@ namespace Batch { TypeMap[USER].type = STRING; TypeMap[USER].maxelem = 1; + + TypeMap[WORKDIR].type = STRING; + TypeMap[WORKDIR].maxelem = 1; } - // Operateur de recherche dans la map - // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de - // la valeur associée à la clef car il retourne une reference non constante + // Operateur de recherche dans la map + // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de + // la valeur associée à la clef car il retourne une reference non constante Versatile & Parametre::operator [] (const string & mk) { - // On controle que la clef est valide + // On controle que la clef est valide if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str()); - // On recherche la valeur associee... + // On recherche la valeur associee... Versatile & V = map< string, Versatile >::operator [] (mk); - // ... et on l'initialise systematiquement - // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type - // different de celui inscrit dans TypeMap) une exception TypeMismatchException est - // levee + // ... et on l'initialise systematiquement + // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type + // different de celui inscrit dans TypeMap) une exception TypeMismatchException est + // levee V.setName(mk); V.setType(TypeMap[mk].type); V.setMaxSize(TypeMap[mk].maxelem); @@ -197,35 +200,36 @@ namespace Batch { return V; } - // Operateur de recherche dans la map - // Cet operateur agit sur les objets CONSTANTS + // Operateur de recherche dans la map + // Cet operateur agit sur les objets CONSTANTS const Versatile & Parametre::operator [] (const string & mk) const { - // On controle que la clef est valide + // On controle que la clef est valide if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str()); - // On recherche la valeur associee - Parametre::const_iterator it = find(mk); + // On recherche la valeur associee + Parametre::const_iterator it = find(mk); + if (it == end()) throw InvalidKeyException(mk.c_str()); const Versatile & V = (*it).second; return V; } - // Operateur d'affectation + // Operateur d'affectation Parametre & Parametre::operator =(const Parametre & PM) { - // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie + // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie if (this == &PM) return *this; - // On efface toute la map + // On efface toute la map erase(begin(), end()); - // On recopie la map interne - // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques, - // il n'est pas exclu que dans un avenir proche elles puissent etre differentes + // On recopie la map interne + // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques, + // il n'est pas exclu que dans un avenir proche elles puissent etre differentes (*this).TypeMap = PM.TypeMap; - // On recree la structure interne de la map avec les valeurs de celle passee en argument + // On recree la structure interne de la map avec les valeurs de celle passee en argument Parametre::const_iterator it; for(it=PM.begin(); it!=PM.end(); it++) insert(make_pair( (*it).first , @@ -235,26 +239,26 @@ namespace Batch { return *this; } - // Constructeur par recopie + // Constructeur par recopie Parametre::Parametre(const Parametre & PM) { - // inutile car l'objet est vierge : il vient d'etre cree - // On efface toute la map + // inutile car l'objet est vierge : il vient d'etre cree + // On efface toute la map // erase(begin(), end()); - // On recopie la map interne + // On recopie la map interne (*this).TypeMap = PM.TypeMap; - // On cree la structure interne de la map avec les valeurs de celle passee en argument - Parametre::const_iterator it; - for(it=PM.begin(); - it!=PM.end(); - it++) + // On cree la structure interne de la map avec les valeurs de celle passee en argument + Parametre::const_iterator it; + for(it=PM.begin(); + it!=PM.end(); + it++) insert( - make_pair( - (*it).first , - Versatile( (*it).second) - ) ); + make_pair( + (*it).first , + Versatile( (*it).second) + ) ); } // map< string, TypeParam > Parametre::getTypeMap() const diff --git a/src/Batch/Batch_Parametre.hxx b/src/Batch/Batch_Parametre.hxx index ae031342f..a4d47e13b 100644 --- a/src/Batch/Batch_Parametre.hxx +++ b/src/Batch/Batch_Parametre.hxx @@ -10,6 +10,7 @@ #ifndef _PARAMETRE_H_ #define _PARAMETRE_H_ +using namespace std; #include #include #include "Batch_InvalidKeyException.hxx" @@ -21,70 +22,71 @@ // TODO : remplacer ce mecanisme statique par la lecture // TODO : d'une descrption dans un fichier exterieur (genre XML) -#define def_extern_MapKey(mk) extern const std::string & mk; -#define def_static_MapKey(mk) const std::string Batch::Parametre::mk(#mk); \ - const std::string & mk = Batch::Parametre::mk; +#define def_extern_MapKey(mk) extern const string & mk; +#define def_static_MapKey(mk) const string Batch::Parametre::mk(#mk); \ + const string & mk = Batch::Parametre::mk; namespace Batch { - class Parametre : public std::map< std::string, Versatile > + class Parametre : public map< string, Versatile > { public: // Constructeur standard Parametre(); // Constructeur par recopie - Parametre(const Batch::Parametre & PM); + Parametre::Parametre(const Parametre & PM); // Operateur de recherche dans la map - Versatile & operator [] (const std::string &); - const Versatile & operator [] (const std::string &) const; + Versatile & operator [] (const string &); + const Versatile & operator [] (const string &) const; // Operateur d'affectation - Parametre & operator =(const Batch::Parametre & PM); + Parametre & operator =(const Parametre & PM); // Declarations statique des clefs de la map // TODO : supprimer les declarations statiques des clefs de la map - static const std::string ACCOUNT; - static const std::string ARGUMENTS; - static const std::string CHECKPOINT; - static const std::string CKPTINTERVAL; - static const std::string CREATIONTIME; - static const std::string EGROUP; - static const std::string ELIGIBLETIME; - static const std::string ENDTIME; - static const std::string EUSER; - static const std::string EXECUTABLE; - static const std::string EXECUTIONHOST; - static const std::string EXITCODE; - static const std::string HOLD; - static const std::string ID; - static const std::string INFILE; - static const std::string MAIL; - static const std::string MAXCPUTIME; - static const std::string MAXDISKSIZE; - static const std::string MAXRAMSIZE; - static const std::string MAXWALLTIME; - static const std::string MODIFICATIONTIME; - static const std::string NAME; - static const std::string NBPROC; - static const std::string OUTFILE; - static const std::string PID; - static const std::string QUEUE; - static const std::string QUEUEDTIME; - static const std::string SERVER; - static const std::string STARTTIME; - static const std::string STATE; - static const std::string TEXT; - static const std::string TMPDIR; - static const std::string USEDCPUTIME; - static const std::string USEDDISKSIZE; - static const std::string USEDRAMSIZE; - static const std::string USEDWALLTIME; - static const std::string USER; + static const string ACCOUNT; + static const string ARGUMENTS; + static const string CHECKPOINT; + static const string CKPTINTERVAL; + static const string CREATIONTIME; + static const string EGROUP; + static const string ELIGIBLETIME; + static const string ENDTIME; + static const string EUSER; + static const string EXECUTABLE; + static const string EXECUTIONHOST; + static const string EXITCODE; + static const string HOLD; + static const string ID; + static const string INFILE; + static const string MAIL; + static const string MAXCPUTIME; + static const string MAXDISKSIZE; + static const string MAXRAMSIZE; + static const string MAXWALLTIME; + static const string MODIFICATIONTIME; + static const string NAME; + static const string NBPROC; + static const string OUTFILE; + static const string PID; + static const string QUEUE; + static const string QUEUEDTIME; + static const string SERVER; + static const string STARTTIME; + static const string STATE; + static const string TEXT; + static const string TMPDIR; + static const string USEDCPUTIME; + static const string USEDDISKSIZE; + static const string USEDRAMSIZE; + static const string USEDWALLTIME; + static const string USER; + static const string WORKDIR; protected: - std::map< std::string, TypeParam > TypeMap; // map interne servant a controler le type de la valeur associee a chaque clef + map< string, TypeParam > TypeMap; // map interne servant a controler le type de la valeur associee a chaque clef private: @@ -129,5 +131,6 @@ def_extern_MapKey(USEDDISKSIZE); def_extern_MapKey(USEDRAMSIZE); def_extern_MapKey(USEDWALLTIME); def_extern_MapKey(USER); +def_extern_MapKey(WORKDIR); #endif diff --git a/src/Batch/Makefile.am b/src/Batch/Makefile.am new file mode 100644 index 000000000..997083214 --- /dev/null +++ b/src/Batch/Makefile.am @@ -0,0 +1,213 @@ +####################################### library +# SALOME Container : implementation of container and engine for Kernel +# +# Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : EDF +# Module : SALOME +# $Header$ + +include $(top_srcdir)/salome_adm/unix/make_common_starter.am + +# header files +LIB_INCLUDES = \ + Batch_APIInternalFailureException.hxx \ + Batch_BatchManager.hxx \ + Batch_BatchManagerCatalog.hxx \ + Batch_BoolType.hxx \ + Batch_CharType.hxx \ + Batch_ConnexionFailureException.hxx \ + Batch_Couple.hxx \ + Batch_CoupleType.hxx \ + Batch_Date.hxx \ + Batch_DateType.hxx \ + Batch_Environnement.hxx \ + Batch_FactBatchManager.hxx \ + Batch_GenericException.hxx \ + Batch_GenericType.hxx \ + Batch_IntType.hxx \ + Batch_InvalidArgumentException.hxx \ + Batch_InvalidKeyException.hxx \ + Batch_Job.hxx \ + Batch_JobId.hxx \ + Batch_JobInfo.hxx \ + Batch_ListIsFullException.hxx \ + Batch_LongType.hxx \ + Batch_MapKey.hxx \ + Batch_NotYetImplementedException.hxx \ + Batch_Parametre.hxx \ + Batch_PyVersatile.hxx \ + Batch_RunTimeException.hxx \ + Batch_StringType.hxx \ + Batch_TypeMismatchException.hxx + + +LIB_SRC = \ + Batch_APIInternalFailureException.cxx \ + Batch_BatchManager.cxx \ + Batch_BatchManagerCatalog.cxx \ + Batch_BoolType.cxx \ + Batch_CharType.cxx \ + Batch_ConnexionFailureException.cxx \ + Batch_Couple.cxx \ + Batch_CoupleType.cxx \ + Batch_Date.cxx \ + Batch_DateType.cxx \ + Batch_Environnement.cxx \ + Batch_FactBatchManager.cxx \ + Batch_GenericException.cxx \ + Batch_GenericType.cxx \ + Batch_IntType.cxx \ + Batch_InvalidArgumentException.cxx \ + Batch_InvalidKeyException.cxx \ + Batch_Job.cxx \ + Batch_JobId.cxx \ + Batch_JobInfo.cxx \ + Batch_ListIsFullException.cxx \ + Batch_LongType.cxx \ + Batch_MapKey.cxx \ + Batch_NotYetImplementedException.cxx \ + Batch_Parametre.cxx \ + Batch_PyVersatile.cxx \ + Batch_RunTimeException.cxx \ + Batch_StringType.cxx \ + Batch_TypeMismatchException.cxx + + +LIB_CPPFLAGS = \ + @PYTHON_INCLUDES@ \ + -I$(srcdir)/../Basics \ + -I$(srcdir)/../SALOMELocalTrace + +LIB_LIBADD = \ + ../SALOMELocalTrace/libSALOMELocalTrace.la \ + ../Basics/libSALOMEBasics.la + + +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Special add for local batch system +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +if WITH_LOCAL +LIB_INCLUDES +=\ + Batch_Versatile.hxx \ + Batch_BatchManager_Local.hxx \ + Batch_BatchManager_Local_RSH.hxx \ + Batch_BatchManager_Local_SH.hxx \ + Batch_BatchManager_Local_SSH.hxx \ + Batch_FactBatchManager_Local.hxx \ + Batch_FactBatchManager_Local_RSH.hxx \ + Batch_FactBatchManager_Local_SH.hxx \ + Batch_FactBatchManager_Local_SSH.hxx \ + Batch_JobInfo_Local.hxx \ + Batch_Job_Local.hxx \ + Batch_IOMutex.hxx + +LIB_SRC +=\ + Batch_Versatile.cxx \ + Batch_BatchManager_Local.cxx \ + Batch_BatchManager_Local_RSH.cxx \ + Batch_BatchManager_Local_SH.cxx \ + Batch_BatchManager_Local_SSH.cxx \ + Batch_FactBatchManager_Local.cxx \ + Batch_FactBatchManager_Local_RSH.cxx \ + Batch_FactBatchManager_Local_SH.cxx \ + Batch_FactBatchManager_Local_SSH.cxx \ + Batch_JobInfo_Local.cxx \ + Batch_Job_Local.cxx \ + Batch_IOMutex.cxx + +LIB_CPPFLAGS += -DHAVE_CONFIG_H + +endif + +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Special add for openpbs batch system +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +if WITH_OPENPBS +LIB_INCLUDES += \ + Batch_BatchManager_PBS.hxx \ + Batch_FactBatchManager_PBS.hxx \ + Batch_JobInfo_PBS.hxx \ + Batch_Job_PBS.hxx + +LIB_SRC +=\ + Batch_BatchManager_PBS.cxx \ + Batch_FactBatchManager_PBS.cxx \ + Batch_JobInfo_PBS.cxx \ + Batch_Job_PBS.cxx + +LIB_CPPFLAGS += @OPENPBS_INCLUDES@ +LIB_LIBADD += @OPENPBS_LIBDIR@ @OPENPBS_LIBS@ + +endif + +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Special add for lsf batch system +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +if WITH_LSF +LIB_INCLUDES += \ + Batch_BatchManager_LSF.hxx \ + Batch_FactBatchManager_LSF.hxx \ + Batch_JobInfo_LSF.hxx \ + Batch_Job_LSF.hxx + +LIB_SRC += \ + Batch_BatchManager_LSF.cxx \ + Batch_FactBatchManager_LSF.cxx \ + Batch_JobInfo_LSF.cxx \ + Batch_Job_LSF.cxx + +LIB_CPPFLAGS += @LSF_INCLUDES@ +LIB_LIBADD += @LSF_LIBDIR@ @LSF_LIBS@ +endif + + + + +salomeinclude_HEADERS = $(LIB_INCLUDES) + +# +# =============================================================== +# Libraries targets +# =============================================================== +# +lib_LTLIBRARIES = libSalomeBatch.la +libSalomeBatch_la_SOURCES = $(LIB_SRC) +libSalomeBatch_la_CPPFLAGS = \ + @PYTHON_INCLUDES@ \ + -I$(srcdir)/../Basics \ + -I$(srcdir)/../SALOMELocalTrace \ + -I$(top_builddir)/salome_adm/unix \ + $(LIB_CPPFLAGS) + +libSalomeBatch_la_LDFLAGS = -no-undefined -version-info=0:0:0 +libSalomeBatch_la_LIBADD = \ + ../SALOMELocalTrace/libSALOMELocalTrace.la \ + ../Basics/libSALOMEBasics.la \ + $(LIB_LIBADD) diff --git a/src/Batch/Makefile.in b/src/Batch/Makefile.in deleted file mode 100644 index 6b83960e3..000000000 --- a/src/Batch/Makefile.in +++ /dev/null @@ -1,159 +0,0 @@ -# SALOME Container : implementation of container and engine for Kernel -# -# Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -# -# -# -# File : Makefile.in -# Author : EDF -# Module : SALOME -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl - - -@COMMENCE@ - -EXPORT_HEADERS = \ - Batch_APIInternalFailureException.hxx \ - Batch_BatchManager.hxx \ - Batch_BatchManagerCatalog.hxx \ - Batch_BoolType.hxx \ - Batch_CharType.hxx \ - Batch_ConnexionFailureException.hxx \ - Batch_Couple.hxx \ - Batch_CoupleType.hxx \ - Batch_Date.hxx \ - Batch_DateType.hxx \ - Batch_Environnement.hxx \ - Batch_FactBatchManager.hxx \ - Batch_GenericException.hxx \ - Batch_GenericType.hxx \ - Batch_IntType.hxx \ - Batch_InvalidArgumentException.hxx \ - Batch_InvalidKeyException.hxx \ - Batch_Job.hxx \ - Batch_JobId.hxx \ - Batch_JobInfo.hxx \ - Batch_ListIsFullException.hxx \ - Batch_LongType.hxx \ - Batch_MapKey.hxx \ - Batch_NotYetImplementedException.hxx \ - Batch_Parametre.hxx \ - Batch_PyVersatile.hxx \ - Batch_RunTimeException.hxx \ - Batch_StringType.hxx \ - Batch_TypeMismatchException.hxx \ - Batch_Versatile.hxx - - -# Libraries targets - -LIB = libSalomeBatch.la -LIB_SRC = \ - Batch_APIInternalFailureException.cxx \ - Batch_BatchManager.cxx \ - Batch_BatchManagerCatalog.cxx \ - Batch_BoolType.cxx \ - Batch_CharType.cxx \ - Batch_ConnexionFailureException.cxx \ - Batch_Couple.cxx \ - Batch_CoupleType.cxx \ - Batch_Date.cxx \ - Batch_DateType.cxx \ - Batch_Environnement.cxx \ - Batch_FactBatchManager.cxx \ - Batch_GenericException.cxx \ - Batch_GenericType.cxx \ - Batch_IntType.cxx \ - Batch_InvalidArgumentException.cxx \ - Batch_InvalidKeyException.cxx \ - Batch_Job.cxx \ - Batch_JobId.cxx \ - Batch_JobInfo.cxx \ - Batch_ListIsFullException.cxx \ - Batch_LongType.cxx \ - Batch_MapKey.cxx \ - Batch_NotYetImplementedException.cxx \ - Batch_Parametre.cxx \ - Batch_PyVersatile.cxx \ - Batch_RunTimeException.cxx \ - Batch_StringType.cxx \ - Batch_TypeMismatchException.cxx \ - Batch_Versatile.cxx - -LIB_SERVER_IDL = - - -CPPFLAGS += $(PYTHON_INCLUDES) -CXXFLAGS += $(PYTHON_INCLUDES) -LDFLAGS += -LIBS += -lSALOMELocalTrace - - - -# Specialisation pour OpenPBS -ifeq (@WITHOPENPBS@,yes) -EXPORT_HEADERS += \ - Batch_BatchManager_PBS.hxx \ - Batch_FactBatchManager_PBS.hxx \ - Batch_JobInfo_PBS.hxx \ - Batch_Job_PBS.hxx - -LIB_SRC += \ - Batch_BatchManager_PBS.cxx \ - Batch_FactBatchManager_PBS.cxx \ - Batch_JobInfo_PBS.cxx \ - Batch_Job_PBS.cxx - -CPPFLAGS += $(OPENPBS_INCLUDES) -CXXFLAGS += $(OPENPBS_INCLUDES) -LDFLAGS += $(OPENPBS_LIBDIR) -LIBS += $(OPENPBS_LIBS) -endif - - - - -# Specialisation pour LSF -ifeq (@WITH_LSF@,yes) -EXPORT_HEADERS += \ - Batch_BatchManager_LSF.hxx \ - Batch_FactBatchManager_LSF.hxx \ - Batch_JobInfo_LSF.hxx \ - Batch_Job_LSF.hxx - -LIB_SRC += \ - Batch_BatchManager_LSF.cxx \ - Batch_FactBatchManager_LSF.cxx \ - Batch_JobInfo_LSF.cxx \ - Batch_Job_LSF.cxx - -CPPFLAGS += $(LSF_INCLUDES) -CXXFLAGS += $(LSF_INCLUDES) -LDFLAGS += $(LSF_LIBDIR) -LIBS += $(LSF_LIBS) -endif - - -@CONCLUDE@