Salome HOME
- Major update for launcher:
[modules/kernel.git] / src / ResourcesManager / ResourcesManager.cxx
index fe92bda979a377dc8155e56da71fec20741e081b..a265e9f251c37929872f3ad996c6ef681c61d145 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "ResourcesManager.hxx" 
 #include <Basics_Utils.hxx>
 #include <fstream>
@@ -39,8 +40,6 @@
 
 #define MAX_SIZE_FOR_HOSTNAME 256;
 
-using namespace std;
-
 static LoadRateManagerFirst first;
 static LoadRateManagerCycl cycl;
 static LoadRateManagerAltCycl altcycl;
@@ -55,7 +54,7 @@ ResourcesManager_cpp(const char *xmlFilePath)
 {
   _path_resources.push_back(xmlFilePath);
 #if defined(_DEBUG_) || defined(_DEBUG)
-  cerr << "ResourcesManager_cpp constructor" << endl;
+  std::cerr << "ResourcesManager_cpp constructor" << std::endl;
 #endif
   _resourceManagerMap["first"]=&first;
   _resourceManagerMap["cycl"]=&cycl;
@@ -232,7 +231,7 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re
     li.sort();
 
     vec.clear();
-    for (list<ResourceDataToSort>::iterator iter2 = li.begin(); iter2 != li.end(); iter2++)
+    for (std::list<ResourceDataToSort>::iterator iter2 = li.begin(); iter2 != li.end(); iter2++)
       vec.push_back((*iter2)._Name);
   }
 
@@ -249,7 +248,7 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re
   // Send an exception if return list is empty...
   if (vec.size() == 0)
   {
-    std::string error("[GetFittingResources] ResourcesManager doesn't find any resource that feets to your parameters");
+    std::string error("[GetFittingResources] ResourcesManager doesn't find any resource that fits to your parameters");
     throw ResourcesException(error);
   }
 
@@ -258,44 +257,15 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re
 
 //=============================================================================
 /*!
- *  add an entry in the ressources catalog  xml file.
- *  Return 0 if OK (KERNEL found in new resources components) else throw exception
+ *  add an entry in the ressources catalog xml file.
  */ 
 //=============================================================================
 
-int
-ResourcesManager_cpp::AddResourceInCatalog(const resourceParams& paramsOfNewResources,
-                                           const vector<string>& componentsOnNewResources,
-                                           const char *userName,
-                                           AccessModeType mode,
-                                           AccessProtocolType prot,
-                                           AccessProtocolType iprot) throw(ResourcesException)
+void
+ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) throw(ResourcesException)
 {
-  vector<string>::const_iterator iter = find(componentsOnNewResources.begin(),
-                                             componentsOnNewResources.end(),
-                                             "KERNEL");
-
-  if (iter != componentsOnNewResources.end())
-    {
-      ParserResourcesType newElt;
-      newElt.DataForSort._Name = paramsOfNewResources.name;
-      newElt.HostName = paramsOfNewResources.hostname;
-      newElt.Protocol = prot;
-      newElt.ClusterInternalProtocol = iprot;
-      newElt.Mode = mode;
-      newElt.UserName = userName;
-      newElt.ComponentsList = componentsOnNewResources;
-      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._Name] = newElt;
-      return 0;
-    }
-  else
-    throw ResourcesException("KERNEL is not present in this resource");
+  // TODO - Add minimal check
+  _resourcesList[new_resource.Name] = new_resource;
 }
 
 //=============================================================================
@@ -306,7 +276,11 @@ ResourcesManager_cpp::AddResourceInCatalog(const resourceParams& paramsOfNewReso
 
 void ResourcesManager_cpp::DeleteResourceInCatalog(const char * name)
 {
-  _resourcesList.erase(name);
+  MapOfParserResourcesType_it it = _resourcesList.find(name);
+  if (it != _resourcesList.end())
+    _resourcesList.erase(name);
+  else
+    RES_INFOS("You try to delete a resource that does not exist... : " << name);
 }
 
 //=============================================================================
@@ -315,10 +289,16 @@ void ResourcesManager_cpp::DeleteResourceInCatalog(const char * name)
  */ 
 //=============================================================================
 
-void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file)
+void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file)
 {
   RES_MESSAGE("WriteInXmlFile : start");
 
+  if (xml_file == "")
+  {
+    _path_resources_it = _path_resources.begin();
+    xml_file = *_path_resources_it;
+  }
+
   const char* aFilePath = xml_file.c_str();
   FILE* aFile = fopen(aFilePath, "w");
 
@@ -336,7 +316,7 @@ void ResourcesManager_cpp::WriteInXmlFile(std::string & xml_file)
   handler->PrepareDocToXmlFile(aDoc);
   delete handler;
 
-  int isOk = xmlSaveFile(aFilePath, aDoc);
+  int isOk = xmlSaveFormatFile(aFilePath, aDoc, 1);
   if (!isOk) 
      std::cerr << "Error while XML file saving : " << xml_file << std::endl;
   
@@ -403,7 +383,7 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles()
             }
             else
             {
-              std::cerr << "ParseXmlFiles Warning, to resource with the same name was found, taking the first declaration : " << i->first << std::endl;
+              std::cerr << "ParseXmlFiles Warning, two resources with the same name were found, taking the first declaration : " << i->first << std::endl;
             }
           }
         }
@@ -433,7 +413,7 @@ const MapOfParserResourcesType& ResourcesManager_cpp::GetList() const
   return _resourcesList;
 }
 
-string ResourcesManager_cpp::Find(const std::string& policy, const std::vector<std::string>& listOfResources)
+std::string ResourcesManager_cpp::Find(const std::string& policy, const std::vector<std::string>& listOfResources)
 {
   if(_resourceManagerMap.count(policy)==0)
     return _resourceManagerMap[""]->Find(listOfResources, _resourcesList);
@@ -454,7 +434,7 @@ ResourcesManager_cpp::SelectOnlyResourcesWithOS(std::vector<std::string>& resour
     // a computer list is given : take only resources with OS on those computers
     std::vector<std::string> vec_tmp = resources;
     resources.clear();
-    vector<string>::iterator iter = vec_tmp.begin();
+    std::vector<std::string>::iterator iter = vec_tmp.begin();
     for (; iter != vec_tmp.end(); iter++)
     {
       MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
@@ -473,13 +453,13 @@ ResourcesManager_cpp::SelectOnlyResourcesWithOS(std::vector<std::string>& resour
 //=============================================================================
 void 
 ResourcesManager_cpp::KeepOnlyResourcesWithComponent(std::vector<std::string>& resources, 
-                                                     const vector<string>& componentList)
+                                                     const std::vector<std::string>& componentList)
 {
   std::vector<std::string>::iterator iter = resources.begin();
   for (; iter != resources.end(); iter++)
   {
     MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
-    const vector<string>& mapOfComponentsOfCurrentHost = (*it).second.ComponentsList;
+    const std::vector<std::string>& mapOfComponentsOfCurrentHost = (*it).second.ComponentsList;
 
     bool erasedHost = false;
     if( mapOfComponentsOfCurrentHost.size() > 0 )
@@ -487,7 +467,7 @@ ResourcesManager_cpp::KeepOnlyResourcesWithComponent(std::vector<std::string>& r
       for(unsigned int i=0; i<componentList.size(); i++)
       {
         const char* compoi = componentList[i].c_str();
-        vector<string>::const_iterator itt = find(mapOfComponentsOfCurrentHost.begin(),
+        std::vector<std::string>::const_iterator itt = find(mapOfComponentsOfCurrentHost.begin(),
                                                   mapOfComponentsOfCurrentHost.end(),
                                                   compoi);
         if (itt == mapOfComponentsOfCurrentHost.end())