Salome HOME
7b1f26eab23e6d971d7fb4603b2a22758ac68b00
[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   Engines::Container_ptr
46   FindOrStartContainer(const Engines::MachineParameters& params,
47                        const Engines::MachineList& possibleComputer);
48
49   Engines::Container_ptr
50   StartContainer(const Engines::MachineParameters& params,
51                  const Engines::MachineList& possibleComputer,
52                  Engines::ResPolicy policy,
53      const std::string& container_exe="SALOME_Container");
54
55   Engines::Container_ptr
56   StartContainer(const Engines::MachineParameters& params,
57                 Engines::ResPolicy policy,
58                 const Engines::CompoList& componentList);
59
60   Engines::Container_ptr
61   GiveContainer(const Engines::MachineParameters& params,
62                 Engines::ResPolicy policy,
63                 const Engines::CompoList& componentList);
64
65   void Shutdown();
66   void ShutdownContainers();
67
68   static const char *_ContainerManagerNameInNS;
69
70   // Parallel extension
71   Engines::Container_ptr
72   FindOrStartParallelContainer(const Engines::MachineParameters& params,
73                                const Engines::MachineList& possibleComputer);
74 protected:
75   Engines::Container_ptr
76   FindContainer(const Engines::MachineParameters& params,
77                 const Engines::MachineList& possibleComputers);
78
79   Engines::Container_ptr
80   FindContainer(const Engines::MachineParameters& params,
81                 const char *theMachine);
82
83   // Parallel extension
84   CORBA::Object_ptr 
85   LaunchParallelContainer(const std::string& command, 
86                           const Engines::MachineParameters& params,
87                           const std::string& name);
88
89   void fillBatchLaunchedContainers();
90
91   long GetIdForContainer(void);
92
93   std::string BuildCommandToLaunchRemoteContainer(const std::string& machine,
94                                                   const Engines::MachineParameters& params, const long id,
95               const std::string& container_exe="SALOME_Container");
96
97   std::string BuildCommandToLaunchLocalContainer(const Engines::MachineParameters& params, const long id,
98                                                  const std::string& container_exe="SALOME_Container");
99
100   std::string BuildTempFileToLaunchRemoteContainer(const std::string& machine,
101                                                    const Engines::MachineParameters& params) throw(SALOME_Exception);
102
103   void RmTmpFile();
104
105   void AddOmninamesParams(std::string& command) const;
106
107   void AddOmninamesParams(std::ofstream& fileStream) const;
108
109   std::string BuildTemporaryFileName() const;
110
111   // Parallel extension
112   std::string BuildCommandToLaunchLocalParallelContainer(const std::string& exe_name, 
113                                                          const Engines::MachineParameters& params, 
114                                                          const std::string& log = "default");
115   void startMPI();
116   bool _MpiStarted;
117
118   long _id;
119   CORBA::ORB_var _orb;
120   PortableServer::POA_var _poa;
121
122   SALOME_ResourcesManager *_ResManager;
123   SALOME_NamingService *_NS;
124   static std::vector<Engines::Container_ptr> _batchLaunchedContainers;
125   static std::vector<Engines::Container_ptr>::iterator _batchLaunchedContainersIter;
126
127   //! attribute that contains current tmp files generated
128   std::string _TmpFileName;
129
130   //! contains the rsh or ssh command to access directly to machine.
131   //  Only used by this->RmTmpFile in case of a remote launch.
132   std::string _CommandForRemAccess;
133
134   //! different behaviour if $APPLI exists (SALOME Application) 
135   bool _isAppliSalomeDefined;
136
137 };
138 #endif