1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef __SALOME_CONTAINERMANAGER_HXX__
24 #define __SALOME_CONTAINERMANAGER_HXX__
26 #include "SALOME_Container.hxx"
28 #include <SALOMEconfig.h>
29 #include CORBA_CLIENT_HEADER(SALOME_Component)
30 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
31 #include "SALOME_ResourcesCatalog_Parser.hxx"
33 #include "Utils_Mutex.hxx"
41 class SALOME_NamingService_Abstract;
42 class SALOME_ResourcesManager_Client;
44 class CONTAINER_EXPORT SALOME_ContainerManager : public POA_Engines::ContainerManager
48 SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns);
49 ~SALOME_ContainerManager();
52 Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params) override;
54 void ShutdownContainers() override;
56 void ShutdownContainersNow() override;
58 void SetOverrideEnvForContainers(const Engines::KeyValDict& env) override;
60 Engines::KeyValDict *GetOverrideEnvForContainers() override;
62 void SetCodeOnContainerStartUp(const char *code) override;
67 void DeclareUsingSalomeSession() { _isSSL = false; }
69 CORBA::Long GetTimeOutToLaunchServerInSecond() override;
71 void SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond) override;
73 CORBA::Long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond() override;
75 void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) override;
77 CORBA::Long GetDeltaTimeBetweenCPUMemMeasureInMilliSecond() override;
79 void SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(CORBA::Long timeInMS) override;
81 void SetBigObjOnDiskThreshold(CORBA::Long thresholdInByte) override;
83 void SetBigObjOnDiskDirectory(const char *directory) override;
85 static const char *_ContainerManagerNameInNS;
89 void ShutdownContainersGeneric(std::function<void(Engines::Container_ptr)> funcToBeCalledOnContainer);
93 Engines::Container_ptr
94 FindContainer(const Engines::ContainerParameters& params,
95 const Engines::ResourceList& possibleResources);
97 Engines::Container_ptr
98 FindContainer(const Engines::ContainerParameters& params,
99 const std::string& resource);
101 std::string GetCppBinaryOfKernelSSLContainer() const;
103 std::string GetCppBinaryOfKernelContainer() const;
105 std::string GetRunRemoteExecutableScript() const;
107 std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
108 const Engines::ContainerParameters& params,
109 const std::string& container_exe="SALOME_Container") const;
111 std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
112 const std::string& machinesFile,
113 const std::string& container_exe,//"SALOME_Container"
114 std::string& tmpFileName) const;
116 std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
117 const Engines::ContainerParameters& params, std::string& tmpFileName) const;
119 static void RmTmpFile(std::string& tmpFile);
121 void AddOmninamesParams(std::string& command) const;
123 void AddOmninamesParams(std::ostream& fileStream) const;
125 static std::string BuildTemporaryFileName();
127 std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
129 std::string machinesFile(const int nbproc);
131 std::string getCommandToRunRemoteProcessCommon(const std::string& templateName, const std::string& remoteScript,
132 AccessProtocolType protocol,
133 const std::string & hostname,
134 const std::string & username,
135 const std::string & applipath,
136 const std::string & workdir) const;
138 std::string getCommandToRunRemoteProcess(AccessProtocolType protocol,
139 const std::string & hostname,
140 const std::string & username,
141 const std::string & applipath,
142 const std::string & workdir="") const;
144 std::string getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol,
145 const std::string & hostname,
146 const std::string & username,
147 const std::string & applipath,
148 const std::string & workdir="") const;
150 Engines::Container_ptr
151 LaunchContainer(const Engines::ContainerParameters& params,
152 const std::string & resource_selected,
153 const std::string & hostname,
154 const std::string & machFile,
155 const std::string & containerNameInNS);
158 PortableServer::POA_var _poa;
160 SALOME_ResourcesManager_Client *_resManager;
161 SALOME_NamingService_Abstract *_NS;
163 //! different behaviour if $APPLI exists (SALOME Application)
164 bool _isAppliSalomeDefined;
166 //! attribute that contains the number of processes used in batch mode by MPI containers
169 //! attribute that specifies the launch mode.
172 static omni_mutex _numInstanceMutex ; // lib and instance protection
174 //! attributes to allow concurrency for // GiveContainer
175 Utils_Mutex _giveContainerMutex1;
177 pid_t _pid_mpiServer;
179 // Begin of PacO++ Parallel extension
180 typedef std::vector<std::string> actual_launch_machine_t;
182 bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
184 Engines::Container_ptr
185 StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
189 std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
190 std::string machine_file_name,
191 std::string & proxy_hostname);
193 std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
194 const std::string & machine_file_name,
195 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
196 const std::string & proxy_hostname);
198 void LogConfiguration(const std::string & log_type,
199 const std::string & exe_type,
200 const std::string & container_name,
201 const std::string & hostname,
206 LaunchPaCOProxyContainer(const std::string& command,
207 const Engines::ContainerParameters& params,
208 const std::string& hostname);
211 LaunchPaCONodeContainer(const std::string& command,
212 const Engines::ContainerParameters& params,
213 const std::string& name,
214 SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
215 // End of PaCO++ Parallel extension
217 static char *GetenvThreadSafe(const char *name);
218 static std::string GetenvThreadSafeAsString(const char *name);
219 static int SystemThreadSafe(const char *command);
220 static long SystemWithPIDThreadSafe(const std::vector<std::string>& command);
221 static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns);
222 static void MakeTheCommandToBeLaunchedASync(std::string& command);
223 static int GetTimeOutToLoaunchServer();
224 static void SleepInSecond(int ellapseTimeInSecond);
226 static const int TIME_OUT_TO_LAUNCH_CONT;
227 static const int DFT_DELTA_TIME_NS_LOOKUP_IN_MS;
228 static Utils_Mutex _getenvMutex;
229 static Utils_Mutex _systemMutex;
231 std::vector< std::pair<std::string, std::string> > _override_env;
232 int _time_out_in_second;
233 int _delta_time_ns_lookup_in_ms;
234 int _delta_time_measure_in_ms;
235 std::string _code_to_exe_on_startup;