Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesManager.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #ifndef __SALOME_RESOURCESMANAGER_HXX__
21 #define __SALOME_RESOURCESMANAGER_HXX__
22
23 #include "Utils_SALOME_Exception.hxx"
24 #include "utilities.h"
25 #include <SALOMEconfig.h>
26 #include "SALOME_ResourcesCatalog_Handler.hxx"
27 #include "SALOME_LoadRateManager.hxx"
28 #include "SALOME_NamingService.hxx"
29 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
30 #include <string>
31 #include <fstream>
32 #include <vector>
33
34 #if defined RESOURCESMANAGER_EXPORTS
35 #if defined WIN32
36 #define RESOURCESMANAGER_EXPORT __declspec( dllexport )
37 #else
38 #define RESOURCESMANAGER_EXPORT
39 #endif
40 #else
41 #if defined WNT
42 #define RESOURCESMANAGER_EXPORT __declspec( dllimport )
43 #else
44 #define RESOURCESMANAGER_EXPORT
45 #endif
46 #endif
47
48 // --- WARNING ---
49 // The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done
50 // in a critical section to be sure to be clean.
51 // Only one thread should use the SALOME_ResourcesManager class in a SALOME
52 // session.
53
54 class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager:
55   public POA_Engines::ResourcesManager,
56   public PortableServer::RefCountServantBase
57   {
58
59   public:
60
61     SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns, const char *xmlFilePath);
62     SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns);
63
64     ~SALOME_ResourcesManager();
65
66     Engines::MachineList *
67     GetFittingResources(const Engines::MachineParameters& params,
68                         const Engines::CompoList& componentList);
69 //     throw(SALOME_Exception);
70
71     char* FindFirst(const Engines::MachineList& listOfMachines);
72     std::string FindNext(const Engines::MachineList& listOfMachines);
73     std::string FindBest(const Engines::MachineList& listOfMachines);
74
75     std::string BuildCommandToLaunchRemoteContainer
76     (const std::string& machine,
77      const Engines::MachineParameters& params, const long id);
78
79     std::string BuildCommandToLaunchLocalContainer
80     (const Engines::MachineParameters& params, const long id);
81
82     void RmTmpFile();
83
84     std::string BuildCommand(const std::string& machine,
85                              const char *containerName);
86
87     int AddResourceInCatalog
88     (const Engines::MachineParameters& paramsOfNewResources,
89      const std::vector<std::string>& modulesOnNewResources,
90      const char *alias,
91      const char *userName,
92      AccessModeType mode,
93      AccessProtocolType prot)
94     throw(SALOME_Exception);
95
96     void DeleteResourceInCatalog(const char *hostname);
97
98     void WriteInXmlFile();
99
100     const MapOfParserResourcesType& ParseXmlFile();
101
102     const MapOfParserResourcesType& GetList() const;
103
104     // Parallel extension
105     std::string BuildCommandToLaunchLocalParallelContainer(const std::string& exe_name, 
106                                                            const Engines::MachineParameters& params, 
107                                                            const std::string& log = "default");
108     Engines::MachineParameters* GetMachineParameters(const char *hostname);
109
110     void Shutdown();
111
112     static const char *_ResourcesManagerNameInNS;
113
114   protected:
115     
116     // Parallel extension
117     void startMPI();
118     bool _MpiStarted;
119
120     SALOME_NamingService *_NS;
121     CORBA::ORB_var _orb;
122     PortableServer::POA_var _poa;
123
124     std::string BuildTempFileToLaunchRemoteContainer
125     (const std::string& machine,
126      const Engines::MachineParameters& params) throw(SALOME_Exception);
127
128     void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,
129                                    const char *OS) const
130       throw(SALOME_Exception);
131
132     void KeepOnlyResourcesWithModule(std::vector<std::string>& hosts,
133                                      const Engines::CompoList& componentList) const
134       throw(SALOME_Exception);
135
136     void AddOmninamesParams(std::string& command) const;
137
138     void AddOmninamesParams(std::ofstream& fileStream) const;
139
140     std::string BuildTemporaryFileName() const;
141
142     //! will contain the path to the ressources catalog
143     std::string _path_resources;
144
145     //! attribute that contains current tmp files generated
146     std::string _TmpFileName;
147
148     //! contains the rsh or ssh command to access directly to machine.
149     //  Only used by this->RmTmpFile in case of a remote launch.
150     std::string _CommandForRemAccess;
151
152     //! will contain the informations on the data type catalog(after parsing)
153     MapOfParserResourcesType _resourcesList;
154
155     SALOME_LoadRateManager _dynamicResourcesSelecter;
156
157     //! different behaviour if $APPLI exists (SALOME Application) 
158     bool _isAppliSalomeDefined;
159   };
160
161 #endif // RESSOURCESCATALOG_IMPL_H