1 // Copyright (C) 2017-2021 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 "SalomeResourceModel.hxx"
21 #include "RuntimeSALOME.hxx"
22 #include "SALOME_ResourcesManager.hxx"
23 #include "SALOME_LifeCycleCORBA.hxx"
26 SalomeResourceModel::SalomeResourceModel()
27 : AbstractResourceModel(),
28 _wantedMachine("localhost"),
32 _wcKey("P11U5:CARBONES"),
33 _localDirectory("/tmp"),
34 _remoteDirectory("/tmp"),
35 _parallelizeStatus(true),
40 SalomeResourceModel::~SalomeResourceModel()
44 bool SalomeResourceModel::isMachineInteractive(const std::string& machine)const
46 return !machine.compare("localhost");
49 std::vector< std::string > SalomeResourceModel::getFittingMachines()const
51 std::vector< std::string > resultat;
52 YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
53 CORBA::ORB_ptr orb = runTime->getOrb();
54 if (!orb) return resultat;
56 SALOME_NamingService namingService(orb);
57 SALOME_LifeCycleCORBA lcc(&namingService);
59 CORBA::Object_var obj;
60 obj=namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
61 if (CORBA::is_nil(obj)) return resultat;
63 Engines::ResourcesManager_var resManager;
64 resManager = Engines::ResourcesManager::_narrow(obj);
65 if(!resManager) return resultat;
67 Engines::ResourceParameters params;
70 Engines::ResourceList* resourceList = resManager->GetFittingResources(params);
72 for (int i = 0; i < resourceList->length(); i++)
74 const char* aResource = (*resourceList)[i];
75 resultat.push_back(aResource);
80 void SalomeResourceModel::setWantedMachine(const std::string& v)
85 std::string SalomeResourceModel::getWantedMachine()const
87 return _wantedMachine;
90 void SalomeResourceModel::setNbprocs(unsigned int v)
95 unsigned int SalomeResourceModel::getNbprocs()const
100 void SalomeResourceModel::setMaxDurationHours(int v)
105 int SalomeResourceModel::getMaxDurationHours()const
110 void SalomeResourceModel::setMaxDurationMinutes(int v)
115 int SalomeResourceModel::getMaxDurationMinutes()const
120 void SalomeResourceModel::setWckey(const std::string& v)
125 std::string SalomeResourceModel::getWckey()const
130 void SalomeResourceModel::setLocalDir(const std::string& v)
135 std::string SalomeResourceModel::getLocalDir()const
137 return _localDirectory;
140 void SalomeResourceModel::setRemoteDir(const std::string& v)
142 _remoteDirectory = v;
145 std::string SalomeResourceModel::getRemoteDir()const
147 return _remoteDirectory;
150 std::string SalomeResourceModel::getDefaultRemoteDir(std::string machine)const
152 std::string result = "";
153 YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
154 CORBA::ORB_ptr orb = runTime->getOrb();
155 if (!orb) return result;
157 SALOME_NamingService namingService(orb);
158 SALOME_LifeCycleCORBA lcc(&namingService);
160 CORBA::Object_var obj;
161 obj=namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
162 if (CORBA::is_nil(obj)) return result;
164 Engines::ResourcesManager_var resManager;
165 resManager = Engines::ResourcesManager::_narrow(obj);
166 if(!resManager) return result;
168 Engines::ResourceParameters params;
173 Engines::ResourceDefinition * rd;
174 rd = resManager->GetResourceDefinition(machine.c_str());
175 result = rd->working_directory.in();
180 std::string launch_date = ctime(&rawtime);
181 for (int i = 0; i < launch_date.size(); i++)
182 if (launch_date[i] == '/' ||
183 launch_date[i] == '-' ||
184 launch_date[i] == ':' ||
185 launch_date[i] == ' ')
186 launch_date[i] = '_';
187 launch_date.erase(--launch_date.end()); // Last caracter is a \n
189 result += launch_date;
199 void SalomeResourceModel::setParallelizeStatus(bool v)
201 _parallelizeStatus = v;
204 bool SalomeResourceModel::getParallelizeStatus()const
206 return _parallelizeStatus;
209 const std::list<std::string>& SalomeResourceModel::getInFiles()const
214 std::list<std::string>& SalomeResourceModel::getInFiles()