Salome HOME
Copyright update 2021
[modules/yacs.git] / src / evalyfx / YACSEvalResource.hxx
1 // Copyright (C) 2012-2021  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 #include <list>
30
31 #ifdef WIN32
32 #define NOMINMAX
33 #endif
34
35 namespace YACS
36 {
37   namespace ENGINE
38   {
39     class Container;
40     class DeploymentTree;
41   }
42 }
43
44 class YACSEvalNonConstLocker
45 {
46 public:
47   YACSEVALYFX_EXPORT YACSEvalNonConstLocker():_isLocked(false) { }
48   YACSEVALYFX_EXPORT YACSEvalNonConstLocker(const YACSEvalNonConstLocker& other):_isLocked(false) { }
49   YACSEVALYFX_EXPORT void lock() { _isLocked=true; }
50   YACSEVALYFX_EXPORT bool isLocked() const { return _isLocked; }
51   YACSEVALYFX_EXPORT void checkNonLocked() const;
52   YACSEVALYFX_EXPORT void checkLocked() const;
53 private:
54   bool _isLocked;
55 };
56
57 class ParserResourcesType;
58 class YACSEvalResource;
59
60 class YACSEvalVirtualYACSContainer : public YACSEvalNonConstLocker
61 {
62 public:
63   YACSEvalVirtualYACSContainer(YACSEvalResource *gf, YACS::ENGINE::Container *cont);
64   YACSEVALYFX_EXPORT ~YACSEvalVirtualYACSContainer();
65   YACSEVALYFX_EXPORT std::string getChosenMachine() const { return _chosenHost; }
66   YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
67   YACSEVALYFX_EXPORT std::vector<std::string> listOfPropertyKeys() const;
68   YACSEVALYFX_EXPORT std::string getValueOfKey(const char *key) const;
69   YACSEVALYFX_EXPORT void setProperty(const std::string& key, const std::string &value);
70   YACSEVALYFX_EXPORT void resetOverloadedProps() { checkNonLocked(); _overloadedPropertyMap.clear(); }
71   YACSEVALYFX_EXPORT std::string getName() const;
72   void apply(bool interactiveStatus);
73 public:
74   YACSEvalVirtualYACSContainer();
75   void set(YACSEvalResource *gf, YACS::ENGINE::Container *cont);
76   void aggregate(ParserResourcesType& entry) const;
77   void setMachineNoCheck(const std::string& machine) { checkNonLocked(); _chosenHost=machine; }
78   std::string findDefault(bool isInteractive) const;
79 private:
80   std::string getHostName() const { return getValueOfKey(HOSTNAME_KEY); }
81   unsigned int getMem() const { return getValueOfKeyUInt(MEM_KEY); }
82   unsigned int getNbNodes() const { return getValueOfKeyUInt(NB_NODE_KEY); }
83   unsigned int getCPUFreq() const { return getValueOfKeyUInt(CPU_CLOCK_KEY); }
84   unsigned int getNbProcPerNode() const { return getValueOfKeyUInt(NB_PROC_PER_NODE_KEY); }
85   unsigned int getValueOfKeyUInt(const char *key) const;
86   std::map<std::string,std::string> listOfPropertiesInYACSContainer() const;
87   void checkNotNullYACSContainer() const;
88 public:
89   static const char CONTAINER_NAME_KEY[];
90   static const char CPU_CLOCK_KEY[];
91   static const char HOSTNAME_KEY[];
92   static const char MEM_KEY[];
93   static const char NB_NODE_KEY[];
94   static const char NB_PROC_PER_NODE_KEY[];
95   static const char NB_RESOURCE_PROCS_KEY[];
96   static const char POLICY_KEY[];
97   static const char OS_KEY[];
98 private:
99   std::string _chosenHost;
100   //! list of properties that overloads.
101   std::map<std::string,std::string> _overloadedPropertyMap;
102   //! property map at the origin.
103   std::map<std::string,std::string> _propertyMap;
104   YACSEvalResource *_gf;
105   YACS::ENGINE::Container *_cont;
106 };
107
108 class YACSEvalListOfResources;
109
110 class YACSEvalResource : public YACSEvalNonConstLocker
111 {
112 public:
113   YACSEVALYFX_EXPORT virtual ~YACSEvalResource();
114   YACSEVALYFX_EXPORT std::vector<std::string> getAllChosenMachines() const;
115   YACSEVALYFX_EXPORT std::vector<std::string> getAllFittingMachines() const;
116   YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
117   YACSEVALYFX_EXPORT std::size_t size() const { return _containers.size(); }
118   YACSEVALYFX_EXPORT YACSEvalVirtualYACSContainer *at(std::size_t i) const;
119   YACSEVALYFX_EXPORT void apply(bool interactiveStatus);
120 public:
121   void fitWithCurrentCatalogAbs();
122   void aggregate(ParserResourcesType& entry) const;
123   YACSEvalListOfResources *getGodFather() const { return _gf; }
124   void notifyWantedMachine(YACSEvalVirtualYACSContainer *sender, const std::string& oldMachine, const std::string& newMachine);
125   void setMachineNoCheck(const std::string& machine);
126 protected:
127   YACSEvalResource(YACSEvalListOfResources *gf, const std::vector< YACS::ENGINE::Container * >& conts);
128 protected:
129   YACSEvalListOfResources *_gf;
130   std::vector< YACSEvalVirtualYACSContainer > _containers;
131 };
132
133 class ResourcesManager_cpp;
134
135 class YACSEvalParamsForCluster
136 {
137 public:
138   YACSEvalParamsForCluster():_exclusiveness(false),_nbOfProcs(1) { }
139   bool getExclusiveness() const { return _exclusiveness; }
140   YACSEVALYFX_EXPORT void setExclusiveness(bool newStatus);
141   std::string getRemoteWorkingDir() const { return _remoteWorkingDir; }
142   void setRemoteWorkingDir(const std::string& remoteWorkingDir) { _remoteWorkingDir=remoteWorkingDir; }
143   std::string getLocalWorkingDir() const { return _localWorkingDir; }
144   void setLocalWorkingDir(const std::string& localWorkingDir) { _localWorkingDir=localWorkingDir; }
145   std::string getWCKey() const { return _wcKey; }
146   void setWCKey(const std::string& wcKey) { _wcKey=wcKey; }
147   unsigned int getNbProcs() const { return _nbOfProcs; }
148   void setNbProcs(unsigned int nbProcs) { _nbOfProcs=nbProcs; }
149   void setMaxDuration(const std::string& maxDuration) { _maxDuration=maxDuration; }
150   std::string getMaxDuration() const { return _maxDuration; }
151   std::list<std::string>& getInFiles(){ return _in_files;}
152   const std::list<std::string>& getInFiles()const { return _in_files;}
153   YACSEVALYFX_EXPORT void checkConsistency() const;
154 private:
155   bool _exclusiveness;
156   std::string _remoteWorkingDir;
157   std::string _localWorkingDir;
158   std::string _wcKey;
159   std::string _maxDuration;
160   unsigned int _nbOfProcs;
161   std::list<std::string> _in_files;
162 };
163
164 class YACSEvalListOfResources : public YACSEvalNonConstLocker
165 {
166 public:
167   YACSEvalListOfResources(int maxLevOfPara, ResourcesManager_cpp *rm, const YACS::ENGINE::DeploymentTree& dt);
168   YACSEVALYFX_EXPORT std::vector<std::string> getAllChosenMachines() const;
169   YACSEVALYFX_EXPORT std::vector<std::string> getAllFittingMachines() const;
170   YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
171   YACSEVALYFX_EXPORT std::size_t size() const { return _resources.size(); }
172   YACSEVALYFX_EXPORT YACSEvalResource *at(std::size_t i) const;
173   YACSEVALYFX_EXPORT bool isInteractive() const;
174   YACSEVALYFX_EXPORT unsigned int getNumberOfProcsDeclared() const;
175   YACSEVALYFX_EXPORT void checkOKForRun() const;
176   YACSEVALYFX_EXPORT YACSEvalParamsForCluster& getAddParamsForCluster() { return _paramsInCaseOfCluster; }
177   YACSEVALYFX_EXPORT const YACSEvalParamsForCluster& getAddParamsForCluster() const { return _paramsInCaseOfCluster; }
178   void apply();
179   YACSEVALYFX_EXPORT ~YACSEvalListOfResources();
180 public:// info only
181   YACSEVALYFX_EXPORT bool isMachineInteractive(const std::string& machine) const;
182 public:
183   ResourcesManager_cpp *getCatalogEntry() const { return _rm; }
184   YACS::ENGINE::DeploymentTree *getDeploymentTree() const { return _dt; }
185   int getMaxLevelOfParallelism() const { return _maxLevOfPara; }
186   std::vector<std::string> getFittingResources(ParserResourcesType *request) const;
187   void notifyWantedMachine(YACSEvalVirtualYACSContainer *sender, const std::string& oldMachine, const std::string& newMachine);
188   bool hasRightInteractiveStatus(const std::string& machineToTest, bool isInteractive) const;
189 private:
190   void fitWithCurrentCatalog();
191   unsigned int getNumberOfProcOfResource(const std::string& machine) const;
192 private:
193   ResourcesManager_cpp *_rm;
194   int _maxLevOfPara;
195   std::vector<YACSEvalResource *> _resources;
196   YACS::ENGINE::DeploymentTree *_dt;
197   YACSEvalParamsForCluster _paramsInCaseOfCluster;
198 };
199
200 #endif