]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Changes for ResourceManager default resource:
authorbarate <barate>
Tue, 22 Jan 2013 13:10:13 +0000 (13:10 +0000)
committerbarate <barate>
Tue, 22 Jan 2013 13:10:13 +0000 (13:10 +0000)
- File CatalogResources.xml is no more generated by appli_gen.py.
- The default resource "localhost" is always generated by the ResourceManager. It can't be edited or deleted.
- This default resource can be used for local batch jobs.

bin/appli_gen.py
idl/SALOME_ContainerManager.idl
src/Launcher/Launcher.cxx
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
src/ResourcesManager/ResourcesManager.cxx
src/ResourcesManager/ResourcesManager.hxx
src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx
src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx
src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx
src/ResourcesManager/SALOME_ResourcesManager.cxx

index 648656c83ba0a753fd908ae9431810aa7397cb7f..b627b56498c5dab30eda65aa304d8c5f281e8ab5 100644 (file)
@@ -270,17 +270,6 @@ export MMGT_REENTRANT=1
     f.write(command % ",".join(mods))
     f.close()
 
-    #Add default CatalogResources.xml file
-    f =open(os.path.join(home_dir,'CatalogResources.xml'),'w')
-    command="""<!DOCTYPE ResourcesCatalog>
-<resources>
-   <machine name="localhost"
-            hostname="localhost" />
-</resources>
-"""
-    f.write(command)
-    f.close()
-
     #Add USERS directory with 777 permission to store users configuration files
     users_dir=os.path.join(home_dir,'USERS')
     makedirs(users_dir)
index b15f357f728f8313eaa60c9c716b6b45ce20a8b4..d209ef71de6fb9a500ffcbbf0b8083ac7bcab564 100644 (file)
@@ -273,7 +273,7 @@ interface ResourcesManager
   ResourceList GetFittingResources(in ResourceParameters params) raises (SALOME::SALOME_Exception);
 
   //!  Get definition of a resource
-  ResourceDefinition GetResourceDefinition(in string name);
+  ResourceDefinition GetResourceDefinition(in string name) raises (SALOME::SALOME_Exception);
 
   //! Add a new resource to the resource_manager
   /*!
index 29538c893036f0c91e906e9e0ea0b2e3e01541ab..986ec6703b5e537bb6ba8d1e3bc4d445054f3e21 100644 (file)
@@ -372,6 +372,9 @@ Launcher_cpp::FactoryBatchManager(ParserResourcesType& params)
 
   switch(params.Protocol)
   {
+    case sh:
+      protocol = Batch::SH;
+      break;
     case rsh:
       protocol = Batch::RSH;
       break;
index 6d138af19949ffbc07aea0262d7821255842a3bf..eb35541bc0495a9ebf093d99458212da1628bc34 100644 (file)
@@ -234,7 +234,7 @@ FindOrLoad_Component(const Engines::MachineParameters& params,
   if (std::string(new_params.resource_params.hostname.in()) == "localhost")
   {
     new_params.resource_params.hostname = CORBA::string_dup(Kernel_Utils::GetHostname().c_str());
-    new_params.resource_params.name = CORBA::string_dup(Kernel_Utils::GetHostname().c_str());
+    new_params.resource_params.name = CORBA::string_dup("localhost");
   }
 
   Engines::ResourceList_var listOfResources;
index 23d8e781e1221018ac15a5a9ccebf766964bdde4..2426cfcc80f6772700bd81ce2cf98f91aad6b2af 100644 (file)
 
 #include <algorithm>
 
+#include "Utils_SALOME_Exception.hxx"
+
 #define MAX_SIZE_FOR_HOSTNAME 256;
 
+using namespace std;
+
+const string ResourcesManager_cpp::DEFAULT_RESOURCE_NAME = "localhost";
+
 static LoadRateManagerFirst first;
 static LoadRateManagerCycl cycl;
 static LoadRateManagerAltCycl altcycl;
@@ -61,6 +67,8 @@ ResourcesManager_cpp(const char *xmlFilePath)
   _resourceManagerMap["altcycl"]=&altcycl;
   _resourceManagerMap["best"]=&altcycl;
   _resourceManagerMap[""]=&altcycl;
+
+  AddDefaultResourceInCatalog();
 }
 
 //=============================================================================
@@ -84,6 +92,8 @@ ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException)
   _resourceManagerMap["best"]=&altcycl;
   _resourceManagerMap[""]=&altcycl;
 
+  AddDefaultResourceInCatalog();
+
   bool default_catalog_resource = true;
   if (getenv("USER_CATALOG_RESOURCES_FILE") != 0)
   {
@@ -266,7 +276,7 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re
 
   // Step 5
   SelectOnlyResourcesWithOS(vec, params.OS.c_str());
-    
+
   // Step 6
   std::vector<std::string> vec_save(vec);
   KeepOnlyResourcesWithComponent(vec, params.componentList);
@@ -291,8 +301,11 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re
 //=============================================================================
 
 void
-ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) throw(ResourcesException)
+ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource)
 {
+  if (new_resource.Name == DEFAULT_RESOURCE_NAME)
+    throw SALOME_Exception((string("Cannot modify default local resource \"") +
+                            DEFAULT_RESOURCE_NAME + "\"").c_str());
   // TODO - Add minimal check
   _resourcesList[new_resource.Name] = new_resource;
 }
@@ -305,6 +318,9 @@ ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resou
 
 void ResourcesManager_cpp::DeleteResourceInCatalog(const char * name)
 {
+  if (DEFAULT_RESOURCE_NAME == name)
+    throw SALOME_Exception((string("Cannot delete default local resource \"") +
+                            DEFAULT_RESOURCE_NAME + "\"").c_str());
   MapOfParserResourcesType_it it = _resourcesList.find(name);
   if (it != _resourcesList.end())
     _resourcesList.erase(name);
@@ -322,6 +338,16 @@ void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file)
 {
   RES_MESSAGE("WriteInXmlFile : start");
 
+  MapOfParserResourcesType resourceListToSave(_resourcesList);
+  // We do not save default local resource because it is automatically created at startup
+  resourceListToSave.erase(DEFAULT_RESOURCE_NAME);
+  if (resourceListToSave.empty())
+  {
+    RES_MESSAGE("WriteInXmlFile: nothing to do, no resource except default \"" <<
+                DEFAULT_RESOURCE_NAME << "\"");
+    return;
+  }
+
   if (xml_file == "")
   {
     _path_resources_it = _path_resources.begin();
@@ -341,7 +367,7 @@ void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file)
   xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog");
 
   SALOME_ResourcesCatalog_Handler* handler =
-    new SALOME_ResourcesCatalog_Handler(_resourcesList);
+    new SALOME_ResourcesCatalog_Handler(resourceListToSave);
   handler->PrepareDocToXmlFile(aDoc);
   delete handler;
 
@@ -371,7 +397,7 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles()
     int result = stat((*_path_resources_it).c_str(), &statinfo);
     if (result < 0)
     {
-      std::cerr << "Error in method stat for file : " << (*_path_resources_it).c_str() << " no new xml file is parsed" << std::endl;
+      RES_MESSAGE("Resource file " << *_path_resources_it << " does not exist");
       return _resourcesList;
     }
 
@@ -385,6 +411,7 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles()
   if (to_parse)
   {
     _resourcesList.clear();
+    AddDefaultResourceInCatalog();
     // On parse tous les fichiers
     for(_path_resources_it = _path_resources.begin(); _path_resources_it != _path_resources.end(); ++_path_resources_it)
     {
@@ -406,13 +433,19 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles()
           for (MapOfParserResourcesType_it i = _resourcesList_tmp.begin(); i != _resourcesList_tmp.end(); ++i)
           {
             MapOfParserResourcesType_it j = _resourcesList.find(i->first);
-            if (j == _resourcesList.end())
+            if (i->second.HostName == "localhost" || i->second.HostName == Kernel_Utils::GetHostname())
             {
-              _resourcesList[i->first] = i->second;
+              RES_MESSAGE("Resource " << i->first << " is not added because it is the same "
+                          "machine as default local resource \"" << DEFAULT_RESOURCE_NAME << "\"");
+            }
+            else if (j != _resourcesList.end())
+            {
+              cerr << "ParseXmlFiles Warning, two resources with the same name were found, "
+                      "taking the first declaration : " << i->first << endl;
             }
             else
             {
-              std::cerr << "ParseXmlFiles Warning, two resources with the same name were found, taking the first declaration : " << i->first << std::endl;
+              _resourcesList[i->first] = i->second;
             }
           }
         }
@@ -525,3 +558,22 @@ ResourcesManager_cpp::GetResourcesDescr(const std::string & name)
     throw ResourcesException(error);
   }
 }
+
+void ResourcesManager_cpp::AddDefaultResourceInCatalog()
+{
+  ParserResourcesType resource;
+  resource.Clear();
+  resource.Name = DEFAULT_RESOURCE_NAME;
+  // We can't use "localhost" for parameter hostname because the containers are registered in the
+  // naming service with the real hostname, not "localhost"
+  resource.HostName = Kernel_Utils::GetHostname();
+  resource.DataForSort._Name = DEFAULT_RESOURCE_NAME;
+  resource.Protocol = sh;
+  resource.Batch = ssh_batch;
+  if (getenv("HOME") != NULL && getenv("APPLI") != NULL)
+  {
+    resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI");
+  }
+  resource.working_directory = "/tmp/salome_localres_workdir";
+  _resourcesList[resource.Name] = resource;
+}
index a85f6849704d27a9b169fc25c722eccd4c1e7b03..8b55d205b6334fa0dacbb0c657224985704d9ea8 100644 (file)
@@ -87,7 +87,7 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp
     std::string Find(const std::string& policy, 
                      const std::vector<std::string>& listOfResources);
 
-    void AddResourceInCatalog (const ParserResourcesType & new_resource) throw(ResourcesException);
+    void AddResourceInCatalog (const ParserResourcesType & new_resource);
 
     void DeleteResourceInCatalog(const char * name);
 
@@ -106,6 +106,11 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp
     void KeepOnlyResourcesWithComponent(std::vector<std::string>& resources, 
                                         const std::vector<std::string>& componentList);
 
+    /**
+     * Add the default local resource in the catalog
+     */
+    void AddDefaultResourceInCatalog();
+
     //! will contain the path to the ressources catalog
     std::list<std::string> _path_resources;
     std::list<std::string>::iterator _path_resources_it;
@@ -118,6 +123,9 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp
 
     //! contain the time where resourcesList was created
     time_t _lasttime;
+
+    //! the name of the default local resource
+    static const std::string DEFAULT_RESOURCE_NAME;
   };
 
 #endif // __RESOURCESMANAGER_HXX__
index ae42569dd2c2ee34aa32563a28ce15cc295ee5ae..e548b3613c3fe8a0adf378d34eea14f1a22d2269 100755 (executable)
@@ -107,13 +107,6 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc)
   // Empty private elements
   _resources_list.clear();
 
-  //default resources
-  _resource.Clear();
-  _resource.HostName = Kernel_Utils::GetHostname();
-  _resource.Name = Kernel_Utils::GetHostname();
-  _resource.DataForSort._Name = Kernel_Utils::GetHostname();
-  _resources_list[Kernel_Utils::GetHostname()] = _resource;
-
   // Get the document root node
   xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc);
 
index 9cf3cfa99d6e7a9065e19150c9f076dd84969036..5412c670d718f6760edb1beaa008348ac677fddc 100644 (file)
@@ -134,6 +134,8 @@ std::string ParserResourcesType::protocolToString(AccessProtocolType protocol)
 {
   switch (protocol)
   {
+  case sh:
+    return "sh";
   case rsh:
     return "rsh";
   case ssh:
@@ -151,7 +153,9 @@ std::string ParserResourcesType::protocolToString(AccessProtocolType protocol)
 
 AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr)
 {
-  if (protocolStr == "rsh")
+  if (protocolStr == "sh")
+    return sh;
+  else if (protocolStr == "rsh")
     return rsh;
   else if (protocolStr == "ssh")
     return ssh;
index 1ac87b3400ea9e38b298dab2945c4a9835b0cd43..a0d437318dc90642912e4e68c01732e25c49845d 100755 (executable)
@@ -41,7 +41,7 @@
 #pragma warning(disable:4251) // Warning DLL Interface ...
 #endif
 
-enum AccessProtocolType {rsh, ssh, srun, pbsdsh, blaunch};
+enum AccessProtocolType {sh, rsh, ssh, srun, pbsdsh, blaunch};
 
 enum AccessModeType {interactive, batch};
 
index 30a1c1b44eadfb65d220409d7d1aad8dc4a3e868..a96731b02bf5299609887c75ff7409d9b952dc7d 100644 (file)
@@ -46,6 +46,8 @@
 
 #define MAX_SIZE_FOR_HOSTNAME 256;
 
+using namespace std;
+
 const char *SALOME_ResourcesManager::_ResourcesManagerNameInNS = "/ResourcesManager";
 
 //=============================================================================
@@ -209,57 +211,63 @@ SALOME_ResourcesManager::Find(const char* policy, const Engines::ResourceList& l
 Engines::ResourceDefinition* 
 SALOME_ResourcesManager::GetResourceDefinition(const char * name)
 {
-  ParserResourcesType resource = _rm.GetResourcesDescr(name);
-  Engines::ResourceDefinition *p_ptr = new Engines::ResourceDefinition;
-
-  p_ptr->name = CORBA::string_dup(resource.Name.c_str());
-  p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str());
-  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());
-  for(unsigned int i=0;i<resource.ComponentsList.size();i++)
-    p_ptr->componentList[i] = CORBA::string_dup(resource.ComponentsList[i].c_str());
-  p_ptr->OS = CORBA::string_dup(resource.OS.c_str());
-  p_ptr->mem_mb = resource.DataForSort._memInMB;
-  p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz;
-  p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode;
-  p_ptr->nb_node = resource.DataForSort._nbOfNodes;
-  p_ptr->is_cluster_head = resource.is_cluster_head;
-  p_ptr->working_directory = CORBA::string_dup(resource.working_directory.c_str());
-
-  if( resource.mpi == lam )
-    p_ptr->mpiImpl = "lam";
-  else if( resource.mpi == mpich1 )
-    p_ptr->mpiImpl = "mpich1";
-  else if( resource.mpi == mpich2 )
-    p_ptr->mpiImpl = "mpich2";
-  else if( resource.mpi == openmpi )
-    p_ptr->mpiImpl = "openmpi";
-  else if( resource.mpi == ompi )
-    p_ptr->mpiImpl = "ompi";
-  else if( resource.mpi == slurmmpi )
-    p_ptr->mpiImpl = "slurmmpi";
-  else if( resource.mpi == prun )
-    p_ptr->mpiImpl = "prun";
-
-  if( resource.Batch == pbs )
-    p_ptr->batch = "pbs";
-  else if( resource.Batch == lsf )
-    p_ptr->batch = "lsf";
-  else if( resource.Batch == sge )
-    p_ptr->batch = "sge";
-  else if( resource.Batch == ccc )
-    p_ptr->batch = "ccc";
-  else if( resource.Batch == slurm )
-    p_ptr->batch = "slurm";
-  else if( resource.Batch == ssh_batch )
-    p_ptr->batch = "ssh";
-  else if( resource.Batch == ll )
-    p_ptr->batch = "ll";
-  else if( resource.Batch == vishnu )
-    p_ptr->batch = "vishnu";
+  Engines::ResourceDefinition * p_ptr = NULL;
+  try {
+    ParserResourcesType resource = _rm.GetResourcesDescr(name);
+    p_ptr = new Engines::ResourceDefinition;
+
+    p_ptr->name = CORBA::string_dup(resource.Name.c_str());
+    p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str());
+    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());
+    for(unsigned int i=0;i<resource.ComponentsList.size();i++)
+      p_ptr->componentList[i] = CORBA::string_dup(resource.ComponentsList[i].c_str());
+    p_ptr->OS = CORBA::string_dup(resource.OS.c_str());
+    p_ptr->mem_mb = resource.DataForSort._memInMB;
+    p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz;
+    p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode;
+    p_ptr->nb_node = resource.DataForSort._nbOfNodes;
+    p_ptr->is_cluster_head = resource.is_cluster_head;
+    p_ptr->working_directory = CORBA::string_dup(resource.working_directory.c_str());
+
+    if( resource.mpi == lam )
+      p_ptr->mpiImpl = "lam";
+    else if( resource.mpi == mpich1 )
+      p_ptr->mpiImpl = "mpich1";
+    else if( resource.mpi == mpich2 )
+      p_ptr->mpiImpl = "mpich2";
+    else if( resource.mpi == openmpi )
+      p_ptr->mpiImpl = "openmpi";
+    else if( resource.mpi == ompi )
+      p_ptr->mpiImpl = "ompi";
+    else if( resource.mpi == slurmmpi )
+      p_ptr->mpiImpl = "slurmmpi";
+    else if( resource.mpi == prun )
+      p_ptr->mpiImpl = "prun";
+
+    if( resource.Batch == pbs )
+      p_ptr->batch = "pbs";
+    else if( resource.Batch == lsf )
+      p_ptr->batch = "lsf";
+    else if( resource.Batch == sge )
+      p_ptr->batch = "sge";
+    else if( resource.Batch == ccc )
+      p_ptr->batch = "ccc";
+    else if( resource.Batch == slurm )
+      p_ptr->batch = "slurm";
+    else if( resource.Batch == ssh_batch )
+      p_ptr->batch = "ssh";
+    else if( resource.Batch == ll )
+      p_ptr->batch = "ll";
+    else if( resource.Batch == vishnu )
+      p_ptr->batch = "vishnu";
+  } catch (const exception & ex) {
+    INFOS("Caught exception in GetResourceDefinition: " << ex.what());
+    THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::BAD_PARAM);
+  }
 
   return p_ptr;
 }
@@ -375,7 +383,15 @@ SALOME_ResourcesManager::AddResource(const Engines::ResourceDefinition& new_reso
   for (CORBA::ULong i = 0; i < new_resource.componentList.length(); i++)
     resource.ComponentsList.push_back(new_resource.componentList[i].in());
 
-  _rm.AddResourceInCatalog(resource);
+  try
+  {
+    _rm.AddResourceInCatalog(resource);
+  }
+  catch (const SALOME_Exception & e)
+  {
+    INFOS("Error in AddResourceInCatalog: " << e);
+    THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM);
+  }
 
   if (write)
   {
@@ -389,7 +405,16 @@ SALOME_ResourcesManager::RemoveResource(const char * resource_name,
                                         CORBA::Boolean write,
                                         const char * xml_file)
 {
-  _rm.DeleteResourceInCatalog(resource_name);
+  try
+  {
+    _rm.DeleteResourceInCatalog(resource_name);
+  }
+  catch (const SALOME_Exception & e)
+  {
+    INFOS("Error in DeleteResourceInCatalog: " << e);
+    THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM);
+  }
+
   if (write)
   {
     _rm.WriteInXmlFile(std::string(xml_file));