Salome HOME
- New Version with PaCO++
[modules/kernel.git] / src / Container / SALOME_ContainerManager.hxx
1 //  Copyright (C) 2007-2008  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.
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 #ifndef __SALOME_CONTAINERMANAGER_HXX__
23 #define __SALOME_CONTAINERMANAGER_HXX__
24
25 #include "SALOME_Container.hxx"
26
27 #include <SALOMEconfig.h>
28 #include CORBA_CLIENT_HEADER(SALOME_Component)
29 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
30 #include "SALOME_ResourcesManager.hxx"
31 #include "SALOME_LoadRateManager.hxx"
32
33 #include <string>
34
35 class SALOME_NamingService;
36
37 class CONTAINER_EXPORT SALOME_ContainerManager:
38   public POA_Engines::ContainerManager
39 {
40
41 public:
42   SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns);
43   ~SALOME_ContainerManager();
44
45   // Corba Methods
46   Engines::Container_ptr
47   GiveContainer(const Engines::ContainerParameters& params);
48
49   void ShutdownContainers();
50
51   // C++ Methods
52   void Shutdown();
53
54   static const char *_ContainerManagerNameInNS;
55
56 protected:
57   // C++ methods
58   Engines::Container_ptr
59   FindContainer(const Engines::ContainerParameters& params,
60                 const Engines::ResourceList& possibleResources);
61
62   Engines::Container_ptr
63   FindContainer(const Engines::ContainerParameters& params,
64                 const std::string& resource);
65
66   std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
67                                                   const Engines::ContainerParameters& params, 
68                                                   const std::string& container_exe="SALOME_Container");
69
70   std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, 
71                                                  const std::string& machinesFile,
72                                                  const std::string& container_exe="SALOME_Container");
73
74   std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
75                                                    const Engines::ContainerParameters& params) throw(SALOME_Exception);
76
77   void RmTmpFile(std::string& tmpFile);
78
79   void AddOmninamesParams(std::string& command) const;
80
81   void AddOmninamesParams(std::ostringstream& oss) const;
82
83   void AddOmninamesParams(std::ofstream& fileStream) const;
84
85   std::string BuildTemporaryFileName() const;
86
87   std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile);
88
89   std::string machinesFile(const int nbproc);
90
91   CORBA::ORB_var _orb;
92   PortableServer::POA_var _poa;
93
94   SALOME_ResourcesManager *_ResManager;
95   SALOME_NamingService *_NS;
96
97   //! attribute that contains current tmp files generated
98   std::string _TmpFileName;
99
100   //! contains the rsh or ssh command to access directly to machine.
101   //  Only used by this->RmTmpFile in case of a remote launch.
102   std::string _CommandForRemAccess;
103
104   //! different behaviour if $APPLI exists (SALOME Application) 
105   bool _isAppliSalomeDefined;
106
107   //! attribute that contains the number of processes used in batch mode by MPI containers
108   int _nbprocUsed;
109
110   static omni_mutex _numInstanceMutex ; // lib and instance protection
111
112   // Begin of PacO++ Parallel extension
113   typedef std::vector<std::string> actual_launch_machine_t;
114
115   bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected);
116
117   Engines::Container_ptr 
118   StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected);
119
120
121
122   std::string BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
123                                                      std::string machine_file_name,
124                                                      std::string & proxy_hostname);
125
126   std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
127                                                     const std::string & machine_file_name,
128                                                     SALOME_ContainerManager::actual_launch_machine_t & vect_machine, 
129                                                     const std::string & proxy_hostname); 
130
131   void LogConfiguration(const std::string & log_type,
132                         const std::string & exe_type,
133                         const std::string & container_name,
134                         const std::string & hostname,
135                         std::string & begin, 
136                         std::string & end);
137
138   CORBA::Object_ptr 
139   LaunchPaCOProxyContainer(const std::string& command, 
140                            const Engines::ContainerParameters& params,
141                            const std::string& hostname);
142
143   bool 
144   LaunchPaCONodeContainer(const std::string& command, 
145                           const Engines::ContainerParameters& params,
146                           const std::string& name,
147                           SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
148   // End of PaCO++ Parallel extension
149 };
150 #endif