1 // Copyright (C) 2017-2019 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
20 #include "YDFXResourceModel.hxx"
22 #include "YACSEvalYFX.hxx"
23 #include "YACSEvalResource.hxx"
24 //#include "ResourcesManager.hxx"
30 YDFXResourceModel::YDFXResourceModel(YACSEvalYFX* eval)
31 : AbstractResourceModel(),
36 YDFXResourceModel::~YDFXResourceModel()
40 bool YDFXResourceModel::getParallelizeStatus()const
42 return _eval->getParallelizeStatus();
45 void YDFXResourceModel::setParallelizeStatus(bool v)
47 _eval->setParallelizeStatus(v);
50 std::string YDFXResourceModel::getRemoteDir()const
52 return getClusterParams().getRemoteWorkingDir();
55 void YDFXResourceModel::setRemoteDir(const std::string& v)
57 getClusterParams().setRemoteWorkingDir(v);
60 std::string YDFXResourceModel::getDefaultRemoteDir(std::string machine)const
65 std::string YDFXResourceModel::getLocalDir()const
67 return getClusterParams().getLocalWorkingDir();
70 void YDFXResourceModel::setLocalDir(const std::string& v)
72 getClusterParams().setLocalWorkingDir(v);
75 std::string YDFXResourceModel::getWckey()const
77 return getClusterParams().getWCKey();
80 void YDFXResourceModel::setWckey(const std::string& v)
82 getClusterParams().setWCKey(v);
85 int YDFXResourceModel::getMaxDurationMinutes()const
89 getMaxDuration(hours, minutes);
93 void YDFXResourceModel::setMaxDurationMinutes(int v)
97 getMaxDuration(hours, minutes);
98 setMaxDuration(hours, v);
101 int YDFXResourceModel::getMaxDurationHours()const
105 getMaxDuration(hours, minutes);
109 void YDFXResourceModel::setMaxDurationHours(int v)
113 getMaxDuration(hours, minutes);
114 setMaxDuration(v, minutes);
117 unsigned int YDFXResourceModel::getNbprocs()const
119 return getClusterParams().getNbProcs();
122 void YDFXResourceModel::setNbprocs(unsigned int v)
124 getClusterParams().setNbProcs(v);
127 std::string YDFXResourceModel::getWantedMachine()const
129 const std::string default_machine("localhost");
130 std::vector<std::string> chosenMachines = resources()->getAllChosenMachines();
131 std::vector<std::string> fittingMachines = resources()->getAllFittingMachines();
132 std::string wantedMachine="";
133 std::vector<std::string>::const_iterator it;
134 bool foundMachine = false;
135 it = chosenMachines.begin();
136 // take the first chosen machine which is also fitting.
137 while(!foundMachine && it!=chosenMachines.end())
139 if(std::find(fittingMachines.begin(), fittingMachines.end(), *it)
140 != fittingMachines.end())
148 // take localhost if fitting
149 if(std::find(fittingMachines.begin(), fittingMachines.end(),
150 default_machine) != fittingMachines.end())
153 wantedMachine = default_machine;
155 else if(fittingMachines.size() > 0)
158 wantedMachine = fittingMachines[0];
161 return wantedMachine;
164 void YDFXResourceModel::setWantedMachine(const std::string& v)
166 resources()->setWantedMachine(v);
169 std::vector<std::string> YDFXResourceModel::getFittingMachines()const
171 return resources()->getAllFittingMachines();
174 const std::list<std::string>& YDFXResourceModel::getInFiles()const
176 return getClusterParams().getInFiles();
179 std::list<std::string>& YDFXResourceModel::getInFiles()
181 return getClusterParams().getInFiles();
184 bool YDFXResourceModel::isMachineInteractive(const std::string& machine)const
186 return resources()->isMachineInteractive(machine);
189 void YDFXResourceModel::reset(YACSEvalYFX* eval)
194 YACSEvalListOfResources* YDFXResourceModel::resources()
196 return _eval->giveResources();
199 const YACSEvalListOfResources* YDFXResourceModel::resources()const
201 return _eval->giveResources();
204 YACSEvalParamsForCluster& YDFXResourceModel::getClusterParams()
206 return _eval->giveResources()->getAddParamsForCluster();
209 const YACSEvalParamsForCluster& YDFXResourceModel::getClusterParams()const
211 return _eval->giveResources()->getAddParamsForCluster();
214 void YDFXResourceModel::getMaxDuration(int& hours, int& minutes)const
216 std::string duration = getClusterParams().getMaxDuration();
219 if(duration.size() > 0)
221 std::stringstream ss(duration);
223 std::getline(ss, value, ':');
224 hours = atoi(value.c_str());
225 std::getline(ss, value, ':');
226 minutes = atoi(value.c_str());
238 void YDFXResourceModel::setMaxDuration(int hours, int minutes)
240 getClusterParams().setMaxDuration(AbstractResourceModel::getMaxDuration());