]> SALOME platform Git repositories - modules/kernel.git/blob - src/Container/SALOME_ContainerManager.hxx
Salome HOME
[EDF30399] : Steer directory hosting replay files
[modules/kernel.git] / src / Container / SALOME_ContainerManager.hxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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, or (at your option) any later version.
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
23 #pragma once
24
25 #include "SALOME_Container.hxx"
26
27 #include <SALOMEconfig.h>
28 #include CORBA_CLIENT_HEADER(SALOME_Component)
29 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
30 #include "SALOME_ResourcesCatalog_Parser.hxx"
31
32 #include "Utils_Mutex.hxx"
33
34 #include <vector>
35 #include <string>
36 #include <utility>
37 #include <functional>
38 #include <set>
39
40 class SALOME_NamingService_Abstract;
41 class SALOME_ResourcesManager_Client;
42
43 class CONTAINER_EXPORT SALOME_ContainerManager : public POA_Engines::ContainerManager
44 {
45
46 public:
47   SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns);
48   ~SALOME_ContainerManager();
49
50   // Corba Methods
51   Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params) override;
52
53   void ShutdownContainers() override;
54
55   void ShutdownContainersNow() override;
56
57   void SetOverrideEnvForContainers(const Engines::KeyValDict& env) override;
58
59   Engines::KeyValDict *GetOverrideEnvForContainers() override;
60
61   void SetCodeOnContainerStartUp(const char *code) override;
62
63   char *GetCodeOnContainerStartUp() override;
64
65   // C++ Methods
66   void Shutdown();
67
68   void DeclareUsingSalomeSession() { _isSSL = false; }
69
70   CORBA::Long GetTimeOutToLaunchServerInSecond() override;
71
72   void SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond) override;
73
74   CORBA::Long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond() override;
75
76   void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) override;
77
78   CORBA::Long GetDeltaTimeBetweenCPUMemMeasureInMilliSecond() override;
79
80   void SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(CORBA::Long timeInMS) override;
81
82   void SetBigObjOnDiskThreshold(CORBA::Long thresholdInByte) override;
83
84   void SetBigObjOnDiskDirectory(const char *directory) override;
85
86   void SetDirectoryForReplayFiles(const char *directory) override;
87
88   void SetNumberOfRetry(CORBA::Long nbRetry) override;
89
90   CORBA::Long GetNumberOfRetry() override;
91
92   static const char *_ContainerManagerNameInNS;
93
94 private:
95
96   void ShutdownContainersGeneric(std::function<void(Engines::Container_ptr)> funcToBeCalledOnContainer);
97
98 protected:
99   // C++ methods
100   Engines::Container_ptr
101   FindContainer(const Engines::ContainerParameters& params,
102                 const Engines::ResourceList& possibleResources);
103
104   Engines::Container_ptr
105   FindContainer(const Engines::ContainerParameters& params,
106                 const std::string& resource);
107
108   std::string GetCppBinaryOfKernelSSLContainer() const;
109
110   std::string GetCppBinaryOfKernelContainer() const;
111   
112   std::string GetRunRemoteExecutableScript() const;
113
114   std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
115                                                   const Engines::ContainerParameters& params,
116                                                   const std::string& container_exe="SALOME_Container") const;
117
118   std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
119                                                  const std::string& machinesFile,
120                                                  const std::string& container_exe,//"SALOME_Container"
121                                                  std::string& tmpFileName) const;
122
123   std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
124                                                    const Engines::ContainerParameters& params, std::string& tmpFileName) const;
125
126   static void RmTmpFile(std::string& tmpFile);
127
128   void AddOmninamesParams(std::string& command) const;
129
130   void AddOmninamesParams(std::ostream& fileStream) const;
131
132   static std::string BuildTemporaryFileName();
133
134   std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
135
136   std::string machinesFile(const int nbproc);
137   
138   std::string getCommandToRunRemoteProcessCommon(const std::string& templateName, const std::string& remoteScript, 
139                                           AccessProtocolType protocol, 
140                                           const std::string & hostname, 
141                                           const std::string & username,
142                                           const std::string & applipath,
143                                           const std::string & workdir) const;
144
145   std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, 
146                                           const std::string & hostname, 
147                                           const std::string & username,
148                                           const std::string & applipath,
149                                           const std::string & workdir="") const;
150                                           
151   std::string getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, 
152                                           const std::string & hostname, 
153                                           const std::string & username,
154                                           const std::string & applipath,
155                                           const std::string & workdir="") const;
156
157   Engines::Container_ptr
158   LaunchContainer(const Engines::ContainerParameters& params,
159                   const std::string & resource_selected,
160                   const std::string & hostname,
161                   const std::string & machFile,
162                   const std::string & containerNameInNS);
163
164   CORBA::ORB_var _orb;
165   PortableServer::POA_var _poa;
166
167   SALOME_ResourcesManager_Client *_resManager;
168   SALOME_NamingService_Abstract *_NS;
169
170   //! different behaviour if $APPLI exists (SALOME Application)
171   bool _isAppliSalomeDefined;
172
173   //! attribute that contains the number of processes used in batch mode by MPI containers
174   int _nbprocUsed;
175
176   //! attribute that specifies the launch mode.
177   bool _isSSL = true;
178
179   static omni_mutex _numInstanceMutex ; // lib and instance protection
180
181   //! attributes to allow concurrency for // GiveContainer
182   Utils_Mutex _giveContainerMutex1;
183
184   pid_t _pid_mpiServer;
185
186   // Begin of PacO++ Parallel extension
187   typedef std::vector<std::string> actual_launch_machine_t;
188
189   bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
190
191   Engines::Container_ptr
192   StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
193
194
195
196   std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
197                                                      std::string machine_file_name,
198                                                      std::string & proxy_hostname);
199
200   std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
201                                                     const std::string & machine_file_name,
202                                                     SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
203                                                     const std::string & proxy_hostname);
204
205   void LogConfiguration(const std::string & log_type,
206                         const std::string & exe_type,
207                         const std::string & container_name,
208                         const std::string & hostname,
209                         std::string & begin,
210                         std::string & end);
211
212   CORBA::Object_ptr
213   LaunchPaCOProxyContainer(const std::string& command,
214                            const Engines::ContainerParameters& params,
215                            const std::string& hostname);
216
217   bool
218   LaunchPaCONodeContainer(const std::string& command,
219                           const Engines::ContainerParameters& params,
220                           const std::string& name,
221                           SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
222   // End of PaCO++ Parallel extension
223 public:
224   static char *GetenvThreadSafe(const char *name);
225   static std::string GetenvThreadSafeAsString(const char *name);
226   static int SystemThreadSafe(const char *command);
227   static long SystemWithPIDThreadSafe(const std::vector<std::string>& command);
228   static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns);
229   static void MakeTheCommandToBeLaunchedASync(std::string& command);
230   static int GetTimeOutToLoaunchServer();
231   static void SleepInSecond(int ellapseTimeInSecond);
232  private:
233   static const int TIME_OUT_TO_LAUNCH_CONT;
234   static const int DFT_DELTA_TIME_NS_LOOKUP_IN_MS;
235   static Utils_Mutex _getenvMutex;
236   static Utils_Mutex _systemMutex;
237 private:
238   std::vector< std::pair<std::string, std::string> > _override_env;
239   int _time_out_in_second;
240   int _delta_time_ns_lookup_in_ms;
241   int _delta_time_measure_in_ms;
242   std::string _code_to_exe_on_startup;
243 };