Salome HOME
Successful first launch of scheme on cluster.
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 10 Mar 2016 10:43:26 +0000 (11:43 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 24 Mar 2016 17:33:40 +0000 (18:33 +0100)
src/evalyfx/CMakeLists.txt
src/evalyfx/YACSEvalResource.cxx
src/evalyfx/YACSEvalResource.hxx
src/evalyfx/YACSEvalSession.cxx
src/evalyfx/YACSEvalSession.hxx
src/evalyfx/YACSEvalSessionInternal.cxx [new file with mode: 0644]
src/evalyfx/YACSEvalSessionInternal.hxx [new file with mode: 0644]
src/evalyfx/YACSEvalYFX.cxx
src/evalyfx/YACSEvalYFXPattern.cxx
src/evalyfx/YACSEvalYFXPattern.hxx
src/evalyfx_swig/evalyfx.i

index 928aaaa8f3a932c3425927318a3c9af403dff501..98494643803a5439851265512f9953ac1e3e97e2 100644 (file)
@@ -68,6 +68,7 @@ SET(YACSEvalYFX_HEADERS
   YACSEvalSeqAny.hxx
   YACSEvalResource.hxx
   YACSEvalSession.hxx
+  YACSEvalSessionInternal.hxx
   YACSEvalObserver.hxx
   YACSEvalExecParams.hxx
   )
@@ -79,6 +80,7 @@ SET(YACSevalYFX_SOURCES
   YACSEvalSeqAny.cxx
   YACSEvalResource.cxx
   YACSEvalSession.cxx
+  YACSEvalSessionInternal.cxx
   YACSEvalObserver.cxx
   )
 
index b15c6a55812f6ccd94debea9fa82855831bb2081..a3132d0d26eed9d15415d99d556996c0fd9c615f 100644 (file)
@@ -337,6 +337,8 @@ void YACSEvalParamsForCluster::checkConsistency() const
 {
   if(_remoteWorkingDir.empty())
     throw YACS::Exception("YACSEvalParamsForCluster::checkConsistency : remote work dir is not set !");
+  if(_localWorkingDir.empty())
+    throw YACS::Exception("YACSEvalParamsForCluster::checkConsistency : local work dir is not set !");
   if(_wcKey.empty())
     throw YACS::Exception("YACSEvalParamsForCluster::checkConsistency : WC key is not set !");
   if(_nbOfProcs==0)
index 75c1fb515112a7c3c6396524b218bfbe42b0d90e..0958e1972fac6c3f35f1f0bea0699e44fd47886f 100644 (file)
@@ -139,15 +139,21 @@ public:
   void setExclusiveness(bool newStatus);
   std::string getRemoteWorkingDir() const { return _remoteWorkingDir; }
   void setRemoteWorkingDir(const std::string& remoteWorkingDir) { _remoteWorkingDir=remoteWorkingDir; }
+  std::string getLocalWorkingDir() const { return _localWorkingDir; }
+  void setLocalWorkingDir(const std::string& localWorkingDir) { _localWorkingDir=localWorkingDir; }
   std::string getWCKey() const { return _wcKey; }
   void setWCKey(const std::string& wcKey) { _wcKey=wcKey; }
   unsigned int getNbProcs() const { return _nbOfProcs; }
   void setNbProcs(unsigned int nbProcs) { _nbOfProcs=nbProcs; }
+  void setMaxDuration(const std::string& maxDuration) { _maxDuration=maxDuration; }
+  std::string getMaxDuration() const { return _maxDuration; }
   void checkConsistency() const;
 private:
   bool _exclusiveness;
   std::string _remoteWorkingDir;
+  std::string _localWorkingDir;
   std::string _wcKey;
+  std::string _maxDuration;
   unsigned int _nbOfProcs;
 };
 
@@ -164,6 +170,7 @@ public:
   YACSEVALYFX_EXPORT unsigned int getNumberOfProcsDeclared() const;
   YACSEVALYFX_EXPORT void checkOKForRun() const;
   YACSEVALYFX_EXPORT YACSEvalParamsForCluster& getAddParamsForCluster() { return _paramsInCaseOfCluster; }
+  YACSEVALYFX_EXPORT const YACSEvalParamsForCluster& getAddParamsForCluster() const { return _paramsInCaseOfCluster; }
   void apply();
   YACSEVALYFX_EXPORT ~YACSEvalListOfResources();
 public:
index 6f4ca712886b8cf193754c05073f5e9b93c20a93..b4f1e2a5bf0fbc3cdb41084962f8ba2ecbc5d7e8 100644 (file)
@@ -19,6 +19,8 @@
 // Author : Anthony Geay (EDF R&D)
 
 #include "YACSEvalSession.hxx"
+#include "YACSEvalSessionInternal.hxx"
+
 #include "Exception.hxx"
 
 #include <Python.h>
@@ -27,7 +29,7 @@ const char YACSEvalSession::KERNEL_ROOT_DIR[]="KERNEL_ROOT_DIR";
 
 const char YACSEvalSession::CORBA_CONFIG_ENV_VAR_NAME[]="OMNIORB_CONFIG";
 
-YACSEvalSession::YACSEvalSession():_isLaunched(false),_port(-1),_salomeInstanceModule(0),_salomeInstance(0)
+YACSEvalSession::YACSEvalSession():_isLaunched(false),_port(-1),_salomeInstanceModule(0),_salomeInstance(0),_internal(new YACSEvalSessionInternal)
 {
   if(!Py_IsInitialized())
     Py_Initialize();
@@ -37,6 +39,7 @@ YACSEvalSession::YACSEvalSession():_isLaunched(false),_port(-1),_salomeInstanceM
 
 YACSEvalSession::~YACSEvalSession()
 {
+  delete _internal;
   if(isLaunched())
     {
       PyObject *terminateSession(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("stop")));//new
index 8f421fceb1da8407bf048033b44dc645e1173c74..a58c340114943962d6eb66e35bfc8fdd273caa22 100644 (file)
@@ -30,6 +30,8 @@ typedef _object PyObject;
 
 class YACSEvalSession
 {
+public:
+  class YACSEvalSessionInternal;
 public:
   YACSEVALYFX_EXPORT YACSEvalSession();
   YACSEVALYFX_EXPORT ~YACSEvalSession();
@@ -38,6 +40,8 @@ public:
   YACSEVALYFX_EXPORT void checkLaunched() const;
   YACSEVALYFX_EXPORT int getPort() const;
   YACSEVALYFX_EXPORT std::string getCorbaConfigFileName() const;
+public:
+  YACSEvalSessionInternal *getInternal() { checkLaunched(); return _internal; }
 private:
   static std::string GetPathToAdd();
 public:
@@ -49,6 +53,7 @@ private:
   std::string _corbaConfigFileName;
   PyObject *_salomeInstanceModule;
   PyObject *_salomeInstance;
+  YACSEvalSessionInternal *_internal;
 };
 
 #endif
diff --git a/src/evalyfx/YACSEvalSessionInternal.cxx b/src/evalyfx/YACSEvalSessionInternal.cxx
new file mode 100644 (file)
index 0000000..cfa5442
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2012-2015  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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
+// 
+// Author : Anthony Geay (EDF R&D)
+
+#include "YACSEvalSessionInternal.hxx"
+#include "YACSEvalSession.hxx"
+
+#include "PyStdout.hxx"
+#include "AutoGIL.hxx"
+#include "Exception.hxx"
+
+YACSEvalSession::YACSEvalSessionInternal::YACSEvalSessionInternal():_orb(CORBA::ORB::_nil()),_sl(Engines::SalomeLauncher::_nil())
+{
+}
+
+void YACSEvalSession::YACSEvalSessionInternal::checkSalomeLauncher()
+{
+  if(CORBA::is_nil(_sl))
+    throw YACS::Exception("YACSEvalSessionInternal::checkSalomeLauncher : salome launcher is null !");
+}
+
+Engines::SalomeLauncher_var YACSEvalSession::YACSEvalSessionInternal::goFetchingSalomeLauncherInNS()
+{
+  if(!CORBA::is_nil(_sl))
+    return _sl;
+  int argc(0);
+  _orb=CORBA::ORB_init(argc,0);
+  if(CORBA::is_nil(_orb))
+    throw YACS::Exception("YACSEvalSessionInternal contrctor : ORB is null !");
+  //
+  const char methName[]="goFetchingSalomeLauncherInNS";
+  const char fetchPyCmd[]="import salome,CORBA\nsalome.salome_init()\nsl=salome.naming_service.Resolve(\"/SalomeLauncher\")\nif not CORBA.is_nil(sl):\n  return salome.orb.object_to_string(sl)\nelse:\n  raise Exception(\"Impossible to locate salome launcher !\")";
+  YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy(methName,fetchPyCmd));
+  YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
+  std::string ior(PyString_AsString(val));
+  CORBA::Object_var obj(string_to_object(ior));
+  if(CORBA::is_nil(obj))
+    throw YACS::Exception("goFetchingSalomeLauncherInNS : fetched ior is NIL !");
+  _sl=Engines::SalomeLauncher::_narrow(obj);
+  checkSalomeLauncher();
+  return _sl;
+}
+
+Engines::SalomeLauncher_var YACSEvalSession::YACSEvalSessionInternal::getNotNullSL()
+{
+  checkSalomeLauncher();
+  return _sl;
+}
diff --git a/src/evalyfx/YACSEvalSessionInternal.hxx b/src/evalyfx/YACSEvalSessionInternal.hxx
new file mode 100644 (file)
index 0000000..cdbf402
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2012-2015  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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
+// 
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __YACSEVALSESSIONINTERNAL_HXX__
+#define __YACSEVALSESSIONINTERNAL_HXX__
+
+#include "YACSEvalSession.hxx"
+
+#include "SALOMEconfig.h"
+#include CORBA_CLIENT_HEADER(SALOME_Launcher)
+#include "omniORB4/CORBA.h"
+
+#include <string>
+
+class YACSEvalSession::YACSEvalSessionInternal
+{
+public:
+  YACSEvalSessionInternal();
+  CORBA::Object_var string_to_object(const std::string& ior) { return _orb->string_to_object(ior.c_str()); }
+  Engines::SalomeLauncher_var goFetchingSalomeLauncherInNS();
+  Engines::SalomeLauncher_var getNotNullSL();
+private:
+  void checkSalomeLauncher();
+private:
+  CORBA::ORB_var _orb;
+  Engines::SalomeLauncher_var _sl;
+};
+
+#endif
index 423c46f4de297c5aad69b40cde3c5bdf44873fba..17f46ae71ee0306d2068b04babcb2a154b9212bc 100644 (file)
@@ -101,7 +101,7 @@ bool YACSEvalYFX::run(YACSEvalSession *session, int& nbOfBranches)
   //  throw YACS::Exception("YACSEvalYFX::run : not implemented yet for non interactive !");
   rss->apply();
   nbOfBranches=_pattern->assignNbOfBranches();
-  return _pattern->go(_params.getStopASAPAfterErrorStatus());
+  return _pattern->go(_params.getStopASAPAfterErrorStatus(),session);
 }
 
 void YACSEvalYFX::registerObserver(YACSEvalObserver *observer)
index d35fb80834b0ac08c05dbcb21e454bb8fbdcd611..69bd3ccb36e373783399724778244ca9adfd26bc 100644 (file)
@@ -21,7 +21,9 @@
 #include "YACSEvalYFXPattern.hxx"
 #include "YACSEvalResource.hxx"
 #include "YACSEvalSeqAny.hxx"
+#include "YACSEvalSession.hxx"
 #include "YACSEvalObserver.hxx"
+#include "YACSEvalSessionInternal.hxx"
 #include "YACSEvalAutoPtr.hxx"
 
 #include "ElementaryNode.hxx"
@@ -662,7 +664,7 @@ void YACSEvalYFXRunOnlyPattern::emitStart() const
   obs->notifyNumberOfSamplesToEval(getBoss(),_FEInGeneratedGraph->getNbOfElementsToBeProcessed());
 }
 
-bool YACSEvalYFXRunOnlyPattern::go(bool stopASAP) const
+bool YACSEvalYFXRunOnlyPattern::go(bool stopASAP, YACSEvalSession *session) const
 {
   emitStart();
   if(getResourcesInternal()->isInteractive())
@@ -677,13 +679,60 @@ bool YACSEvalYFXRunOnlyPattern::go(bool stopASAP) const
     }
   else
     {
-      char EFXGenFileName[]="EFXGenFileName";
-      char EFXGenContent[]="import getpass,datetime,os\nn=datetime.datetime.now()\nreturn os.path.join(os.path.sep,\"tmp\",\"EvalYFX_%s_%s_%s.xml\"%(getpass.getuser(),n.strftime(\"%d%b%y\"),n.strftime(\"%H%M%S\")))";
+      const char EFXGenFileName[]="EFXGenFileName";
+      const char EFXGenContent[]="import getpass,datetime,os\nn=datetime.datetime.now()\nreturn os.path.join(os.path.sep,\"tmp\",\"EvalYFX_%s_%s_%s.xml\"%(getpass.getuser(),n.strftime(\"%d%b%y\"),n.strftime(\"%H%M%S\")))";
+      const char EFXGenContent2[]="import getpass,datetime\nn=datetime.datetime.now()\nreturn \"EvalYFX_%s_%s_%s\"%(getpass.getuser(),n.strftime(\"%d%b%y\"),n.strftime(\"%H%M%S\"))";
       //
       YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy(EFXGenFileName,EFXGenContent));
       YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
-      std::string fn(PyString_AsString(val));
-      getUndergroundGeneratedGraph()->saveSchema(fn);
+      std::string locSchemaFile(PyString_AsString(val));
+      getUndergroundGeneratedGraph()->saveSchema(locSchemaFile);
+      func=YACS::ENGINE::evalPy(EFXGenFileName,EFXGenContent2);
+      val=YACS::ENGINE::evalFuncPyWithNoParams(func);
+      std::string jobName(PyString_AsString(val));
+      YACSEvalListOfResources *rss(getResourcesInternal());
+      const YACSEvalParamsForCluster& cli(rss->getAddParamsForCluster());
+      std::vector<std::string> machines(rss->getAllChosenMachines());
+      if(machines.size()!=1)
+        throw YACS::Exception("YACSEvalYFXRunOnlyPattern::go : internal error ! In batch mode and not exactly one machine !");
+      Engines::SalomeLauncher_var sl(session->getInternal()->goFetchingSalomeLauncherInNS());
+      Engines::ResourceParameters rr;
+      rr.name=CORBA::string_dup(machines[0].c_str());
+      rr.hostname=CORBA::string_dup("");
+      rr.can_launch_batch_jobs=true;
+      rr.can_run_containers=true;
+      rr.OS=CORBA::string_dup("Linux");
+      rr.componentList.length(0);
+      rr.nb_proc=rss->getNumberOfProcsDeclared();// <- important
+      rr.mem_mb=1024;
+      rr.cpu_clock=1000;
+      rr.nb_node=1;// useless only nb_proc used.
+      rr.nb_proc_per_node=1;// useless only nb_proc used.
+      rr.policy=CORBA::string_dup("cycl");
+      rr.resList.length(0);
+      Engines::JobParameters jp;
+      jp.job_name=CORBA::string_dup(jobName.c_str());
+      jp.job_type=CORBA::string_dup("yacs_file");
+      jp.job_file=CORBA::string_dup(locSchemaFile.c_str());
+      jp.env_file=CORBA::string_dup("");
+      jp.in_files.length();
+      jp.out_files.length();
+      jp.work_directory=CORBA::string_dup(cli.getRemoteWorkingDir().c_str());
+      jp.local_directory=CORBA::string_dup(cli.getLocalWorkingDir().c_str());
+      jp.result_directory=CORBA::string_dup(cli.getLocalWorkingDir().c_str());
+      jp.maximum_duration=CORBA::string_dup(cli.getMaxDuration().c_str());
+      jp.resource_required=rr;
+      jp.queue=CORBA::string_dup("");
+      jp.exclusive=false;
+      jp.mem_per_cpu=rr.mem_mb;
+      jp.wckey=CORBA::string_dup(cli.getWCKey().c_str());
+      jp.extra_params=CORBA::string_dup("");
+      jp.specific_parameters.length(0);
+      jp.launcher_file=CORBA::string_dup("");
+      jp.launcher_args=CORBA::string_dup("");
+      CORBA::Long jobid(sl->createJob(jp));
+      sl->launchJob(jobid);
+      std::cerr << "*** " << jobName << " -> " << jobid << std::endl;
       return false;
     }
 }
index bcfe0e6d57347de200a561eed94a18f7e9970ab6..a53bf4a05d3ef266839ddb008a75239aac524cc1 100644 (file)
@@ -43,6 +43,7 @@ namespace YACS
 }
 
 class YACSEvalYFX;
+class YACSEvalSession;
 class YACSEvalObserver;
 class YACSEvalListOfResources;
 class ResourcesManager_cpp;
@@ -79,7 +80,7 @@ public:
   virtual std::string getStatusOfRunStr() const = 0;
   virtual std::vector<YACSEvalSeqAny *> getResults() const = 0;
   virtual std::vector<YACSEvalSeqAny *> getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const = 0;
-  virtual bool go(bool stopASAP) const = 0;
+  virtual bool go(bool stopASAP, YACSEvalSession *session) const = 0;
 public:
   static const char DFT_PROC_NAME[];
 protected:
@@ -129,7 +130,7 @@ public:
   std::string getStatusOfRunStr() const;
   std::vector<YACSEvalSeqAny *> getResults() const;
   std::vector<YACSEvalSeqAny *> getResultsInCaseOfFailure(std::vector<unsigned int>& passedIds) const;
-  bool go(bool stopASAP) const;
+  bool go(bool stopASAP, YACSEvalSession *session) const;
   //
   YACS::ENGINE::ForEachLoop *getUndergroundForEach() const { return _FEInGeneratedGraph; }
   static bool IsMatching(YACS::ENGINE::Proc *scheme, YACS::ENGINE::ComposedNode *& runNode);
index aceff91ae4284416678385f960a19843afe5f06e..3c2c12e4aa25ce5902e3384cc7f07fdf1d1665be 100644 (file)
@@ -344,10 +344,14 @@ public:
   void setExclusiveness(bool newStatus);
   std::string getRemoteWorkingDir();
   void setRemoteWorkingDir(const std::string& remoteWorkingDir);
+  std::string getLocalWorkingDir();
+  void setLocalWorkingDir(const std::string& localWorkingDir);
   std::string getWCKey() const;
   void setWCKey(const std::string& wcKey);
   unsigned int getNbProcs() const;
   void setNbProcs(unsigned int nbProcs);
+  void setMaxDuration(const std::string& maxDuration);
+  std::string getMaxDuration() const;
   void checkConsistency() const;
 private:
   YACSEvalParamsForCluster();