1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, 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"
38 class SALOME_NamingService;
39 class SALOME_ResourcesManager_Client;
41 class CONTAINER_EXPORT SALOME_ContainerManager : public POA_Engines::ContainerManager
45 SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns);
46 ~SALOME_ContainerManager();
49 Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params);
51 void ShutdownContainers();
56 static const char *_ContainerManagerNameInNS;
60 Engines::Container_ptr
61 FindContainer(const Engines::ContainerParameters& params,
62 const Engines::ResourceList& possibleResources);
64 Engines::Container_ptr
65 FindContainer(const Engines::ContainerParameters& params,
66 const std::string& resource);
68 std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
69 const Engines::ContainerParameters& params,
70 const std::string& container_exe="SALOME_Container") const;
72 std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
73 const std::string& machinesFile,
74 const std::string& container_exe,//"SALOME_Container"
75 std::string& tmpFileName) const;
77 std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
78 const Engines::ContainerParameters& params, std::string& tmpFileName) const;
80 static void RmTmpFile(std::string& tmpFile);
82 void AddOmninamesParams(std::string& command) const;
84 void AddOmninamesParams(std::ostream& fileStream) const;
86 static std::string BuildTemporaryFileName();
88 std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
90 std::string machinesFile(const int nbproc);
92 static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol,
93 const std::string & hostname,
94 const std::string & username,
95 const std::string & applipath,
96 const std::string & workdir="");
98 Engines::Container_ptr
99 LaunchContainer(const Engines::ContainerParameters& params,
100 const std::string & resource_selected,
101 const std::string & hostname,
102 const std::string & machFile,
103 const std::string & containerNameInNS);
106 PortableServer::POA_var _poa;
108 SALOME_ResourcesManager_Client *_resManager;
109 SALOME_NamingService *_NS;
111 //! different behaviour if $APPLI exists (SALOME Application)
112 bool _isAppliSalomeDefined;
114 //! attribute that contains the number of processes used in batch mode by MPI containers
117 static omni_mutex _numInstanceMutex ; // lib and instance protection
119 //! attributes to allow concurrency for // GiveContainer
120 Utils_Mutex _giveContainerMutex1;
122 pid_t _pid_mpiServer;
124 // Begin of PacO++ Parallel extension
125 typedef std::vector<std::string> actual_launch_machine_t;
127 bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
129 Engines::Container_ptr
130 StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
134 std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
135 std::string machine_file_name,
136 std::string & proxy_hostname);
138 std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
139 const std::string & machine_file_name,
140 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
141 const std::string & proxy_hostname);
143 void LogConfiguration(const std::string & log_type,
144 const std::string & exe_type,
145 const std::string & container_name,
146 const std::string & hostname,
151 LaunchPaCOProxyContainer(const std::string& command,
152 const Engines::ContainerParameters& params,
153 const std::string& hostname);
156 LaunchPaCONodeContainer(const std::string& command,
157 const Engines::ContainerParameters& params,
158 const std::string& name,
159 SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
160 // End of PaCO++ Parallel extension
162 static char *GetenvThreadSafe(const char *name);
163 static std::string GetenvThreadSafeAsString(const char *name);
164 static int SystemThreadSafe(const char *command);
165 static long SystemWithPIDThreadSafe(const std::vector<std::string>& command);
166 static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns);
167 static void MakeTheCommandToBeLaunchedASync(std::string& command);
168 static int GetTimeOutToLoaunchServer();
169 static void SleepInSecond(int ellapseTimeInSecond);
171 static const int TIME_OUT_TO_LAUNCH_CONT;
172 static Utils_Mutex _getenvMutex;
173 static Utils_Mutex _systemMutex;