Salome HOME
updated copyright message
[modules/yacs.git] / src / engine / WlmTask.cxx
1 // Copyright (C) 2006-2023  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
20 #include "WlmTask.hxx"
21 #include "Runtime.hxx"
22 #include "Container.hxx"
23
24 namespace YACS
25 {
26 namespace ENGINE
27 {
28 WlmTask::WlmTask(Executor& executor, YACS::ENGINE::Task* yacsTask)
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);
63     _executor.makeDatastreamConnections(_yacsTask);
64     YACS::Event ev = _executor.runTask(_yacsTask);
65     _executor.endTask(_yacsTask, ev);
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 }