]> SALOME platform Git repositories - modules/kernel.git/blob - src/Container/SALOME_ContainerManager.hxx
Salome HOME
YACS in SSL mode
[modules/kernel.git] / src / Container / SALOME_ContainerManager.hxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef __SALOME_CONTAINERMANAGER_HXX__
24 #define __SALOME_CONTAINERMANAGER_HXX__
25
26 #include "SALOME_Container.hxx"
27
28 #include <SALOMEconfig.h>
29 #include CORBA_CLIENT_HEADER(SALOME_Component)
30 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
31 #include "SALOME_ResourcesCatalog_Parser.hxx"
32
33 #include "Utils_Mutex.hxx"
34
35 #include <string>
36 #include <set>
37
38 class SALOME_NamingService_Abstract;
39 class SALOME_ResourcesManager_Client;
40
41 class CONTAINER_EXPORT SALOME_ContainerManager : public POA_Engines::ContainerManager
42 {
43
44 public:
45   SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns);
46   ~SALOME_ContainerManager();
47
48   // Corba Methods
49   Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params);
50
51   void ShutdownContainers();
52
53   // C++ Methods
54   void Shutdown();
55
56   void DeclareUsingSalomeSession() { _isSSL = false; }
57
58   static const char *_ContainerManagerNameInNS;
59
60 protected:
61   // C++ methods
62   Engines::Container_ptr
63   FindContainer(const Engines::ContainerParameters& params,
64                 const Engines::ResourceList& possibleResources);
65
66   Engines::Container_ptr
67   FindContainer(const Engines::ContainerParameters& params,
68                 const std::string& resource);
69
70   std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
71                                                   const Engines::ContainerParameters& params,
72                                                   const std::string& container_exe="SALOME_Container") const;
73
74   std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
75                                                  const std::string& machinesFile,
76                                                  const std::string& container_exe,//"SALOME_Container"
77                                                  std::string& tmpFileName) const;
78
79   std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
80                                                    const Engines::ContainerParameters& params, std::string& tmpFileName) const;
81
82   static void RmTmpFile(std::string& tmpFile);
83
84   void AddOmninamesParams(std::string& command) const;
85
86   void AddOmninamesParams(std::ostream& fileStream) const;
87
88   static std::string BuildTemporaryFileName();
89
90   std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
91
92   std::string machinesFile(const int nbproc);
93
94  static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, 
95                                                  const std::string & hostname, 
96                                                  const std::string & username,
97                                                  const std::string & applipath,
98                                                  const std::string & workdir="");
99
100   Engines::Container_ptr
101   LaunchContainer(const Engines::ContainerParameters& params,
102                   const std::string & resource_selected,
103                   const std::string & hostname,
104                   const std::string & machFile,
105                   const std::string & containerNameInNS);
106
107   CORBA::ORB_var _orb;
108   PortableServer::POA_var _poa;
109
110   SALOME_ResourcesManager_Client *_resManager;
111   SALOME_NamingService_Abstract *_NS;
112
113   //! different behaviour if $APPLI exists (SALOME Application)
114   bool _isAppliSalomeDefined;
115
116   //! attribute that contains the number of processes used in batch mode by MPI containers
117   int _nbprocUsed;
118
119   //! attribute that specifies the launch mode.
120   bool _isSSL = true;
121
122   static omni_mutex _numInstanceMutex ; // lib and instance protection
123
124   //! attributes to allow concurrency for // GiveContainer
125   Utils_Mutex _giveContainerMutex1;
126
127   pid_t _pid_mpiServer;
128
129   // Begin of PacO++ Parallel extension
130   typedef std::vector<std::string> actual_launch_machine_t;
131
132   bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
133
134   Engines::Container_ptr
135   StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
136
137
138
139   std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
140                                                      std::string machine_file_name,
141                                                      std::string & proxy_hostname);
142
143   std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
144                                                     const std::string & machine_file_name,
145                                                     SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
146                                                     const std::string & proxy_hostname);
147
148   void LogConfiguration(const std::string & log_type,
149                         const std::string & exe_type,
150                         const std::string & container_name,
151                         const std::string & hostname,
152                         std::string & begin,
153                         std::string & end);
154
155   CORBA::Object_ptr
156   LaunchPaCOProxyContainer(const std::string& command,
157                            const Engines::ContainerParameters& params,
158                            const std::string& hostname);
159
160   bool
161   LaunchPaCONodeContainer(const std::string& command,
162                           const Engines::ContainerParameters& params,
163                           const std::string& name,
164                           SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
165   // End of PaCO++ Parallel extension
166 public:
167   static char *GetenvThreadSafe(const char *name);
168   static std::string GetenvThreadSafeAsString(const char *name);
169   static int SystemThreadSafe(const char *command);
170   static long SystemWithPIDThreadSafe(const std::vector<std::string>& command);
171   static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns);
172   static void MakeTheCommandToBeLaunchedASync(std::string& command);
173   static int GetTimeOutToLoaunchServer();
174   static void SleepInSecond(int ellapseTimeInSecond);
175  private:
176   static const int TIME_OUT_TO_LAUNCH_CONT;
177   static Utils_Mutex _getenvMutex;
178   static Utils_Mutex _systemMutex;
179 };
180 #endif