Salome HOME
PR: resource list of machines must contain actual hostname, not only localhost
[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 "SALOME_ResourcesCatalog_Parser.hxx"
31 #include "SALOME_ResourcesCatalog_Handler.hxx"
32 #include "SALOME_LoadRateManager.hxx"
33
34 // --- WARNING ---
35 // The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done
36 // in a critical section to be sure to be clean.
37 // Only one thread should use the SALOME_ResourcesManager class in a SALOME
38 // session.
39
40 struct machineParams{
41   std::string hostname;
42   std::string OS;
43   unsigned int nb_node;
44   unsigned int nb_proc_per_node;
45   unsigned int cpu_clock;
46   unsigned int mem_mb;
47 };
48
49 class RESOURCESMANAGER_EXPORT ResourcesException
50 {
51 public:
52   const std::string msg;
53
54   ResourcesException(const std::string m) : msg(m) {}
55 };
56
57 class RESOURCESMANAGER_EXPORT ResourcesManager_cpp
58   {
59
60   public:
61
62     ResourcesManager_cpp(const char *xmlFilePath);
63     ResourcesManager_cpp() throw(ResourcesException);
64
65     ~ResourcesManager_cpp();
66
67     std::vector<std::string> 
68     GetFittingResources(const machineParams& params,
69                         const std::vector<std::string>& componentList) throw(ResourcesException);
70
71     std::string FindFirst(const std::vector<std::string>& listOfMachines);
72     std::string FindNext(const std::vector<std::string>& listOfMachines);
73     std::string FindBest(const std::vector<std::string>& listOfMachines);
74
75     int AddResourceInCatalog
76     (const machineParams& paramsOfNewResources,
77      const std::vector<std::string>& modulesOnNewResources,
78      const char *alias,
79      const char *userName,
80      AccessModeType mode,
81      AccessProtocolType prot) throw(ResourcesException);
82
83     void DeleteResourceInCatalog(const char *hostname);
84
85     void WriteInXmlFile();
86
87     const MapOfParserResourcesType& ParseXmlFile();
88
89     const MapOfParserResourcesType& GetList() const;
90
91     ParserResourcesType GetResourcesList(const std::string& machine);
92
93   protected:
94     
95     void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,
96                                    const char *OS) const
97       throw(ResourcesException);
98
99     void KeepOnlyResourcesWithModule(std::vector<std::string>& hosts,
100                                      const std::vector<std::string>& componentList) const
101       throw(ResourcesException);
102
103     //! will contain the path to the ressources catalog
104     std::string _path_resources;
105
106     //! will contain the informations on the data type catalog(after parsing)
107     MapOfParserResourcesType _resourcesList;
108
109     //! will contain the informations on the data type catalog(after parsing)
110     MapOfParserResourcesType _resourcesBatchList;
111
112     SALOME_LoadRateManager _dynamicResourcesSelecter;
113
114     //! different behaviour if $APPLI exists (SALOME Application) 
115     bool _isAppliSalomeDefined;    
116   };
117
118 #endif // __RESOURCESMANAGER_HXX__