using namespace std;
-//----------------------------------------------------------------------
-//Function : SALOME_ResourcesCatalog_Handler
-//Purpose: Constructor
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Constructor
+ * \param listOfResources: map of ParserResourcesType to fill when parsing
+ */
+//=============================================================================
+
SALOME_ResourcesCatalog_Handler::
SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):
_resources_list(listOfResources)
test_protocol = "protocol";
test_mode = "mode";
test_user_name = "userName";
+ test_appli_path = "appliPath";
test_modules = "modules";
test_module_name = "moduleName";
test_module_path = "modulePath";
test_nb_of_proc_per_node = "nbOfProcPerNode";
}
-//----------------------------------------------------------------------
-//Function : ~SALOME_ResourcesCatalog_Handler
-//Purpose: Destructor
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Destructor
+ */
+//=============================================================================
+
SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
{
MESSAGE("SALOME_ResourcesCatalog_Handler destruction");
}
-//----------------------------------------------------------------------
-//Function : GetResourcesAfterParsing
-//Purpose: Retrieves DS after the file parse.
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Retrieves DS after the file parse.
+ */
+//=============================================================================
+
const MapOfParserResourcesType&
SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
{
return _resources_list;
}
-//----------------------------------------------------------------------
-//Function : startDocument
-//Purpose: overload handler function
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Overload handler function startDocument.
+ * Called before an xml file is parsed.
+ * Clears the list of resources.
+ * \return true (if no error detected...)
+ */
+//=============================================================================
+
bool SALOME_ResourcesCatalog_Handler::startDocument()
{
MESSAGE("Begin parse document");
- // Empty private elements
+
+ // --- Empty private elements
+
_resources_list.clear();
return true;
}
-//----------------------------------------------------------------------
-//Function : startElement
-//Purpose: overload handler function
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Overload handler function startElement.
+ * \param QString argument by reference (not used here ?)
+ * \param QString argument by reference (not used here ?)
+ * \param name (not used here ?)
+ * \param atts
+ * \return true if no error was detected
+ */
+//=============================================================================
+
bool
SALOME_ResourcesCatalog_Handler::
startElement( const QString&,
if ((qName.compare(QString(test_user_name)) == 0))
_resource.UserName = content;
+ if ((qName.compare(QString(test_appli_path)) == 0))
+ _resource.AppliPath = content;
+
if ((qName.compare(QString(test_module_name)) == 0))
previous_module_name = content;
return true;
}
-//----------------------------------------------------------------------
-//Function : endElement
-//Purpose: overload handler function
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Overload handler function endElement.
+ * \param QString argument by reference (not used here ?)
+ * \param QString argument by reference (not used here ?)
+ * \param qName
+ * \return true (if no error detected ...)
+ */
+//=============================================================================
+
bool SALOME_ResourcesCatalog_Handler::
endElement(const QString&,
const QString&,
return true;
}
-//----------------------------------------------------------------------
-//Function : characters
-//Purpose: overload handler function
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Overload handler function characters.
+ * fills the private attribute string 'content'.
+ * \param chars
+ * \return true (if no error detected ...)
+ */
+//=============================================================================
+
bool SALOME_ResourcesCatalog_Handler::characters(const QString& chars)
{
content = (const char *)chars ;
return true;
}
-//----------------------------------------------------------------------
-//Function : endDocument
-//Purpose: overload handler function
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Overload handler function endDocument.
+ * Called after the document has been parsed.
+ * \return true (if no error detected ...)
+ */
+//=============================================================================
+
bool SALOME_ResourcesCatalog_Handler::endDocument()
{
- //_resources_list
- // for (unsigned int ind = 0; ind < _resources_list.size(); ind++)
- // {
- // MESSAGE("Resources name :"<<_resources_list[ind].Parsername);
- // MESSAGE("OS :"<<_resources_list[ind].ParserOS);
- // MESSAGE("OS version :"<<_resources_list[ind].ParserOS_version);
- // for (unsigned int i = 0; i < _resources_list[ind].Parserprocs.size(); i++)
- // {
- // MESSAGE("Proc number :" << _resources_list[ind].Parserprocs[i].Parsernumber);
- // MESSAGE("Model name :" << _resources_list[ind].Parserprocs[i].Parsermodel_name);
- // MESSAGE("CPU(MHz) :" << _resources_list[ind].Parserprocs[i].Parsercpu_mhz);
- // MESSAGE("Cache :" << _resources_list[ind].Parserprocs[i].Parsercache_size);
- // }
- // for (unsigned int j = 0; j < _resources_list[ind].Parsercontainertype.size(); j++)
- // MESSAGE("Container Type :" << _resources_list[ind].Parsercontainertype[j]);
- // }
+ for (map<string, ParserResourcesType>::const_iterator iter =
+ _resources_list.begin();
+ iter != _resources_list.end();
+ iter++)
+ {
+ SCRUTE((*iter).second.Alias);
+ SCRUTE((*iter).second.UserName);
+ SCRUTE((*iter).second.AppliPath);
+ SCRUTE((*iter).second.PreReqFilePath);
+ SCRUTE((*iter).second.OS);
+ SCRUTE((*iter).second.Protocol);
+ SCRUTE((*iter).second.Mode);
+ }
+
MESSAGE("This is the end of document");
return true;
}
-//----------------------------------------------------------------------
-//Function : errorProtocol
-//Purpose: overload handler function
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Overload handler function errorProtocol.
+ * \return the error message.
+ */
+//=============================================================================
+
QString SALOME_ResourcesCatalog_Handler::errorProtocol()
{
- INFOS(" ------------- error protocole !");
+ INFOS(" ------------- error protocol !");
return errorProt;
}
-//----------------------------------------------------------------------
-//Function : fatalError
-//Purpose: overload handler function
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Overload handler function fatalError.
+ * Fills the private string errorProt with details on error.
+ * \param exception from parser
+ * \return boolean (meaning ?)
+ */
+//=============================================================================
+
bool
SALOME_ResourcesCatalog_Handler::fatalError
(const QXmlParseException& exception)
return QXmlDefaultHandler::fatalError( exception );
}
-//----------------------------------------------------------------------
-//Function : FillDocument
-//Purpose: Fill the document tree in xml file, used to write in xml file.
-//----------------------------------------------------------------------
+//=============================================================================
+/*!
+ * Fill the document tree in xml file, used to write in an xml file.
+ * \param doc document to fill.
+ */
+//=============================================================================
+
void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(QDomDocument& doc)
{
QDomElement root = doc.createElement("resources");
SALOME_ResourcesManager::
SALOME_ResourcesManager(CORBA::ORB_ptr orb,
- const char *xmlFilePath) :
- _path_resources(xmlFilePath)
+ const char *xmlFilePath) :
+ _path_resources(xmlFilePath)
{
_NS = new SALOME_NamingService(orb);
}
SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb)
{
_NS = new SALOME_NamingService(orb);
- // _path_resources=getenv("KERNEL_ROOT_DIR");
- // _path_resources+="/share/salome/resources/CatalogResources.xml";
- _path_resources = getenv("HOME");
- _path_resources += "/";
- _path_resources += getenv("APPLI");
- _path_resources += "/CatalogResources.xml";
+ _isAppliSalomeDefined = (getenv("APPLI") != 0);
+
+ if (_isAppliSalomeDefined)
+ {
+ _path_resources = getenv("HOME");
+ _path_resources += "/";
+ _path_resources += getenv("APPLI");
+ _path_resources += "/CatalogResources.xml";
+ }
+
+ else
+ {
+ _path_resources = getenv("KERNEL_ROOT_DIR");
+ _path_resources += "/share/salome/resources/CatalogResources.xml";
+ }
+
ParseXmlFile();
}
* - then select the sublist of machines on witch the module is known
* (if the result is empty, that probably means that the inventory of
* modules is probably not done, so give complete list from previous step)
- *
*/
//=============================================================================
else if (_resourcesList.find(hostname) != _resourcesList.end())
{
- // --- params.hostame is in the list of resources so return it.
+ // --- params.hostname is in the list of resources so return it.
ret.push_back(hostname);
}
SelectOnlyResourcesWithOS(ret, params.OS);
KeepOnlyResourcesWithModule(ret, moduleName);
+
if (ret.size() == 0)
- SelectOnlyResourcesWithOS(ret, params.OS);
+ SelectOnlyResourcesWithOS(ret, params.OS);
// --- set wanted parameters
ResourceDataToSort::_nbOfNodesWanted = params.nb_node;
+
ResourceDataToSort::_nbOfProcPerNodeWanted = params.nb_proc_per_node;
+
ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock;
+
ResourceDataToSort::_memInMBWanted = params.mem_mb;
+
// --- end of set
list<ResourceDataToSort> li;
//=============================================================================
/*!
* add an entry in the ressources catalog xml file.
- * Return 1 if OK.
- * Return 0 if the ressource with the same hostname already exists.
- *
+ * Return 0 if OK (KERNEL found in new resources modules) else throw exception
*/
//=============================================================================
throw SALOME_Exception("KERNEL is not present in this resource");
}
-
//=============================================================================
/*!
* Deletes a resource from the catalog
_resourcesList.erase(hostname);
}
-
//=============================================================================
/*!
* write the current data in memory in file.
new SALOME_ResourcesCatalog_Handler(_resourcesList);
handler->PrepareDocToXmlFile(doc);
delete handler;
+
QFile file( _path_resources );
if ( !file.open( IO_WriteOnly ) )
- cout << "WRITING ERROR !!!" << endl;
+ INFOS("WRITING ERROR !");
QTextStream ts( &file );
file.close();
- cout << "WRITING DONE!!!" << endl;
+ MESSAGE("WRITING DONE!");
}
-
//=============================================================================
/*!
* parse the data type catalog
return _resourcesList;
}
-//=============================================================================
-/*!
- * verify ressources catalog content - return true if verfication is OK
- */
-//=============================================================================
-
-
-bool
-SALOME_ResourcesManager::_verify_resources
-(MapOfParserResourcesType resourceslist)
-{
- // bool _return_value = true;
- // bool _bool = false ;
- // vector<string> _machine_list;
- // _machine_list.resize(0);
-
- // // Fill a list of all computers indicated in the resources list
- // for (unsigned int ind = 0; ind < resourceslist.size(); ind++)
- // _machine_list.push_back(resourceslist[ind].HostName);
-
- // // Parse if a computer name is twice in the list of computers
- // for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
- // {
- // for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
- // {
- // if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
- // {
- // MESSAGE("The computer " << _machine_list[ind] << " is indicated more than once in the resources list")
- // _return_value = false;
- // }
- // }
- // }
-
- // return _return_value;
- return true;
-}
-
-
//=============================================================================
/*!
* consult the content of the list
//=============================================================================
/*!
- * builds in a temporary file the script to be launched
+ * Builds the script to be launched
+ *
+ * If SALOME Application not defined ($APPLI),
+ * see BuildTempFileToLaunchRemoteContainer()
+ *
+ * Else rely on distant configuration. Command is under the form (example):
+ * ssh user@machine distantPath/runRemote.sh hostNS portNS \
+ * SALOME_Container containerName &"
+
+ * - where user is ommited if not specified in CatalogResources,
+ * - where distant path is always relative to user@machine $HOME, and
+ * equal to $APPLI if not specified in CatalogResources,
+ * - where hostNS is the hostname of CORBA naming server (set by scripts to
+ * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
+ * - where portNS is the port used by CORBA naming server (set by scripts to
+ * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
*/
//=============================================================================
string
-SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer
+SALOME_ResourcesManager::BuildCommandToLaunchRemoteContainer
(const string& machine,
const Engines::MachineParameters& params)
{
- // _TmpFileName=BuildTemporaryFileName();
- // ofstream tempOutputFile;
- // tempOutputFile.open(_TmpFileName.c_str(),ofstream::out );
-
- const ParserResourcesType& resInfo=_resourcesList[machine];
-
- // tempOutputFile << "#! /bin/sh" << endl;
- // //set env vars
- // for(map<string,string>::const_iterator iter =
- // resInfo.ModulesPath.begin();iter!=resInfo.ModulesPath.end();iter++)
- // {
- // string curModulePath((*iter).second);
- // tempOutputFile << (*iter).first << "_ROOT_DIR="<< curModulePath << endl;
- // tempOutputFile << "export " << (*iter).first << "_ROOT_DIR" << endl;
- // tempOutputFile << "LD_LIBRARY_PATH=" << curModulePath << "/lib/salome" << ":${LD_LIBRARY_PATH}" << endl;
- // tempOutputFile << "PYTHONPATH=" << curModulePath << "/bin/salome:" << curModulePath << "/lib/salome:" << curModulePath << "/lib/python2.2/site-packages/salome:";
- // tempOutputFile << curModulePath << "/lib/python2.2/site-packages/salome/shared_modules:${PYTHONPATH}" << endl;
- // }
- // tempOutputFile << "export LD_LIBRARY_PATH" << endl;
- // tempOutputFile << "export PYTHONPATH" << endl;
- // tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
- // // ! env vars
-
- if (params.isMPI)
- {
- // tempOutputFile << "mpirun -np ";
- int nbproc;
-
- if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
- nbproc = 1;
- else if ( params.nb_node == 0 )
- nbproc = params.nb_proc_per_node;
- else if ( params.nb_proc_per_node == 0 )
- nbproc = params.nb_node;
- else
- nbproc = params.nb_node * params.nb_proc_per_node;
-
- // std::ostringstream o;
- // tempOutputFile << nbproc << " ";
- }
-
- // tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second << "/bin/salome/";
- // if(params.isMPI){
- // if(isPythonContainer(params.container_name))
- // tempOutputFile << "pyMPI SALOME_ContainerPy.py ";
- // else
- // tempOutputFile << "SALOME_MPIContainer ";
- // }
- // else{
- // if(isPythonContainer(params.container_name))
- // tempOutputFile << "SALOME_ContainerPy.py ";
- // else
- // tempOutputFile << "SALOME_Container ";
- // }
- // tempOutputFile << _NS->ContainerName(params) << " -";
- // AddOmninamesParams(tempOutputFile);
- // tempOutputFile << " &" << endl;
- // tempOutputFile.flush();
- // tempOutputFile.close();
- // chmod(_TmpFileName.c_str(),0x1ED);
- //Build command
string command;
- if (resInfo.Protocol == rsh)
- {
- command = "rsh ";
- // string commandRcp="rcp ";
- // commandRcp+=_TmpFileName;
- // commandRcp+=" ";
- // commandRcp+=machine;
- // commandRcp+=":";
- // commandRcp+=_TmpFileName;
- // system(commandRcp.c_str());
- }
+ if ( ! _isAppliSalomeDefined )
+ command = BuildTempFileToLaunchRemoteContainer(machine, params);
- else if (resInfo.Protocol == ssh)
- command = "ssh ";
else
- throw SALOME_Exception("Unknown protocol");
+ {
+ const ParserResourcesType& resInfo = _resourcesList[machine];
- // command+=machine;
- // _CommandForRemAccess=command;
- // command+=" ";
- // command+=_TmpFileName;
- // command += " > ";
- // command += "/tmp/";
- // command += _NS->ContainerName(params);
- // command += "_";
- // command += machine;
- // command += ".log 2>&1 &";
- // cout << "Command is ... " << command << endl;
+ if (params.isMPI)
+ {
+ int nbproc;
+
+ if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
+ nbproc = 1;
+ else if ( params.nb_node == 0 )
+ nbproc = params.nb_proc_per_node;
+ else if ( params.nb_proc_per_node == 0 )
+ nbproc = params.nb_node;
+ else
+ nbproc = params.nb_node * params.nb_proc_per_node;
+ }
- command += machine; // on suppose le même user par defaut
+ // "ssh user@machine distantPath/runRemote.sh hostNS portNS \
+ // SALOME_Container containerName &"
- command += " ";
+ if (resInfo.Protocol == rsh)
+ command = "rsh ";
+ else if (resInfo.Protocol == ssh)
+ command = "ssh ";
+ else
+ throw SALOME_Exception("Unknown protocol");
- command += getenv("APPLI"); // chemin relatif a $HOME
+ if (resInfo.UserName != "")
+ {
+ command += resInfo.UserName;
+ command += "@";
+ }
- command += "/runRemote.sh ";
+ command += machine;
+ command += " ";
- command += GetHostname(); // ********** A CHANGER, le naming service n'est pas obligatoirement ici
+ if (resInfo.AppliPath != "")
+ command += resInfo.AppliPath; // path relative to user@machine $HOME
+ else
+ {
+ ASSERT(getenv("APPLI"));
+ command += getenv("APPLI"); // path relative to user@machine $HOME
+ }
- command += " ";
+ command += "/runRemote.sh ";
- command += getenv("NSPORT");
+ ASSERT(getenv("NSHOST"));
+ command += getenv("NSHOST"); // hostname of CORBA name server
- command += " SALOME_Container ";
+ command += " ";
+ ASSERT(getenv("NSPORT"));
+ command += getenv("NSPORT"); // port of CORBA name server
- command += _NS->ContainerName(params);
+ command += " SALOME_Container ";
+ command += _NS->ContainerName(params);
+ command += "&";
- command += "&";
-
- MESSAGE("command =" << command);
+ MESSAGE("command =" << command);
+ }
return command;
}
// rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 &
const ParserResourcesType& resInfo = _resourcesList[machine];
bool pyCont = isPythonContainer(containerName);
+
string command;
if (resInfo.Protocol == rsh)
}
+//=============================================================================
+/*!
+ * Builds in a temporary file the script to be launched.
+ *
+ * Used if SALOME Application ($APPLI) is not defined.
+ * The command is build with data from CatalogResources, in which every path
+ * used on remote computer must be defined.
+ */
+//=============================================================================
+
+string
+SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer
+(const string& machine,
+ const Engines::MachineParameters& params)
+{
+ _TmpFileName = BuildTemporaryFileName();
+ ofstream tempOutputFile;
+ tempOutputFile.open(_TmpFileName.c_str(), ofstream::out );
+ const ParserResourcesType& resInfo = _resourcesList[machine];
+ tempOutputFile << "#! /bin/sh" << endl;
+
+ // --- set env vars
+
+ for (map<string, string>::const_iterator iter = resInfo.ModulesPath.begin();
+ iter != resInfo.ModulesPath.end();
+ iter++)
+ {
+ string curModulePath((*iter).second);
+ tempOutputFile << (*iter).first << "_ROOT_DIR=" << curModulePath << endl;
+ tempOutputFile << "export " << (*iter).first << "_ROOT_DIR" << endl;
+ tempOutputFile << "LD_LIBRARY_PATH=" << curModulePath
+ << "/lib/salome" << ":${LD_LIBRARY_PATH}" << endl;
+ tempOutputFile << "PYTHONPATH=" << curModulePath << "/bin/salome:"
+ << curModulePath << "/lib/salome:" << curModulePath
+ << "/lib/python2.2/site-packages/salome:";
+ tempOutputFile << curModulePath
+ << "/lib/python2.2/site-packages/salome/shared_modules:${PYTHONPATH}"
+ << endl;
+ }
+
+ tempOutputFile << "export LD_LIBRARY_PATH" << endl;
+ tempOutputFile << "export PYTHONPATH" << endl;
+ tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
+
+ // ! env vars
+
+ if (params.isMPI)
+ {
+ tempOutputFile << "mpirun -np ";
+ int nbproc;
+
+ if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
+ nbproc = 1;
+ else if ( params.nb_node == 0 )
+ nbproc = params.nb_proc_per_node;
+ else if ( params.nb_proc_per_node == 0 )
+ nbproc = params.nb_node;
+ else
+ nbproc = params.nb_node * params.nb_proc_per_node;
+
+ std::ostringstream o;
+
+ tempOutputFile << nbproc << " ";
+ }
+
+ tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second
+ << "/bin/salome/";
+
+ if (params.isMPI)
+ {
+ if (isPythonContainer(params.container_name))
+ tempOutputFile << "pyMPI SALOME_ContainerPy.py ";
+ else
+ tempOutputFile << "SALOME_MPIContainer ";
+ }
+
+ else
+ {
+ if (isPythonContainer(params.container_name))
+ tempOutputFile << "SALOME_ContainerPy.py ";
+ else
+ tempOutputFile << "SALOME_Container ";
+ }
+
+ tempOutputFile << _NS->ContainerName(params) << " -";
+ AddOmninamesParams(tempOutputFile);
+ tempOutputFile << " &" << endl;
+ tempOutputFile.flush();
+ tempOutputFile.close();
+ chmod(_TmpFileName.c_str(), 0x1ED);
+
+ // --- Build command
+
+ string command;
+
+ if (resInfo.Protocol == rsh)
+ {
+ command = "rsh ";
+ string commandRcp = "rcp ";
+ commandRcp += _TmpFileName;
+ commandRcp += " ";
+ commandRcp += machine;
+ commandRcp += ":";
+ commandRcp += _TmpFileName;
+ system(commandRcp.c_str());
+ }
+
+ else if (resInfo.Protocol == ssh)
+ command = "ssh ";
+ else
+ throw SALOME_Exception("Unknown protocol");
+
+ command += machine;
+ _CommandForRemAccess = command;
+ command += " ";
+ command += _TmpFileName;
+ command += " > ";
+ command += "/tmp/";
+ command += _NS->ContainerName(params);
+ command += "_";
+ command += machine;
+ command += ".log 2>&1 &";
+ SCRUTE(command);
+
+ return command;
+
+}
+
+