]> SALOME platform Git repositories - modules/yacs.git/blob - src/evalyfx/YACSEvalResource.hxx
Salome HOME
344d7648827d73c279b7a08866c94e30cf1912c3
[modules/yacs.git] / src / evalyfx / YACSEvalResource.hxx
1 // Copyright (C) 2012-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 // 
19 // Author : Anthony Geay (EDF R&D)
20
21 #ifndef __YACSEVALRESOURCE_HXX__
22 #define __YACSEVALRESOURCE_HXX__
23
24 #include "YACSEvalYFXExport.hxx"
25
26 #include <map>
27 #include <string>
28 #include <vector>
29
30 namespace YACS
31 {
32   namespace ENGINE
33   {
34     class Container;
35     class DeploymentTree;
36   }
37 }
38
39 class YACSEvalNonConstLocker
40 {
41 public:
42   YACSEVALYFX_EXPORT YACSEvalNonConstLocker():_isLocked(false) { }
43   YACSEVALYFX_EXPORT YACSEvalNonConstLocker(const YACSEvalNonConstLocker& other):_isLocked(false) { }
44   YACSEVALYFX_EXPORT void lock() { _isLocked=true; }
45   YACSEVALYFX_EXPORT bool isLocked() const { return _isLocked; }
46   YACSEVALYFX_EXPORT void checkNonLocked() const;
47 private:
48   bool _isLocked;
49 };
50
51 class ParserResourcesType;
52 class YACSEvalResource;
53
54 class YACSEvalVirtualYACSContainer : public YACSEvalNonConstLocker
55 {
56 public:
57   YACSEvalVirtualYACSContainer(YACSEvalResource *gf, YACS::ENGINE::Container *cont);
58   YACSEVALYFX_EXPORT ~YACSEvalVirtualYACSContainer();
59   YACSEVALYFX_EXPORT std::string getChosenMachine() const { return _chosenHost; }
60   YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
61   YACSEVALYFX_EXPORT std::vector<std::string> listOfPropertyKeys() const;
62   YACSEVALYFX_EXPORT std::string getValueOfKey(const char *key) const;
63   YACSEVALYFX_EXPORT void setProperty(const std::string& key, const std::string &value);
64   YACSEVALYFX_EXPORT void resetOverloadedProps() { checkNonLocked(); _overloadedPropertyMap.clear(); }
65   void apply();
66 public:
67   YACSEvalVirtualYACSContainer();
68   void set(YACSEvalResource *gf, YACS::ENGINE::Container *cont);
69   void aggregate(ParserResourcesType& entry) const;
70   void setMachineNoCheck(const std::string& machine) { checkNonLocked(); _chosenHost=machine; }
71   std::string findDefault(bool isInteractive) const;
72 private:
73   std::string getHostName() const { return getValueOfKey(HOSTNAME_KEY); }
74   unsigned int getMem() const { return getValueOfKeyUInt(MEM_KEY); }
75   unsigned int getNbNodes() const { return getValueOfKeyUInt(NB_NODE_KEY); }
76   unsigned int getCPUFreq() const { return getValueOfKeyUInt(CPU_CLOCK_KEY); }
77   unsigned int getNbProcPerNode() const { return getValueOfKeyUInt(NB_PROC_PER_NODE_KEY); }
78   unsigned int getValueOfKeyUInt(const char *key) const;
79   std::map<std::string,std::string> listOfPropertiesInYACSContainer() const;
80 public:
81   YACSEVALYFX_EXPORT static const char CONTAINER_NAME_KEY[];
82   YACSEVALYFX_EXPORT static const char CPU_CLOCK_KEY[];
83   YACSEVALYFX_EXPORT static const char HOSTNAME_KEY[];
84   YACSEVALYFX_EXPORT static const char MEM_KEY[];
85   YACSEVALYFX_EXPORT static const char NB_NODE_KEY[];
86   YACSEVALYFX_EXPORT static const char NB_PROC_PER_NODE_KEY[];
87   YACSEVALYFX_EXPORT static const char NB_RESOURCE_PROCS_KEY[];
88   YACSEVALYFX_EXPORT static const char POLICY_KEY[];
89   YACSEVALYFX_EXPORT static const char OS_KEY[];
90 private:
91   std::string _chosenHost;
92   //! list of properties that overloads.
93   std::map<std::string,std::string> _overloadedPropertyMap;
94   //! property map at the origin.
95   std::map<std::string,std::string> _propertyMap;
96   YACSEvalResource *_gf;
97   YACS::ENGINE::Container *_cont;
98 };
99
100 class YACSEvalListOfResources;
101
102 class YACSEvalResource : public YACSEvalNonConstLocker
103 {
104 public:
105   YACSEVALYFX_EXPORT virtual ~YACSEvalResource();
106   YACSEVALYFX_EXPORT std::vector<std::string> getAllChosenMachines() const;
107   YACSEVALYFX_EXPORT std::vector<std::string> getAllFittingMachines() const;
108   YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
109   YACSEVALYFX_EXPORT std::size_t size() const { return _containers.size(); }
110   YACSEVALYFX_EXPORT YACSEvalVirtualYACSContainer *at(std::size_t i) const;
111   YACSEVALYFX_EXPORT void apply();
112 public:
113   void fitWithCurrentCatalogAbs();
114   void aggregate(ParserResourcesType& entry) const;
115   YACSEvalListOfResources *getGodFather() const { return _gf; }
116   void notifyWantedMachine(YACSEvalVirtualYACSContainer *sender, const std::string& oldMachine, const std::string& newMachine);
117   void setMachineNoCheck(const std::string& machine);
118 protected:
119   YACSEvalResource(YACSEvalListOfResources *gf, const std::vector< YACS::ENGINE::Container * >& conts);
120 protected:
121   YACSEvalListOfResources *_gf;
122   std::vector< YACSEvalVirtualYACSContainer > _containers;
123 };
124
125 class ResourcesManager_cpp;
126
127 class YACSEvalListOfResources : public YACSEvalNonConstLocker
128 {
129 public:
130   YACSEvalListOfResources(int maxLevOfPara, ResourcesManager_cpp *rm, const YACS::ENGINE::DeploymentTree& dt);
131   YACSEVALYFX_EXPORT std::vector<std::string> getAllChosenMachines() const;
132   YACSEVALYFX_EXPORT std::vector<std::string> getAllFittingMachines() const;
133   YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
134   YACSEVALYFX_EXPORT std::size_t size() const { return _resources.size(); }
135   YACSEVALYFX_EXPORT YACSEvalResource *at(std::size_t i) const;
136   YACSEVALYFX_EXPORT bool isInteractive() const;
137   YACSEVALYFX_EXPORT unsigned int getNumberOfProcsDeclared() const;
138   void apply();
139   YACSEVALYFX_EXPORT ~YACSEvalListOfResources();
140 public:
141   ResourcesManager_cpp *getCatalogEntry() const { return _rm; }
142   YACS::ENGINE::DeploymentTree *getDeploymentTree() const { return _dt; }
143   int getMaxLevelOfParallelism() const { return _maxLevOfPara; }
144   std::vector<std::string> getFittingResources(ParserResourcesType *request) const;
145   void notifyWantedMachine(YACSEvalVirtualYACSContainer *sender, const std::string& oldMachine, const std::string& newMachine);
146   bool hasRightInteractiveStatus(const std::string& machineToTest, bool isInteractive) const;
147 private:
148   void fitWithCurrentCatalog();
149   unsigned int getNumberOfProcOfResource(const std::string& machine) const;
150 private:
151   ResourcesManager_cpp *_rm;
152   int _maxLevOfPara;
153   std::vector<YACSEvalResource *> _resources;
154   YACS::ENGINE::DeploymentTree *_dt;
155 };
156
157 #endif