Salome HOME
add ccc batch manager for CCRT machines
authorsecher <secher>
Wed, 9 Jun 2010 14:16:14 +0000 (14:16 +0000)
committersecher <secher>
Wed, 9 Jun 2010 14:16:14 +0000 (14:16 +0000)
src/CCC/Batch_BatchManager_eCCC.cxx [new file with mode: 0644]
src/CCC/Batch_BatchManager_eCCC.hxx [new file with mode: 0644]
src/CCC/Batch_FactBatchManager_eCCC.cxx [new file with mode: 0644]
src/CCC/Batch_FactBatchManager_eCCC.hxx [new file with mode: 0644]
src/CCC/Batch_JobInfo_eCCC.cxx [new file with mode: 0644]
src/CCC/Batch_JobInfo_eCCC.hxx [new file with mode: 0644]
src/CCC/CMakeLists.txt [new file with mode: 0644]
src/CMakeLists.txt

diff --git a/src/CCC/Batch_BatchManager_eCCC.cxx b/src/CCC/Batch_BatchManager_eCCC.cxx
new file mode 100644 (file)
index 0000000..ce521ab
--- /dev/null
@@ -0,0 +1,331 @@
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * BatchManager_eCCC.cxx : emulation of CCC client for CCRT machines
+ *
+ * Auteur : Bernard SECHER - CEA DEN
+ * Mail   : mailto:bernard.secher@cea.fr
+ * Date   : Thu Apr 24 10:17:22 2010
+ * Projet : PAL Salome
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <sys/stat.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef WIN32
+#include <io.h>
+#else
+#include <libgen.h>
+#endif
+
+#include "Batch_BatchManager_eCCC.hxx"
+#include "Batch_JobInfo_eCCC.hxx"
+
+using namespace std;
+
+namespace Batch {
+
+  BatchManager_eCCC::BatchManager_eCCC(const FactBatchManager * parent, const char * host,
+                                       CommunicationProtocolType protocolType, const char * mpiImpl)
+  : BatchManager_eClient(parent, host, protocolType, mpiImpl),
+    BatchManager(parent, host)
+  {
+    // Nothing to do
+  }
+
+  // Destructeur
+  BatchManager_eCCC::~BatchManager_eCCC()
+  {
+    // Nothing to do
+  }
+
+  // Methode pour le controle des jobs : soumet un job au gestionnaire
+  const JobId BatchManager_eCCC::submitJob(const Job & job)
+  {
+    int status;
+    Parametre params = job.getParametre();
+    const std::string workDir = params[WORKDIR];
+    const string fileToExecute = params[EXECUTABLE];
+    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);
+
+    // export input files on cluster
+    cerr << "Export des fichiers en entree" << endl;
+    exportInputFiles(job);
+
+    // build batch script for job
+    cerr << "Construction du script de batch" << endl;
+    buildBatchScript(job);
+    cerr << "Script envoye" << endl;
+
+    // define name of log file (local)
+    string logFile = generateTemporaryFileName("CCC-submitlog");
+
+    // define command to submit batch
+    string subCommand = string("cd ") + workDir + "; ccc_msub " + fileNameToExecute + "_Batch.sh";
+    string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+    command += " > ";
+    command += logFile;
+    command += " 2>&1";
+    cerr << command.c_str() << endl;
+    status = system(command.c_str());
+    if(status)
+    {
+      ifstream error_message(logFile.c_str());
+      std::string mess;
+      std::string temp;
+      while(std::getline(error_message, temp))
+       mess += temp;
+      error_message.close();
+      throw EmulationException("Error of connection on remote host, error was: " + mess);
+    }
+
+    // read id of submitted job in log file
+    ifstream idfile(logFile.c_str());
+    string sidj;
+    idfile >> sidj;
+    idfile >> sidj;
+    idfile >> sidj;
+    idfile >> sidj;
+    idfile.close();
+    if (sidj.size() == 0)
+      throw EmulationException("Error in the submission of the job on the remote host");
+
+    JobId id(this, sidj);
+    return id;
+  }
+
+  // Methode pour le controle des jobs : retire un job du gestionnaire
+  void BatchManager_eCCC::deleteJob(const JobId & jobid)
+  {
+    int status;
+    int ref;
+    istringstream iss(jobid.getReference());
+    iss >> ref;
+
+    // define command to delete batch
+    string subCommand = string("ccc_mdel ") + iss.str();
+    string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+    cerr << command.c_str() << endl;
+    status = system(command.c_str());
+    if (status)
+      throw EmulationException("Error of connection on remote host");
+
+    cerr << "jobId = " << ref << "killed" << endl;
+  }
+
+  // Methode pour le controle des jobs : suspend un job en file d'attente
+  void BatchManager_eCCC::holdJob(const JobId & jobid)
+  {
+    throw EmulationException("Not yet implemented");
+  }
+
+  // Methode pour le controle des jobs : relache un job suspendu
+  void BatchManager_eCCC::releaseJob(const JobId & jobid)
+  {
+    throw EmulationException("Not yet implemented");
+  }
+
+
+  // Methode pour le controle des jobs : modifie un job en file d'attente
+  void BatchManager_eCCC::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
+  {
+    throw EmulationException("Not yet implemented");
+  }
+
+  // Methode pour le controle des jobs : modifie un job en file d'attente
+  void BatchManager_eCCC::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_eCCC::alterJob(const JobId & jobid, const Environnement & env)
+  {
+    alterJob(jobid, Parametre(), env);
+  }
+
+  // Methode pour le controle des jobs : renvoie l'etat du job
+  JobInfo BatchManager_eCCC::queryJob(const JobId & jobid)
+  {
+    int id;
+    istringstream iss(jobid.getReference());
+    iss >> id;
+
+    // define name of log file (local)
+    string logFile = generateTemporaryFileName(string("CCC-querylog-id") + jobid.getReference());
+
+    // define command to query batch
+    string subCommand = string("bjobs ") + iss.str();
+    string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+    command += " > ";
+    command += logFile;
+    cerr << command.c_str() << endl;
+    int status = system(command.c_str());
+    if (status)
+      throw EmulationException("Error of connection on remote host");
+
+    JobInfo_eCCC ji = JobInfo_eCCC(id,logFile);
+    return ji;
+  }
+
+
+
+  // Methode pour le controle des jobs : teste si un job est present en machine
+  bool BatchManager_eCCC::isRunning(const JobId & jobid)
+  {
+    throw EmulationException("Not yet implemented");
+  }
+
+  void BatchManager_eCCC::buildBatchScript(const Job & job)
+  {
+#ifndef WIN32 //TODO: need for porting on Windows
+    Parametre params = job.getParametre();
+
+    // Job Parameters
+    string workDir       = "";
+    string fileToExecute = "";
+    int nbproc          = 0;
+    int edt             = 0;
+    int mem              = 0;
+    string queue         = "";
+
+    // Mandatory parameters
+    if (params.find(WORKDIR) != params.end()) 
+      workDir = params[WORKDIR].str();
+    else 
+      throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job");
+    if (params.find(EXECUTABLE) != params.end()) 
+      fileToExecute = params[EXECUTABLE].str();
+    else 
+      throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job");
+
+    // Optional parameters
+    if (params.find(NBPROC) != params.end()) 
+      nbproc = params[NBPROC];
+    if (params.find(MAXWALLTIME) != params.end()) 
+      edt = params[MAXWALLTIME];
+    if (params.find(MAXRAMSIZE) != params.end()) 
+      mem = params[MAXRAMSIZE];
+    if (params.find(QUEUE) != params.end()) 
+      queue = params[QUEUE].str();
+
+    string::size_type p1 = fileToExecute.find_last_of("/");
+    string::size_type p2 = fileToExecute.find_last_of(".");
+    string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
+    string fileNameToExecute = fileToExecute.substr(p1+1);
+    // Create batch submit file
+    ofstream tempOutputFile;
+    std::string TmpFileName = createAndOpenTemporaryFile("LSF-script", tempOutputFile);
+
+    tempOutputFile << "#! /bin/sh -f" << endl ;
+    if (queue != "")
+      tempOutputFile << "#MSUB -q " << queue << endl;
+    if( edt > 0 )
+      tempOutputFile << "#MSUB -T " << edt << endl ;
+    if( mem > 0 )
+      tempOutputFile << "#MSUB -M " << mem/1024 << endl ;
+    tempOutputFile << "#MSUB -n " << nbproc << endl ;
+    size_t pos = workDir.find("$HOME");
+    string baseDir;
+    if( pos != string::npos )
+      baseDir = getHomeDir(workDir) + workDir.substr(pos+5,workDir.length()-5);
+    else{
+      pos = workDir.find("~");
+      if( pos != string::npos )
+       baseDir = getHomeDir(workDir) + workDir.substr(pos+1,workDir.length()-1);
+      else
+       baseDir = workDir;
+    }
+    tempOutputFile << "#MSUB -o " << baseDir << "/logs/output.log." << rootNameToExecute << endl ;
+    tempOutputFile << "#MSUB -e " << baseDir << "/logs/error.log." << rootNameToExecute << endl ;
+
+    tempOutputFile << "cd " << workDir << endl ;
+
+    // generate nodes file
+    tempOutputFile << "bool=0" << endl;
+    tempOutputFile << "for i in $LSB_MCPU_HOSTS; do" << endl;
+    tempOutputFile << "  if test $bool = 0; then" << endl;
+    tempOutputFile << "    n=$i" << endl;
+    tempOutputFile << "    bool=1" << endl;
+    tempOutputFile << "  else" << endl;
+    tempOutputFile << "    for ((j=0;j<$i;j++)); do" << endl;
+    tempOutputFile << "      echo $n >> nodesFile" << endl;
+    tempOutputFile << "    done" << endl;
+    tempOutputFile << "    bool=0" << endl;
+    tempOutputFile << "  fi" << endl;
+    tempOutputFile << "done" << endl;
+
+    // Abstraction of PBS_NODEFILE - TODO
+    tempOutputFile << "export LIBBATCH_NODEFILE=nodesFile" << endl;
+
+    // Launch the executable
+    tempOutputFile << "./" + fileNameToExecute << endl;
+    tempOutputFile.flush();
+    tempOutputFile.close();
+
+    BATCH_CHMOD(TmpFileName.c_str(), 0x1ED);
+    cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+
+    int status = _protocol.copyFile(TmpFileName, "", "",
+                                    workDir + "/" + rootNameToExecute + "_Batch.sh",
+                                    _hostname, _username);
+    if (status)
+      throw EmulationException("Error of connection on remote host");
+
+#endif
+
+  }
+
+  std::string BatchManager_eCCC::getHomeDir(std::string tmpdir)
+  {
+    std::string home;
+    int idx = tmpdir.find("Batch/");
+    std::string filelogtemp = tmpdir.substr(idx+6, tmpdir.length());
+    filelogtemp = "/tmp/logs" + filelogtemp + "_home";
+
+    string subCommand = string("echo $HOME");
+    string command = _protocol.getExecCommand(subCommand, _hostname, _username) + " > " + filelogtemp;
+    cerr << command.c_str() << endl;
+    int status = system(command.c_str());
+    if (status)
+      throw EmulationException("Error of launching home command on remote host");
+
+    std::ifstream file_home(filelogtemp.c_str());
+    std::getline(file_home, home);
+    file_home.close();
+    return home;
+  }
+
+}
diff --git a/src/CCC/Batch_BatchManager_eCCC.hxx b/src/CCC/Batch_BatchManager_eCCC.hxx
new file mode 100644 (file)
index 0000000..5a149a5
--- /dev/null
@@ -0,0 +1,88 @@
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * BatchManager_eCCC.hxx : emulation of CCC client for CCRT machines
+ *
+ * Auteur : Bernard SECHER - CEA DEN
+ * Mail   : mailto:bernard.secher@cea.fr
+ * Date   : Thu Apr 24 10:17:22 2010
+ * Projet : PAL Salome
+ *
+ */
+
+#ifndef _BATCHMANAGER_ECCC_H_
+#define _BATCHMANAGER_ECCC_H_
+
+#include "Batch_Defines.hxx"
+#include "Batch_JobId.hxx"
+#include "Batch_JobInfo.hxx"
+#include "Batch_FactBatchManager.hxx"
+#include "Batch_BatchManager_eClient.hxx"
+
+namespace Batch {
+
+  class BATCH_EXPORT BatchManager_eCCC : public BatchManager_eClient
+  {
+  public:
+    // Constructeur et destructeur
+    BatchManager_eCCC(const FactBatchManager * parent, const char * host="localhost",
+                      CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host
+    virtual ~BatchManager_eCCC();
+
+    // Recupere le nom du serveur par defaut
+    // static string BatchManager_LSF::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:
+    void buildBatchScript(const Job & job);
+    std::string getWallTime(const long edt);
+
+  private:
+
+    std::string getHomeDir(std::string tmpdir);
+
+#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/CCC/Batch_FactBatchManager_eCCC.cxx b/src/CCC/Batch_FactBatchManager_eCCC.cxx
new file mode 100644 (file)
index 0000000..b467447
--- /dev/null
@@ -0,0 +1,64 @@
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * FactBatchManager_eCCC.cxx : 
+ *
+ * Auteur : Bernard SECHER - CEA DEN
+ * Date   : Avril 2010
+ * Projet : PAL Salome
+ *
+ */
+
+#include "Batch_BatchManager_eCCC.hxx"
+#include "Batch_FactBatchManager_eCCC.hxx"
+
+namespace Batch {
+
+  // Constructeur
+  FactBatchManager_eCCC::FactBatchManager_eCCC() : FactBatchManager_eClient("eCCC")
+  {
+    // Nothing to do
+  }
+
+  // Destructeur
+  FactBatchManager_eCCC::~FactBatchManager_eCCC()
+  {
+    // Nothing to do
+  }
+
+  // Functor
+  BatchManager * FactBatchManager_eCCC::operator() (const char * hostname) const
+  {
+    // MESSAGE("Building new BatchManager_CCC on host '" << hostname << "'");
+    return new BatchManager_eCCC(this, hostname);
+  }
+
+  BatchManager_eClient * FactBatchManager_eCCC::operator() (const char * hostname,
+                                                            CommunicationProtocolType protocolType,
+                                                            const char * mpiImpl,
+                                                           int nb_proc_per_node) const
+  {
+    // MESSAGE("Building new BatchManager_CCC on host '" << hostname << "'");
+    return new BatchManager_eCCC(this, hostname, protocolType, mpiImpl);
+  }
+
+}
diff --git a/src/CCC/Batch_FactBatchManager_eCCC.hxx b/src/CCC/Batch_FactBatchManager_eCCC.hxx
new file mode 100644 (file)
index 0000000..bdca46f
--- /dev/null
@@ -0,0 +1,61 @@
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * FactBatchManager_eCCC.hxx : 
+ *
+ * Auteur : Bernard SECHER : CEA DEN
+ * Date   : Avril 2010
+ * Projet : PAL Salome
+ *
+ */
+
+#ifndef _FACTBATCHMANAGER_eCCC_H_
+#define _FACTBATCHMANAGER_eCCC_H_
+
+#include "Batch_Defines.hxx"
+#include "Batch_BatchManager_eClient.hxx"
+#include "Batch_FactBatchManager_eClient.hxx"
+
+namespace Batch {
+  
+  class BATCH_EXPORT FactBatchManager_eCCC : public FactBatchManager_eClient
+  {
+  public:
+    // Constructeur et destructeur
+    FactBatchManager_eCCC();
+    virtual ~FactBatchManager_eCCC();
+
+    virtual BatchManager * operator() (const char * hostname) const;
+    virtual BatchManager_eClient * operator() (const char * hostname,
+                                               CommunicationProtocolType protocolType,
+                                               const char * mpiImpl,
+                                              int nb_proc_per_node = 1) const;
+
+  protected:
+
+  private:
+
+  };
+
+}
+
+#endif
diff --git a/src/CCC/Batch_JobInfo_eCCC.cxx b/src/CCC/Batch_JobInfo_eCCC.cxx
new file mode 100644 (file)
index 0000000..219d0e8
--- /dev/null
@@ -0,0 +1,127 @@
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * JobInfo_eCCC.cxx :  emulation of CCC client for CCRT machines
+ *
+ * Auteur : Bernard SECHER - CEA DEN
+ * Mail   : mailto:bernard.secher@cea.fr
+ * Date   : Thu Apr 24 10:17:22 2010
+ * Projet : PAL Salome 
+ *
+ */
+
+#include <cstdio>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include "Batch_Parametre.hxx"
+#include "Batch_Environnement.hxx"
+#include "Batch_RunTimeException.hxx"
+#include "Batch_APIInternalFailureException.hxx"
+#include "Batch_JobInfo_eCCC.hxx"
+
+using namespace std;
+
+namespace Batch {
+
+
+
+  // Constructeurs
+  JobInfo_eCCC::JobInfo_eCCC(int id, string logFile) : JobInfo()
+  {
+    // On remplit les membres _param et _env
+    ostringstream oss;
+    oss << id;
+    _param[ID] = oss.str();
+
+    // read status of job in log file
+    char line[128];
+    ifstream fp(logFile.c_str(),ios::in);
+    fp.getline(line,80,'\n');
+    
+    string sjobid, username, status;
+    fp >> sjobid;
+    fp >> username;
+    fp >> status;
+
+    if (status == "PEND") {         // Pending
+      _param[STATE] = QUEUED;
+    } else if (status == "PSUSP") { // Suspended while pending
+      _param[STATE] = PAUSED;
+    } else if (status == "RUN") {   // Running
+      _param[STATE] = RUNNING;
+    } else if (status == "USUSP") { // Suspended while running
+      _param[STATE] = PAUSED;
+    } else if (status == "SSUSP") { // Suspended by CCC
+      _param[STATE] = PAUSED;
+    } else if (status == "DONE") {  // Finished successfully
+      _param[STATE] = FINISHED;
+    } else if (status == "EXIT") {  // Finished in error
+      _param[STATE] = FAILED;
+    } else if (status == "UNKWN") { // Lost contact
+      _param[STATE] = FAILED;
+    } else if (status == "ZOMBI") { // Zombie
+      _param[STATE] = FAILED;
+    } else {
+      cerr << "Unknown job state code: " << status << endl;
+    }
+
+    if( status.find("RUN") != string::npos)
+      _running = true;
+
+  }
+
+  // Teste si un job est present en machine
+  bool JobInfo_eCCC::isRunning() const
+  {
+    return _running;
+  }
+
+
+  // Destructeur
+  JobInfo_eCCC::~JobInfo_eCCC()
+  {
+    // Nothing to do
+  }
+
+  // Convertit une date HH:MM:SS en secondes
+  long JobInfo_eCCC::HMStoLong(const string & s)
+  {
+    long hour, min, sec;
+
+    sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec);
+    return ( ( ( hour * 60L ) + min ) * 60L ) + sec;
+  }
+
+  // Methode pour l'interfacage avec Python (SWIG) : affichage en Python
+  string JobInfo_eCCC::__str__() const
+  {
+    ostringstream sst;
+    sst << "<JobInfo_eCCC (" << this << ") :" << endl;
+    sst << " ID = " <<_param[ID] << endl;
+    sst << " STATE = " <<_param[STATE] << endl;
+
+    return sst.str();
+  }
+
+
+}
diff --git a/src/CCC/Batch_JobInfo_eCCC.hxx b/src/CCC/Batch_JobInfo_eCCC.hxx
new file mode 100644 (file)
index 0000000..999d0b5
--- /dev/null
@@ -0,0 +1,72 @@
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * JobInfo_eCCC.hxx :  emulation of CCC client for CCRT machines
+ *
+ * Auteur : Bernard SECHER - CEA DEN
+ * Mail   : mailto:bernard.secher@cea.fr
+ * Date   : Thu Apr 24 10:17:22 2010
+ * Projet : PAL Salome 
+ *
+ */
+
+#ifndef _JOBINFO_CCC_H_
+#define _JOBINFO_CCC_H_
+
+#include "Batch_RunTimeException.hxx"
+#include "Batch_JobInfo.hxx"
+
+#include <string>
+
+namespace Batch {
+
+  class JobInfo_eCCC : public JobInfo
+  {
+  public:
+    // Constructeurs et destructeur
+    JobInfo_eCCC() : _running(false) {};
+    JobInfo_eCCC(int id,std::string logFile);
+    virtual ~JobInfo_eCCC();
+
+    // Constructeur par recopie
+    JobInfo_eCCC(const JobInfo_eCCC & jinfo) : JobInfo(jinfo) {};
+
+    // Teste si un job est present en machine
+    virtual bool isRunning() 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
+
+  protected:
+    bool _running; // etat du job en machine
+
+  private:
+    // Convertit une date HH:MM:SS en secondes
+    long HMStoLong(const std::string &);
+
+  };
+
+}
+
+#endif
diff --git a/src/CCC/CMakeLists.txt b/src/CCC/CMakeLists.txt
new file mode 100644 (file)
index 0000000..968a674
--- /dev/null
@@ -0,0 +1,29 @@
+#  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+#  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+SET(CLASS_LIST CCC/Batch_BatchManager_eCCC
+               CCC/Batch_FactBatchManager_eCCC
+               CCC/Batch_JobInfo_eCCC
+   )
+
+APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST})
+APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST})
index c9f00583ca5fe5a263b974d09418dc9477b2d9c9..29328cf90a2c419d1d34432c0fbe7aa223f26e5a 100644 (file)
@@ -50,6 +50,7 @@ IF (BUILD_LOCAL_SUBMISSION)
     add_subdirectory (Local)
 ENDIF (BUILD_LOCAL_SUBMISSION)
 
+add_subdirectory (CCC)
 add_subdirectory (LSF)
 add_subdirectory (PBS)
 add_subdirectory (SGE)