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
25 #include "SALOME_Container.hxx"
27 #include <SALOMEconfig.h>
28 #include CORBA_CLIENT_HEADER(SALOME_Component)
29 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
30 #include "SALOME_ResourcesCatalog_Parser.hxx"
32 #include "Utils_Mutex.hxx"
40 class SALOME_NamingService_Abstract;
41 class SALOME_ResourcesManager_Client;
43 class CONTAINER_EXPORT SALOME_ContainerManager : public POA_Engines::ContainerManager
47 SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns);
48 ~SALOME_ContainerManager();
51 Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params) override;
53 void ShutdownContainers() override;
55 void ShutdownContainersNow() override;
57 void SetOverrideEnvForContainers(const Engines::KeyValDict& env) override;
59 Engines::KeyValDict *GetOverrideEnvForContainers() override;
61 void SetCodeOnContainerStartUp(const char *code) override;
63 char *GetCodeOnContainerStartUp() override;
68 void DeclareUsingSalomeSession() { _isSSL = false; }
70 CORBA::Long GetTimeOutToLaunchServerInSecond() override;
72 void SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond) override;
74 CORBA::Long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond() override;
76 void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) override;
78 CORBA::Long GetDeltaTimeBetweenCPUMemMeasureInMilliSecond() override;
80 void SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(CORBA::Long timeInMS) override;
82 void SetBigObjOnDiskThreshold(CORBA::Long thresholdInByte) override;
84 void SetBigObjOnDiskDirectory(const char *directory) override;
86 static const char *_ContainerManagerNameInNS;
90 void ShutdownContainersGeneric(std::function<void(Engines::Container_ptr)> funcToBeCalledOnContainer);
94 Engines::Container_ptr
95 FindContainer(const Engines::ContainerParameters& params,
96 const Engines::ResourceList& possibleResources);
98 Engines::Container_ptr
99 FindContainer(const Engines::ContainerParameters& params,
100 const std::string& resource);
102 std::string GetCppBinaryOfKernelSSLContainer() const;
104 std::string GetCppBinaryOfKernelContainer() const;
106 std::string GetRunRemoteExecutableScript() const;
108 std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
109 const Engines::ContainerParameters& params,
110 const std::string& container_exe="SALOME_Container") const;
112 std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
113 const std::string& machinesFile,
114 const std::string& container_exe,//"SALOME_Container"
115 std::string& tmpFileName) const;
117 std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
118 const Engines::ContainerParameters& params, std::string& tmpFileName) const;
120 static void RmTmpFile(std::string& tmpFile);
122 void AddOmninamesParams(std::string& command) const;
124 void AddOmninamesParams(std::ostream& fileStream) const;
126 static std::string BuildTemporaryFileName();
128 std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
130 std::string machinesFile(const int nbproc);
132 std::string getCommandToRunRemoteProcessCommon(const std::string& templateName, const std::string& remoteScript,
133 AccessProtocolType protocol,
134 const std::string & hostname,
135 const std::string & username,
136 const std::string & applipath,
137 const std::string & workdir) const;
139 std::string getCommandToRunRemoteProcess(AccessProtocolType protocol,
140 const std::string & hostname,
141 const std::string & username,
142 const std::string & applipath,
143 const std::string & workdir="") const;
145 std::string getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol,
146 const std::string & hostname,
147 const std::string & username,
148 const std::string & applipath,
149 const std::string & workdir="") const;
151 Engines::Container_ptr
152 LaunchContainer(const Engines::ContainerParameters& params,
153 const std::string & resource_selected,
154 const std::string & hostname,
155 const std::string & machFile,
156 const std::string & containerNameInNS);
159 PortableServer::POA_var _poa;
161 SALOME_ResourcesManager_Client *_resManager;
162 SALOME_NamingService_Abstract *_NS;
164 //! different behaviour if $APPLI exists (SALOME Application)
165 bool _isAppliSalomeDefined;
167 //! attribute that contains the number of processes used in batch mode by MPI containers
170 //! attribute that specifies the launch mode.
173 static omni_mutex _numInstanceMutex ; // lib and instance protection
175 //! attributes to allow concurrency for // GiveContainer
176 Utils_Mutex _giveContainerMutex1;
178 pid_t _pid_mpiServer;
180 // Begin of PacO++ Parallel extension
181 typedef std::vector<std::string> actual_launch_machine_t;
183 bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
185 Engines::Container_ptr
186 StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
190 std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
191 std::string machine_file_name,
192 std::string & proxy_hostname);
194 std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
195 const std::string & machine_file_name,
196 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
197 const std::string & proxy_hostname);
199 void LogConfiguration(const std::string & log_type,
200 const std::string & exe_type,
201 const std::string & container_name,
202 const std::string & hostname,
207 LaunchPaCOProxyContainer(const std::string& command,
208 const Engines::ContainerParameters& params,
209 const std::string& hostname);
212 LaunchPaCONodeContainer(const std::string& command,
213 const Engines::ContainerParameters& params,
214 const std::string& name,
215 SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
216 // End of PaCO++ Parallel extension
218 static char *GetenvThreadSafe(const char *name);
219 static std::string GetenvThreadSafeAsString(const char *name);
220 static int SystemThreadSafe(const char *command);
221 static long SystemWithPIDThreadSafe(const std::vector<std::string>& command);
222 static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns);
223 static void MakeTheCommandToBeLaunchedASync(std::string& command);
224 static int GetTimeOutToLoaunchServer();
225 static void SleepInSecond(int ellapseTimeInSecond);
227 static const int TIME_OUT_TO_LAUNCH_CONT;
228 static const int DFT_DELTA_TIME_NS_LOOKUP_IN_MS;
229 static Utils_Mutex _getenvMutex;
230 static Utils_Mutex _systemMutex;
232 std::vector< std::pair<std::string, std::string> > _override_env;
233 int _time_out_in_second;
234 int _delta_time_ns_lookup_in_ms;
235 int _delta_time_measure_in_ms;
236 std::string _code_to_exe_on_startup;