SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& resource_name, const Engines::ContainerParameters& params, const std::string& container_exe) const
{
std::string command,tmpFileName;
+ const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
+ std::string wdir = params.workingdir.in();
if (!_isAppliSalomeDefined)
- command = BuildTempFileToLaunchRemoteContainer(resource_name, params, tmpFileName);
+ {
+ command = getCommandToRunRemoteProcessNoAppli(resInfo.Protocol, resInfo.HostName,
+ resInfo.UserName, resInfo.AppliPath,
+ wdir);
+ }
else
{
- const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
-
- std::string wdir = params.workingdir.in();
-
// "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
// SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
// or
command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
resInfo.UserName, resInfo.AppliPath,
wdir);
-
- if(params.isMPI)
- {
- int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
- command += " mpirun -np ";
- std::ostringstream o;
- o << nbproc << " ";
- command += o.str();
+ }
+ if(params.isMPI)
+ {
+ int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
+ command += " mpirun -np ";
+ std::ostringstream o;
+ o << nbproc << " ";
+ command += o.str();
#ifdef LAM_MPI
- command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
+ command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
#elif defined(OPEN_MPI)
- if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
- command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
- else{
- command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
- command += GetenvThreadSafeAsString("OMPI_URI_FILE");
- }
+ if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
+ command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
+ else{
+ command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
+ command += GetenvThreadSafeAsString("OMPI_URI_FILE");
+ }
#elif defined(MPICH)
- command += "-nameserver " + Kernel_Utils::GetHostname();
+ command += "-nameserver " + Kernel_Utils::GetHostname();
#endif
- command += " SALOME_MPIContainer ";
- }
- else
- command += " " +container_exe+ " ";
+ command += " SALOME_MPIContainer ";
+ }
+ else
+ command += " " +container_exe+ " ";
- command += _NS->ContainerName(params) + " ";
- if(this->_isSSL)
- {
- Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
- CORBA::String_var iorNS = _orb->object_to_string(ns);
- command += std::string(iorNS);
- }
- else //if(!this->_isSSL)
- {
- command += " -";
- AddOmninamesParams(command);
- }
- MESSAGE("command =" << command);
+ command += _NS->ContainerName(params) + " ";
+ if(this->_isSSL)
+ {
+ Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+ CORBA::String_var iorNS = _orb->object_to_string(ns);
+ command += std::string(iorNS);
+ }
+ else //if(!this->_isSSL)
+ {
+ command += " -";
+ AddOmninamesParams(command);
}
+ MESSAGE("command =" << command);
return command;
}
}
-std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
+std::string SALOME_ContainerManager::getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
+{
+ return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE","salome shell --",protocol,hostname,username,applipath,workdir);
+}
+
+std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
+{
+ return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE_OLD",this->GetRunRemoteExecutableScript(),protocol,hostname,username,applipath,workdir);
+}
+
+std::string SALOME_ContainerManager::getCommandToRunRemoteProcessCommon(const std::string& templateName,
+ const std::string& remoteScript,
+ AccessProtocolType protocol,
const std::string & hostname,
const std::string & username,
const std::string & applipath,
script_parameters.push(nsport.empty() ? "NULL" : nsport);
// ===== Remote script (key = "remote_script")
- std::string remoteScript = this->GetRunRemoteExecutableScript();
script_parameters.push(remoteScript.empty() ? "NONE" : remoteScript);
// ===== Naming service (key = "naming_service")
// we prepare the remote command according to the case
script_parameters.push(appli_mode);
- command << GetCommandFromTemplate("SALOME_CM_REMOTE", script_parameters);
-
- /* //====================================================================================
- bool envd = true; // source the environment
- switch (protocol)
- {
- case rsh:
- command << "rsh ";
- if (username != "")
- {
- command << "-l " << username << " ";
- }
- command << hostname << " ";
- break;
- case ssh:
- command << "ssh ";
- if (username != "")
- {
- 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 -s --mem-per-cpu=0 --cpu-bind=none --nodelist=" << hostname << " ";
- envd = false;
- break;
- case pbsdsh:
- command << "pbsdsh -o -h " << hostname << " ";
- break;
- case blaunch:
- command << "blaunch -no-shell " << hostname << " ";
- break;
- default:
- throw SALOME_Exception("Unknown protocol");
- }
-
- std::string remoteapplipath;
- if (applipath=="")
- remoteapplipath = GetenvThreadSafeAsString("APPLI");
- else
- remoteapplipath = applipath;
-
- if(!this->_isSSL)
- {
- 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" ;
- if(!this->_isSSL)
- {
- command << " -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 << "/" << this->GetRunRemoteExecutableScript() << " ";
- if (!envd)
- command << "--noenvd ";
-
- if(this->_isSSL)
- {
- Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
- CORBA::String_var iorNS = _orb->object_to_string(ns);
- command << iorNS;
- }
- else
- {
- 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 << "'";
- }
- }
- //==================================================================================== */
+ command << GetCommandFromTemplate(templateName, script_parameters);
return command.str();
}
--- /dev/null
+import sys
+
+class ScriptRemoteParameters:
+ def __init__(self, args):
+ self.debug = False
+ if args[0] == "-d":
+ self.debug = True
+ args = args[1:]
+
+ self.protocol = args[0]
+ self.user = self._read_arg(args[1], "NULL")
+ self.host = self._read_arg(args[2], "NULL")
+ self.appli = self._read_arg(args[3], "NULL")
+ self.workdir = self._read_arg(args[4], "NULL")
+ self.ssl = True if args[5] == "1" else False
+ self.nshost = args[6]
+ self.nsport = args[7]
+ self.remote_script = self._read_arg(args[8], "NULL")
+ self.naming_service = self._read_arg(args[9], "NULL")
+ self.appli_mode = args[10]
+
+ import platform
+ self.Windows = platform.system() == "Windows"
+
+ def _read_arg(self, value, null_value):
+ if value == null_value:
+ return None
+ return value
+
+ def __str__(self):
+ str = []
+ str.append("protocol: %s" % self.protocol)
+ str.append("user: %s" % self.user)
+ str.append("hostname: %s" % self.host)
+ str.append("appli: %s" % self.appli)
+ str.append("workdir: %s" % self.workdir)
+ str.append("ssl: %s" % self.ssl)
+ str.append("nshost: %s" % self.nshost)
+ str.append("nsport: %s" % self.nsport)
+ str.append("remote_script: %s" % self.remote_script)
+ str.append("naming_service: %s" % self.naming_service)
+ str.append("appil_mode: %s" % self.appli_mode)
+ str.append("--")
+ return "\n".join(str)
+
+# ----------------------------------------------
+def command(args):
+ options = ScriptRemoteParameters(args)
+ if options.debug: print(options)
+
+ # build command depending on protocol
+ cmd = []
+ envd = (options.protocol != "srun")
+
+ if options.protocol == "rsh":
+ # RSH command
+ cmd.append("rsh")
+ if options.user:
+ cmd.append("-l " + options.user)
+ cmd.append(options.host)
+
+ elif options.protocol == "ssh":
+ # SSH command
+ cmd.append("ssh")
+ if options.user:
+ cmd.append("-l " + options.user)
+ cmd.append(options.host)
+
+ elif options.protocol == "srun":
+ # srun command
+ cmd.append("srun")
+ cmd.append("-n 1 -N 1 -s --mem-per-cpu=0 --cpu-bind=none")
+ cmd.append("--nodelist=" + options.host)
+
+ elif options.protocol == "pbsdsh":
+ # pbsdh command
+ cmd.append("pbsdsh")
+ cmd.append("-o -h")
+ cmd.append(options.host)
+
+ elif options.protocol == "blaunch":
+ # blaunch command
+ cmd.append("blaunch")
+ cmd.append("-no-shell")
+ cmd.append(options.host)
+
+ else:
+ # unknown protocol
+ raise ValueError("Unknown protocol: %s" % options.protocol)
+
+
+ if options.appli_mode == "dir":
+ cmd.append(options.appli + "/" + options.remote_script)
+ if not envd:
+ cmd.append("--noenvd")
+ if options.ssl:
+ cmd.append(options.naming_service)
+ else:
+ cmd.append(options.nshost)
+ cmd.append(options.nsport)
+
+ if options.workdir:
+ cmd.append(" WORKINGDIR '%s'" % options.workdir)
+
+ elif options.appli_mode == "launcher":
+ cmd.append(options.appli + " remote")
+ if not options.ssl:
+ cmd.append("-m %s -p %s" % (options.nshost, options.nsport))
+
+ if options.workdir:
+ cmd.append("-d " + options.workdir)
+ cmd.append("--")
+
+ # elif ignore other appli_mode value
+
+ return " ".join(cmd)
\ No newline at end of file