[2453] | 1 | #include "service_node.hpp" |
---|
| 2 | |
---|
| 3 | namespace xios |
---|
| 4 | { |
---|
| 5 | |
---|
| 6 | CServiceNode::CServiceNode(void) : CObjectTemplate<CServiceNode>(), CServiceNodeAttributes() |
---|
| 7 | { /* Ne rien faire de plus */ } |
---|
| 8 | |
---|
| 9 | CServiceNode::CServiceNode(const StdString & id) : CObjectTemplate<CServiceNode>(id), CServiceNodeAttributes() |
---|
| 10 | { /* Ne rien faire de plus */ } |
---|
| 11 | |
---|
| 12 | CServiceNode::~CServiceNode(void) |
---|
[2612] | 13 | { |
---|
| 14 | for(auto& serviceOnto : servicesOnto_) |
---|
| 15 | { |
---|
| 16 | delete serviceOnto; |
---|
| 17 | } |
---|
| 18 | } |
---|
[2453] | 19 | |
---|
| 20 | |
---|
| 21 | void CServiceNode::parse(xml::CXMLNode & node) |
---|
| 22 | { |
---|
| 23 | SuperClass::parse(node); |
---|
[2612] | 24 | if (node.goToChildElement()) |
---|
| 25 | { |
---|
| 26 | do |
---|
| 27 | { |
---|
| 28 | CServiceNode* serviceOnto = new CServiceNode(); |
---|
| 29 | serviceOnto->parse( node ); |
---|
| 30 | if ( (serviceOnto->name.isEmpty()) || (serviceOnto->type.isEmpty()) ) |
---|
| 31 | { |
---|
| 32 | ERROR("void CServiceNode::parse(xml::CXMLNode & node)",<<"Service onto is not defined correctly <name> and <type> must be specified") |
---|
| 33 | } |
---|
| 34 | servicesOnto_.push_back( serviceOnto ); |
---|
| 35 | } while (node.goToNextElement()); |
---|
| 36 | node.goToParentElement(); |
---|
| 37 | } |
---|
[2453] | 38 | } |
---|
| 39 | |
---|
| 40 | void CServiceNode::allocateRessources(const string& poolId) |
---|
| 41 | { |
---|
| 42 | int nonEmpty=0 ; |
---|
| 43 | if (!nprocs.isEmpty()) nonEmpty++ ; |
---|
| 44 | if (!global_fraction.isEmpty()) nonEmpty++ ; |
---|
| 45 | if (!remain_fraction.isEmpty()) nonEmpty++ ; |
---|
| 46 | if (!remain.isEmpty()) nonEmpty++ ; |
---|
| 47 | if (nonEmpty==0) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"A number a ressource for allocate service must be specified." |
---|
| 48 | <<"At least attributes, <nprocs> or <global_fraction> or <remain_fraction> or <remain> must be specified") |
---|
| 49 | else if (nonEmpty>1) ERROR("void void CServiceNode::allocateRessources(const string& poolId)",<<"Only one of these attributes : <nprocs> or <global_fraction>" |
---|
| 50 | <<" or <remain_fraction> or <remain> must be specified to determine allocated ressources." |
---|
| 51 | <<" More than one is currently specified") |
---|
| 52 | auto servicesManager=CXios::getServicesManager() ; |
---|
| 53 | auto ressourcesManager=CXios::getRessourcesManager() ; |
---|
| 54 | int nbRessources ; |
---|
| 55 | int globalRessources ; |
---|
| 56 | ressourcesManager->getPoolSize(poolId, globalRessources) ; |
---|
| 57 | int freeRessources ; |
---|
| 58 | ressourcesManager->getPoolFreeSize(poolId, freeRessources ) ; |
---|
| 59 | if (!nprocs.isEmpty()) nbRessources = nprocs ; |
---|
| 60 | if (!global_fraction.isEmpty()) nbRessources = std::round(globalRessources * global_fraction) ; |
---|
| 61 | if (!remain_fraction.isEmpty()) nbRessources = std::round(freeRessources * remain_fraction) ; |
---|
| 62 | if (!remain.isEmpty()) nbRessources = freeRessources ; |
---|
| 63 | if (nbRessources>freeRessources) |
---|
| 64 | ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Cannot allocate required ressources for the service." |
---|
| 65 | <<" Required is : "<<nbRessources<<" but free ressource is currently : "<<freeRessources) |
---|
| 66 | if (nb_partitions.isEmpty()) nb_partitions=1 ; |
---|
| 67 | if (nb_partitions > nbRessources) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Cannot allocate required ressources for the service." |
---|
| 68 | <<" The number of service partition : < nb_partitions = "<<nb_partitions<<" > " |
---|
| 69 | <<"is greater than the required ressources required < nbRessources = "<<nbRessources<<" >") |
---|
| 70 | |
---|
| 71 | int serviceType ; |
---|
| 72 | if (type.isEmpty()) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Service type must be specified") |
---|
| 73 | if (type.getValue() == type_attr::writer) serviceType=CServicesManager::WRITER ; |
---|
| 74 | else if (type.getValue() == type_attr::reader) serviceType=CServicesManager::READER ; |
---|
| 75 | else if (type.getValue() == type_attr::gatherer) serviceType=CServicesManager::GATHERER ; |
---|
| 76 | |
---|
| 77 | string serviceId ; |
---|
| 78 | if (!name.isEmpty()) serviceId=name ; |
---|
| 79 | else if (!hasAutoGeneratedId() ) serviceId=getId() ; |
---|
| 80 | else ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Service has no name or id, attributes <id> or <name> must be specified") |
---|
[2547] | 81 | |
---|
[2453] | 82 | servicesManager->createServices(poolId, serviceId, serviceType, nbRessources, nb_partitions, true) ; |
---|
[2612] | 83 | |
---|
| 84 | for(auto& serviceOnto : servicesOnto_) |
---|
| 85 | { |
---|
| 86 | if (serviceOnto->type.getValue() == type_attr::writer) serviceType=CServicesManager::WRITER ; |
---|
| 87 | else if (serviceOnto->type.getValue() == type_attr::reader) serviceType=CServicesManager::READER ; |
---|
| 88 | else if (serviceOnto->type.getValue() == type_attr::gatherer) serviceType=CServicesManager::GATHERER ; |
---|
| 89 | servicesManager->createServicesOnto(poolId, serviceOnto->name, serviceType, serviceId, true) ; |
---|
| 90 | } |
---|
| 91 | |
---|
[2547] | 92 | if (CThreadManager::isUsingThreads()) |
---|
| 93 | for(int i=0; i<nb_partitions; i++) |
---|
| 94 | while(!servicesManager->hasService(poolId, serviceId, i)) |
---|
| 95 | { |
---|
| 96 | CXios::getDaemonsManager()->eventLoop() ; |
---|
| 97 | CThreadManager::yield() ; |
---|
| 98 | } |
---|
| 99 | else servicesManager->waitServiceRegistration(CXios::defaultPoolId, CXios::defaultWriterId) ; |
---|
| 100 | |
---|
[2453] | 101 | } |
---|
| 102 | |
---|
[2612] | 103 | } |
---|