Back to index

salome-kernel  6.5.0
ResourcesManager.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef __RESOURCESMANAGER_HXX__
00024 #define __RESOURCESMANAGER_HXX__
00025 
00026 #include "ResourcesManager_Defs.hxx"
00027 
00028 #include <string>
00029 #include <fstream>
00030 #include <vector>
00031 #include <list>
00032 #include "SALOME_ResourcesCatalog_Parser.hxx"
00033 #include "SALOME_ResourcesCatalog_Handler.hxx"
00034 #include "SALOME_LoadRateManager.hxx"
00035 #include <sys/types.h>
00036 #include <sys/stat.h>
00037 #ifdef WNT
00038 #else
00039 #include <unistd.h>
00040 #endif
00041 
00042 #ifdef WNT
00043 #pragma warning(disable:4251) // Warning DLL Interface ...
00044 #pragma warning(disable:4290) // Warning Exception ...
00045 #endif
00046 
00047 // --- WARNING ---
00048 // The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done
00049 // in a critical section to be sure to be clean.
00050 // Only one thread should use the SALOME_ResourcesManager class in a SALOME
00051 // session.
00052 struct resourceParams
00053 {
00054   std::string name;
00055   std::string hostname;
00056   std::string OS;
00057   long nb_proc;
00058   long nb_node;
00059   long nb_proc_per_node;
00060   long cpu_clock;
00061   long mem_mb;
00062   std::vector<std::string> componentList;
00063   std::vector<std::string> resourceList;
00064 };
00065 
00066 class RESOURCESMANAGER_EXPORT ResourcesException
00067 {
00068 public:
00069   const std::string msg;
00070 
00071   ResourcesException(const std::string m) : msg(m) {}
00072 };
00073 
00074 class RESOURCESMANAGER_EXPORT ResourcesManager_cpp
00075   {
00076 
00077   public:
00078 
00079     ResourcesManager_cpp(const char *xmlFilePath);
00080     ResourcesManager_cpp() throw(ResourcesException);
00081 
00082     ~ResourcesManager_cpp();
00083 
00084     std::vector<std::string> 
00085     GetFittingResources(const resourceParams& params) throw(ResourcesException);
00086 
00087     std::string Find(const std::string& policy, 
00088                      const std::vector<std::string>& listOfResources);
00089 
00090     void AddResourceInCatalog (const ParserResourcesType & new_resource) throw(ResourcesException);
00091 
00092     void DeleteResourceInCatalog(const char * name);
00093 
00094     void WriteInXmlFile(std::string xml_file);
00095 
00096     const MapOfParserResourcesType& ParseXmlFiles();
00097 
00098     const MapOfParserResourcesType& GetList() const;
00099 
00100     ParserResourcesType GetResourcesDescr(const std::string & name);
00101 
00102   protected:
00103     
00104     void SelectOnlyResourcesWithOS(std::vector<std::string>& resources, std::string OS);
00105 
00106     void KeepOnlyResourcesWithComponent(std::vector<std::string>& resources, 
00107                                         const std::vector<std::string>& componentList);
00108 
00110     std::list<std::string> _path_resources;
00111     std::list<std::string>::iterator _path_resources_it;
00112 
00114     MapOfParserResourcesType _resourcesList;
00115 
00117     std::map<std::string , LoadRateManager*> _resourceManagerMap;
00118 
00120     time_t _lasttime;
00121   };
00122 
00123 #endif // __RESOURCESMANAGER_HXX__