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="<server_launch_cmd>",
- type="string",
+ # server launch mode
+ help_str = "Mode used to launch server processes (daemon or fork)."
+ o_slm = optparse.Option("--server-launch-mode",
+ metavar="<server_launch_mode>",
+ type="choice",
+ choices=["daemon","fork"],
action="store",
- dest="server_launch_cmd",
+ dest="server_launch_mode",
help=help_str)
# All options
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",
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)
#
# 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
class Server:
"""Generic class for CORBA server launch"""
- server_launch_args = []
+ server_launch_mode = "daemon"
def initArgs(self):
self.PID=None
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
#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
#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)
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);
// "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
//=============================================================================
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;
}
}
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
- o << getCommandToRunProcess(resInfo.Protocol);
-
if (isPythonContainer(params.container_name))
o << "SALOME_ContainerPy.py ";
else
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=<user>")
- 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");
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");
std::set<pid_t> 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;
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;
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"
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@
//
#include "SALOME_ResourcesCatalog_Handler.hxx"
#include "Basics_Utils.hxx"
+#include "Utils_SALOME_Exception.hxx"
#include <iostream>
#include <sstream>
#include <map>
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);
}
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);
}
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);
}
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);
}
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)
{
//
#include "SALOME_ResourcesCatalog_Parser.hxx"
+#include "Utils_SALOME_Exception.hxx"
#include <iostream>
#include <sstream>
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;
"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 <<
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
#pragma warning(disable:4251) // Warning DLL Interface ...
#endif
-enum AccessProtocolType {rsh, ssh, srun};
+enum AccessProtocolType {rsh, ssh, srun, pbsdsh, blaunch};
enum AccessModeType {interactive, batch};
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;
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());
}
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;
}
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;