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