Salome HOME
Workload manager: source code organization.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 4 Jun 2020 15:53:31 +0000 (17:53 +0200)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 4 Jun 2020 15:53:31 +0000 (17:53 +0200)
src/engine/CMakeLists.txt
src/engine/Executor.cxx
src/engine/WlmTask.cxx [new file with mode: 0644]
src/engine/WlmTask.hxx [new file with mode: 0644]

index d8f4d296dd0037e526435843820fc8fe292c8c4f..b4d9f7bfd46cd0f944387ebeeff33a98b2d63a03 100644 (file)
@@ -116,6 +116,7 @@ SET(YACSlibEngine_HEADERS
   PlayGround.hxx
   ObserverAsPlugin.hxx
   NbBranches.hxx
+  WlmTask.hxx
   )
 
 # --- sources ---
@@ -194,6 +195,7 @@ SET(YACSlibEngine_SOURCES
   PlayGround.cxx
   ComplexWeight.cxx
   ObserverAsPlugin.cxx
+  WlmTask.cxx
   )
 SET(YACSlibEngine_HEADERS ${YACSlibEngine_HEADERS} PARENT_SCOPE)  # Make it visible to src/engine_swig to handle dependencies
 
index 24603ef0af736d3e0199ac0ac4b234bb18298032..d899ae99599976a73a1ba0f5d01f3465c322f54f 100644 (file)
@@ -30,6 +30,7 @@
 #include "ServiceNode.hxx"
 #include "ComposedNode.hxx"
 
+#include "WlmTask.hxx"
 #include "workloadmanager/WorkloadManager.hxx"
 #include "workloadmanager/DefaultAlgorithm.hxx"
 
@@ -1664,88 +1665,6 @@ void Executor::makeDatastreamConnections(Task *task)
   traceExec(task, "state:"+Node::getStateName(task->getState()),ComputePlacement(task));
 }
 
-#include "Runtime.hxx"
-static
-void loadResources(WorkloadManager::WorkloadManager& wm)
-{
-  Runtime *r(getRuntime());
-  if(!r)
-    throw YACS::Exception("loadResources : no runtime  !");
-  std::vector< std::pair<std::string,int> > data(r->getCatalogOfComputeNodes());
-  int id = 0;
-  for(const std::pair<std::string,int>& res : data)
-  {
-    WorkloadManager::Resource newResource;
-    newResource.name = res.first;
-    newResource.id = id;
-    id++;
-    newResource.nbCores = res.second;
-    wm.addResource(newResource);
-  }
-}
-
-class NewTask : public WorkloadManager::Task
-{
-public:
-  NewTask(Executor& executor, YACS::ENGINE::Task* yacsTask);
-  const WorkloadManager::ContainerType& type()const override;
-  void run(const WorkloadManager::RunInfo& runInfo)override;
-  bool isAccepted(const WorkloadManager::Resource& r)override;
-private:
-  WorkloadManager::ContainerType _type;
-  Executor& _executor;
-  YACS::ENGINE::Task * _yacsTask;
-};
-
-NewTask::NewTask(Executor& executor, YACS::ENGINE::Task* yacsTask)
-: _type()
-, _executor(executor)
-, _yacsTask(yacsTask)
-{
-  Container * yacsContainer = yacsTask->getContainer();
-  if(yacsContainer != nullptr && yacsTask->canAcceptImposedResource())
-  {
-    _type.ignoreResources = false;
-    _type.name = yacsContainer->getName();
-    std::string nb_procs_str = yacsContainer->getProperty("nb_parallel_procs");
-    float needed_cores = 0.0;
-    if(!nb_procs_str.empty())
-      needed_cores = std::stof(nb_procs_str);
-    _type.neededCores = needed_cores;
-  }
-  else
-  {
-    _type.ignoreResources = true;
-    _type.name = "test";
-    _type.neededCores = 0;
-  }
-  _type.id = 0;
-}
-
-const WorkloadManager::ContainerType& NewTask::type()const
-{
-  return _type;
-}
-
-void NewTask::run(const WorkloadManager::RunInfo& runInfo)
-{
-  _executor.loadTask(_yacsTask, runInfo);
-  _executor.makeDatastreamConnections(_yacsTask);
-  YACS::Event ev = _executor.runTask(_yacsTask);
-  _executor.endTask(_yacsTask, ev);
-  delete this; // provisoire
-}
-
-bool NewTask::isAccepted(const WorkloadManager::Resource& r)
-{
-  Container * yacsContainer = _yacsTask->getContainer();
-  std::string hostname = yacsContainer->getProperty("hostname");
-  bool accept = true;
-  if(!hostname.empty())
-    accept = (hostname == r.name);
-  return accept;
-}
-
 void Executor::runWlm(Scheduler *graph,int debug, bool fromScratch)
 {
   DEBTRACE("Executor::runWlm debug: "<< graph->getName() <<" "<< debug<<" fromScratch: "<<fromScratch);
@@ -1800,7 +1719,7 @@ void Executor::runWlm(Scheduler *graph,int debug, bool fromScratch)
 
   WorkloadManager::DefaultAlgorithm algo;
   WorkloadManager::WorkloadManager wlm(algo);
-  loadResources(wlm);
+  WlmTask::loadResources(wlm);
   wlm.start();
 
   while (_toContinue)
@@ -1829,7 +1748,7 @@ void Executor::runWlm(Scheduler *graph,int debug, bool fromScratch)
         for(Task * task : _tasks)
         {
           beginTask(task);
-          NewTask* newTask = new NewTask(*this, task);
+          WlmTask* newTask = new WlmTask(*this, task);
           wlm.addTask(newTask);
         }
       }
diff --git a/src/engine/WlmTask.cxx b/src/engine/WlmTask.cxx
new file mode 100644 (file)
index 0000000..09ae95b
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2006-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "WlmTask.hxx"
+#include "Runtime.hxx"
+#include "Container.hxx"
+
+namespace YACS
+{
+namespace ENGINE
+{
+WlmTask::WlmTask(Executor& executor, YACS::ENGINE::Task* yacsTask)
+: _type()
+, _executor(executor)
+, _yacsTask(yacsTask)
+{
+  Container * yacsContainer = yacsTask->getContainer();
+  if(yacsContainer != nullptr && yacsTask->canAcceptImposedResource())
+  {
+    _type.ignoreResources = false;
+    _type.name = yacsContainer->getName();
+    std::string nb_procs_str = yacsContainer->getProperty("nb_parallel_procs");
+    float needed_cores = 0.0;
+    if(!nb_procs_str.empty())
+      needed_cores = std::stof(nb_procs_str);
+    _type.neededCores = needed_cores;
+  }
+  else
+  {
+    _type.ignoreResources = true;
+    _type.name = "test";
+    _type.neededCores = 0;
+  }
+  _type.id = 0;
+}
+
+const WorkloadManager::ContainerType& WlmTask::type()const
+{
+  return _type;
+}
+
+void WlmTask::run(const WorkloadManager::RunInfo& runInfo)
+{
+  _executor.loadTask(_yacsTask, runInfo);
+  _executor.makeDatastreamConnections(_yacsTask);
+  YACS::Event ev = _executor.runTask(_yacsTask);
+  _executor.endTask(_yacsTask, ev);
+  delete this; // provisoire
+}
+
+bool WlmTask::isAccepted(const WorkloadManager::Resource& r)
+{
+  Container * yacsContainer = _yacsTask->getContainer();
+  std::string hostname = yacsContainer->getProperty("hostname");
+  bool accept = true;
+  if(!hostname.empty())
+    accept = (hostname == r.name);
+  return accept;
+}
+
+void WlmTask::loadResources(WorkloadManager::WorkloadManager& wm)
+{
+  Runtime *r(getRuntime());
+  if(!r)
+    throw YACS::Exception("loadResources : no runtime  !");
+  std::vector< std::pair<std::string,int> > data(r->getCatalogOfComputeNodes());
+  int id = 0;
+  for(const std::pair<std::string,int>& res : data)
+  {
+    WorkloadManager::Resource newResource;
+    newResource.name = res.first;
+    newResource.id = id;
+    id++;
+    newResource.nbCores = res.second;
+    wm.addResource(newResource);
+  }
+}
+
+}
+}
diff --git a/src/engine/WlmTask.hxx b/src/engine/WlmTask.hxx
new file mode 100644 (file)
index 0000000..d97889d
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2006-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#ifndef __WLM_TASK_HXX__
+#define __WLM_TASK_HXX__
+#include "Executor.hxx"
+#include "Task.hxx"
+#include "workloadmanager/WorkloadManager.hxx"
+
+namespace YACS
+{
+namespace ENGINE
+{
+class YACSLIBENGINE_EXPORT WlmTask : public WorkloadManager::Task
+{
+public:
+  WlmTask(Executor& executor, YACS::ENGINE::Task* yacsTask);
+  const WorkloadManager::ContainerType& type()const override;
+  void run(const WorkloadManager::RunInfo& runInfo)override;
+  bool isAccepted(const WorkloadManager::Resource& r)override;
+  
+  static void loadResources(WorkloadManager::WorkloadManager& wm);
+private:
+  WorkloadManager::ContainerType _type;
+  Executor& _executor;
+  YACS::ENGINE::Task * _yacsTask;
+};
+
+}
+}
+
+#endif //__WLM_TASK_HXX__