From c9944e5eb864a01b4aba1a6ad12782bea69dcf64 Mon Sep 17 00:00:00 2001 From: barate Date: Thu, 5 Jan 2012 15:10:28 +0000 Subject: [PATCH] Improvements for Salome on clusters (fix bug PAL #1966): - New option to launch Salome servers with a simple fork instead of daemons - Add internal protocols pbsdsh and blaunch for PBS and LSF clusters --- bin/launchConfigureParser.py | 19 +-- bin/runSalome.py | 4 +- bin/server.py | 21 ++- src/Container/SALOME_ContainerManager.cxx | 56 ++++---- src/Container/SALOME_ContainerManager.hxx | 9 +- src/Launcher/Launcher_Job_SALOME.cxx | 14 +- src/Launcher/Makefile.am | 7 +- .../SALOME_ResourcesCatalog_Handler.cxx | 123 ++++++------------ .../SALOME_ResourcesCatalog_Parser.cxx | 55 ++++++-- .../SALOME_ResourcesCatalog_Parser.hxx | 5 +- .../SALOME_ResourcesManager.cxx | 44 ++----- 11 files changed, 152 insertions(+), 205 deletions(-) diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index caf138cd1..f273e7364 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -746,13 +746,14 @@ def CreateOptionParser (theAdditionalOptions=[]): dest="wake_up_session", default=False, help=help_str) - # Launch server processes with a specific command. Default: False. - help_str = "Launch server processes with a specific command." - o_slc = optparse.Option("--server-launch-cmd", - metavar="", - type="string", + # server launch mode + help_str = "Mode used to launch server processes (daemon or fork)." + o_slm = optparse.Option("--server-launch-mode", + metavar="", + type="choice", + choices=["daemon","fork"], action="store", - dest="server_launch_cmd", + dest="server_launch_mode", help=help_str) # All options @@ -783,7 +784,7 @@ def CreateOptionParser (theAdditionalOptions=[]): o_shutdown, o_foreground, o_wake_up, - o_slc, # Server launch command + o_slm, # Server launch mode ] #std_options = ["gui", "desktop", "log_file", "py_scripts", "resources", @@ -1133,8 +1134,8 @@ def get_env(theAdditionalOptions=[], appname=salomeappname, cfgname=salomecfgnam args[play_nam] += re.split( "[:;,]", filename ) # Server launch command - if cmd_opts.server_launch_cmd is not None: - args["server_launch_cmd"] = cmd_opts.server_launch_cmd + if cmd_opts.server_launch_mode is not None: + args["server_launch_mode"] = cmd_opts.server_launch_mode # return arguments os.environ[config_var] = separator.join(dirs) diff --git a/bin/runSalome.py b/bin/runSalome.py index 5dd6137c6..9f52819db 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -418,8 +418,8 @@ def startSalome(args, modules_list, modules_root_dir): # # Set server launch command # - if args.has_key('server_launch_cmd'): - Server.set_server_launch_cmd(args['server_launch_cmd']) + if args.has_key('server_launch_mode'): + Server.set_server_launch_mode(args['server_launch_mode']) # # Wake up session option diff --git a/bin/server.py b/bin/server.py index 3fde06b40..1f6d95c44 100755 --- a/bin/server.py +++ b/bin/server.py @@ -34,7 +34,7 @@ process_id = {} class Server: """Generic class for CORBA server launch""" - server_launch_args = [] + server_launch_mode = "daemon" def initArgs(self): self.PID=None @@ -51,12 +51,11 @@ class Server: self.initArgs() @staticmethod - def set_server_launch_cmd(cmd): - if cmd == "srun": - Server.server_launch_args = ["srun", "-n", "1", "-N", "1"] - Server.server_launch_args += ["--share", "--nodelist=%s" % getHostName()] - else: - print >>sys.stderr, "Unknown server launch command:%s" % cmd + def set_server_launch_mode(mode): + if mode == "daemon" or mode == "fork": + Server.server_launch_mode = mode + else: + raise Exception("Unsupported server launch mode: %s" % mode) def run(self): global process_id @@ -76,8 +75,9 @@ class Server: #pid = win32pm.spawnpid( cmd_str ) pid = win32pm.spawnpid( string.join(command, " "), '-nc' ) #pid = win32pm.spawnpid( string.join(command, " ") ) - else: - #pid = os.spawnvp(os.P_NOWAIT, command[0], command) + elif Server.server_launch_mode == "fork": + pid = os.spawnvp(os.P_NOWAIT, command[0], command) + else: # Server launch mode is daemon pid=self.daemonize(command) if pid is not None: #store process pid if it really exists @@ -134,9 +134,8 @@ class Server: #I am a daemon os.close(0) #close stdin os.open("/dev/null", os.O_RDWR) # redirect standard input (0) to /dev/null - all_args = Server.server_launch_args + args try: - os.execvp(all_args[0], all_args) + os.execvp(args[0], args) except OSError, e: if args[0] != "notifd": print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror) diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 8ad253294..f8fde3759 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -444,10 +444,10 @@ SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& param std::string command; // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer" if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI ) - command = BuildCommandToLaunchLocalContainer(resource_selected, params, machFile, container_exe); + command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe); // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer" else if(hostname == Kernel_Utils::GetHostname()) - command = BuildCommandToLaunchLocalContainer(resource_selected, params, machFile, container_exe); + command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe); // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer" else command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe); @@ -652,7 +652,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \ // SALOME_Container containerName &" - command = getCommandToRunProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName); + command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName); if (resInfo.AppliPath != "") command += resInfo.AppliPath; // path relative to user@machine $HOME @@ -722,7 +722,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer //============================================================================= std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer -(const std::string & resource_name, const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe) +(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe) { _TmpFileName = BuildTemporaryFileName(); std::string command; @@ -793,9 +793,6 @@ SALOME_ContainerManager::BuildCommandToLaunchLocalContainer } } - const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name); - o << getCommandToRunProcess(resInfo.Protocol); - if (isPythonContainer(params.container_name)) o << "SALOME_ContainerPy.py "; else @@ -1167,48 +1164,39 @@ std::set SALOME_ContainerManager::getpidofprogram(const std::string progr return thepids; } -std::string SALOME_ContainerManager::getCommandToRunProcess(AccessProtocolType protocol, - const std::string & hostname, - const std::string & username) +std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol, + const std::string & hostname, + const std::string & username) { - std::string hostRealName = hostname; - std::string localHostRealName = Kernel_Utils::GetHostname(); - bool isLocal = false; - if (hostname == "localhost" || hostname == localHostRealName) - { - isLocal = true; - hostRealName = localHostRealName; - } - std::ostringstream command; switch (protocol) { case rsh: - if (!isLocal) + command << "rsh "; + if (username != "") { - command << "rsh "; - if (username != "") - { - command << "-l " << username << " "; - } - command << hostRealName << " "; + command << "-l " << username << " "; } + command << hostname << " "; break; case ssh: - if (!isLocal) + command << "ssh "; + if (username != "") { - command << "ssh "; - if (username != "") - { - command << "-l " << username << " "; - } - command << hostRealName << " "; + command << "-l " << username << " "; } + command << hostname << " "; break; case srun: // no need to redefine the user with srun, the job user is taken by default // (note: for srun, user id can be specified with " --uid=") - command << "srun -n 1 -N 1 --share --nodelist=" << hostRealName << " "; + command << "srun -n 1 -N 1 --share --nodelist=" << hostname << " "; + break; + case pbsdsh: + command << "pbsdsh -o -h " << hostname << " "; + break; + case blaunch: + command << "blaunch " << hostname << " "; break; default: throw SALOME_Exception("Unknown protocol"); diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 3aa218c2a..ef5729d20 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -69,8 +69,7 @@ protected: const Engines::ContainerParameters& params, const std::string& container_exe="SALOME_Container"); - std::string BuildCommandToLaunchLocalContainer(const std::string & resource_name, - const Engines::ContainerParameters& params, + std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe="SALOME_Container"); @@ -93,9 +92,9 @@ protected: std::set getpidofprogram(const std::string program); - std::string getCommandToRunProcess(AccessProtocolType protocol, - const std::string & hostname = "localhost", - const std::string & username = ""); + std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, + const std::string & hostname, + const std::string & username); CORBA::ORB_var _orb; PortableServer::POA_var _poa; diff --git a/src/Launcher/Launcher_Job_SALOME.cxx b/src/Launcher/Launcher_Job_SALOME.cxx index b9005c2e6..f50f12da0 100644 --- a/src/Launcher/Launcher_Job_SALOME.cxx +++ b/src/Launcher/Launcher_Job_SALOME.cxx @@ -81,12 +81,7 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params) launch_script_stream << "export SALOME_TMP_DIR=" << work_directory << "/logs" << std::endl; // -- Generates Catalog Resources - std::string resource_protocol = "ssh"; - if (_resource_definition.ClusterInternalProtocol == rsh) - resource_protocol = "rsh"; - else if (_resource_definition.ClusterInternalProtocol == srun) - resource_protocol = "srun"; - + std::string resource_protocol = ParserResourcesType::protocolToString(_resource_definition.ClusterInternalProtocol); launch_script_stream << "if [ \"x$LIBBATCH_NODEFILE\" != \"x\" ]; then " << std::endl; launch_script_stream << "CATALOG_FILE=" << "CatalogResources_" << _launch_date << ".xml" << std::endl; launch_script_stream << "export USER_CATALOG_RESOURCES_FILE=" << "$CATALOG_FILE" << std::endl; @@ -111,12 +106,7 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params) launch_script_stream << "NS_PORT_FILE_NAME=`basename $NS_PORT_FILE_PATH` &&\n"; // Launch SALOME with an appli - launch_script_stream << _resource_definition.AppliPath << "/runAppli --terminal --ns-port-log=$NS_PORT_FILE_NAME "; - if (_resource_definition.ClusterInternalProtocol != rsh && - _resource_definition.ClusterInternalProtocol != ssh) - { - launch_script_stream << "--server-launch-cmd=" << resource_protocol << " "; - } + launch_script_stream << _resource_definition.AppliPath << "/runAppli --terminal --ns-port-log=$NS_PORT_FILE_NAME --server-launch-mode=fork "; launch_script_stream << "> logs/salome_" << _launch_date << ".log 2>&1 &&" << std::endl; launch_script_stream << "current=0 &&\n" << "stop=20 &&\n" diff --git a/src/Launcher/Makefile.am b/src/Launcher/Makefile.am index fdf3ce7d3..cf702075b 100644 --- a/src/Launcher/Makefile.am +++ b/src/Launcher/Makefile.am @@ -184,4 +184,9 @@ if WITH_LIBBATCH TestLauncher_CPPFLAGS += -DWITH_LIBBATCH endif -TestLauncher_LDADD = @LIBXML_LIBS@ ../ResourcesManager/libResourcesManager.la libLauncher.la @LIBBATCH_LIBS@ +TestLauncher_LDADD = \ + @LIBXML_LIBS@ \ + ../ResourcesManager/libResourcesManager.la \ + libLauncher.la \ + ../Utils/libOpUtil.la \ + @LIBBATCH_LIBS@ diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx index 54efedf58..d4faed75c 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -28,6 +28,7 @@ // #include "SALOME_ResourcesCatalog_Handler.hxx" #include "Basics_Utils.hxx" +#include "Utils_SALOME_Exception.hxx" #include #include #include @@ -304,21 +305,15 @@ SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserRe if (xmlHasProp(member_descr, (const xmlChar*)test_protocol)) { xmlChar* protocol= xmlGetProp(member_descr, (const xmlChar*)test_protocol); - switch (protocol[0]) + try { - case 'r': - resource.Protocol = rsh; - break; - case 's': - if (protocol[1] == 's') - resource.Protocol = ssh; - else - resource.Protocol = srun; - break; - default: - std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl; - std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl; - return false; + resource.Protocol = ParserResourcesType::stringToProtocol((const char *)protocol); + } + catch (SALOME_Exception e) + { + std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl; + std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl; + return false; } xmlFree(protocol); } @@ -332,21 +327,15 @@ SALOME_ResourcesCatalog_Handler::ProcessMember(xmlNodePtr member_descr, ParserRe if (xmlHasProp(member_descr, (const xmlChar*)test_cluster_internal_protocol)) { xmlChar* iprotocol= xmlGetProp(member_descr, (const xmlChar*)test_cluster_internal_protocol); - switch (iprotocol[0]) + try { - case 'r': - resource.ClusterInternalProtocol = rsh; - break; - case 's': - if (iprotocol[1] == 's') - resource.ClusterInternalProtocol = ssh; - else - resource.ClusterInternalProtocol = srun; - break; - default: - std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl; - std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl; - return false; + resource.ClusterInternalProtocol = ParserResourcesType::stringToProtocol((const char *)iprotocol); + } + catch (SALOME_Exception e) + { + std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning found a machine with a bad protocol" << std::endl; + std::cerr << "SALOME_ResourcesCatalog_Handler::ProcessMember : Warning this machine will not be added" << std::endl; + return false; } xmlFree(iprotocol); } @@ -462,21 +451,14 @@ SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, Parser if (xmlHasProp(machine_descr, (const xmlChar*)test_protocol)) { xmlChar* protocol= xmlGetProp(machine_descr, (const xmlChar*)test_protocol); - switch ( protocol[0]) + try { - case 'r': - resource.Protocol = rsh; - break; - case 's': - if (protocol[1] == 's') - resource.Protocol = ssh; - else - resource.Protocol = srun; - break; - default: - // If it'not in all theses cases, the protocol is affected to rsh - resource.Protocol = rsh; - break; + resource.Protocol = ParserResourcesType::stringToProtocol((const char *)protocol); + } + catch (SALOME_Exception e) + { + // If it'not in all theses cases, the protocol is affected to rsh + resource.Protocol = rsh; } xmlFree(protocol); } @@ -486,21 +468,14 @@ SALOME_ResourcesCatalog_Handler::ProcessMachine(xmlNodePtr machine_descr, Parser if (xmlHasProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol)) { xmlChar* iprotocol= xmlGetProp(machine_descr, (const xmlChar*)test_cluster_internal_protocol); - switch ( iprotocol[0]) + try { - case 'r': - resource.ClusterInternalProtocol = rsh; - break; - case 's': - if (iprotocol[1] == 's') - resource.ClusterInternalProtocol = ssh; - else - resource.ClusterInternalProtocol = srun; - break; - default: - // If it'not in all theses cases, the protocol is affected to rsh - resource.ClusterInternalProtocol = rsh; - break; + resource.ClusterInternalProtocol = ParserResourcesType::stringToProtocol((const char *)iprotocol); + } + catch (SALOME_Exception e) + { + // If it'not in all theses cases, the protocol is affected to rsh + resource.ClusterInternalProtocol = rsh; } xmlFree(iprotocol); } @@ -691,36 +666,12 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc) xmlNewProp(node, BAD_CAST test_appli_path, BAD_CAST (*iter).second.AppliPath.c_str()); xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str()); xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str()); - - switch ((*iter).second.Protocol) - { - case rsh: - xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh"); - break; - case ssh: - xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "ssh"); - break; - case srun: - xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "srun"); - break; - default: - xmlNewProp(node, BAD_CAST test_protocol, BAD_CAST "rsh"); - } - - switch ((*iter).second.ClusterInternalProtocol) - { - case rsh: - xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh"); - break; - case ssh: - xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "ssh"); - break; - case srun: - xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "srun"); - break; - default: - xmlNewProp(node, BAD_CAST test_cluster_internal_protocol, BAD_CAST "rsh"); - } + xmlNewProp(node, + BAD_CAST test_protocol, + BAD_CAST ParserResourcesType::protocolToString((*iter).second.Protocol).c_str()); + xmlNewProp(node, + BAD_CAST test_cluster_internal_protocol, + BAD_CAST ParserResourcesType::protocolToString((*iter).second.ClusterInternalProtocol).c_str()); switch ((*iter).second.Mode) { diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx index 31d99920f..0dd68beac 100644 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx @@ -21,6 +21,7 @@ // #include "SALOME_ResourcesCatalog_Parser.hxx" +#include "Utils_SALOME_Exception.hxx" #include #include @@ -128,6 +129,42 @@ void ResourceDataToSort::Print() const std::cout << _memInMB << std::endl; } + +std::string ParserResourcesType::protocolToString(AccessProtocolType protocol) +{ + switch (protocol) + { + case rsh: + return "rsh"; + case ssh: + return "ssh"; + case srun: + return "srun"; + case pbsdsh: + return "pbsdsh"; + case blaunch: + return "blaunch"; + default: + throw SALOME_Exception("Unknown protocol"); + } +} + +AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr) +{ + if (protocolStr == "rsh") + return rsh; + else if (protocolStr == "ssh") + return ssh; + else if (protocolStr == "srun") + return srun; + else if (protocolStr == "pbsdsh") + return pbsdsh; + else if (protocolStr == "blaunch") + return blaunch; + else + throw SALOME_Exception("Unknown protocol"); +} + void ParserResourcesType::Print() { std::ostringstream oss; @@ -138,8 +175,8 @@ void ParserResourcesType::Print() "NbOfProcPerNode : " << DataForSort._nbOfProcPerNode << std::endl << "CPUFreqMHz : " << DataForSort._CPUFreqMHz << std::endl << "MemInMB : " << DataForSort._memInMB << std::endl << - "Protocol : " << Protocol << std::endl << - "ClusterInternalProtocol : " << ClusterInternalProtocol << std::endl << + "Protocol : " << protocolToString(Protocol) << std::endl << + "ClusterInternalProtocol : " << protocolToString(ClusterInternalProtocol) << std::endl << "Mode : " << Mode << std::endl << "Batch : " << Batch << std::endl << "mpi : " << mpi << std::endl << @@ -170,23 +207,13 @@ void ParserResourcesType::Print() std::string ParserResourcesType::PrintAccessProtocolType() const { - if (Protocol == rsh) - return "rsh"; - else if (Protocol == srun) - return "srun"; - else - return "ssh"; + return protocolToString(Protocol); } std::string ParserResourcesType::PrintClusterInternalProtocol() const { - if (ClusterInternalProtocol == rsh) - return "rsh"; - else if (ClusterInternalProtocol == srun) - return "srun"; - else - return "ssh"; + return protocolToString(ClusterInternalProtocol); } std::string diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx index 39b732dca..cb6fb79e6 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx @@ -41,7 +41,7 @@ #pragma warning(disable:4251) // Warning DLL Interface ... #endif -enum AccessProtocolType {rsh, ssh, srun}; +enum AccessProtocolType {rsh, ssh, srun, pbsdsh, blaunch}; enum AccessModeType {interactive, batch}; @@ -112,6 +112,9 @@ struct RESOURCESMANAGER_EXPORT ParserResourcesType void Print(); void Clear(); + static std::string protocolToString(AccessProtocolType protocol); + static AccessProtocolType stringToProtocol(const std::string & protocolStr); + std::string PrintAccessProtocolType() const; std::string PrintAccessModeType() const; std::string PrintBatchType() const; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 3d0b9f48f..0a4e5598a 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -214,18 +214,8 @@ SALOME_ResourcesManager::GetResourceDefinition(const char * name) p_ptr->name = CORBA::string_dup(resource.Name.c_str()); p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str()); - if( resource.Protocol == rsh ) - p_ptr->protocol = "rsh"; - else if( resource.Protocol == ssh ) - p_ptr->protocol = "ssh"; - else if( resource.Protocol == srun ) - p_ptr->protocol = "srun"; - if( resource.ClusterInternalProtocol == rsh ) - p_ptr->iprotocol = "rsh"; - else if( resource.ClusterInternalProtocol == ssh ) - p_ptr->iprotocol = "ssh"; - else if( resource.ClusterInternalProtocol == srun ) - p_ptr->iprotocol = "srun"; + p_ptr->protocol = ParserResourcesType::protocolToString(resource.Protocol).c_str(); + p_ptr->iprotocol = ParserResourcesType::protocolToString(resource.ClusterInternalProtocol).c_str(); p_ptr->username = CORBA::string_dup(resource.UserName.c_str()); p_ptr->applipath = CORBA::string_dup(resource.AppliPath.c_str()); p_ptr->componentList.length(resource.ComponentsList.size()); @@ -345,15 +335,12 @@ SALOME_ResourcesManager::AddResource(const Engines::ResourceDefinition& new_reso } std::string protocol = new_resource.protocol.in(); - if (protocol == "rsh") - resource.Protocol = rsh; - else if (protocol == "ssh") - resource.Protocol = ssh; - else if (protocol == "srun") - resource.Protocol = srun; - else if (protocol == "") - resource.Protocol = rsh; - else { + try + { + resource.Protocol = ParserResourcesType::stringToProtocol(protocol); + } + catch (SALOME_Exception e) + { INFOS("Bad protocol definition in AddResource: " << protocol); std::string message("Bad protocol definition in AddResource: "); message += protocol; @@ -361,15 +348,12 @@ SALOME_ResourcesManager::AddResource(const Engines::ResourceDefinition& new_reso } std::string iprotocol = new_resource.iprotocol.in(); - if (iprotocol == "rsh") - resource.ClusterInternalProtocol = rsh; - else if (iprotocol == "ssh") - resource.ClusterInternalProtocol = ssh; - else if (iprotocol == "srun") - resource.ClusterInternalProtocol = srun; - else if (iprotocol == "") - resource.ClusterInternalProtocol = rsh; - else { + try + { + resource.ClusterInternalProtocol = ParserResourcesType::stringToProtocol(iprotocol); + } + catch (SALOME_Exception e) + { INFOS("Bad iprotocol definition in AddResource: " << iprotocol); std::string message("Bad iprotocol definition in AddResource: "); message += iprotocol; -- 2.39.2