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