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 static const char *_ContainerManagerNameInNS;
85 void ShutdownContainersGeneric(std::function<void(Engines::Container_ptr)> funcToBeCalledOnContainer);
89 Engines::Container_ptr
90 FindContainer(const Engines::ContainerParameters& params,
91 const Engines::ResourceList& possibleResources);
93 Engines::Container_ptr
94 FindContainer(const Engines::ContainerParameters& params,
95 const std::string& resource);
97 std::string GetCppBinaryOfKernelSSLContainer() const;
99 std::string GetCppBinaryOfKernelContainer() const;
101 std::string GetRunRemoteExecutableScript() const;
103 std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
104 const Engines::ContainerParameters& params,
105 const std::string& container_exe="SALOME_Container") const;
107 std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
108 const std::string& machinesFile,
109 const std::string& container_exe,//"SALOME_Container"
110 std::string& tmpFileName) const;
112 std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
113 const Engines::ContainerParameters& params, std::string& tmpFileName) const;
115 static void RmTmpFile(std::string& tmpFile);
117 void AddOmninamesParams(std::string& command) const;
119 void AddOmninamesParams(std::ostream& fileStream) const;
121 static std::string BuildTemporaryFileName();
123 std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
125 std::string machinesFile(const int nbproc);
127 std::string getCommandToRunRemoteProcessCommon(const std::string& templateName, const std::string& remoteScript,
128 AccessProtocolType protocol,
129 const std::string & hostname,
130 const std::string & username,
131 const std::string & applipath,
132 const std::string & workdir) const;
134 std::string getCommandToRunRemoteProcess(AccessProtocolType protocol,
135 const std::string & hostname,
136 const std::string & username,
137 const std::string & applipath,
138 const std::string & workdir="") const;
140 std::string getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol,
141 const std::string & hostname,
142 const std::string & username,
143 const std::string & applipath,
144 const std::string & workdir="") const;
146 Engines::Container_ptr
147 LaunchContainer(const Engines::ContainerParameters& params,
148 const std::string & resource_selected,
149 const std::string & hostname,
150 const std::string & machFile,
151 const std::string & containerNameInNS);
154 PortableServer::POA_var _poa;
156 SALOME_ResourcesManager_Client *_resManager;
157 SALOME_NamingService_Abstract *_NS;
159 //! different behaviour if $APPLI exists (SALOME Application)
160 bool _isAppliSalomeDefined;
162 //! attribute that contains the number of processes used in batch mode by MPI containers
165 //! attribute that specifies the launch mode.
168 static omni_mutex _numInstanceMutex ; // lib and instance protection
170 //! attributes to allow concurrency for // GiveContainer
171 Utils_Mutex _giveContainerMutex1;
173 pid_t _pid_mpiServer;
175 // Begin of PacO++ Parallel extension
176 typedef std::vector<std::string> actual_launch_machine_t;
178 bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
180 Engines::Container_ptr
181 StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
185 std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
186 std::string machine_file_name,
187 std::string & proxy_hostname);
189 std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
190 const std::string & machine_file_name,
191 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
192 const std::string & proxy_hostname);
194 void LogConfiguration(const std::string & log_type,
195 const std::string & exe_type,
196 const std::string & container_name,
197 const std::string & hostname,
202 LaunchPaCOProxyContainer(const std::string& command,
203 const Engines::ContainerParameters& params,
204 const std::string& hostname);
207 LaunchPaCONodeContainer(const std::string& command,
208 const Engines::ContainerParameters& params,
209 const std::string& name,
210 SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
211 // End of PaCO++ Parallel extension
213 static char *GetenvThreadSafe(const char *name);
214 static std::string GetenvThreadSafeAsString(const char *name);
215 static int SystemThreadSafe(const char *command);
216 static long SystemWithPIDThreadSafe(const std::vector<std::string>& command);
217 static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns);
218 static void MakeTheCommandToBeLaunchedASync(std::string& command);
219 static int GetTimeOutToLoaunchServer();
220 static void SleepInSecond(int ellapseTimeInSecond);
222 static const int TIME_OUT_TO_LAUNCH_CONT;
223 static const int DFT_DELTA_TIME_NS_LOOKUP_IN_MS;
224 static Utils_Mutex _getenvMutex;
225 static Utils_Mutex _systemMutex;
227 std::vector< std::pair<std::string, std::string> > _override_env;
228 int _time_out_in_second;
229 int _delta_time_ns_lookup_in_ms;
230 int _delta_time_measure_in_ms;
231 std::string _code_to_exe_on_startup;