1 // Copyright (C) 2012-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #ifndef __YACSEVALRESOURCE_HXX__
22 #define __YACSEVALRESOURCE_HXX__
24 #include "YACSEvalYFXExport.hxx"
43 class YACSEvalNonConstLocker
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;
55 class ParserResourcesType;
56 class YACSEvalResource;
58 class YACSEvalVirtualYACSContainer : public YACSEvalNonConstLocker
61 YACSEvalVirtualYACSContainer(YACSEvalResource *gf, YACS::ENGINE::Container *cont);
62 YACSEVALYFX_EXPORT ~YACSEvalVirtualYACSContainer();
63 YACSEVALYFX_EXPORT std::string getChosenMachine() const { return _chosenHost; }
64 YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
65 YACSEVALYFX_EXPORT std::vector<std::string> listOfPropertyKeys() const;
66 YACSEVALYFX_EXPORT std::string getValueOfKey(const char *key) const;
67 YACSEVALYFX_EXPORT void setProperty(const std::string& key, const std::string &value);
68 YACSEVALYFX_EXPORT void resetOverloadedProps() { checkNonLocked(); _overloadedPropertyMap.clear(); }
71 YACSEvalVirtualYACSContainer();
72 void set(YACSEvalResource *gf, YACS::ENGINE::Container *cont);
73 void aggregate(ParserResourcesType& entry) const;
74 void setMachineNoCheck(const std::string& machine) { checkNonLocked(); _chosenHost=machine; }
75 std::string findDefault(bool isInteractive) const;
77 std::string getHostName() const { return getValueOfKey(HOSTNAME_KEY); }
78 unsigned int getMem() const { return getValueOfKeyUInt(MEM_KEY); }
79 unsigned int getNbNodes() const { return getValueOfKeyUInt(NB_NODE_KEY); }
80 unsigned int getCPUFreq() const { return getValueOfKeyUInt(CPU_CLOCK_KEY); }
81 unsigned int getNbProcPerNode() const { return getValueOfKeyUInt(NB_PROC_PER_NODE_KEY); }
82 unsigned int getValueOfKeyUInt(const char *key) const;
83 std::map<std::string,std::string> listOfPropertiesInYACSContainer() const;
85 static const char CONTAINER_NAME_KEY[];
86 static const char CPU_CLOCK_KEY[];
87 static const char HOSTNAME_KEY[];
88 static const char MEM_KEY[];
89 static const char NB_NODE_KEY[];
90 static const char NB_PROC_PER_NODE_KEY[];
91 static const char NB_RESOURCE_PROCS_KEY[];
92 static const char POLICY_KEY[];
93 static const char OS_KEY[];
95 std::string _chosenHost;
96 //! list of properties that overloads.
97 std::map<std::string,std::string> _overloadedPropertyMap;
98 //! property map at the origin.
99 std::map<std::string,std::string> _propertyMap;
100 YACSEvalResource *_gf;
101 YACS::ENGINE::Container *_cont;
104 class YACSEvalListOfResources;
106 class YACSEvalResource : public YACSEvalNonConstLocker
109 YACSEVALYFX_EXPORT virtual ~YACSEvalResource();
110 YACSEVALYFX_EXPORT std::vector<std::string> getAllChosenMachines() const;
111 YACSEVALYFX_EXPORT std::vector<std::string> getAllFittingMachines() const;
112 YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
113 YACSEVALYFX_EXPORT std::size_t size() const { return _containers.size(); }
114 YACSEVALYFX_EXPORT YACSEvalVirtualYACSContainer *at(std::size_t i) const;
115 YACSEVALYFX_EXPORT void apply();
117 void fitWithCurrentCatalogAbs();
118 void aggregate(ParserResourcesType& entry) const;
119 YACSEvalListOfResources *getGodFather() const { return _gf; }
120 void notifyWantedMachine(YACSEvalVirtualYACSContainer *sender, const std::string& oldMachine, const std::string& newMachine);
121 void setMachineNoCheck(const std::string& machine);
123 YACSEvalResource(YACSEvalListOfResources *gf, const std::vector< YACS::ENGINE::Container * >& conts);
125 YACSEvalListOfResources *_gf;
126 std::vector< YACSEvalVirtualYACSContainer > _containers;
129 class ResourcesManager_cpp;
131 class YACSEvalListOfResources : public YACSEvalNonConstLocker
134 YACSEvalListOfResources(int maxLevOfPara, ResourcesManager_cpp *rm, const YACS::ENGINE::DeploymentTree& dt);
135 YACSEVALYFX_EXPORT std::vector<std::string> getAllChosenMachines() const;
136 YACSEVALYFX_EXPORT std::vector<std::string> getAllFittingMachines() const;
137 YACSEVALYFX_EXPORT void setWantedMachine(const std::string& machine);
138 YACSEVALYFX_EXPORT std::size_t size() const { return _resources.size(); }
139 YACSEVALYFX_EXPORT YACSEvalResource *at(std::size_t i) const;
140 YACSEVALYFX_EXPORT bool isInteractive() const;
141 YACSEVALYFX_EXPORT unsigned int getNumberOfProcsDeclared() const;
143 YACSEVALYFX_EXPORT ~YACSEvalListOfResources();
145 ResourcesManager_cpp *getCatalogEntry() const { return _rm; }
146 YACS::ENGINE::DeploymentTree *getDeploymentTree() const { return _dt; }
147 int getMaxLevelOfParallelism() const { return _maxLevOfPara; }
148 std::vector<std::string> getFittingResources(ParserResourcesType *request) const;
149 void notifyWantedMachine(YACSEvalVirtualYACSContainer *sender, const std::string& oldMachine, const std::string& newMachine);
150 bool hasRightInteractiveStatus(const std::string& machineToTest, bool isInteractive) const;
152 void fitWithCurrentCatalog();
153 unsigned int getNumberOfProcOfResource(const std::string& machine) const;
155 ResourcesManager_cpp *_rm;
157 std::vector<YACSEvalResource *> _resources;
158 YACS::ENGINE::DeploymentTree *_dt;