Salome HOME
Revert commit bc803f251236fa3b020c (14/03/2020) due to new ForEachLoopDyn implementation
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 25 Mar 2020 15:59:24 +0000 (16:59 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 25 Mar 2020 16:03:38 +0000 (17:03 +0100)
13 files changed:
src/engine/Bloc_impl.cxx
src/engine/HomogeneousPoolContainer.hxx
src/engine/InlineNode.cxx
src/engine/InlineNode.hxx
src/engine/NewAPI.hxx [new file with mode: 0644]
src/runtime/DistributedPythonNode.cxx
src/runtime/PythonNode.cxx
src/runtime/SalomeContainerTools.cxx
src/runtime/SalomeContainerTools.hxx
src/runtime/SalomeHPContainer.cxx
src/runtime/SalomeHPContainer.hxx
src/runtime/SalomeHPContainerTools.cxx
src/runtime/SalomeHPContainerTools.hxx

index 1678225c6fca9a1c628cbcafd477aefecf00080c..21e83bcc7a6feb6eeb8bc8e04afd77c2a6430d3b 100644 (file)
@@ -62,9 +62,7 @@ void Bloc::fitToPlayGround(const PlayGround *pg)
           if(!cont2)
             return ;
           _cont.push_back(cont2);
-          HomogeneousPoolContainer *cont3(cont2->getDirectFather());
-          if(cont3)
-            _cont2.insert(cont3);
+          _cont2.insert(cont2);
       }
       void visitInlineFuncNode(InlineFuncNode *node) { throw YACS::Exception(MSG); }
       void visitLoop(Loop *node) { throw YACS::Exception(MSG); }
@@ -108,6 +106,5 @@ void Bloc::fitToPlayGround(const PlayGround *pg)
     }
   for(std::set< HomogeneousPoolContainer * >::const_iterator it=vis._cont2.begin();it!=vis._cont2.end();it++)
     (*it)->setSizeOfPool(pg->getNumberOfWorkers((*it)->getNumberOfCoresPerWorker()));
-  for(std::list< HomogeneousPoolContainer *>::const_iterator it=vis._cont.begin();it!=vis._cont.end();it++)
-    (*it)->prepareMaskForExecution();
+  //FIXME
 }
index 9007305b69f348b1b5cd9533862c0eeef28d0c75..eabf75416474ac5fc4b775f26da58933daa0de81 100644 (file)
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __HOMOGENEOUSPOOLCONTAINER_HXX__
-#define __HOMOGENEOUSPOOLCONTAINER_HXX__
+#pragma once
 
 #include "YACSlibEngineExport.hxx"
 #include "Exception.hxx"
@@ -50,12 +49,7 @@ namespace YACS
       virtual std::size_t getNumberOfFreePlace() const = 0;
       virtual void allocateFor(const std::vector<const Task *>& nodes) = 0;
       virtual void release(const Task *node) = 0;
-      virtual YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> decorate(YACS::BASES::AutoConstRefCnt<PartDefinition> pd) = 0;
-      virtual HomogeneousPoolContainer *getDirectFather() = 0;
-      virtual const HomogeneousPoolContainer *getDirectFather() const = 0;
       virtual int getNumberOfCoresPerWorker() const = 0;
-      virtual void prepareMaskForExecution() const = 0;
-      virtual void forYourTestsOnly(ForTestOmlyHPContCls *data) const = 0;
       static const char SIZE_OF_POOL_KEY[];
       static const char INITIALIZE_SCRIPT_KEY[];
     protected:
@@ -67,4 +61,3 @@ namespace YACS
   }
 }
 
-#endif
index 418ba2b04d0194b9e08c62ef3e17c874ccad2501..fd687044dd02b009fec80be14583aef4b9f87106 100644 (file)
@@ -20,7 +20,6 @@
 #include "InlineNode.hxx"
 #include "Visitor.hxx"
 #include "Container.hxx"
-#include "HomogeneousPoolContainer.hxx"
 #include <iostream>
 
 #define _DEVDEBUG_
@@ -156,18 +155,3 @@ int InlineNode::getMaxLevelOfParallelism() const
   int ret(1); iss >> ret;
   return ret;
 }
-
-void InlineNode::partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap)
-{
-  if(!isDeployable())
-    return ;
-  if(!_container)
-    return ;
-  HomogeneousPoolContainer *contC(dynamic_cast<HomogeneousPoolContainer *>(_container));
-  if(!contC)
-    return ;
-  YACS::BASES::AutoConstRefCnt<PartDefinition> zePd;
-  zePd.takeRef(pd);
-  YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> zeCont(contC->decorate(zePd));
-  setContainer(zeCont);
-}
index 74930305ed4f5e88f35b906b445b5240c0719eb1..67d917722a03ec6a2c2cdb41edc725341fe1a70f 100644 (file)
@@ -68,7 +68,6 @@ namespace YACS
       void performShallowDuplicationOfPlacement(const Node& other);
       bool isDeployable() const;
       int getMaxLevelOfParallelism() const;
-      void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap);
     public:
       static const char LOCAL_STR[];
       static const char REMOTE_STR[];
diff --git a/src/engine/NewAPI.hxx b/src/engine/NewAPI.hxx
new file mode 100644 (file)
index 0000000..b3722a0
--- /dev/null
@@ -0,0 +1,87 @@
+#include <string>
+
+// ça sera peut-être une struct s'il n'y a rien d'autre que les deux paramètres
+class Resource
+{
+public:
+    unsigned int nbCores()const;
+    const std::string& name()const;
+};
+
+// ça sera peut-être une struct s'il n'y a rien d'autre que les deux paramètres
+class ContainerType
+{
+public:
+  const std::string& name()const;
+  // float pour pouvoir gérer plus tard des containers qui peuvent être lancé
+  // à plusieurs sur le même coeur.
+  const float parallelism()const;
+  // normalement, pas besoin de start. Quand yacs lance un traitement, il
+  // commence par faire un "load" qui cherche le container avec les
+  // caractéristiques données et il lance un nouveau s'il ne le trouve pas.
+  // Donc on peut s'appuyer sur le mécanisme existant et jouer sur les
+  // caractéristiques pour identifier le container.
+  //virtual void start(const std::string& resourceName, unsigned int index);
+};
+
+// probablement une struct
+class Container
+// Cet objet est créé par le WorkloadManager chaque fois qu'une tâche peut être
+// lancée et il contient l'identification du container à utiliser pour faire
+// le traitement. voir Task.run
+{
+public:
+  const Resource* resource()const;
+  const ContainerType* type()const;
+  // indice du container parmi ceux du même type sur la resource:
+  unsigned int index()const;
+};
+
+class Task
+// Cet objet doit être créé par YACS et soumis au WorkloadManager
+{
+public:
+  const ContainerType* type()const;
+  // Cette méthode est à implémenter dans YACS. Elle est appelée par le
+  // WorkloadManager au moment où une ressource est disponible et en paramétre
+  // on trouve l'identification du container à utiliser. YACS permet déjà
+  // d'identifier les containers par leur nom. A partir des informations de
+  // l'objet en paramètre on peut construire un nom de container qui sera unique.
+  // Avec ce nom, on peut utiliser les méthodes existantes pour charger le
+  // container salome / kernel et lancer le traitement à faire dans le noeud
+  // YACS.
+  // Les traitements à faire dans cette fonction sont: trouver le container
+  // kernel et si besoin l'initialiser, lancer le traitement du noeud et
+  // attendre la fin du calcul.
+  virtual void run(const Container& container)=0;
+};
+
+class WorkloadManager
+// Cet objet doit être créé par YACS à chaque exécution d'un schéma.
+{
+public:
+  // Fonction à appeler par YACS avant le début de l'exécution du schéma pour
+  // renseigner les ressources disponibles. A mon avis, on peut se limiter dans
+  // un premier temps de prendre toutes les ressources du catalogue qui peuvent
+  // lancer des containers. Cela suffit pour le lancement sur cluster. En local
+  // on pourrait avoir envie de ne pas utiliser tous ce qu'il y a dans le
+  // catalogue, mais on n'a qu'à modifier le catalogue à la main si on veut
+  // faire le malin.
+  void addResource(Resource* r);
+  
+  // Fonction à appeler par YACS au moment où un noeud de traitement est prêt à
+  // être lancé. Cet appel ajoute la tâche dans la queue d'attente et rend tout
+  // de suite la main. La fonction 'run' de la tâche sera appelée plus tard, au
+  // moment où une ressource est effectivement disponible.
+  void addTask(Task* t);
+  
+  // Fonction à appeler par YACS pour démarrer le moteur qui distribue les tâches.
+  // Il y aura au moins deux fils d'exécution: un qui gère les arrivées dans la
+  // queue et un qui gère les fins de tâche. Ce sont ces deux fils qui démarrent
+  // ici. Après, chaque exécution de tâche aura son propre fil.
+  void start();
+  
+  // Fonction à appeler par YACS pour indiquer qu'il n'y aura plus de tâches à
+  // soumettre. Le moteur pourra s'arrêter à la fin des tâches en cours.
+  void stop();
+};
index 40f75b1187aa4d558bc7b49776b2324e00ea6438..8e7643962167a6650a1580ad8f3fa3701ff2cda0 100644 (file)
@@ -113,12 +113,13 @@ void DistributedPythonNode::load()
     if(!_container)
       throw Exception("No container specified !");
     SalomeContainer *containerCast0(dynamic_cast<SalomeContainer *>(_container));
-    SalomeHPContainerBase *containerCast1(dynamic_cast<SalomeHPContainerBase *>(_container));
+    SalomeHPContainer *containerCast1(dynamic_cast<SalomeHPContainer *>(_container));
     if(containerCast0)
       objContainer=containerCast0->getContainerPtr(this);
     else if(containerCast1)
       {
-        objContainer=containerCast1->getContainerPtr(this);
+        YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(containerCast1,this));
+        objContainer=tmpCont->getContainerPtr(this);
       }
     else
       throw Exception("Unrecognized type of container ! Salome one is expected !");
index 0227c2adfc4be76ee830bd924fb2c1f213bf6194..03d17def580b0dce6cfdf9adf48e6755d0fbf325 100644 (file)
@@ -128,7 +128,7 @@ Engines::Container_var GetContainerObj(InlineNode *reqNode, bool& isStandardCont
   if(!container)
     throw YACS::Exception("No container specified !");
   SalomeContainer *containerCast0(dynamic_cast<SalomeContainer *>(container));
-  SalomeHPContainerBase *containerCast1(dynamic_cast<SalomeHPContainerBase *>(container));
+  SalomeHPContainer *containerCast1(dynamic_cast<SalomeHPContainer *>(container));
   if(containerCast0)
     {
       isStandardCont = true;
@@ -136,7 +136,8 @@ Engines::Container_var GetContainerObj(InlineNode *reqNode, bool& isStandardCont
     }
   else if(containerCast1)
     {
-      objContainer=containerCast1->getContainerPtr(reqNode);
+      YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(containerCast1,reqNode));
+      objContainer=tmpCont->getContainerPtr(reqNode);
     }
   else
     throw YACS::Exception("Unrecognized type of container ! Salome one is expected for PythonNode/PyFuncNode !");
index fac85c3144014a3bbde0763bcbe4c010c2e10055..aaf96813f95e203a948dc75bc651136a3c3a7bea 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016  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
@@ -30,7 +30,6 @@
 #include "ServiceNode.hxx"
 #include "ComponentInstance.hxx"
 #include "SalomeContainerHelper.hxx"
-#include "SalomeHPContainerTools.hxx"
 #include "RuntimeSALOME.hxx"
 #include "Exception.hxx"
 
 
 using namespace YACS::ENGINE;
 
-/*!
- * \param [in] compoNames
- * \param [in,out] shutdownLevel
- */
-void SalomeContainerToolsBase::Start(const std::vector<std::string>& compoNames, SalomeContainerHelper *schelp, SalomeContainerToolsBase& sct, int& shutdownLevel, const Container *cont, const Task *askingNode)
-{
-  CORBA::ORB_ptr orb(getSALOMERuntime()->getOrb());
-  SALOME_NamingService ns;
-  try
-  {
-      ns.init_orb(orb);
-  }
-  catch(SALOME_Exception& e)
-  {
-      throw Exception("SalomeContainer::start : Unable to contact the SALOME Naming Service");
-  }
-  CORBA::Object_var obj(ns.Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS));
-  Engines::ContainerManager_var contManager(Engines::ContainerManager::_narrow(obj));
-
-  bool isEmptyName;
-  std::string str(sct.getNotNullContainerName(cont,askingNode,isEmptyName));
-  DEBTRACE("SalomeContainer::start " << str <<";"<< sct.getHostName() <<";"<< schelp->getType());
-
-  // Finalize parameters with components found in the container
-
-  for(std::vector<std::string>::const_iterator iter=compoNames.begin();iter!=compoNames.end();iter++)
-    sct.addToComponentList(*iter);
-
-  Engines::ContainerParameters myparams(sct.getParameters());
-  {
-    std::string dftLauchMode(schelp->getDftLaunchMode());
-    myparams.mode=CORBA::string_dup(dftLauchMode.c_str());
-  }
-
-  //If a container_name is given try to find an already existing container in naming service
-  //If not found start a new container with the given parameters
-  if (dynamic_cast<SalomeContainerMonoHelper *>(schelp) && !isEmptyName)
-    {
-      myparams.mode=CORBA::string_dup("getorstart");
-    }
-
-  if (isEmptyName)
-    {
-      shutdownLevel=1;
-    }
-  //sct.setContainerName(str);
-  SetContainerNameOf(myparams,str);
-  Engines::Container_var trueCont(Engines::Container::_nil());
-  if(!isEmptyName && shutdownLevel==999)
-    {
-      //Make this only the first time start is called (_shutdownLevel==999)
-      //If the container is named, first try to get an existing container
-      //If there is an existing container use it and set the shutdown level to 3
-      //If there is no existing container, try to launch a new one and set the shutdown level to 2
-      myparams.mode="get";
-      try
-      {
-          trueCont=contManager->GiveContainer(myparams);
-      }
-      catch( const SALOME::SALOME_Exception& ex )
-      {
-          std::string msg="SalomeContainer::start : no existing container : ";
-          msg += '\n';
-          msg += ex.details.text.in();
-          DEBTRACE( msg );
-      }
-      catch(...)
-      {
-      }
-
-      if(!CORBA::is_nil(trueCont))
-        {
-          shutdownLevel=3;
-          DEBTRACE( "container found: " << str << " " << _shutdownLevel );
-        }
-      else
-        {
-          shutdownLevel=2;
-          myparams.mode="start";
-          DEBTRACE( "container not found: " << str << " " << _shutdownLevel);
-        }
-    }
-
-  if(CORBA::is_nil(trueCont))
-    try
-  {
-        // --- GiveContainer is used in batch mode to retreive launched containers,
-        //     and is equivalent to StartContainer when not in batch.
-        trueCont=contManager->GiveContainer(myparams);
-  }
-  catch( const SALOME::SALOME_Exception& ex )
-  {
-      std::string msg="SalomeContainer::start : Unable to launch container in Salome : ";
-      msg += '\n';
-      msg += ex.details.text.in();
-      throw Exception(msg);
-  }
-  catch(CORBA::COMM_FAILURE&)
-  {
-      throw Exception("SalomeContainer::start : Unable to launch container in Salome : CORBA Comm failure detected");
-  }
-  catch(CORBA::Exception&)
-  {
-      throw Exception("SalomeContainer::start : Unable to launch container in Salome : Unexpected CORBA failure detected");
-  }
-
-  if(CORBA::is_nil(trueCont))
-    throw Exception("SalomeContainer::start : Unable to launch container in Salome. Check your CatalogResources.xml file");
-
-  schelp->setContainer(askingNode,trueCont);
-
-  CORBA::String_var containerName(trueCont->name()),hostName(trueCont->getHostName());
-  std::cerr << "SalomeContainer launched : " << containerName << " " << hostName << " " << trueCont->getPID() << std::endl;
-}
-
-CORBA::Object_ptr SalomeContainerToolsBase::LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode)
-{
-  DEBTRACE("SalomeContainer::loadComponent ");
-  const ComponentInstance *inst(askingNode?askingNode->getComponent():0);
-  {
-    YACS::BASES::AutoLocker<Container> alck(cont);//To be sure
-    if(!cont->isAlreadyStarted(askingNode))
-      cont->start(askingNode);
-  }
-  if(!inst)
-    throw Exception("SalomeContainerTools::LoadComponent : no instance of component in the task requesting for a load of its component !");
-  CORBA::Object_ptr objComponent=CORBA::Object::_nil();
-  {
-    YACS::BASES::AutoLocker<Container> alck(cont);//To be sure
-    std::string compoName(inst->getCompoName());
-    Engines::Container_var container(launchModeType->getContainer(askingNode));
-
-    char *reason;
-    bool isLoadable(container->load_component_Library(compoName.c_str(), reason));
-    if(isLoadable)
-      objComponent=CreateComponentInstance(cont,container,inst);
-  }
-  return objComponent;
-}
-
-CORBA::Object_ptr SalomeContainerToolsBase::CreateComponentInstance(Container *cont, Engines::Container_ptr contPtr, const ComponentInstance *inst)
-{
-  if(!inst)
-    throw Exception("SalomeContainerTools::CreateComponentInstance : no instance of component in the task requesting for a load of its component !");
-  char *reason(0);
-  std::string compoName(inst->getCompoName());
-  CORBA::Object_ptr objComponent=CORBA::Object::_nil();
-  int studyid(1);
-  Proc* p(cont->getProc());
-  if(p)
-    {
-      std::string value(p->getProperty("DefaultStudyID"));
-      if(!value.empty())
-        studyid= atoi(value.c_str());
-    }
-  // prepare component instance properties
-  Engines::FieldsDict_var env(new Engines::FieldsDict);
-  std::map<std::string, std::string> properties(inst->getProperties());
-  if(p)
-    {
-      std::map<std::string,std::string> procMap=p->getProperties();
-      properties.insert(procMap.begin(),procMap.end());
-    }
-
-  std::map<std::string, std::string>::const_iterator itm;
-  env->length(properties.size());
-  int item=0;
-  for(itm = properties.begin(); itm != properties.end(); ++itm, item++)
-    {
-      DEBTRACE("envname="<<itm->first<<" envvalue="<< itm->second);
-      env[item].key= CORBA::string_dup(itm->first.c_str());
-      env[item].value <<= itm->second.c_str();
-    }
-
-  objComponent=contPtr->create_component_instance_env(compoName.c_str(), env, reason);
-  if(CORBA::is_nil(objComponent))
-    {
-      std::string text="Error while trying to create a new component: component '"+ compoName;
-      text=text+"' is not installed or it's a wrong name";
-      text += '\n';
-      text += reason;
-      CORBA::string_free(reason);
-      throw Exception(text);
-    }
-  return objComponent;
-}
-
-std::string SalomeContainerToolsBase::GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode)
-{
-  if(cont->isAlreadyStarted(askingNode))
-    {
-      Engines::Container_var container(launchModeType->getContainer(askingNode));
-      const char *what="/";
-      CORBA::String_var corbaStr(container->name());
-      std::string ret(corbaStr);
-
-      //Salome FOREVER ...
-      std::string::size_type i=ret.find_first_of(what,0);
-      i=ret.find_first_of(what, i==std::string::npos ? i:i+1);
-      if(i!=std::string::npos)
-        return ret.substr(i+1);
-      return ret;
-    }
-  else
-    return "Not placed yet !!!";
-}
-
-std::string SalomeContainerToolsBase::GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode)
-{
-  if(cont->isAlreadyStarted(askingNode))
-    {
-      Engines::Container_var container(launchModeType->getContainer(askingNode));
-      try
-      {
-          CORBA::String_var corbaStr(container->name());
-          std::string ret(corbaStr);
-          return ret;
-      }
-      catch(...)
-      {
-          return "Unknown_placement";
-      }
-    }
-  else
-    return "Not_placed_yet";
-}
-
-void SalomeContainerToolsBase::SetContainerNameOf(Engines::ContainerParameters& params, const std::string& name)
-{
-  params.container_name=CORBA::string_dup(name.c_str());
-}
-
-
-/////////////////////////////////
-
-SalomeContainerToolsInter::SalomeContainerToolsInter(const SalomeContainerToolsInter& other):_propertyMap(other._propertyMap)
-{
-}
-
-void SalomeContainerToolsInter::clearProperties()
-{
-  _propertyMap.clear();
-}
-
-std::string SalomeContainerToolsInter::getProperty(const std::string& name) const
-{
-  std::map<std::string,std::string>::const_iterator it(_propertyMap.find(name));
-  if(it!=_propertyMap.end())
-    return (*it).second;
-  else
-    return std::string();
-}
-
-std::map<std::string,std::string> SalomeContainerToolsInter::getResourceProperties(const std::string& name) const
-{
-  std::map<std::string,std::string> properties;
-
-  YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
-  CORBA::ORB_ptr orb = runTime->getOrb();
-  if (!orb) return properties;
-  SALOME_NamingService namingService(orb);
-  SALOME_LifeCycleCORBA lcc(&namingService);
-  CORBA::Object_var obj = namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
-  if (CORBA::is_nil(obj))
-    return properties;
-  Engines::ResourcesManager_var resManager = Engines::ResourcesManager::_narrow(obj);
-  if (CORBA::is_nil(resManager))
-    return properties;
-
-  std::ostringstream value;
-  Engines::ResourceDefinition_var resource_definition = resManager->GetResourceDefinition(name.c_str());
-  properties["hostname"]=resource_definition->hostname.in();
-  properties["OS"]=resource_definition->OS.in();
-  value.str(""); value << resource_definition->mem_mb;
-  properties["mem_mb"]=value.str();
-  value.str(""); value << resource_definition->cpu_clock;
-  properties["cpu_clock"]=value.str();
-  value.str(""); value << resource_definition->nb_node;
-  properties["nb_node"]=value.str();
-  value.str(""); value << resource_definition->nb_proc_per_node;
-  properties["nb_proc_per_node"]=value.str();
-  /*
-  properties["component_list"]="";
-  for(CORBA::ULong i=0; i < resource_definition->componentList.length(); i++)
-    {
-      if(i > 0)
-        properties["component_list"]=properties["component_list"]+",";
-      properties["component_list"]=properties["component_list"]+resource_definition->componentList[i].in();
-    }
-    */
-  return properties;
-}
-
-////////////////////////
-
 SalomeContainerTools::SalomeContainerTools()
 {
   /* Init ContainerParameters */
   SALOME_LifeCycleCORBA::preSet(_params);
 }
 
-SalomeContainerTools::SalomeContainerTools(const SalomeContainerTools& other):SalomeContainerToolsInter(other),_params(other._params)
+SalomeContainerTools::SalomeContainerTools(const SalomeContainerTools& other):_params(other._params),_propertyMap(other._propertyMap)
 {
 }
 
-int SalomeContainerTools::getNumberOfCoresPerWorker() const
+void SalomeContainerTools::clearProperties()
 {
-  return _params.resource_params.nb_proc_per_node;
+  _propertyMap.clear();
+  _params=Engines::ContainerParameters();
 }
 
-void SalomeContainerTools::clearProperties()
+std::string SalomeContainerTools::getProperty(const std::string& name) const
 {
-  SalomeContainerToolsInter::clearProperties();
-  _params=Engines::ContainerParameters();
+  std::map<std::string,std::string>::const_iterator it(_propertyMap.find(name));
+  if(it!=_propertyMap.end())
+    return (*it).second;
+  else
+    return std::string();
 }
 
 void SalomeContainerTools::setProperty(const std::string& name, const std::string& value)
@@ -527,11 +235,6 @@ void SalomeContainerTools::setContainerName(const std::string& name)
   SetContainerNameOf(_params,name);
 }
 
-std::string SalomeContainerTools::getHostName() const
-{
-  return std::string(_params.resource_params.hostname);
-}
-
 std::string SalomeContainerTools::getNotNullContainerName(const Container *contPtr, const Task *askingNode, bool& isEmpty) const
 {
   isEmpty=true;
@@ -554,82 +257,272 @@ std::string SalomeContainerTools::getNotNullContainerName(const Container *contP
     }
 }
 
-//////////////////////////
-
-std::string SalomeContainerToolsDecoratorBase::getProperty(const std::string& name) const
+std::string SalomeContainerTools::getHostName() const
 {
-  return _sct->getProperty(name);
+  return std::string(_params.resource_params.hostname);
 }
 
-void SalomeContainerToolsDecoratorBase::setProperty(const std::string& name, const std::string& value)
+void SalomeContainerTools::SetContainerNameOf(Engines::ContainerParameters& params, const std::string& name)
 {
-  _sct->setProperty(name,value);
+  params.container_name=CORBA::string_dup(name.c_str());
 }
 
-const std::map<std::string,std::string>& SalomeContainerToolsDecoratorBase::getProperties() const
+std::map<std::string,std::string> SalomeContainerTools::getResourceProperties(const std::string& name) const
 {
-  return _sct->getProperties();
-}
+  std::map<std::string,std::string> properties;
 
-void SalomeContainerToolsDecoratorBase::clearProperties()
-{
-  _sct->clearProperties();
-}
+  YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
+  CORBA::ORB_ptr orb = runTime->getOrb();
+  if (!orb) return properties;
+  SALOME_NamingService namingService(orb);
+  SALOME_LifeCycleCORBA lcc(&namingService);
+  CORBA::Object_var obj = namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
+  if (CORBA::is_nil(obj))
+    return properties;
+  Engines::ResourcesManager_var resManager = Engines::ResourcesManager::_narrow(obj);
+  if (CORBA::is_nil(resManager))
+    return properties;
 
-std::map<std::string,std::string> SalomeContainerToolsDecoratorBase::getResourceProperties(const std::string& name) const
-{
-  return _sct->getResourceProperties(name);
+  std::ostringstream value;
+  Engines::ResourceDefinition_var resource_definition = resManager->GetResourceDefinition(name.c_str());
+  properties["hostname"]=resource_definition->hostname.in();
+  properties["OS"]=resource_definition->OS.in();
+  value.str(""); value << resource_definition->mem_mb;
+  properties["mem_mb"]=value.str();
+  value.str(""); value << resource_definition->cpu_clock;
+  properties["cpu_clock"]=value.str();
+  value.str(""); value << resource_definition->nb_node;
+  properties["nb_node"]=value.str();
+  value.str(""); value << resource_definition->nb_proc_per_node;
+  properties["nb_proc_per_node"]=value.str();
+  /*
+  properties["component_list"]="";
+  for(CORBA::ULong i=0; i < resource_definition->componentList.length(); i++)
+    {
+      if(i > 0)
+        properties["component_list"]=properties["component_list"]+",";
+      properties["component_list"]=properties["component_list"]+resource_definition->componentList[i].in();
+    }
+    */
+  return properties;
 }
 
-void SalomeContainerToolsDecoratorBase::addToComponentList(const std::string& name)
+/*!
+ * \param [in] compoNames
+ * \param [in,out] shutdownLevel
+ */
+void SalomeContainerTools::Start(const std::vector<std::string>& compoNames, SalomeContainerHelper *schelp, SalomeContainerTools& sct, int& shutdownLevel, const Container *cont, const Task *askingNode)
 {
-  _sct->addToComponentList(name);
-}
+  CORBA::ORB_ptr orb(getSALOMERuntime()->getOrb());
+  SALOME_NamingService ns;
+  try
+  {
+      ns.init_orb(orb);
+  }
+  catch(SALOME_Exception& e)
+  {
+      throw Exception("SalomeContainer::start : Unable to contact the SALOME Naming Service");
+  }
+  CORBA::Object_var obj(ns.Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS));
+  Engines::ContainerManager_var contManager(Engines::ContainerManager::_narrow(obj));
 
-void SalomeContainerToolsDecoratorBase::addToResourceList(const std::string& name)
-{
-  _sct->addToResourceList(name);
-}
+  bool isEmptyName;
+  std::string str(sct.getNotNullContainerName(cont,askingNode,isEmptyName));
+  DEBTRACE("SalomeContainer::start " << str <<";"<< _sct.getHostName() <<";"<<_type);
 
-Engines::ContainerParameters SalomeContainerToolsDecoratorBase::getParameters() const
-{
-  return _sct->getParameters();
-}
+  // Finalize parameters with components found in the container
 
-std::string SalomeContainerToolsDecoratorBase::getContainerName() const
-{
-  return _sct->getContainerName();
+  for(std::vector<std::string>::const_iterator iter=compoNames.begin();iter!=compoNames.end();iter++)
+    sct.addToComponentList(*iter);
+
+  Engines::ContainerParameters myparams(sct.getParameters());
+  {
+    std::string dftLauchMode(schelp->getDftLaunchMode());
+    myparams.mode=CORBA::string_dup(dftLauchMode.c_str());
+  }
+
+  //If a container_name is given try to find an already existing container in naming service
+  //If not found start a new container with the given parameters
+  if (dynamic_cast<SalomeContainerMonoHelper *>(schelp) && !isEmptyName)
+    {
+      myparams.mode=CORBA::string_dup("getorstart");
+    }
+
+  if (isEmptyName)
+    {
+      shutdownLevel=1;
+    }
+  //sct.setContainerName(str);
+  SetContainerNameOf(myparams,str);
+  Engines::Container_var trueCont(Engines::Container::_nil());
+  if(!isEmptyName && shutdownLevel==999)
+    {
+      //Make this only the first time start is called (_shutdownLevel==999)
+      //If the container is named, first try to get an existing container
+      //If there is an existing container use it and set the shutdown level to 3
+      //If there is no existing container, try to launch a new one and set the shutdown level to 2
+      myparams.mode="get";
+      try
+      {
+          trueCont=contManager->GiveContainer(myparams);
+      }
+      catch( const SALOME::SALOME_Exception& ex )
+      {
+          std::string msg="SalomeContainer::start : no existing container : ";
+          msg += '\n';
+          msg += ex.details.text.in();
+          DEBTRACE( msg );
+      }
+      catch(...)
+      {
+      }
+
+      if(!CORBA::is_nil(trueCont))
+        {
+          shutdownLevel=3;
+          DEBTRACE( "container found: " << str << " " << _shutdownLevel );
+        }
+      else
+        {
+          shutdownLevel=2;
+          myparams.mode="start";
+          DEBTRACE( "container not found: " << str << " " << _shutdownLevel);
+        }
+    }
+
+  if(CORBA::is_nil(trueCont))
+    try
+  {
+        // --- GiveContainer is used in batch mode to retreive launched containers,
+        //     and is equivalent to StartContainer when not in batch.
+        trueCont=contManager->GiveContainer(myparams);
+  }
+  catch( const SALOME::SALOME_Exception& ex )
+  {
+      std::string msg="SalomeContainer::start : Unable to launch container in Salome : ";
+      msg += '\n';
+      msg += ex.details.text.in();
+      throw Exception(msg);
+  }
+  catch(CORBA::COMM_FAILURE&)
+  {
+      throw Exception("SalomeContainer::start : Unable to launch container in Salome : CORBA Comm failure detected");
+  }
+  catch(CORBA::Exception&)
+  {
+      throw Exception("SalomeContainer::start : Unable to launch container in Salome : Unexpected CORBA failure detected");
+  }
+
+  if(CORBA::is_nil(trueCont))
+    throw Exception("SalomeContainer::start : Unable to launch container in Salome. Check your CatalogResources.xml file");
+
+  schelp->setContainer(askingNode,trueCont);
+
+  CORBA::String_var containerName(trueCont->name()),hostName(trueCont->getHostName());
+  std::cerr << "SalomeContainer launched : " << containerName << " " << hostName << " " << trueCont->getPID() << std::endl;
 }
 
-void SalomeContainerToolsDecoratorBase::setContainerName(const std::string& name)
+CORBA::Object_ptr SalomeContainerTools::LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode)
 {
-  _sct->setContainerName(name);
+  DEBTRACE("SalomeContainer::loadComponent ");
+  const ComponentInstance *inst(askingNode?askingNode->getComponent():0);
+  {
+    YACS::BASES::AutoLocker<Container> alck(cont);//To be sure
+    if(!cont->isAlreadyStarted(askingNode))
+      cont->start(askingNode);
+  }
+  if(!inst)
+    throw Exception("SalomeContainerTools::LoadComponent : no instance of component in the task requesting for a load of its component !");
+  CORBA::Object_ptr objComponent=CORBA::Object::_nil();
+  {
+    YACS::BASES::AutoLocker<Container> alck(cont);//To be sure
+    std::string compoName(inst->getCompoName());
+    Engines::Container_var container(launchModeType->getContainer(askingNode));
+
+    char *reason;
+    bool isLoadable(container->load_component_Library(compoName.c_str(), reason));
+    if(isLoadable)
+      objComponent=CreateComponentInstance(cont,container,inst);
+  }
+  return objComponent;
 }
 
-std::string SalomeContainerToolsDecoratorBase::getHostName() const
+CORBA::Object_ptr SalomeContainerTools::CreateComponentInstance(Container *cont, Engines::Container_ptr contPtr, const ComponentInstance *inst)
 {
-  return _sct->getHostName();
-}
+  if(!inst)
+    throw Exception("SalomeContainerTools::CreateComponentInstance : no instance of component in the task requesting for a load of its component !");
+  char *reason(0);
+  std::string compoName(inst->getCompoName());
+  CORBA::Object_ptr objComponent=CORBA::Object::_nil();
+  Proc* p(cont->getProc());
+  // prepare component instance properties
+  Engines::FieldsDict_var env(new Engines::FieldsDict);
+  std::map<std::string, std::string> properties(inst->getProperties());
+  if(p)
+    {
+      std::map<std::string,std::string> procMap=p->getProperties();
+      properties.insert(procMap.begin(),procMap.end());
+    }
+
+  std::map<std::string, std::string>::const_iterator itm;
+  env->length(properties.size());
+  int item=0;
+  for(itm = properties.begin(); itm != properties.end(); ++itm, item++)
+    {
+      DEBTRACE("envname="<<itm->first<<" envvalue="<< itm->second);
+      env[item].key= CORBA::string_dup(itm->first.c_str());
+      env[item].value <<= itm->second.c_str();
+    }
 
+  objComponent=contPtr->create_component_instance_env(compoName.c_str(), env, reason);
+  if(CORBA::is_nil(objComponent))
+    {
+      std::string text="Error while trying to create a new component: component '"+ compoName;
+      text=text+"' is not installed or it's a wrong name";
+      text += '\n';
+      text += reason;
+      CORBA::string_free(reason);
+      throw Exception(text);
+    }
+  return objComponent;
+}
 
-std::string SalomeContainerToolsDecoratorBase::getNotNullContainerName(const Container *contPtr, const Task *askingNode, bool& isEmpty) const
+std::string SalomeContainerTools::GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode)
 {
-  return _sct->getNotNullContainerName(contPtr,askingNode,isEmpty);
-}
+  if(cont->isAlreadyStarted(askingNode))
+    {
+      Engines::Container_var container(launchModeType->getContainer(askingNode));
+      const char *what="/";
+      CORBA::String_var corbaStr(container->name());
+      std::string ret(corbaStr);
 
-//////////////////////////////
+      //Salome FOREVER ...
+      std::string::size_type i=ret.find_first_of(what,0);
+      i=ret.find_first_of(what, i==std::string::npos ? i:i+1);
+      if(i!=std::string::npos)
+        return ret.substr(i+1);
+      return ret;
+    }
+  else
+    return "Not placed yet !!!";
+}
 
-Engines::ContainerParameters SalomeContainerToolsSpreadOverTheResDecorator::getParameters() const
+std::string SalomeContainerTools::GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode)
 {
-  Engines::ContainerParameters ret(getWorker()->getParameters());
-  std::string st(ret.resource_params.hostname);
-  if(!st.empty())
-    return ret;
-  int nbProcPerNode(ret.resource_params.nb_proc_per_node);
-  std::size_t iPos(_vh->locateTask(_node)),nPos(_vh->size());
-  if(_vh->size()!=_pg->getNumberOfWorkers(nbProcPerNode))
-    throw YACS::Exception("SalomeContainerToolsSpreadOverTheResDecorator::getParameters : Internal error !");
-  std::string zeMachine(_pg->deduceMachineFrom(iPos,nbProcPerNode));
-  ret.resource_params.hostname=CORBA::string_dup(zeMachine.c_str());
-  return ret;
+  if(cont->isAlreadyStarted(askingNode))
+    {
+      Engines::Container_var container(launchModeType->getContainer(askingNode));
+      try
+      {
+          CORBA::String_var corbaStr(container->name());
+          std::string ret(corbaStr);
+          return ret;
+      }
+      catch(...)
+      {
+          return "Unknown_placement";
+      }
+    }
+  else
+    return "Not_placed_yet";
 }
index 3433624eaa1259a4b7be6c6b3d03bda39b2eefa3..44e37926e197bf86e5014681e1bf8be5d814955f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// 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
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __SALOMECONTAINERTOOLS_HXX__
-#define __SALOMECONTAINERTOOLS_HXX__
+#pragma once
 
 #include "YACSRuntimeSALOMEExport.hxx"
 #include "SALOMEconfig.h"
@@ -37,104 +36,34 @@ namespace YACS
     class ComponentInstance;
     class SalomeContainerHelper;
 
-    class YACSRUNTIMESALOME_EXPORT SalomeContainerToolsBase
-    {
-    public:
-      virtual ~SalomeContainerToolsBase() { }
-      virtual std::string getProperty(const std::string& name) const = 0;
-      virtual void setProperty(const std::string& name, const std::string& value) = 0;
-      virtual const std::map<std::string,std::string>& getProperties() const = 0;
-      virtual void clearProperties() = 0;
-      virtual std::map<std::string,std::string> getResourceProperties(const std::string& name) const = 0;
-      virtual void addToComponentList(const std::string& name) = 0;
-      virtual void addToResourceList(const std::string& name) = 0;
-      virtual Engines::ContainerParameters getParameters() const = 0;
-      virtual std::string getContainerName() const = 0;
-      virtual void setContainerName(const std::string& name) = 0;
-      virtual std::string getHostName() const = 0;
-      virtual std::string getNotNullContainerName(const Container *contPtr, const Task *askingNode, bool& isEmpty) const = 0;
-    public:
-      static void Start(const std::vector<std::string>& compoNames, SalomeContainerHelper *schelp, SalomeContainerToolsBase& sct, int& shutdownLevel, const Container *cont, const Task *askingNode);
-      static CORBA::Object_ptr LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode);
-      static CORBA::Object_ptr CreateComponentInstance(Container *cont, Engines::Container_ptr contPtr, const ComponentInstance *inst);
-      static std::string GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode);
-      static std::string GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode);
-      static void SetContainerNameOf(Engines::ContainerParameters& params, const std::string& name);
-    };
-    
-    class YACSRUNTIMESALOME_EXPORT SalomeContainerToolsInter : public SalomeContainerToolsBase
-    {
-    public:
-      SalomeContainerToolsInter() { }
-      SalomeContainerToolsInter(const SalomeContainerToolsInter& other);
-      std::string getProperty(const std::string& name) const;
-      const std::map<std::string,std::string>& getProperties() const { return _propertyMap; }
-      void clearProperties();
-      std::map<std::string,std::string> getResourceProperties(const std::string& name) const;
-    protected:
-      std::map<std::string,std::string> _propertyMap;
-    };
-
-    class YACSRUNTIMESALOME_EXPORT SalomeContainerTools : public SalomeContainerToolsInter
+    class YACSRUNTIMESALOME_EXPORT SalomeContainerTools
     {
     public:
       SalomeContainerTools();
       SalomeContainerTools(const SalomeContainerTools& other);
-      int getNumberOfCoresPerWorker() const;
-    public:
-      Engines::ContainerParameters getParameters() const { return _params; }
-      void clearProperties();
-      void setProperty(const std::string& name, const std::string& value);
-      void addToComponentList(const std::string& name);
-      void addToResourceList(const std::string& name);
-      std::string getContainerName() const;
-      void setContainerName(const std::string& name);
-      std::string getHostName() const;
-      std::string getNotNullContainerName(const Container *contPtr, const Task *askingNode, bool& isEmpty) const;
-    protected:
-      Engines::ContainerParameters _params;
-    };
-
-    class PlayGround;
-    
-    class YACSRUNTIMESALOME_EXPORT SalomeContainerToolsDecoratorBase : public SalomeContainerToolsBase
-    {
-    protected:
-      SalomeContainerToolsDecoratorBase(SalomeContainerToolsBase *sct):_sct(sct) { }
-      SalomeContainerToolsBase *getWorker() { return _sct; }
-      const SalomeContainerToolsBase *getWorker() const { return _sct; }
-    public:
       std::string getProperty(const std::string& name) const;
       void setProperty(const std::string& name, const std::string& value);
-      const std::map<std::string,std::string>& getProperties() const;
+      const std::map<std::string,std::string>& getProperties() const { return _propertyMap; }
       void clearProperties();
       std::map<std::string,std::string> getResourceProperties(const std::string& name) const;
       void addToComponentList(const std::string& name);
       void addToResourceList(const std::string& name);
-      Engines::ContainerParameters getParameters() const;
+    public:
       std::string getContainerName() const;
       void setContainerName(const std::string& name);
-      std::string getHostName() const;
       std::string getNotNullContainerName(const Container *contPtr, const Task *askingNode, bool& isEmpty) const;
-    private:
-      SalomeContainerToolsBase *_sct;
-    };
-
-    class SalomeHPContainerVectOfHelper;
-    
-    class YACSRUNTIMESALOME_EXPORT SalomeContainerToolsSpreadOverTheResDecorator : public SalomeContainerToolsDecoratorBase
-    {
+      std::string getHostName() const;
+      Engines::ContainerParameters getParameters() const { return _params; }
+      static void SetContainerNameOf(Engines::ContainerParameters& params, const std::string& name);
     public:
-      SalomeContainerToolsSpreadOverTheResDecorator(SalomeContainerToolsBase *sct, const PlayGround *pg, const SalomeHPContainerVectOfHelper *vh, const Task *node):SalomeContainerToolsDecoratorBase(sct),_pg(pg),_vh(vh),_node(node) { }
-      Engines::ContainerParameters getParameters() const;
-    private:
-      static std::string DeduceMachineFrom(const std::vector< std::pair<std::string,int> >& allResInfo, int iPos, int sz, int nbProcPerNode);
-    private:
-      const PlayGround *_pg;
-      const SalomeHPContainerVectOfHelper *_vh;
-      const Task *_node;
+      static void Start(const std::vector<std::string>& compoNames, SalomeContainerHelper *schelp, SalomeContainerTools& sct, int& shutdownLevel, const Container *cont, const Task *askingNode);
+      static CORBA::Object_ptr LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode);
+      static CORBA::Object_ptr CreateComponentInstance(Container *cont, Engines::Container_ptr contPtr, const ComponentInstance *inst);
+      static std::string GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode);
+      static std::string GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode);
+    protected:
+      std::map<std::string,std::string> _propertyMap;
+      Engines::ContainerParameters _params;
     };
   }
 }
-
-#endif
index 8e86b3abee2219073d546b6c6d15f2e3a4fb61f0..1cbc1e00092b30fac83ef58999f59611f8617026 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016  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
@@ -21,7 +21,6 @@
 #include "SalomeHPComponent.hxx"
 #include "SalomeContainerTmpForHP.hxx"
 #include "AutoLocker.hxx"
-#include "AutoRefCnt.hxx"
 
 #include <algorithm>
 
@@ -29,238 +28,108 @@ using namespace YACS::ENGINE;
 
 const char SalomeHPContainer::KIND[]="HPSalome";
 
-SalomeHPContainerBase::SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared):_launchModeType(resShared),_shutdownLevel(999)
+SalomeHPContainer::SalomeHPContainer():_shutdownLevel(999)
 {
 }
 
-SalomeHPContainerBase::SalomeHPContainerBase(const SalomeHPContainerBase& other):_shutdownLevel(999),_launchModeType(new SalomeHPContainerVectOfHelper),_initScript(other._initScript)
+SalomeHPContainer::SalomeHPContainer(const SalomeHPContainer& other):_componentNames(other._componentNames),_shutdownLevel(999),_sct(other._sct),_initScript(other._initScript)
 {
 }
 
-SalomeHPContainer *SalomeHPContainerBase::getTheBoss()
+void SalomeHPContainer::setSizeOfPool(int sz)
 {
-  HomogeneousPoolContainer *ret(this);
-  while(ret->getDirectFather())
-    ret=ret->getDirectFather();
-  SalomeHPContainer *retC(dynamic_cast<SalomeHPContainer *>(ret));
-  if(!retC)
-    throw Exception("SalomeHPContainerBase::getTheBoss : unexpected type of object !");
-  return retC;
+  _launchModeType.resize(sz);
 }
 
-const SalomeHPContainer *SalomeHPContainerBase::getTheBoss() const
+int SalomeHPContainer::getSizeOfPool() const
 {
-  const HomogeneousPoolContainer *ret(this);
-  while(ret->getDirectFather())
-    ret=ret->getDirectFather();
-  const SalomeHPContainer *retC(dynamic_cast<const SalomeHPContainer *>(ret));
-  if(!retC)
-    throw Exception("SalomeHPContainerBase::getTheBoss : unexpected type of object !");
-  return retC;
+  return _launchModeType.size();
 }
 
-void SalomeHPContainerBase::startInternal(const Task *askingNode, SalomeContainerToolsBase& sct, const std::vector<std::string>& compoNames)
+std::size_t SalomeHPContainer::getNumberOfFreePlace() const
 {
-  SalomeContainerMonoHelper *helper(_launchModeType->getHelperOfTaskThreadSafe(askingNode));
-  SalomeContainerTools::Start(compoNames,helper,sct,_shutdownLevel,this,askingNode);
+  return _launchModeType.getNumberOfFreePlace();
 }
 
-void SalomeHPContainerBase::shutdown(int level)
+void SalomeHPContainer::allocateFor(const std::vector<const Task *>& nodes)
 {
-  if(level < _shutdownLevel)
-      return;
-  _shutdownLevel=999;
-  _launchModeType->shutdown();
+  _launchModeType.allocateFor(nodes);
 }
 
-SalomeHPContainerBase::SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared, bool isRefEaten):_launchModeType(resShared)
+void SalomeHPContainer::release(const Task *node)
 {
-  if(!isRefEaten)
-    if(_launchModeType.isNotNull())
-      _launchModeType->incrRef();
+  _launchModeType.release(node);
 }
 
-bool SalomeHPContainerBase::isAlreadyStarted(const Task *askingNode) const
+SalomeHPContainer::~SalomeHPContainer()
 {
-  const SalomeContainerMonoHelper *helper(_launchModeType->getHelperOfTaskThreadSafe(askingNode));
-  return helper->isAlreadyStarted(askingNode);
 }
 
-void SalomeHPContainerBase::release(const Task *node)
+void SalomeHPContainer::lock()
 {
-  _launchModeType->release(node);
+  _mutex.lock();
 }
 
-void SalomeHPContainerBase::lock()
+void SalomeHPContainer::unLock()
 {
-  _launchModeType->lock();
+  _mutex.unLock();
 }
 
-void SalomeHPContainerBase::unLock()
+std::string SalomeHPContainer::getKind() const
 {
-  _launchModeType->unLock();
+  return KIND;
 }
 
-void SalomeHPContainerBase::setSizeOfPool(int sz)
+std::string SalomeHPContainer::getDiscreminantStrOfThis(const Task *askingNode) const
 {
-  _launchModeType->resize(sz);
+  YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(this,askingNode));
+  return tmpCont->getDiscreminantStrOfThis(askingNode);
 }
 
-int SalomeHPContainerBase::getSizeOfPool() const
+bool SalomeHPContainer::isAlreadyStarted(const Task *askingNode) const
 {
-  return _launchModeType->size();
+  const SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTaskThreadSafe(this,askingNode));
+  return helper->isAlreadyStarted(askingNode);
 }
 
-void SalomeHPContainerBase::setProperty(const std::string& name,const std::string& value)
+void SalomeHPContainer::start(const Task *askingNode) throw(YACS::Exception)
 {
-  if(name==AOC_ENTRY)//no sense to set it ! It is always true ! ignore it !
-    return ;
-  else if(name==SIZE_OF_POOL_KEY)
-    {
-      std::istringstream iss(value);
-      int val(0);
-      iss >> val;
-      setSizeOfPool(val);
-    }
-  else if(name==INITIALIZE_SCRIPT_KEY)
-    {
-      _initScript=value;
-    }
-  else
-    getTheBoss()->getContainerInfo().setProperty(name,value);
+  SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTaskThreadSafe(this,askingNode));
+  SalomeContainerTools::Start(_componentNames,helper,_sct,_shutdownLevel,this,askingNode);
 }
 
-std::string SalomeHPContainerBase::getProperty(const std::string& name) const
+void SalomeHPContainer::shutdown(int level)
 {
-  if(name==AOC_ENTRY)
-    {
-      return std::string("1");
-    }
-  else if(name==SIZE_OF_POOL_KEY)
-    {
-      std::ostringstream oss; oss << getSizeOfPool();
-      return oss.str();
-    }
-  else if(name==INITIALIZE_SCRIPT_KEY)
+  if(level < _shutdownLevel)
+      return;
+  _shutdownLevel=999;
+  for(std::size_t i=0;i<_launchModeType.size();i++)
     {
-      return _initScript;
+      SalomeContainerMonoHelper *helper(_launchModeType.at(i));
+      helper->shutdown();
     }
-  else
-    return getTheBoss()->getContainerInfo().getProperty(name);
-}
-
-std::map<std::string,std::string> SalomeHPContainerBase::getProperties() const
-{
-  std::map<std::string,std::string> ret(getTheBoss()->getContainerInfo().getProperties());
-  std::ostringstream oss; oss << getSizeOfPool();
-  ret[SIZE_OF_POOL_KEY]=oss.str();
-  if(!_initScript.empty())
-    ret[INITIALIZE_SCRIPT_KEY]=_initScript;
-  return ret;
-}
-
-void SalomeHPContainerBase::clearProperties()
-{
-  _initScript.clear();
-  getTheBoss()->getContainerInfo().clearProperties();
 }
 
-std::string SalomeHPContainerBase::getPlacementId(const Task *askingNode) const
+std::string SalomeHPContainer::getPlacementId(const Task *askingNode) const
 {
   const SalomeContainerMonoHelper *helper(0);
   {
-    YACS::BASES::AutoLocker<Container> alckCont(const_cast<SalomeHPContainerBase *>(this));
-    helper=_launchModeType->getHelperOfTask(askingNode);
+    YACS::BASES::AutoLocker<Container> alckCont(const_cast<SalomeHPContainer *>(this));
+    helper=_launchModeType.getHelperOfTask(askingNode);
   }
   return SalomeContainerTools::GetPlacementId(helper,this,askingNode);
 }
 
-std::string SalomeHPContainerBase::getFullPlacementId(const Task *askingNode) const
+std::string SalomeHPContainer::getFullPlacementId(const Task *askingNode) const
 {
   const SalomeContainerMonoHelper *helper(0);
   {
-    YACS::BASES::AutoLocker<Container> alckCont(const_cast<SalomeHPContainerBase *>(this));
-    helper=_launchModeType->getHelperOfTask(askingNode);
+    YACS::BASES::AutoLocker<Container> alckCont(const_cast<SalomeHPContainer *>(this));
+    helper=_launchModeType.getHelperOfTask(askingNode);
   }
   return SalomeContainerTools::GetFullPlacementId(helper,this,askingNode);
 }
 
-std::map<std::string,std::string> SalomeHPContainerBase::getResourceProperties(const std::string& name) const
-{
-  return getTheBoss()->getResourceProperties(name);
-}
-
-void SalomeHPContainerBase::addComponentName(const std::string& name)
-{
-  getTheBoss()->addComponentNameSpe(name);
-}
-
-void SalomeHPContainerBase::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
-{
-  getTheBoss()->checkCapabilityToDealWith(inst);
-}
-
-YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> SalomeHPContainerBase::decorate(YACS::BASES::AutoConstRefCnt<PartDefinition> pd)
-{
-  YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> ret(new SalomeHPContainerShared(pd,_launchModeType,this));
-  return ret;
-}
-
-Engines::Container_var SalomeHPContainerBase::getContainerPtr(const Task *askingNode) const
-{
-  const SalomeContainerMonoHelper *helper(0);
-  {
-    YACS::BASES::AutoLocker<SalomeHPContainerBase> alck(const_cast<SalomeHPContainerBase *>(this));
-    helper=_launchModeType->getHelperOfTask(askingNode);
-  }
-  return helper->getContainer(NULL);
-}
-
-std::vector<std::string> SalomeHPContainerBase::getKernelContainerNames() const
-{
-  return _launchModeType->getKernelContainerNames();
-}
-
-////////////////
-
-SalomeHPContainer::SalomeHPContainer():SalomeHPContainerBase(new SalomeHPContainerVectOfHelper)
-{
-}
-
-SalomeHPContainer::SalomeHPContainer(const SalomeHPContainer& other):SalomeHPContainerBase(other),_sct(other._sct),_componentNames(other._componentNames)
-{
-}
-
-std::size_t SalomeHPContainer::getNumberOfFreePlace() const
-{
-  return _launchModeType->getNumberOfFreePlace();
-}
-
-void SalomeHPContainer::allocateFor(const std::vector<const Task *>& nodes)
-{
-  _launchModeType->allocateFor(nodes);
-}
-
-SalomeHPContainer::~SalomeHPContainer()
-{
-}
-
-std::string SalomeHPContainer::getKind() const
-{
-  return KIND;
-}
-
-std::string SalomeHPContainer::getDiscreminantStrOfThis(const Task *askingNode) const
-{
-  YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(this,askingNode));
-  return tmpCont->getDiscreminantStrOfThis(askingNode);
-}
-
-void SalomeHPContainer::start(const Task *askingNode) throw(YACS::Exception)
-{
-  startInternal(askingNode,_sct,_componentNames);
-}
-
 /*!
  * It is not a bug here ! clone for homogeneous container is not supposed to be copied !
  */
@@ -275,100 +144,84 @@ Container *SalomeHPContainer::cloneAlways() const
   return new SalomeHPContainer(*this);
 }
 
-int SalomeHPContainer::getNumberOfCoresPerWorker() const
-{
-  return _sct.getNumberOfCoresPerWorker();
-}
-
-std::map<std::string,std::string> SalomeHPContainer::getResourceProperties(const std::string& name) const
-{
-  return _sct.getResourceProperties(name);
-}
-
-void SalomeHPContainer::addComponentNameSpe(const std::string& name)
-{
-  _componentNames.push_back(name);
-}
-
-void SalomeHPContainer::checkCapabilityToDealWithSpe(const ComponentInstance *inst) const throw(YACS::Exception)
-{
-  if(inst->getKind()!=SalomeHPComponent::KIND)
-    throw Exception("SalomeHPContainer::checkCapabilityToDealWithSpe : SalomeContainer is not able to deal with this type of ComponentInstance.");
-}
-
-void SalomeHPContainer::forYourTestsOnly(ForTestOmlyHPContCls *data) const
-{
-  data->setContainerType("HPContainer");
-}
-
-//////////////////////////////////
-
-SalomeHPContainerShared::SalomeHPContainerShared(YACS::BASES::AutoConstRefCnt<PartDefinition> pd, SalomeHPContainerVectOfHelper *resShared, SalomeHPContainerBase *directFather):SalomeHPContainerBase(resShared,false),_pd(pd)
-{
-  if(!directFather)
-    throw Exception("SalomeHPContainerShared : NULL pointer not allowed !");
-  _directFather.takeRef(directFather);
-}
-
-std::string SalomeHPContainerShared::getKind() const
-{
-  return SalomeHPContainer::KIND;
-}
-
-void SalomeHPContainerShared::prepareMaskForExecution() const
+void SalomeHPContainer::setProperty(const std::string& name,const std::string& value)
 {
-  _idsOfKernelContainers=_pd->computeWorkerIdsCovered(getNumberOfCoresPerWorker());
+  if(name==AOC_ENTRY)//no sense to set it ! It is always true ! ignore it !
+    return ;
+  else if(name==SIZE_OF_POOL_KEY)
+    {
+      std::istringstream iss(value);
+      int val(0);
+      iss >> val;
+      setSizeOfPool(val);
+    }
+  else if(name==INITIALIZE_SCRIPT_KEY)
+    {
+      _initScript=value;
+    }
+  else
+    _sct.setProperty(name,value);
 }
 
-/*!
- * It is not a bug here ! clone for homogeneous container is not supposed to be copied !
- */
-Container *SalomeHPContainerShared::clone() const
+std::string SalomeHPContainer::getProperty(const std::string& name) const
 {
-  incrRef();
-  return const_cast<SalomeHPContainerShared*>(this);
+  if(name==AOC_ENTRY)
+    {
+      return std::string("1");
+    }
+  else if(name==SIZE_OF_POOL_KEY)
+    {
+      std::ostringstream oss; oss << getSizeOfPool();
+      return oss.str();
+    }
+  else if(name==INITIALIZE_SCRIPT_KEY)
+    {
+      return _initScript;
+    }
+  else
+    return _sct.getProperty(name);
 }
 
-Container *SalomeHPContainerShared::cloneAlways() const
+void SalomeHPContainer::clearProperties()
 {
-  throw Exception("SalomeHPContainerShared::cloneAlways : you are not supposed to be in this situation ! This type of container has only existence during execution !");
+  _initScript.clear();
+  _sct.clearProperties();
 }
 
-std::string SalomeHPContainerShared::getName() const
+void SalomeHPContainer::addComponentName(const std::string& name)
 {
-  return getTheBoss()->getName();
+  _componentNames.push_back(name);
 }
 
-std::string SalomeHPContainerShared::getDiscreminantStrOfThis(const Task *askingNode) const
+std::map<std::string,std::string> SalomeHPContainer::getProperties() const
 {
-  return getTheBoss()->getDiscreminantStrOfThis(askingNode);
+  std::map<std::string,std::string> ret(_sct.getProperties());
+  std::ostringstream oss; oss << getSizeOfPool();
+  ret[SIZE_OF_POOL_KEY]=oss.str();
+  if(!_initScript.empty())
+    ret[INITIALIZE_SCRIPT_KEY]=_initScript;
+  return ret;
 }
 
-void SalomeHPContainerShared::start(const Task *askingNode) throw(YACS::Exception)
+std::map<std::string,std::string> SalomeHPContainer::getResourceProperties(const std::string& name) const
 {
-  SalomeContainerToolsSpreadOverTheResDecorator sct(&getTheBoss()->getContainerInfo(),_pd->getPlayGround(),_launchModeType,askingNode);
-  startInternal(askingNode,sct,getTheBoss()->getComponentNames());
+  return _sct.getResourceProperties(name);
 }
 
-void SalomeHPContainerShared::allocateFor(const std::vector<const Task *>& nodes)
+void SalomeHPContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
 {
-  _launchModeType->allocateForAmong(_idsOfKernelContainers,nodes);
+  if(inst->getKind()!=SalomeHPComponent::KIND)
+    throw Exception("SalomeHPContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
 }
 
-std::size_t SalomeHPContainerShared::getNumberOfFreePlace() const
+std::vector<std::string> SalomeHPContainer::getKernelContainerNames() const
 {
-  return _launchModeType->getNumberOfFreePlaceAmong(_idsOfKernelContainers);
+  throw Exception("FIXME");
+  //return _launchModeType->getKernelContainerNames();
 }
 
-void SalomeHPContainerShared::forYourTestsOnly(ForTestOmlyHPContCls *data) const
+int SalomeHPContainer::getNumberOfCoresPerWorker() const
 {
-  data->setContainerType("HPContainerShared");
-  data->setPD(_pd);
-  data->setIDS(_idsOfKernelContainers);
-}
-
-/*
- * SalomeHPContainerVectOfHelper is an holder of vector of SalomeContainerMonoHelper (holding itself a Kernel Container)
- * SalomeContainerTools is a Engines::ContainerParameters holder. It is the data keeper for GiveContainer invokation.
- * 
- */
+  throw Exception("FIXME");
+  //return _sct.getNumberOfCoresPerWorker();
+}
\ No newline at end of file
index 692770f80f87c8c49613d94f666baad6e17642a0..63e5a783b4f36d7cfd590d06ff0fc01403d42e45 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016  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
 #include "SalomeContainerHelper.hxx"
 #include "SalomeContainerTools.hxx"
 #include "SalomeHPContainerTools.hxx"
-#include "PlayGround.hxx"
-
 #include "Mutex.hxx"
-#include "AutoRefCnt.hxx"
-
 #include <string>
 #include <vector>
 #include <map>
@@ -43,83 +39,51 @@ namespace YACS
   {
     class Task;
     class SalomeComponent;
-    class SalomeHPContainer;
-    
-    class YACSRUNTIMESALOME_EXPORT SalomeHPContainerBase : public HomogeneousPoolContainer
-    {
-    protected:
-      SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared);
-      SalomeHPContainerBase(SalomeHPContainerVectOfHelper *resShared, bool isRefEaten);
-      SalomeHPContainerBase(const SalomeHPContainerBase& other);
-      void startInternal(const Task *askingNode, SalomeContainerToolsBase& sct, const std::vector<std::string>& compoNames);
-      SalomeHPContainer *getTheBoss();
-      const SalomeHPContainer *getTheBoss() const;
-    public:
-      void release(const Task *node);
-      //
-      bool isAlreadyStarted(const Task *askingNode) const;
-      void shutdown(int level);
-      //! For thread safety for concurrent load operation on same Container.
-      void lock();
-      //! For thread safety for concurrent load operation on same Container.
-      void unLock();
-      void setSizeOfPool(int sz);
-      int getSizeOfPool() const;
-      void setProperty(const std::string& name,const std::string& value);
-      std::string getProperty(const std::string& name) const;
-      std::map<std::string,std::string> getProperties() const;
-      void clearProperties();
-      std::string getPlacementId(const Task *askingNode) const;
-      std::string getFullPlacementId(const Task *askingNode) const;
-      std::map<std::string,std::string> getResourceProperties(const std::string& name) const;
-      void addComponentName(const std::string& name);
-      void checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception);
-      Engines::Container_var getContainerPtr(const Task *askingNode) const;
-      std::vector<std::string> getKernelContainerNames() const;
-    public:
-      int getShutdownLev() const { return _shutdownLevel; }
-      YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> decorate(YACS::BASES::AutoConstRefCnt<PartDefinition> pd);
-#ifndef SWIG
-      const SalomeHPContainerVectOfHelper *getDirectAccessToVecOfCont() const { return _launchModeType; }
-#endif
-    protected:
-      int _shutdownLevel;
-      YACS::BASES::AutoRefCnt<SalomeHPContainerVectOfHelper> _launchModeType;
-      std::string _initScript;
-    };
-    
-    class YACSRUNTIMESALOME_EXPORT SalomeHPContainer : public SalomeHPContainerBase
+
+    class YACSRUNTIMESALOME_EXPORT SalomeHPContainer : public HomogeneousPoolContainer
     {
     public:
       SalomeHPContainer();
       SalomeHPContainer(const SalomeHPContainer& other);
       //HP specific part
+      void setSizeOfPool(int sz);
+      int getSizeOfPool() const;
       std::size_t getNumberOfFreePlace() const;
       void allocateFor(const std::vector<const Task *>& nodes);
+      void release(const Task *node);
+      //! For thread safety for concurrent load operation on same Container.
+      void lock();
+      //! For thread safety for concurrent load operation on same Container.
+      void unLock();
       //
       std::string getKind() const;
       std::string getDiscreminantStrOfThis(const Task *askingNode) const;
+      bool isAlreadyStarted(const Task *askingNode) const;
       void start(const Task *askingNode) throw(Exception);
+      void shutdown(int level);
+      std::string getPlacementId(const Task *askingNode) const;
+      std::string getFullPlacementId(const Task *askingNode) const;
       Container *clone() const;
       Container *cloneAlways() const;
+      void setProperty(const std::string& name,const std::string& value);
+      std::string getProperty(const std::string& name) const;
+      void clearProperties();
+      void addComponentName(const std::string& name);
+      std::map<std::string,std::string> getProperties() const;
+      std::map<std::string,std::string> getResourceProperties(const std::string& name) const;
+      void checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception);
+      std::vector<std::string> getKernelContainerNames() const;
       int getNumberOfCoresPerWorker() const;
-      //! do nothing. because no special actions to do. Only for decorators
-      void prepareMaskForExecution() const { }
       //
 #ifndef SWIG
-      void forYourTestsOnly(ForTestOmlyHPContCls *data) const;
-      std::map<std::string,std::string> getResourceProperties(const std::string& name) const;
-      void addComponentNameSpe(const std::string& name);
-      void checkCapabilityToDealWithSpe(const ComponentInstance *inst) const throw(YACS::Exception);
-      std::size_t locateTask(const Task *askingNode) const { return _launchModeType->locateTask(askingNode); }
+      std::size_t locateTask(const Task *askingNode) const { return _launchModeType.locateTask(askingNode); }
       const SalomeContainerTools &getContainerInfo() const { return _sct; }
-      SalomeContainerTools &getContainerInfo() { return _sct; }
       std::vector<std::string> getComponentNames() const { return _componentNames; }
-      SalomeContainerMonoHelper *getHelperOfTask(const Task *node) { return _launchModeType->getHelperOfTask(node); }
-      const SalomeContainerMonoHelper *getHelperOfTask(const Task *node) const { return _launchModeType->getHelperOfTask(node); }
+      int getShutdownLev() const { return _shutdownLevel; }
+      SalomeContainerMonoHelper *getHelperOfTask(const Task *node) { return _launchModeType.getHelperOfTask(node); }
+      const SalomeContainerMonoHelper *getHelperOfTask(const Task *node) const { return _launchModeType.getHelperOfTask(node); }
       //
-      HomogeneousPoolContainer *getDirectFather() { return NULL; }
-      const HomogeneousPoolContainer *getDirectFather() const { return NULL; }
+      YACS::BASES::Mutex& getLocker() { return _mutex; }
 #endif
     public:
       static const char KIND[];
@@ -128,38 +92,14 @@ namespace YACS
       ~SalomeHPContainer();
 #endif
     protected:
+      int _shutdownLevel;
       SalomeContainerTools _sct;
+      YACS::BASES::Mutex _mutex;
       std::vector<std::string> _componentNames;
-    };
-
-#ifndef SWIG
-    class YACSRUNTIMESALOME_EXPORT SalomeHPContainerShared : public SalomeHPContainerBase
-    {
-    public:
-      SalomeHPContainerShared(YACS::BASES::AutoConstRefCnt<PartDefinition> pd, SalomeHPContainerVectOfHelper *resShared, SalomeHPContainerBase *directFather);
-      HomogeneousPoolContainer *getDirectFather() { return _directFather; }
-      const HomogeneousPoolContainer *getDirectFather() const { return _directFather; }
-      int getNumberOfCoresPerWorker() const { return _directFather->getNumberOfCoresPerWorker(); }
-      std::string getProperty(const std::string& name) const { return _directFather->getProperty(name); }
-      void prepareMaskForExecution() const;
-      void forYourTestsOnly(ForTestOmlyHPContCls *data) const;
-      std::string getName() const;
-      std::string getDiscreminantStrOfThis(const Task *askingNode) const;
-    public:
-      std::string getKind() const;
-      void start(const Task *askingNode) throw(Exception);
-      Container *clone() const;
-      Container *cloneAlways() const;
       //
-      void allocateFor(const std::vector<const Task *>& nodes);
-      std::size_t getNumberOfFreePlace() const;
-    private:
-      YACS::BASES::AutoRefCnt<SalomeHPContainerBase> _directFather;
-      YACS::BASES::AutoConstRefCnt<PartDefinition> _pd;
-      //! ids in _launchModeType covered by _pd.
-      mutable std::vector<std::size_t> _idsOfKernelContainers;
+      SalomeHPContainerVectOfHelper _launchModeType;
+      std::string _initScript;
     };
-#endif
   }
 }
 
index 38e58830364c57614bd913a61002385776a0b5d9..bd73a472663f79fda116fbe3f65c7912a602f1c1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016  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
@@ -23,7 +23,6 @@
 #include "Exception.hxx"
 
 #include <algorithm>
-#include <limits>
 
 using namespace YACS::ENGINE;
 
@@ -45,15 +44,6 @@ std::size_t SalomeHPContainerVectOfHelper::getNumberOfFreePlace() const
   return std::count(_whichOccupied.begin(),_whichOccupied.end(),false);
 }
 
-std::size_t SalomeHPContainerVectOfHelper::getNumberOfFreePlaceAmong(const std::vector<std::size_t>& idsOfKernelContainers) const
-{
-  std::size_t ret(0);
-  for(std::vector<std::size_t>::const_iterator it=idsOfKernelContainers.begin();it!=idsOfKernelContainers.end();it++)
-    if(!_whichOccupied[*it])
-      ret++;
-  return ret;
-}
-
 void SalomeHPContainerVectOfHelper::allocateFor(const std::vector<const Task *>& nodes)
 {
   for(std::vector<const Task *>::const_iterator it=nodes.begin();it!=nodes.end();it++)
@@ -70,27 +60,6 @@ void SalomeHPContainerVectOfHelper::allocateFor(const std::vector<const Task *>&
     }
 }
 
-void SalomeHPContainerVectOfHelper::allocateForAmong(const std::vector<std::size_t>& idsOfKernelContainers, const std::vector<const Task *>& nodes)
-{
-  for(std::vector<const Task *>::const_iterator it=nodes.begin();it!=nodes.end();it++)
-    {
-      if(!(*it))
-        continue;
-      if(_currentlyWorking.find(*it)!=_currentlyWorking.end())
-        throw Exception("Searching 2 to allocate for a ServiceNode instance already declared as allocated !");
-      std::size_t it2(std::numeric_limits<std::size_t>::max());
-      for(std::vector<std::size_t>::const_iterator it=idsOfKernelContainers.begin();it!=idsOfKernelContainers.end();it++)
-        if(!_whichOccupied[*it])
-          {
-            it2=*it;
-            break;
-          }
-      if(it2==std::numeric_limits<std::size_t>::max())
-        throw Exception("All 2 ressources are already occupied ! You are expected to wait for released resources !");
-      _currentlyWorking[*it]=it2; _whichOccupied[it2]=true;
-    }
-}
-
 void SalomeHPContainerVectOfHelper::release(const Task *node)
 {
   if(!node)
@@ -112,9 +81,9 @@ std::size_t SalomeHPContainerVectOfHelper::locateTask(const Task *node) const
   return ret;
 }
 
-const SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTaskThreadSafe(const Task *node) const
+const SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTaskThreadSafe(const SalomeHPContainer *cont, const Task *node) const
 {
-  YACS::BASES::AutoLocker<SalomeHPContainerVectOfHelper> alck(const_cast<SalomeHPContainerVectOfHelper *>(this));
+  YACS::BASES::AutoLocker<Container> alck(const_cast<SalomeHPContainer *>(cont));
   return _launchModeType[locateTask(node)];
 }
 
@@ -123,9 +92,9 @@ const SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTask(
   return _launchModeType[locateTask(node)];
 }
 
-SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTaskThreadSafe(const Task *node)
+SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTaskThreadSafe(SalomeHPContainer *cont, const Task *node)
 {
-  YACS::BASES::AutoLocker<SalomeHPContainerVectOfHelper> alck(this);
+  YACS::BASES::AutoLocker<Container> alck(cont);
   return _launchModeType[locateTask(node)];
 }
 
@@ -134,35 +103,11 @@ SalomeContainerMonoHelper *SalomeHPContainerVectOfHelper::getHelperOfTask(const
   return _launchModeType[locateTask(node)];
 }
 
-void SalomeHPContainerVectOfHelper::checkNoCurrentWork() const
-{
-  for(std::map<const Task *,std::size_t >::const_iterator it=_currentlyWorking.begin();it!=_currentlyWorking.end();it++)
-    if((*it).first)
-      throw Exception("Something wrong a node is still declared to be using the ressource !");
-  for(std::vector< YACS::BASES::AutoRefCnt<SalomeContainerMonoHelper> >::const_iterator it=_launchModeType.begin();it!=_launchModeType.end();it++)
-    if((*it)->isAlreadyStarted(0))
-      throw Exception("Some of the containers have be started ! Please shutdown them before !");
-}
-
-void SalomeHPContainerVectOfHelper::checkPosInVec(std::size_t pos) const
-{
-  if(pos<0 || pos>=_launchModeType.size())
-    throw Exception("The task has been found, but its id is not in the correct range ! resize of of container size during run ?");
-}
-
-void SalomeHPContainerVectOfHelper::shutdown()
-{
-  for(std::vector< BASES::AutoRefCnt<YACS::ENGINE::SalomeContainerMonoHelper> >::iterator it=_launchModeType.begin();it!=_launchModeType.end();it++)
-    if((*it).isNotNull())
-      if(!(*it)->isKernelContNull())
-        (*it)->shutdown();
-}
-
-std::vector<std::string> SalomeHPContainerVectOfHelper::getKernelContainerNames() const
+std::vector<std::string> SalomeHPContainerVectOfHelper::getKernelContainerNames(const SalomeHPContainer *cont) const
 {
   std::vector<std::string> ret;
   {
-    YACS::BASES::AutoLocker<SalomeHPContainerVectOfHelper> alck(const_cast<SalomeHPContainerVectOfHelper *>(this));
+    YACS::BASES::AutoLocker<Container> alck(const_cast<SalomeHPContainer *>(cont));
     std::size_t sz(_launchModeType.size());
     ret.resize(sz);
     for(std::size_t i=0;i<sz;i++)
@@ -173,12 +118,18 @@ std::vector<std::string> SalomeHPContainerVectOfHelper::getKernelContainerNames(
   return ret;
 }
 
-void SalomeHPContainerVectOfHelper::lock()
+void SalomeHPContainerVectOfHelper::checkNoCurrentWork() const
 {
-  _mutex.lock();
+  for(std::map<const Task *,std::size_t >::const_iterator it=_currentlyWorking.begin();it!=_currentlyWorking.end();it++)
+    if((*it).first)
+      throw Exception("Something wrong a node is still declared to be using the ressource !");
+  for(std::vector< YACS::BASES::AutoRefCnt<SalomeContainerMonoHelper> >::const_iterator it=_launchModeType.begin();it!=_launchModeType.end();it++)
+    if((*it)->isAlreadyStarted(0))
+      throw Exception("Some of the containers have be started ! Please shutdown them before !");
 }
 
-void SalomeHPContainerVectOfHelper::unLock()
+void SalomeHPContainerVectOfHelper::checkPosInVec(std::size_t pos) const
 {
-  _mutex.unLock();
+  if(pos<0 || pos>=_launchModeType.size())
+    throw Exception("The task has been found, but its id is not in the correct range ! resize of of container size during run ?");
 }
index 35520b646834618f547e29da05a63a0824bb2089..bbc103ba736271c60b64ff3b414d23552817f2c9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// 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
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __SALOMEHPCONTAINERTOOLS_HXX__
-#define __SALOMEHPCONTAINERTOOLS_HXX__
+#pragma once
 
 #include "YACSRuntimeSALOMEExport.hxx"
 #include "SalomeContainerHelper.hxx"
 
-#include "RefCounter.hxx"
-
-#include "Mutex.hxx"
 #include "AutoRefCnt.hxx"
 
 #include <map>
@@ -39,41 +35,29 @@ namespace YACS
     class SalomeComponent;
     class SalomeHPContainer;
     class SalomeContainerMonoHelper;
-    class SalomeHPContainerVectOfHelper : public RefCounter
+    class SalomeHPContainerVectOfHelper
     {
     public:
       std::size_t size() const { return _launchModeType.size(); }
       void resize(std::size_t sz);
       std::size_t getNumberOfFreePlace() const;
-      std::size_t getNumberOfFreePlaceAmong(const std::vector<std::size_t>& idsOfKernelContainers) const;
       void allocateFor(const std::vector<const Task *>& nodes);
-      void allocateForAmong(const std::vector<std::size_t>& idsOfKernelContainers, const std::vector<const Task *>& nodes);
       void release(const Task *node);
       std::size_t locateTask(const Task *node) const;
       const SalomeContainerMonoHelper *at(std::size_t pos) const { checkPosInVec(pos); return _launchModeType[pos]; }
       SalomeContainerMonoHelper *at(std::size_t pos) { checkPosInVec(pos); return _launchModeType[pos]; }
-      const SalomeContainerMonoHelper *getHelperOfTaskThreadSafe(const Task *node) const;
+      const SalomeContainerMonoHelper *getHelperOfTaskThreadSafe(const SalomeHPContainer *cont, const Task *node) const;
       const SalomeContainerMonoHelper *getHelperOfTask(const Task *node) const;
-      SalomeContainerMonoHelper *getHelperOfTaskThreadSafe(const Task *node);
+      SalomeContainerMonoHelper *getHelperOfTaskThreadSafe(SalomeHPContainer *cont, const Task *node);
       SalomeContainerMonoHelper *getHelperOfTask(const Task *node);
-      void shutdown();
-      //! For thread safety for concurrent load operation on same Container.
-      void lock();
-      //! For thread safety for concurrent load operation on same Container.
-      void unLock();
-    public:
-      std::vector<std::string> getKernelContainerNames() const;
+      std::vector<std::string> getKernelContainerNames(const SalomeHPContainer *cont) const;
     private:
-      ~SalomeHPContainerVectOfHelper() { }
       void checkNoCurrentWork() const;
       void checkPosInVec(std::size_t pos) const;
     private:
-      YACS::BASES::Mutex _mutex;
       std::vector<bool> _whichOccupied;
       std::vector< BASES::AutoRefCnt<YACS::ENGINE::SalomeContainerMonoHelper> > _launchModeType;
       std::map<const Task *,std::size_t > _currentlyWorking;
     };
   }
 }
-
-#endif