Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesManager.hxx
1 #ifndef __SALOME_RESOURCESMANAGER_HXX__
2 #define __SALOME_RESOURCESMANAGER_HXX__
3
4 #include "Utils_SALOME_Exception.hxx"
5 #include "utilities.h"
6 #include <SALOMEconfig.h>
7 #include "SALOME_ResourcesCatalog_Handler.hxx"
8 #include "SALOME_LoadRateManager.hxx"
9 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
10 #include <string>
11 #include <fstream>
12 #include <vector>
13
14 //WARNING the call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done in a critical section to be sure to be clean.
15 //Only one thread should use the SALOME_ResourcesManager class in a SALOME session.
16
17 class SALOME_ResourcesManager
18 {
19 public:
20   //! standard constructor
21   SALOME_ResourcesManager();
22
23   //!just for test
24   SALOME_ResourcesManager(const char *xmlFilePath);
25   
26   //! standard destructor
27   ~SALOME_ResourcesManager();
28
29   //! method to get the list of name of ressources fitting for the specified module.
30   std::vector<std::string> GetFittingResources(const Engines::MachineParameters& params,const char *moduleName) throw(SALOME_Exception);
31
32   //! method to dynamically obtain the best machines
33   std::string FindBest(const Engines::MachineList& listOfMachines);
34
35   //! method that builds in a temporary file the script to be launched
36   std::string BuildTempFileToLaunchRemoteContainer(const std::string& machine,const char *containerName);
37
38   //! method that builds the command to be launched.
39   std::string BuildCommandToLaunchLocalContainer(const char *containerName);
40
41   //! method that remove the generated temporary file in case of a remote launch.
42   void RmTmpFile();
43
44   //! method that builds the script to be launched
45   std::string BuildCommand(const std::string& machine,const char *containerName);
46
47   //! add an entry in the ressources catalog  xml file. Return 1 if OK. Return 0 if the ressource with the same hostname already exists.
48   int AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources, const std::map<std::string,std::string>& modulesOnNewResources,
49                            const char *environPathOfPrerequired,
50                            const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception);
51   
52   //! delete a ressource from the Catalog.
53   void DeleteResourceInCatalog(const char *hostname);
54
55   //! write the current data in memory in file.
56   void WriteInXmlFile();
57
58   //! method to parse the data type catalog
59   const MapOfParserResourcesType& ParseXmlFile();
60
61   //! to consult the content of the list
62   const MapOfParserResourcesType& GetList() const;
63
64 private:
65
66   //! method to verify ressources catalog content - return true if verfication is OK
67   bool _verify_resources(MapOfParserResourcesType resourceslist);
68
69   //! method that fill hosts with only resources in xml files that are on the specified OS
70   void SelectOnlyResourcesWithOS(std::vector<std::string>& hosts,const char *OS) const throw(SALOME_Exception);
71
72   //! method that keep from hosts only those having component of name moduleName.
73   void KeepOnlyResourcesWithModule(std::vector<std::string>& hosts,const char *moduleName) const throw(SALOME_Exception);
74
75   //! methode that add to command all options relative to naming service.
76   void AddOmninamesParams(std::string& command) const;
77
78   //! method that add to command all options relative to naming service.
79   void AddOmninamesParams(std::ofstream& fileStream) const;
80
81   //! method that generate a file name in /tmp directory
82   std::string BuildTemporaryFileName() const;
83
84   // will contain the path to the ressources catalog
85   QString _path_resources;
86
87   //! attribute that contains current tmp files generated
88   std::string _TmpFileName;
89
90   //! attribute that contains the rsh or ssh command to access directly to machine. Only used by this->RmTmpFile in case of a remote launch.
91   std::string _CommandForRemAccess;
92   
93   //will contain the informations on the data type catalog(after parsing)
94   MapOfParserResourcesType _resourcesList;
95
96   SALOME_LoadRateManager _dynamicResourcesSelecter;
97 };
98
99 #endif // RESSOURCESCATALOG_IMPL_H