Version: 8.3.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
SALOME_ContainerManager.hxx
1 // Copyright (C) 2007-2016 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 
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 *ns);
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  static const char *_ContainerManagerNameInNS;
57 
58 protected:
59  // C++ methods
60  Engines::Container_ptr
61  FindContainer(const Engines::ContainerParameters& params,
62  const Engines::ResourceList& possibleResources);
63 
64  Engines::Container_ptr
65  FindContainer(const Engines::ContainerParameters& params,
66  const std::string& resource);
67 
68  std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
69  const Engines::ContainerParameters& params,
70  const std::string& container_exe="SALOME_Container") const;
71 
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;
76 
77  std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
78  const Engines::ContainerParameters& params, std::string& tmpFileName) const;
79 
80  static void RmTmpFile(std::string& tmpFile);
81 
82  void AddOmninamesParams(std::string& command) const;
83 
84  void AddOmninamesParams(std::ostream& fileStream) const;
85 
86  static std::string BuildTemporaryFileName();
87 
88  std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
89 
90  std::string machinesFile(const int nbproc);
91 
92  std::set<pid_t> getpidofprogram(const std::string program);
93 
94  static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username);
95 
96  Engines::Container_ptr
97  LaunchContainer(const Engines::ContainerParameters& params,
98  const std::string & resource_selected,
99  const std::string & hostname,
100  const std::string & machFile,
101  const std::string & containerNameInNS);
102 
103  CORBA::ORB_var _orb;
104  PortableServer::POA_var _poa;
105 
106  SALOME_ResourcesManager_Client *_resManager;
108 
111 
114 
115  static omni_mutex _numInstanceMutex ; // lib and instance protection
116 
119 
120  pid_t _pid_mpiServer;
121 
122  // Begin of PacO++ Parallel extension
123  typedef std::vector<std::string> actual_launch_machine_t;
124 
125  bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
126 
127  Engines::Container_ptr
128  StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
129 
130 
131 
132  std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
133  std::string machine_file_name,
134  std::string & proxy_hostname);
135 
136  std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
137  const std::string & machine_file_name,
138  SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
139  const std::string & proxy_hostname);
140 
141  void LogConfiguration(const std::string & log_type,
142  const std::string & exe_type,
143  const std::string & container_name,
144  const std::string & hostname,
145  std::string & begin,
146  std::string & end);
147 
148  CORBA::Object_ptr
149  LaunchPaCOProxyContainer(const std::string& command,
150  const Engines::ContainerParameters& params,
151  const std::string& hostname);
152 
153  bool
154  LaunchPaCONodeContainer(const std::string& command,
155  const Engines::ContainerParameters& params,
156  const std::string& name,
157  SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
158  // End of PaCO++ Parallel extension
159 public:
160  static char *GetenvThreadSafe(const char *name);
161  static std::string GetenvThreadSafeAsString(const char *name);
162  static int SystemThreadSafe(const char *command);
163  static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns);
164  static void MakeTheCommandToBeLaunchedASync(std::string& command);
165  static int GetTimeOutToLoaunchServer();
166  static void SleepInSecond(int ellapseTimeInSecond);
167  private:
168  static const int TIME_OUT_TO_LAUNCH_CONT;
169  static Utils_Mutex _getenvMutex;
170  static Utils_Mutex _systemMutex;
171 };
172 #endif