Salome HOME
merge from BR_V51_AR 7 may 09
[modules/kernel.git] / src / ResourcesManager / ResourcesManager.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef __RESOURCESMANAGER_HXX__
23 #define __RESOURCESMANAGER_HXX__
24
25 #include "ResourcesManager_Defs.hxx"
26
27 #include <string>
28 #include <fstream>
29 #include <vector>
30 #include <list>
31 #include "SALOME_ResourcesCatalog_Parser.hxx"
32 #include "SALOME_ResourcesCatalog_Handler.hxx"
33 #include "SALOME_LoadRateManager.hxx"
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37
38 // --- WARNING ---
39 // The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done
40 // in a critical section to be sure to be clean.
41 // Only one thread should use the SALOME_ResourcesManager class in a SALOME
42 // session.
43
44 struct machineParams{
45   std::string hostname;
46   std::string OS;
47   std::string parallelLib;
48   unsigned int nb_node;
49   unsigned int nb_proc_per_node;
50   unsigned int cpu_clock;
51   unsigned int mem_mb;
52   unsigned int nb_component_nodes;
53   std::vector<std::string> componentList;
54   std::vector<std::string> computerList;
55 };
56
57 class RESOURCESMANAGER_EXPORT ResourcesException
58 {
59 public:
60   const std::string msg;
61
62   ResourcesException(const std::string m) : msg(m) {}
63 };
64
65 class RESOURCESMANAGER_EXPORT ResourcesManager_cpp
66   {
67
68   public:
69
70     ResourcesManager_cpp(const char *xmlFilePath);
71     ResourcesManager_cpp() throw(ResourcesException);
72
73     ~ResourcesManager_cpp();
74
75     std::vector<std::string> 
76     GetFittingResources(const machineParams& params) throw(ResourcesException);
77
78     std::string Find(const std::string& policy, const std::vector<std::string>& listOfMachines);
79
80     int AddResourceInCatalog
81     (const machineParams& paramsOfNewResources,
82      const std::vector<std::string>& componentsOnNewResources,
83      const char *alias,
84      const char *userName,
85      AccessModeType mode,
86      AccessProtocolType prot) throw(ResourcesException);
87
88     void DeleteResourceInCatalog(const char *hostname);
89
90     void WriteInXmlFile(std::string & xml_file);
91
92     const MapOfParserResourcesType& ParseXmlFiles();
93
94     const MapOfParserResourcesType& GetList() const;
95
96     ParserResourcesType GetResourcesList(const std::string& machine);
97
98   protected:
99     
100     void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,
101                                    const char *OS) const
102       throw(ResourcesException);
103
104     void KeepOnlyResourcesWithComponent(std::vector<std::string>& hosts,
105                                      const std::vector<std::string>& componentList) const
106       throw(ResourcesException);
107
108     //! will contain the path to the ressources catalog
109     std::list<std::string> _path_resources;
110     std::list<std::string>::iterator _path_resources_it;
111
112     //! will contain the informations on the data type catalog(after parsing)
113     MapOfParserResourcesType _resourcesList;
114
115     //! will contain the informations on the data type catalog(after parsing)
116     MapOfParserResourcesType _resourcesBatchList;
117
118     //! a map that contains all the available load rate managers (the key is the name)
119     std::map<std::string , LoadRateManager*> _resourceManagerMap;
120
121     //! contain the time where resourcesList was created
122     time_t _lasttime;
123   };
124
125 #endif // __RESOURCESMANAGER_HXX__