Salome HOME
PR: default policy
[modules/kernel.git] / src / ResourcesManager / ResourcesManager.cxx
index 5bcf6d8437d7fb61d098b20a525053cc85241400..e09908f767975df73826f3c927d0065ccf7a5df8 100644 (file)
@@ -38,6 +38,9 @@
 
 using namespace std;
 
+static LoadRateManagerFirst first;
+static LoadRateManagerCycl cycl;
+static LoadRateManagerAltCycl altcycl;
 //=============================================================================
 /*!
  * just for test
@@ -51,6 +54,11 @@ ResourcesManager_cpp(const char *xmlFilePath) :
 #if defined(_DEBUG_) || defined(_DEBUG)
   cerr << "ResourcesManager_cpp constructor" << endl;
 #endif
+  _resourceManagerMap["first"]=&first;
+  _resourceManagerMap["cycl"]=&cycl;
+  _resourceManagerMap["altcycl"]=&altcycl;
+  _resourceManagerMap["best"]=&altcycl;
+  _resourceManagerMap[""]=&altcycl;
 }
 
 //=============================================================================
@@ -69,6 +77,11 @@ ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException)
 #if defined(_DEBUG_) || defined(_DEBUG)
   cerr << "ResourcesManager_cpp constructor" << endl;
 #endif
+  _resourceManagerMap["first"]=&first;
+  _resourceManagerMap["cycl"]=&cycl;
+  _resourceManagerMap["altcycl"]=&altcycl;
+  _resourceManagerMap["best"]=&altcycl;
+  _resourceManagerMap[""]=&altcycl;
   _isAppliSalomeDefined = (getenv("APPLI") != 0);
   if(!getenv("KERNEL_ROOT_DIR"))
     throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!!");
@@ -108,15 +121,15 @@ ResourcesManager_cpp::~ResourcesManager_cpp()
 
 //=============================================================================
 /*!
- *  get the list of name of ressources fitting for the specified module.
+ *  get the list of name of ressources fitting for the specified component.
  *  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 witch the module is known
+ *  - then select the sublist of machines on witch the component 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)
+ *    components is probably not done, so give complete list from previous step)
  */ 
 //=============================================================================
 
@@ -185,7 +198,7 @@ ResourcesManager_cpp::GetFittingResources(const machineParams& params,
     // --- Search for available resources sorted by priority
     SelectOnlyResourcesWithOS(vec, params.OS.c_str());
       
-    KeepOnlyResourcesWithModule(vec, componentList);
+    KeepOnlyResourcesWithComponent(vec, componentList);
        
     if (vec.size() == 0)
       SelectOnlyResourcesWithOS(vec, params.OS.c_str());
@@ -225,25 +238,25 @@ ResourcesManager_cpp::GetFittingResources(const machineParams& params,
 //=============================================================================
 /*!
  *  add an entry in the ressources catalog  xml file.
- *  Return 0 if OK (KERNEL found in new resources modules) else throw exception
+ *  Return 0 if OK (KERNEL found in new resources components) else throw exception
  */ 
 //=============================================================================
 
 int
 ResourcesManager_cpp::
 AddResourceInCatalog(const machineParams& paramsOfNewResources,
-                     const vector<string>& modulesOnNewResources,
+                     const vector<string>& componentsOnNewResources,
                      const char *alias,
                      const char *userName,
                      AccessModeType mode,
                      AccessProtocolType prot)
 throw(ResourcesException)
 {
-  vector<string>::const_iterator iter = find(modulesOnNewResources.begin(),
-                                            modulesOnNewResources.end(),
+  vector<string>::const_iterator iter = find(componentsOnNewResources.begin(),
+                                            componentsOnNewResources.end(),
                                             "KERNEL");
 
-  if (iter != modulesOnNewResources.end())
+  if (iter != componentsOnNewResources.end())
     {
       ParserResourcesType newElt;
       newElt.DataForSort._hostName = paramsOfNewResources.hostname;
@@ -251,7 +264,7 @@ throw(ResourcesException)
       newElt.Protocol = prot;
       newElt.Mode = mode;
       newElt.UserName = userName;
-      newElt.ModulesList = modulesOnNewResources;
+      newElt.ComponentsList = componentsOnNewResources;
       newElt.OS = paramsOfNewResources.OS;
       newElt.DataForSort._memInMB = paramsOfNewResources.mem_mb;
       newElt.DataForSort._CPUFreqMHz = paramsOfNewResources.cpu_clock;
@@ -369,41 +382,15 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFile()
 //=============================================================================
 
 const MapOfParserResourcesType& ResourcesManager_cpp::GetList() const
-  {
-    return _resourcesList;
-  }
-
-
-//=============================================================================
-/*!
- *  dynamically obtains the first machines
- */ 
-//=============================================================================
-
-string ResourcesManager_cpp::FindFirst(const std::vector<std::string>& listOfMachines)
 {
-  return _dynamicResourcesSelecter.FindFirst(listOfMachines);
-}
-
-//=============================================================================
-/*!
- *  dynamically obtains the best machines
- */ 
-//=============================================================================
-
-string ResourcesManager_cpp::FindNext(const std::vector<std::string>& listOfMachines)
-{
-  return _dynamicResourcesSelecter.FindNext(listOfMachines,_resourcesList);
+  return _resourcesList;
 }
-//=============================================================================
-/*!
- *  dynamically obtains the best machines
- */ 
-//=============================================================================
 
-string ResourcesManager_cpp::FindBest(const std::vector<std::string>& listOfMachines)
+string ResourcesManager_cpp::Find(const std::string& policy, const std::vector<std::string>& listOfMachines)
 {
-  return _dynamicResourcesSelecter.FindBest(listOfMachines);
+  if(_resourceManagerMap.count(policy)==0)
+    return _resourceManagerMap[""]->Find(listOfMachines,_resourcesList);
+  return _resourceManagerMap[policy]->Find(listOfMachines,_resourcesList);
 }
 
 //=============================================================================
@@ -432,28 +419,28 @@ throw(ResourcesException)
 
 //=============================================================================
 /*!
- *  Gives a sublist of machines on which the module is known.
+ *  Gives a sublist of machines on which the component is known.
  */ 
 //=============================================================================
 
 //Warning need an updated parsed list : _resourcesList
-void ResourcesManager_cpp::KeepOnlyResourcesWithModule( vector<string>& hosts, const vector<string>& componentList) const
+void ResourcesManager_cpp::KeepOnlyResourcesWithComponent( vector<string>& hosts, const vector<string>& componentList) const
 throw(ResourcesException)
 {
   for (vector<string>::iterator iter = hosts.begin(); iter != hosts.end();)
     {
       MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter);
-      const vector<string>& mapOfModulesOfCurrentHost = (((*it).second).ModulesList);
+      const vector<string>& mapOfComponentsOfCurrentHost = (((*it).second).ComponentsList);
 
       bool erasedHost = false;
-      if( mapOfModulesOfCurrentHost.size() > 0 ){
+      if( mapOfComponentsOfCurrentHost.size() > 0 ){
        for(unsigned int i=0;i<componentList.size();i++){
           const char* compoi = componentList[i].c_str();
-         vector<string>::const_iterator itt = find(mapOfModulesOfCurrentHost.begin(),
-                                             mapOfModulesOfCurrentHost.end(),
+         vector<string>::const_iterator itt = find(mapOfComponentsOfCurrentHost.begin(),
+                                             mapOfComponentsOfCurrentHost.end(),
                                              compoi);
 //                                           componentList[i]);
-         if (itt == mapOfModulesOfCurrentHost.end()){
+         if (itt == mapOfComponentsOfCurrentHost.end()){
            erasedHost = true;
            break;
          }