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 GetCppBinaryOfKernelContainer() const;
99 std::string GetRunRemoteExecutableScript() const;
101 std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
102 const Engines::ContainerParameters& params,
103 const std::string& container_exe="SALOME_Container") const;
105 std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
106 const std::string& machinesFile,
107 const std::string& container_exe,//"SALOME_Container"
108 std::string& tmpFileName) const;
110 std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
111 const Engines::ContainerParameters& params, std::string& tmpFileName) const;
113 static void RmTmpFile(std::string& tmpFile);
115 void AddOmninamesParams(std::string& command) const;
117 void AddOmninamesParams(std::ostream& fileStream) const;
119 static std::string BuildTemporaryFileName();
121 std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
123 std::string machinesFile(const int nbproc);
125 std::string getCommandToRunRemoteProcessCommon(const std::string& templateName, const std::string& remoteScript,
126 AccessProtocolType protocol,
127 const std::string & hostname,
128 const std::string & username,
129 const std::string & applipath,
130 const std::string & workdir) const;
132 std::string getCommandToRunRemoteProcess(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 getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol,
139 const std::string & hostname,
140 const std::string & username,
141 const std::string & applipath,
142 const std::string & workdir="") const;
144 Engines::Container_ptr
145 LaunchContainer(const Engines::ContainerParameters& params,
146 const std::string & resource_selected,
147 const std::string & hostname,
148 const std::string & machFile,
149 const std::string & containerNameInNS);
152 PortableServer::POA_var _poa;
154 SALOME_ResourcesManager_Client *_resManager;
155 SALOME_NamingService_Abstract *_NS;
157 //! different behaviour if $APPLI exists (SALOME Application)
158 bool _isAppliSalomeDefined;
160 //! attribute that contains the number of processes used in batch mode by MPI containers
163 //! attribute that specifies the launch mode.
166 static omni_mutex _numInstanceMutex ; // lib and instance protection
168 //! attributes to allow concurrency for // GiveContainer
169 Utils_Mutex _giveContainerMutex1;
171 pid_t _pid_mpiServer;
173 // Begin of PacO++ Parallel extension
174 typedef std::vector<std::string> actual_launch_machine_t;
176 bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
178 Engines::Container_ptr
179 StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
183 std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
184 std::string machine_file_name,
185 std::string & proxy_hostname);
187 std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
188 const std::string & machine_file_name,
189 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
190 const std::string & proxy_hostname);
192 void LogConfiguration(const std::string & log_type,
193 const std::string & exe_type,
194 const std::string & container_name,
195 const std::string & hostname,
200 LaunchPaCOProxyContainer(const std::string& command,
201 const Engines::ContainerParameters& params,
202 const std::string& hostname);
205 LaunchPaCONodeContainer(const std::string& command,
206 const Engines::ContainerParameters& params,
207 const std::string& name,
208 SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
209 // End of PaCO++ Parallel extension
211 static char *GetenvThreadSafe(const char *name);
212 static std::string GetenvThreadSafeAsString(const char *name);
213 static int SystemThreadSafe(const char *command);
214 static long SystemWithPIDThreadSafe(const std::vector<std::string>& command);
215 static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns);
216 static void MakeTheCommandToBeLaunchedASync(std::string& command);
217 static int GetTimeOutToLoaunchServer();
218 static void SleepInSecond(int ellapseTimeInSecond);
220 static const int TIME_OUT_TO_LAUNCH_CONT;
221 static const int DFT_DELTA_TIME_NS_LOOKUP_IN_MS;
222 static Utils_Mutex _getenvMutex;
223 static Utils_Mutex _systemMutex;
225 std::vector< std::pair<std::string, std::string> > _override_env;
226 int _time_out_in_second;
227 int _delta_time_ns_lookup_in_ms;
228 int _delta_time_measure_in_ms;
229 std::string _code_to_exe_on_startup;