[2408] | 1 | #include "pool_node.hpp" |
---|
[2458] | 2 | #include "cxios.hpp" |
---|
[2547] | 3 | #include "thread_manager.hpp" |
---|
[2458] | 4 | #include<cmath> |
---|
[2408] | 5 | |
---|
| 6 | namespace xios |
---|
| 7 | { |
---|
| 8 | |
---|
| 9 | CPoolNode::CPoolNode(void) : CObjectTemplate<CPoolNode>(), CPoolNodeAttributes() |
---|
[2458] | 10 | { |
---|
| 11 | setVirtualServiceNodeGroup(CServiceNodeGroup::create(getId() + "_virtual_service_node_group")); |
---|
| 12 | } |
---|
[2408] | 13 | |
---|
| 14 | CPoolNode::CPoolNode(const StdString & id) : CObjectTemplate<CPoolNode>(id), CPoolNodeAttributes() |
---|
[2458] | 15 | { |
---|
| 16 | setVirtualServiceNodeGroup(CServiceNodeGroup::create(getId() + "_virtual_service_node_group")); |
---|
| 17 | } |
---|
[2408] | 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); |
---|
[2458] | 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 | } |
---|
[2408] | 34 | } |
---|
| 35 | |
---|
[2458] | 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) ; |
---|
[2547] | 64 | if (CThreadManager::isUsingThreads()) |
---|
[2548] | 65 | while(!ressourcesManager->hasPool(poolId)) |
---|
[2547] | 66 | { |
---|
| 67 | CXios::getDaemonsManager()->eventLoop() ; |
---|
| 68 | CThreadManager::yield() ; |
---|
| 69 | } |
---|
| 70 | else ressourcesManager->waitPoolRegistration(poolId) ; |
---|
[2458] | 71 | auto services=this->getAllServiceNodes() ; |
---|
| 72 | for(auto& service : services) service->allocateRessources(poolId) ; |
---|
| 73 | } |
---|
[2408] | 74 | } |
---|
| 75 | |
---|