Salome HOME
add method NameChanged to update title name
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesManager.cxx
index f84a3586760858222e7b692cd357db1fa716dd65..2b81a3477291a2c4434b3dc883fc6ff36e97c5b9 100644 (file)
-#include "SALOME_ResourcesManager.hxx"
-#include "SALOME_Container_i.hxx"
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_ResourcesManager.hxx" 
 #include "Utils_ExceptHandlers.hxx"
+#include "Utils_CorbaException.hxx"
 #include "OpUtil.hxx"
 
-#include <qdom.h>
-
 #include <stdlib.h>
+#include <stdio.h>
+#ifndef WIN32
 #include <unistd.h>
+#else
+#include <io.h>
+#include <process.h>
+#endif
 #include <fstream>
 #include <iostream>
+#include <sstream>
 #include <string.h>
 #include <map>
+#include <list>
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include "utilities.h"
 
 #define MAX_SIZE_FOR_HOSTNAME 256;
 
 using namespace std;
 
-//just for test
-SALOME_ResourcesManager::SALOME_ResourcesManager(const char *xmlFilePath):_path_resources(xmlFilePath)
+const char *SALOME_ResourcesManager::_ResourcesManagerNameInNS = "/ResourcesManager";
+
+//=============================================================================
+/*!
+ * just for test
+ */ 
+//=============================================================================
+
+SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns, const char *xmlFilePath) : _rm(xmlFilePath)
 {
+  MESSAGE("SALOME_ResourcesManager constructor");
+  _NS = ns;
+  _orb = CORBA::ORB::_duplicate(orb) ;
+  //
+  PortableServer::POAManager_var pman = poa->the_POAManager();
+  CORBA::PolicyList policies;
+  policies.length(1);
+  PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
+  policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
+  _poa = poa->create_POA("SingleThreadPOA",pman,policies);
+  threadPol->destroy();
+  //
+  PortableServer::ObjectId_var id = _poa->activate_object(this);
+  CORBA::Object_var obj = _poa->id_to_reference(id);
+  Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj);
+  _NS->Register(refContMan,_ResourcesManagerNameInNS);
+  MESSAGE("SALOME_ResourcesManager constructor end");
 }
 
-SALOME_ResourcesManager::SALOME_ResourcesManager()
+//=============================================================================
+/*!
+ *  Standard constructor, parse resource file.
+ *  - if ${APPLI} exists in environment,
+ *    look for ${HOME}/${APPLI}/CatalogResources.xml
+ *  - else look for default:
+ *    ${KERNEL_ROOT_DIR}/share/salome/resources/kernel/CatalogResources.xml
+ *  - parse XML resource file.
+ */ 
+//=============================================================================
+
+SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, 
+                                                 PortableServer::POA_var poa, 
+                                                 SALOME_NamingService *ns) : _rm()
 {
-  _path_resources=getenv("KERNEL_ROOT_DIR");
-  _path_resources+="/share/salome/resources/CatalogResources.xml";
-  ParseXmlFile();
+  MESSAGE("SALOME_ResourcesManager constructor");
+  _NS = ns;
+  _orb = CORBA::ORB::_duplicate(orb) ;
+  //
+  PortableServer::POAManager_var pman = poa->the_POAManager();
+  CORBA::PolicyList policies;
+  policies.length(1);
+  PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
+  policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
+  _poa = poa->create_POA("SingleThreadPOA",pman,policies);
+  threadPol->destroy();
+  //
+  PortableServer::ObjectId_var id = _poa->activate_object(this);
+  CORBA::Object_var obj = _poa->id_to_reference(id);
+  Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj);
+  _NS->Register(refContMan,_ResourcesManagerNameInNS);
+
+  MESSAGE("SALOME_ResourcesManager constructor end");
 }
 
+//=============================================================================
+/*!
+ *  Standard Destructor
+ */ 
+//=============================================================================
+
 SALOME_ResourcesManager::~SALOME_ResourcesManager()
 {
+  MESSAGE("SALOME_ResourcesManager destructor");
 }
 
-vector<string> SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params,const char *moduleName) throw(SALOME_Exception)
-{
-  vector <std::string> ret;
-  //To be sure that we search in a correct list.
-  ParseXmlFile();
-  const char *hostname=(const char *)params.hostname;
-  if(hostname[0]!='\0')
-    {
-      if(_resourcesList.find(hostname)!=_resourcesList.end())
-       // params.hostame is in the list of resources so return it.
-       ret.push_back(hostname);
-      else
-       //user specified an unknown hostame so notify to him.
-       throw SALOME_Exception("unknown host");
-    }
-  else
-    // Search for available resources sorted by priority
-    {
-      SelectOnlyResourcesWithOS(ret,params.OS);
-      KeepOnlyResourcesWithModule(ret,moduleName);
-      //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;
-      for(vector<string>::iterator iter=ret.begin();iter!=ret.end();iter++)
-       li.push_back(_resourcesList[(*iter)].DataForSort);
-      li.sort();
-      unsigned int i=0;
-      for(list<ResourceDataToSort>::iterator iter2=li.begin();iter2!=li.end();iter2++)
-       ret[i++]=(*iter2)._hostName;
-    }
-  return ret;
-}
 
-int SALOME_ResourcesManager::AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources, const map<string,string>& modulesOnNewResources,
-                                                 const char *environPathOfPrerequired,
-                                                 const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception)
-{
-  map<string,string>::const_iterator iter=modulesOnNewResources.find("KERNEL");
-  if(iter!=modulesOnNewResources.end())
-    {
-      ParserResourcesType newElt;
-      newElt.DataForSort._hostName=paramsOfNewResources.hostname;
-      newElt.Alias=alias;
-      newElt.Protocol=prot;
-      newElt.Mode=mode;
-      newElt.UserName=userName;
-      newElt.ModulesPath=modulesOnNewResources;
-      newElt.PreReqFilePath=environPathOfPrerequired;
-      newElt.OS=paramsOfNewResources.OS;
-      newElt.DataForSort._memInMB=paramsOfNewResources.mem_mb;
-      newElt.DataForSort._CPUFreqMHz=paramsOfNewResources.cpu_clock;
-      newElt.DataForSort._nbOfNodes=paramsOfNewResources.nb_node;
-      newElt.DataForSort._nbOfProcPerNode=paramsOfNewResources.nb_proc_per_node;
-      _resourcesList[newElt.DataForSort._hostName]=newElt;
-      return 0;
-    }
-  else
-    throw SALOME_Exception("KERNEL is not present in this resource");
-}
+//=============================================================================
+/*! CORBA method:
+ *  shutdown all the containers, then the ContainerManager servant
+ */
+//=============================================================================
 
-void SALOME_ResourcesManager::DeleteResourceInCatalog(const char *hostname)
+void SALOME_ResourcesManager::Shutdown()
 {
-  _resourcesList.erase(hostname);
+  MESSAGE("Shutdown");
+  _NS->Destroy_Name(_ResourcesManagerNameInNS);
+  PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
+  _poa->deactivate_object(oid);
 }
 
-void SALOME_ResourcesManager::WriteInXmlFile()
+//=============================================================================
+//! get the name of resources fitting the specified constraints (params)
+/*!
+ *  If hostname specified, check it is local or known in resources catalog.
+ *
+ *  Else
+ *  - select first machines with corresponding OS (all machines if
+ *    parameter OS empty),
+ *  - then select the sublist of machines on which the component is known
+ *    (if the result is empty, that probably means that the inventory of
+ *    components is probably not done, so give complete list from previous step)
+ */ 
+//=============================================================================
+
+Engines::ResourceList *
+SALOME_ResourcesManager::GetFittingResources(const Engines::ResourceParameters& params)
 {
-  QDomDocument doc("ResourcesCatalog");
-  SALOME_ResourcesCatalog_Handler* handler = new SALOME_ResourcesCatalog_Handler(_resourcesList);
-  handler->PrepareDocToXmlFile(doc);
-  delete handler;
-  QFile file( _path_resources );
-  if( !file.open( IO_WriteOnly ) )
-    cout << "WRITING ERROR !!!" << endl;
-
-  QTextStream ts( &file );
-  ts << doc.toString();
-
-  file.close();
-  cout << "WRITING DONE!!!" << endl;
-}
+  MESSAGE("ResourcesManager::GetFittingResources");
+  Engines::ResourceList_var ret;
 
-const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() 
-{
-  SALOME_ResourcesCatalog_Handler* handler = new SALOME_ResourcesCatalog_Handler(_resourcesList);
-  QFile xmlFile(_path_resources);
-
-  QXmlInputSource source(xmlFile);
-
-  QXmlSimpleReader reader;
-  reader.setContentHandler( handler );
-  reader.setErrorHandler( handler );
-  reader.parse( source );
-  xmlFile.close();
-  delete handler;
-  return _resourcesList;
-}
+  // CORBA -> C++
+  resourceParams p = resourceParameters_CORBAtoCPP(params);
 
-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;
-}
+  try
+  {
+    // Call C++ ResourceManager
+    std::vector <std::string> vec = _rm.GetFittingResources(p);
 
-const MapOfParserResourcesType& SALOME_ResourcesManager::GetList() const
-{
-  return _resourcesList;
+    // C++ -> CORBA
+    ret = resourceList_CPPtoCORBA(vec);
+  }
+  catch(const ResourcesException &ex)
+  {
+    INFOS("Caught exception in GetFittingResources C++:  " << ex.msg);
+    THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
+  }  
+
+  return ret._retn();
 }
 
-string SALOME_ResourcesManager::FindBest(const Engines::MachineList& listOfMachines)
+//=============================================================================
+/*!
+ *  dynamically obtains the first machines
+ */ 
+//=============================================================================
+
+char *
+SALOME_ResourcesManager::FindFirst(const Engines::ResourceList& listOfResources)
 {
-  return _dynamicResourcesSelecter.FindBest(listOfMachines);
+  // CORBA -> C++
+  std::vector<std::string> rl = resourceList_CORBAtoCPP(listOfResources);
+
+  return CORBA::string_dup(_rm.Find("first", rl).c_str());
 }
 
-string SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer(const string& machine,const char *containerName)
+char *
+SALOME_ResourcesManager::Find(const char* policy, const Engines::ResourceList& listOfResources)
 {
-  _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
-  tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second << "/bin/salome/";
-  if(Engines_Container_i::isPythonContainer(containerName))
-    tempOutputFile << "SALOME_ContainerPy.py ";
-  else
-    tempOutputFile << "SALOME_Container ";
-  tempOutputFile << containerName << " -";
-  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 += containerName;
-  command += "_";
-  command += machine;
-  command += ".log &";
-  cout << "Command is ... " << command << endl;
-  return command;
+  // CORBA -> C++
+  std::vector<std::string> rl = resourceList_CORBAtoCPP(listOfResources);
+
+  return CORBA::string_dup(_rm.Find(policy, rl).c_str());
 }
 
-string SALOME_ResourcesManager::BuildCommandToLaunchLocalContainer(const char *containerName)
+Engines::ResourceDefinition*
+SALOME_ResourcesManager::GetResourceDefinition(const char * name)
 {
-  _TmpFileName="";
-  string command;
-  if(Engines_Container_i::isPythonContainer(containerName))
-    command="SALOME_ContainerPy.py ";
-  else
-    command="SALOME_Container ";
-  command+=containerName;
-  command+=" -";
-  AddOmninamesParams(command);
-  command+=" > /tmp/";
-  command+=containerName;
-  command += "_";
-  command += GetHostname();
-  command += ".log 2>&1 &" ;
-  cout << "Command is ... " << command << endl << flush;
-  return command;
+  Engines::ResourceDefinition_var resDef;
+  try {
+    ParserResourcesType resource = _rm.GetResourcesDescr(name);
+    resDef = resourceDefinition_CPPtoCORBA(resource);
+  } catch (const exception & ex) {
+    INFOS("Caught exception in GetResourceDefinition: " << ex.what());
+    THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::BAD_PARAM);
+  }
+
+  return resDef._retn();
 }
 
-void SALOME_ResourcesManager::RmTmpFile()
+void 
+SALOME_ResourcesManager::AddResource(const Engines::ResourceDefinition& new_resource,
+                                     CORBA::Boolean write,
+                                     const char * xml_file)
 {
-  if(_TmpFileName!="")
+  try
+  {
+    ParserResourcesType resource = resourceDefinition_CORBAtoCPP(new_resource);
+    _rm.AddResourceInCatalog(resource);
+
+    if (write)
     {
-      string command="rm ";
-      command+=_TmpFileName;
-      char *temp=strdup(command.c_str());
-      int lgthTemp=strlen(temp);
-      temp[lgthTemp-3]='*';
-      temp[lgthTemp-2]='\0';
-      system(temp);
-      free(temp);
+      _rm.WriteInXmlFile(std::string(xml_file));
+      _rm.ParseXmlFiles();
     }
+  }
+  catch (const SALOME_Exception & e)
+  {
+    INFOS("Error in AddResourceInCatalog: " << e);
+    THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM);
+  }
 }
 
-string SALOME_ResourcesManager::BuildCommand(const string& machine,const char *containerName)
+void
+SALOME_ResourcesManager::RemoveResource(const char * resource_name,
+                                        CORBA::Boolean write,
+                                        const char * xml_file)
 {
-// rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 &
-  const ParserResourcesType& resInfo=_resourcesList[machine];
-  bool pyCont=Engines_Container_i::isPythonContainer(containerName);
-  string command;
-  if(resInfo.Protocol==rsh)
-    command = "rsh -n " ;
-  else if(resInfo.Protocol==ssh)
-    command = "ssh -f -n ";
-  else
-    throw SALOME_Exception("Not implemented yet...");
-      command += machine;
-  command += " ";
-  string path = (*(resInfo.ModulesPath.find("KERNEL"))).second;
-  command +=path;
-  command += "/bin/salome/";
-  if ( pyCont )
-    command += "SALOME_ContainerPy.py ";
-  else
-    command += "SALOME_Container ";
-  command += containerName;
-  command += " -";
-  AddOmninamesParams(command);
-  command += " > /tmp/";
-  command += containerName;
-  command += "_";
-  command += machine;
-  command += ".log 2>&1 &" ;
-  SCRUTE( command );
-  return command;
-}
+  try
+  {
+    _rm.DeleteResourceInCatalog(resource_name);
+  }
+  catch (const SALOME_Exception & e)
+  {
+    INFOS("Error in DeleteResourceInCatalog: " << e);
+    THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM);
+  }
 
-// Warning need an updated parsed list : _resourcesList
-void SALOME_ResourcesManager::SelectOnlyResourcesWithOS(vector<string>& hosts,const char *OS) const throw(SALOME_Exception)
-{
-  string base(OS);
-  for(map<string, ParserResourcesType>::const_iterator iter=_resourcesList.begin();iter!=_resourcesList.end();iter++)
-    if((*iter).second.OS==base)
-      hosts.push_back((*iter).first);
+  if (write)
+  {
+    _rm.WriteInXmlFile(std::string(xml_file));
+    _rm.ParseXmlFiles();
+  }
 }
 
-//Warning need an updated parsed list : _resourcesList
-void SALOME_ResourcesManager::KeepOnlyResourcesWithModule(vector<string>& hosts,const char *moduleName) const throw(SALOME_Exception)
+char *
+SALOME_ResourcesManager::getMachineFile(const char * resource_name,
+                                        CORBA::Long nb_procs, 
+                                        const char * parallelLib)
 {
-   for(vector<string>::iterator iter=hosts.begin();iter!=hosts.end();iter++)
-     {
-       MapOfParserResourcesType::const_iterator it=_resourcesList.find(*iter);
-       const map<string,string>& mapOfModulesOfCurrentHost=(((*it).second).ModulesPath);
-       if(mapOfModulesOfCurrentHost.find(moduleName)==mapOfModulesOfCurrentHost.end())
-        {
-          hosts.erase(iter);
-        }
-     }
-}
+  std::string machine_file_name("");
 
-void SALOME_ResourcesManager::AddOmninamesParams(string& command) const
-{
-  string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ;
-  ifstream omniORBfile( omniORBcfg.c_str() ) ;
-  char ORBInitRef[12] ;
-  char nameservice[132] ;
-  omniORBfile >> ORBInitRef ;
-  command += ORBInitRef ;
-  command += " " ;
-  omniORBfile >> nameservice ;
-  omniORBfile.close() ;
-  char * bsn = strchr( nameservice , '\n' ) ;
-  if ( bsn ) {
-    bsn[ 0 ] = '\0' ;
+  if (std::string(parallelLib) == "Dummy")
+  {
+    MESSAGE("[getMachineFile] parallelLib is Dummy");
+    MapOfParserResourcesType resourcesList = _rm.GetList();
+    if (resourcesList.find(std::string(resource_name)) != resourcesList.end())
+    {
+      ParserResourcesType resource = resourcesList[std::string(resource_name)];
+
+      // Check if resource is cluster or not
+      if (resource.ClusterMembersList.empty())
+      {
+        //It is not a cluster so we create a cluster with one machine
+        ParserResourcesType fake_node;
+        fake_node.HostName = resource.HostName;
+        fake_node.Protocol = resource.Protocol;
+        fake_node.ClusterInternalProtocol = resource.ClusterInternalProtocol;
+        fake_node.UserName = resource.UserName;
+        fake_node.AppliPath = resource.AppliPath;
+        fake_node.DataForSort = resource.DataForSort;
+
+        resource.ClusterMembersList.push_front(fake_node);
+      }
+
+      // Creating list of machines for creating the machine file
+      std::list<std::string> list_of_machines;
+      std::list<ParserResourcesType>::iterator cluster_it =
+        resource.ClusterMembersList.begin();
+      while (cluster_it != resource.ClusterMembersList.end())
+      {
+        // For each member of the cluster we add a nbOfNodes * nbOfProcPerNode in the list
+        unsigned int number_of_proc = (*cluster_it).DataForSort._nbOfNodes * 
+                                      (*cluster_it).DataForSort._nbOfProcPerNode;
+        for (unsigned int i = 0; i < number_of_proc; i++)
+          list_of_machines.push_back((*cluster_it).HostName);
+        cluster_it++;
+      }
+
+      // Creating machine file
+      machine_file_name = tmpnam(NULL);
+      std::ofstream machine_file(machine_file_name.c_str(), std::ios_base::out);
+
+      CORBA::Long machine_number = 0;
+      std::list<std::string>::iterator it = list_of_machines.begin();
+      while (machine_number != nb_procs)
+      {
+        // Adding a new node to the machine file
+        machine_file << *it << std::endl;
+
+        // counting...
+        it++;
+        if (it == list_of_machines.end())
+          it = list_of_machines.begin();
+        machine_number++;
+      }
+    }
+    else
+      INFOS("[getMachineFile] Error resource_name not found in resourcesList -> " << resource_name);
   }
-  command += nameservice ;
-}
+  else if (std::string(parallelLib) == "Mpi")
+  {
+    MESSAGE("[getMachineFile] parallelLib is Mpi");
 
-void SALOME_ResourcesManager::AddOmninamesParams(ofstream& fileStream) const
-{
-  string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ;
-  ifstream omniORBfile( omniORBcfg.c_str() ) ;
-  char ORBInitRef[12] ;
-  char nameservice[132] ;
-  omniORBfile >> ORBInitRef ;
-  fileStream << ORBInitRef;
-  fileStream << " ";
-  omniORBfile >> nameservice ;
-  omniORBfile.close() ;
-  char * bsn = strchr( nameservice , '\n' ) ;
-  if ( bsn ) {
-    bsn[ 0 ] = '\0' ;
+    MapOfParserResourcesType resourcesList = _rm.GetList();
+    if (resourcesList.find(std::string(resource_name)) != resourcesList.end())
+    {
+      ParserResourcesType resource = resourcesList[std::string(resource_name)];
+      // Check if resource is cluster or not
+      if (resource.ClusterMembersList.empty())
+      {
+        //It is not a cluster so we create a cluster with one machine
+        ParserResourcesType fake_node;
+        fake_node.HostName = resource.HostName;
+        fake_node.Protocol = resource.Protocol;
+        fake_node.ClusterInternalProtocol = resource.ClusterInternalProtocol;
+        fake_node.UserName = resource.UserName;
+        fake_node.AppliPath = resource.AppliPath;
+        fake_node.DataForSort = resource.DataForSort;
+
+        resource.ClusterMembersList.push_front(fake_node);
+      }
+
+      // Choose mpi implementation -> each MPI implementation has is own machinefile...
+      if (resource.mpi == lam)
+      {
+        // Creating machine file
+        machine_file_name = tmpnam(NULL);
+        std::ofstream machine_file(machine_file_name.c_str(), std::ios_base::out);
+
+        // We add all cluster machines to the file
+        std::list<ParserResourcesType>::iterator cluster_it =
+          resource.ClusterMembersList.begin();
+        while (cluster_it != resource.ClusterMembersList.end())
+        {
+          unsigned int number_of_proc = (*cluster_it).DataForSort._nbOfNodes * 
+            (*cluster_it).DataForSort._nbOfProcPerNode;
+          machine_file << (*cluster_it).HostName << " cpu=" << number_of_proc << std::endl;
+          cluster_it++;
+        }
+      }
+      else if ((resource.mpi == openmpi) || (resource.mpi == ompi))
+      {
+        // Creating machine file
+        machine_file_name = tmpnam(NULL);
+        std::ofstream machine_file(machine_file_name.c_str(), std::ios_base::out);
+
+        // We add all cluster machines to the file
+        std::list<ParserResourcesType>::iterator cluster_it =
+          resource.ClusterMembersList.begin();
+        while (cluster_it != resource.ClusterMembersList.end())
+        {
+          unsigned int number_of_proc = (*cluster_it).DataForSort._nbOfNodes *
+            (*cluster_it).DataForSort._nbOfProcPerNode;
+          machine_file << (*cluster_it).HostName << " slots=" << number_of_proc << std::endl;
+          cluster_it++;
+        }
+      }
+      else if (resource.mpi == nompi)
+      {
+        INFOS("[getMachineFile] Error resource_name MPI implementation was defined for " << resource_name);
+      }
+      else
+        INFOS("[getMachineFile] Error resource_name MPI implementation not currenly handled for " << resource_name);
+    }
+    else
+      INFOS("[getMachineFile] Error resource_name not found in resourcesList -> " << resource_name);
   }
-  fileStream << nameservice;
-}
+  else
+    INFOS("[getMachineFile] Error parallelLib is not handled -> " << parallelLib);
 
-string SALOME_ResourcesManager::BuildTemporaryFileName() const
-{
-  //build more complex file name to support multiple salome session
-  char *temp=new char[19];
-  strcpy(temp,"/tmp/command");
-  strcat(temp,"XXXXXX");
-  mkstemp(temp);
-  string command(temp);
-  delete [] temp;
-  command += ".sh";
-  return command;
+  return CORBA::string_dup(machine_file_name.c_str());
 }
-
-