source: XIOS3/trunk/src/node/pool_node.cpp @ 2458

Last change on this file since 2458 was 2458, checked in by ymipsl, 17 months ago

Merge XIOS_FILE_SERVICE dev branch into trunk

YM

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#include "pool_node.hpp"
2#include "cxios.hpp"
3#include<cmath>
4
5namespace xios
6{
7 
8  CPoolNode::CPoolNode(void) : CObjectTemplate<CPoolNode>(), CPoolNodeAttributes()
9  { 
10    setVirtualServiceNodeGroup(CServiceNodeGroup::create(getId() + "_virtual_service_node_group"));
11  }
12
13  CPoolNode::CPoolNode(const StdString & id) : CObjectTemplate<CPoolNode>(id), CPoolNodeAttributes()
14  { 
15    setVirtualServiceNodeGroup(CServiceNodeGroup::create(getId() + "_virtual_service_node_group"));
16  }
17
18  CPoolNode::~CPoolNode(void)
19  { /* Ne rien faire de plus */ }
20
21
22  void CPoolNode::parse(xml::CXMLNode & node)
23  {
24    SuperClass::parse(node);
25    if (node.goToChildElement())
26    {
27      do
28      {
29        if (node.getElementName()=="service" || node.getElementName()=="service_group") this->getVirtualServiceNodeGroup()->parseChild(node);
30      } while (node.goToNextElement());
31      node.goToParentElement();
32    }
33  }
34
35  void CPoolNode::allocateRessources(void)
36  {
37    int nonEmpty=0 ;
38    if (!nprocs.isEmpty()) nonEmpty++ ;
39    if (!global_fraction.isEmpty()) nonEmpty++ ;
40    if (!remain_fraction.isEmpty()) nonEmpty++ ;
41    if (!remain.isEmpty()) nonEmpty++ ;
42    if (nonEmpty==0) ERROR("void CPoolNode::allocateRessources(void)",<<"A number a ressource for allocate pool must be specified." 
43                           <<"At least attributes, <nprocs> or <global_fraction> or <remain_fraction> or <remain> must be specified")
44    else if (nonEmpty>1) ERROR("void CPoolNode::allocateRessources(void)",<<"Only one of these attributes : <nprocs> or <global_fraction>"
45                               <<" or <remain_fraction> or <remain> must be specified to determine allocated ressouces."
46                               <<" More than one is currently specified")
47    auto ressourcesManager=CXios::getRessourcesManager() ;
48    int nbRessources ;
49    int globalRessources = ressourcesManager->getRessourcesSize() ;
50    int freeRessources =   ressourcesManager->getFreeRessourcesSize() ;
51    if (!nprocs.isEmpty()) nbRessources = nprocs ;
52    if (!global_fraction.isEmpty()) nbRessources = std::round(globalRessources * global_fraction) ;
53    if (!remain_fraction.isEmpty()) nbRessources = std::round(freeRessources * remain_fraction) ;
54    if (!remain.isEmpty()) nbRessources = freeRessources ;
55    if (nbRessources>freeRessources)
56      ERROR("void CPoolNode::allocateRessources(void)",<<"Cannot allocate required ressources for the pool."
57                                                       <<"  Required is : "<<nbRessources<<"  but free ressource is currently : "<<freeRessources)
58    string poolId ;
59    if (!name.isEmpty()) poolId=name ;
60    else if (!hasAutoGeneratedId() ) poolId=getId() ;
61    else ERROR("void CPoolNode::allocateRessources(void)",<<"Pool has no name or id, attributes <id> or <name> must be specified")
62    ressourcesManager->createPool(poolId, nbRessources) ;
63    ressourcesManager->waitPoolRegistration(poolId) ;
64    auto services=this->getAllServiceNodes() ;
65    for(auto& service : services) service->allocateRessources(poolId) ;
66  }
67}
68
Note: See TracBrowser for help on using the repository browser.