From: Anthony Geay Date: Thu, 10 Mar 2016 10:43:26 +0000 (+0100) Subject: Successful first launch of scheme on cluster. X-Git-Tag: V7_8_0a2~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2967c6bab119215c635eb87184be1a69ed82d9f5;p=modules%2Fyacs.git Successful first launch of scheme on cluster. --- diff --git a/src/evalyfx/CMakeLists.txt b/src/evalyfx/CMakeLists.txt index 928aaaa8f..984946438 100644 --- a/src/evalyfx/CMakeLists.txt +++ b/src/evalyfx/CMakeLists.txt @@ -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 ) diff --git a/src/evalyfx/YACSEvalResource.cxx b/src/evalyfx/YACSEvalResource.cxx index b15c6a558..a3132d0d2 100644 --- a/src/evalyfx/YACSEvalResource.cxx +++ b/src/evalyfx/YACSEvalResource.cxx @@ -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) diff --git a/src/evalyfx/YACSEvalResource.hxx b/src/evalyfx/YACSEvalResource.hxx index 75c1fb515..0958e1972 100644 --- a/src/evalyfx/YACSEvalResource.hxx +++ b/src/evalyfx/YACSEvalResource.hxx @@ -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: diff --git a/src/evalyfx/YACSEvalSession.cxx b/src/evalyfx/YACSEvalSession.cxx index 6f4ca7128..b4f1e2a5b 100644 --- a/src/evalyfx/YACSEvalSession.cxx +++ b/src/evalyfx/YACSEvalSession.cxx @@ -19,6 +19,8 @@ // Author : Anthony Geay (EDF R&D) #include "YACSEvalSession.hxx" +#include "YACSEvalSessionInternal.hxx" + #include "Exception.hxx" #include @@ -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("stop")));//new diff --git a/src/evalyfx/YACSEvalSession.hxx b/src/evalyfx/YACSEvalSession.hxx index 8f421fceb..a58c34011 100644 --- a/src/evalyfx/YACSEvalSession.hxx +++ b/src/evalyfx/YACSEvalSession.hxx @@ -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 index 000000000..cfa5442b1 --- /dev/null +++ b/src/evalyfx/YACSEvalSessionInternal.cxx @@ -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 index 000000000..cdbf402c6 --- /dev/null +++ b/src/evalyfx/YACSEvalSessionInternal.hxx @@ -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 + +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 diff --git a/src/evalyfx/YACSEvalYFX.cxx b/src/evalyfx/YACSEvalYFX.cxx index 423c46f4d..17f46ae71 100644 --- a/src/evalyfx/YACSEvalYFX.cxx +++ b/src/evalyfx/YACSEvalYFX.cxx @@ -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) diff --git a/src/evalyfx/YACSEvalYFXPattern.cxx b/src/evalyfx/YACSEvalYFXPattern.cxx index d35fb8083..69bd3ccb3 100644 --- a/src/evalyfx/YACSEvalYFXPattern.cxx +++ b/src/evalyfx/YACSEvalYFXPattern.cxx @@ -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 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; } } diff --git a/src/evalyfx/YACSEvalYFXPattern.hxx b/src/evalyfx/YACSEvalYFXPattern.hxx index bcfe0e6d5..a53bf4a05 100644 --- a/src/evalyfx/YACSEvalYFXPattern.hxx +++ b/src/evalyfx/YACSEvalYFXPattern.hxx @@ -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 getResults() const = 0; virtual std::vector getResultsInCaseOfFailure(std::vector& 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 getResults() const; std::vector getResultsInCaseOfFailure(std::vector& 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); diff --git a/src/evalyfx_swig/evalyfx.i b/src/evalyfx_swig/evalyfx.i index aceff91ae..3c2c12e4a 100644 --- a/src/evalyfx_swig/evalyfx.i +++ b/src/evalyfx_swig/evalyfx.i @@ -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();