From ed36c0ba9bae49db0e4b72ecd79a3466cb78487a Mon Sep 17 00:00:00 2001 From: crouzet Date: Wed, 5 Dec 2018 17:26:31 +0100 Subject: [PATCH] Extension to the case where APPLI points at a salome launcher file - getCommandToRunRemoteProcess api is extended - it's use is generalised (code factorisation) - salome launcher files are taken into account, containers are distributed by calling salome remote command --- bin/salomeContextUtils.py.in | 10 +- src/Container/SALOME_ContainerManager.cxx | 149 ++++++++++------------ src/Container/SALOME_ContainerManager.hxx | 6 +- src/ResourcesManager/ResourcesManager.cxx | 24 ++-- 4 files changed, 90 insertions(+), 99 deletions(-) diff --git a/bin/salomeContextUtils.py.in b/bin/salomeContextUtils.py.in index 318c40c2b..6971315d7 100644 --- a/bin/salomeContextUtils.py.in +++ b/bin/salomeContextUtils.py.in @@ -308,9 +308,9 @@ def formatScriptsAndArgs(scriptArgs=None): # If OMNIORB_USER_PATH is already set, only checks write access to associated directory ; # an exception is raised if check fails. It allows users for choosing a specific folder. # Else the function sets OMNIORB_USER_PATH this way: -# - If APPLI environment variable is set, OMNIORB_USER_PATH is set to ${APPLI}/USERS. -# The function does not check USERS folder existence or write access. This folder -# must exist ; this is the case if SALOME virtual application has been created using +# - If APPLI environment variable is set, and if ${APPLI}/USERS points at an existing +# folder with write access, then OMNIORB_USER_PATH is set to ${APPLI}/USERS. +# This is the case if SALOME virtual application has been created using # appli_gen.py script. # - Else OMNIORB_USER_PATH is set to user home directory. def setOmniOrbUserPath(): @@ -334,7 +334,9 @@ def setOmniOrbUserPath(): #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS") defaultOmniorbUserPath = homePath if os.getenv("APPLI"): - defaultOmniorbUserPath = os.path.join(homePath, os.getenv("APPLI"), "USERS") + appli_users_path=os.path.join(homePath, os.getenv("APPLI"), "USERS") + if os.access(appli_users_path, os.W_OK): + defaultOmniorbUserPath = appli_users_path pass os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath # diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 0d21953b2..1837cfc6d 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -519,26 +519,13 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par // Only if an application directory is set if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined) { - // Preparing remote command - std::string command = ""; + const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected)); - command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName); - if (resInfo.AppliPath != "") - command += resInfo.AppliPath; - else - { - ASSERT(GetenvThreadSafe("APPLI")); - command += GetenvThreadSafeAsString("APPLI"); - } - command += "/runRemote.sh "; - ASSERT(GetenvThreadSafe("NSHOST")); - command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server - command += " "; - ASSERT(GetenvThreadSafe("NSPORT")); - command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server - command += " \"ls /tmp >/dev/null 2>&1\""; + std::string command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, + resInfo.UserName, resInfo.AppliPath); // Launch remote command + command += " \"ls /tmp >/dev/null 2>&1\""; int status = SystemThreadSafe(command.c_str()); if (status != 0) { @@ -760,37 +747,16 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& nbproc = params.nb_proc; } - // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir - // SALOME_Container containerName &" - command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName); - - if (resInfo.AppliPath != "") - command += resInfo.AppliPath; // path relative to user@machine $HOME - else - { - ASSERT(GetenvThreadSafe("APPLI")); - command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME - } - - command += "/runRemote.sh "; - - ASSERT(GetenvThreadSafe("NSHOST")); - command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server - - command += " "; - ASSERT(GetenvThreadSafe("NSPORT")); - command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server - std::string wdir = params.workingdir.in(); - if(wdir != "") - { - command += " WORKINGDIR "; - command += " '"; - if(wdir == "$TEMPDIR") - wdir="\\$TEMPDIR"; - command += wdir; // requested working directory - command += "'"; - } + + // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \ + // SALOME_Container containerName -ORBInitRef NameService=IOR:01000..." + // or + // "ssh -l user machine distantLauncher remote -p hostNS -m portNS -d dir + // -- SALOME_Container contName -ORBInitRef NameService=IOR:01000..." + command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, + resInfo.UserName, resInfo.AppliPath, + wdir); if(params.isMPI) { @@ -1212,43 +1178,8 @@ std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, c { if (_isAppliSalomeDefined) { - - if (resInfo.Protocol == rsh) - command = "rsh "; - else if (resInfo.Protocol == ssh) - command = "ssh "; - else if (resInfo.Protocol == srun) - command = "srun -n 1 -N 1 --share --mem-per-cpu=0 --nodelist="; - else - throw SALOME_Exception("Unknown protocol"); - - if (resInfo.UserName != "") - { - command += "-l "; - command += resInfo.UserName; - command += " "; - } - - command += resInfo.HostName; - command += " "; - - if (resInfo.AppliPath != "") - command += resInfo.AppliPath; // path relative to user@machine $HOME - else - { - ASSERT(GetenvThreadSafe("APPLI")); - command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME - } - - command += "/runRemote.sh "; - - ASSERT(GetenvThreadSafe("NSHOST")); - command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server - - command += " "; - ASSERT(GetenvThreadSafe("NSPORT")); - command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server - + command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, + resInfo.UserName, resInfo.AppliPath); command += " mpirun -np 1 hostname -s > " + tmpFile; } else @@ -1299,7 +1230,9 @@ std::string SALOME_ContainerManager::machinesFile(const int nbproc) std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, - const std::string & username) + const std::string & username, + const std::string & applipath, + const std::string & workdir) { std::ostringstream command; switch (protocol) @@ -1335,6 +1268,52 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol throw SALOME_Exception("Unknown protocol"); } + std::string remoteapplipath; + if (applipath=="") + remoteapplipath = GetenvThreadSafeAsString("APPLI"); + else + remoteapplipath = applipath; + + ASSERT(GetenvThreadSafe("NSHOST")); + ASSERT(GetenvThreadSafe("NSPORT")); + + // $APPLI points either to an application directory, or to a salome launcher file + // we prepare the remote command according to the case + struct stat statbuf; + if (stat(GetenvThreadSafe("APPLI"), &statbuf) ==0 && S_ISREG(statbuf.st_mode)) + { + // if $APPLI is a regular file, we asume it's a salome Launcher + // generate a command with a salome launcher + command << remoteapplipath + << " remote" + << " -m " + << GetenvThreadSafeAsString("NSHOST") // hostname of CORBA name server + << " -p " + << GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server + if (workdir != "") + command << "-d " << workdir; + command << " -- " ; + } + else // we assume it's a salome application directory + { + // generate a command with runRemote.sh + command << remoteapplipath; + command << "/runRemote.sh "; + command << GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server + command << " "; + command << GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server + if(workdir != "") + { + command << " WORKINGDIR "; + command << " '"; + if(workdir == "$TEMPDIR") + command << "\\$TEMPDIR"; + else + command << workdir; // requested working directory + command << "'"; + } + } + return command.str(); } diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 4c9293e16..941603e93 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -89,7 +89,11 @@ protected: std::string machinesFile(const int nbproc); - static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username); + static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, + const std::string & hostname, + const std::string & username, + const std::string & applipath, + const std::string & workdir=""); Engines::Container_ptr LaunchContainer(const Engines::ContainerParameters& params, diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index f53cce8ac..650160d61 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -148,17 +148,23 @@ ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException) default_file += "/"; default_file += getenv("APPLI"); default_file += "/CatalogResources.xml"; - _path_resources.push_back(default_file); - } - else - { - if(!getenv("KERNEL_ROOT_DIR")) - throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml"); - default_file = getenv("KERNEL_ROOT_DIR"); - default_file += "/share/salome/resources/kernel/CatalogResources.xml"; - _path_resources.push_back(default_file); + std::ifstream ifile(default_file.c_str(), std::ifstream::in ); + if (ifile) { + // The file exists, and is open for input + _path_resources.push_back(default_file); + default_catalog_resource=false; + } } } + if (default_catalog_resource) + { + std::string default_file(""); + if(!getenv("KERNEL_ROOT_DIR")) + throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml"); + default_file = getenv("KERNEL_ROOT_DIR"); + default_file += "/share/salome/resources/kernel/CatalogResources.xml"; + _path_resources.push_back(default_file); + } ParseXmlFiles(); RES_MESSAGE("ResourcesManager_cpp constructor end"); -- 2.39.2