Version: 9.15.0
WlmTask.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
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 
20 #include "WlmTask.hxx"
21 #include "Runtime.hxx"
22 #include "Container.hxx"
23 
24 namespace YACS
25 {
26 namespace ENGINE
27 {
29 : _type()
30 , _executor(executor)
31 , _yacsTask(yacsTask)
32 {
33  Container * yacsContainer = yacsTask->getContainer();
34  if(yacsContainer != nullptr && yacsTask->canAcceptImposedResource())
35  {
36  _type.ignoreResources = false;
37  _type.name = yacsContainer->getName();
38  std::string nb_procs_str = yacsContainer->getProperty("nb_parallel_procs");
39  float needed_cores = 0.0;
40  if(!nb_procs_str.empty())
41  needed_cores = std::stof(nb_procs_str);
42  _type.neededCores = needed_cores;
43  }
44  else
45  {
46  _type.ignoreResources = true;
47  _type.name = "test";
48  _type.neededCores = 0;
49  }
50  _type.id = 0;
51 }
52 
53 const WorkloadManager::ContainerType& WlmTask::type()const
54 {
55  return _type;
56 }
57 
58 void WlmTask::run(const WorkloadManager::RunInfo& runInfo)
59 {
60  if(runInfo.isOk)
61  {
62  _executor.loadTask(_yacsTask, runInfo);
66  }
67  else
68  {
69  _executor.failTask(_yacsTask, runInfo.error_message);
70  }
71  delete this; // provisoire
72 }
73 
74 bool WlmTask::isAccepted(const WorkloadManager::Resource& r)
75 {
76  Container * yacsContainer = _yacsTask->getContainer();
77  std::string hostname = yacsContainer->getProperty("hostname");
78  bool accept = true;
79  if(!hostname.empty())
80  accept = (hostname == r.name);
81  return accept;
82 }
83 
84 void WlmTask::loadResources(WorkloadManager::WorkloadManager& wm)
85 {
86  Runtime *r(getRuntime());
87  if(!r)
88  throw YACS::Exception("loadResources : no runtime !");
89  std::vector< std::pair<std::string,int> > data(r->getCatalogOfComputeNodes());
90  int id = 0;
91  for(const std::pair<std::string,int>& res : data)
92  {
93  WorkloadManager::Resource newResource;
94  newResource.name = res.first;
95  newResource.id = id;
96  id++;
97  newResource.nbCores = res.second;
98  wm.addResource(newResource);
99  }
100  wm.freezeResources();
101 }
102 
103 }
104 }
virtual std::string getProperty(const std::string &name) const =0
virtual std::string getName() const
Definition: Container.hxx:81
Threaded Executor.
Definition: Executor.hxx:63
void failTask(Task *task, const std::string &message)
Definition: Executor.cxx:1524
void makeDatastreamConnections(Task *task)
Definition: Executor.cxx:1605
YACS::Event runTask(Task *task)
Definition: Executor.cxx:1535
void endTask(Task *task, YACS::Event ev)
Definition: Executor.cxx:1473
void loadTask(Task *task, const WorkloadManager::RunInfo &runInfo)
Definition: Executor.cxx:1423
virtual bool canAcceptImposedResource()
Definition: Task.hxx:57
virtual Container * getContainer()=0
bool isAccepted(const WorkloadManager::Resource &r) override
Definition: WlmTask.cxx:74
static void loadResources(WorkloadManager::WorkloadManager &wm)
Definition: WlmTask.cxx:84
void run(const WorkloadManager::RunInfo &runInfo) override
Definition: WlmTask.cxx:58
WlmTask(Executor &executor, YACS::ENGINE::Task *yacsTask)
Definition: WlmTask.cxx:28
const WorkloadManager::ContainerType & type() const override
Definition: WlmTask.cxx:53
WorkloadManager::ContainerType _type
Definition: WlmTask.hxx:39
Executor & _executor
Definition: WlmTask.hxx:40
YACS::ENGINE::Task * _yacsTask
Definition: WlmTask.hxx:41
YACSLIBENGINE_EXPORT Runtime * getRuntime()
Definition: Runtime.cxx:61
Event
Definition: define.hxx:56