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