#include "service_node.hpp" namespace xios { CServiceNode::CServiceNode(void) : CObjectTemplate(), CServiceNodeAttributes() { /* Ne rien faire de plus */ } CServiceNode::CServiceNode(const StdString & id) : CObjectTemplate(id), CServiceNodeAttributes() { /* Ne rien faire de plus */ } CServiceNode::~CServiceNode(void) { for(auto& serviceOnto : servicesOnto_) { delete serviceOnto; } } void CServiceNode::parse(xml::CXMLNode & node) { SuperClass::parse(node); if (node.goToChildElement()) { do { CServiceNode* serviceOnto = new CServiceNode(); serviceOnto->parse( node ); if ( (serviceOnto->name.isEmpty()) || (serviceOnto->type.isEmpty()) ) { ERROR("void CServiceNode::parse(xml::CXMLNode & node)",<<"Service onto is not defined correctly and must be specified") } servicesOnto_.push_back( serviceOnto ); } while (node.goToNextElement()); node.goToParentElement(); } } void CServiceNode::allocateRessources(const string& poolId) { int nonEmpty=0 ; if (!nprocs.isEmpty()) nonEmpty++ ; if (!global_fraction.isEmpty()) nonEmpty++ ; if (!remain_fraction.isEmpty()) nonEmpty++ ; if (!remain.isEmpty()) nonEmpty++ ; if (nonEmpty==0) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"A number a ressource for allocate service must be specified." <<"At least attributes, or or or must be specified") else if (nonEmpty>1) ERROR("void void CServiceNode::allocateRessources(const string& poolId)",<<"Only one of these attributes : or " <<" or or must be specified to determine allocated ressources." <<" More than one is currently specified") auto servicesManager=CXios::getServicesManager() ; auto ressourcesManager=CXios::getRessourcesManager() ; int nbRessources ; int globalRessources ; ressourcesManager->getPoolSize(poolId, globalRessources) ; int freeRessources ; ressourcesManager->getPoolFreeSize(poolId, freeRessources ) ; if (!nprocs.isEmpty()) nbRessources = nprocs ; if (!global_fraction.isEmpty()) nbRessources = std::round(globalRessources * global_fraction) ; if (!remain_fraction.isEmpty()) nbRessources = std::round(freeRessources * remain_fraction) ; if (!remain.isEmpty()) nbRessources = freeRessources ; if (nbRessources>freeRessources) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Cannot allocate required ressources for the service." <<" Required is : "< nbRessources) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Cannot allocate required ressources for the service." <<" The number of service partition : < nb_partitions = "< " <<"is greater than the required ressources required < nbRessources = "<") int serviceType ; if (type.isEmpty()) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Service type must be specified") if (type.getValue() == type_attr::writer) serviceType=CServicesManager::WRITER ; else if (type.getValue() == type_attr::reader) serviceType=CServicesManager::READER ; else if (type.getValue() == type_attr::gatherer) serviceType=CServicesManager::GATHERER ; string serviceId ; if (!name.isEmpty()) serviceId=name ; else if (!hasAutoGeneratedId() ) serviceId=getId() ; else ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Service has no name or id, attributes or must be specified") servicesManager->createServices(poolId, serviceId, serviceType, nbRessources, nb_partitions, true) ; for(auto& serviceOnto : servicesOnto_) { if (serviceOnto->type.getValue() == type_attr::writer) serviceType=CServicesManager::WRITER ; else if (serviceOnto->type.getValue() == type_attr::reader) serviceType=CServicesManager::READER ; else if (serviceOnto->type.getValue() == type_attr::gatherer) serviceType=CServicesManager::GATHERER ; servicesManager->createServicesOnto(poolId, serviceOnto->name, serviceType, serviceId, true) ; } if (CThreadManager::isUsingThreads()) for(int i=0; ihasService(poolId, serviceId, i)) { CXios::getDaemonsManager()->eventLoop() ; CThreadManager::yield() ; } else servicesManager->waitServiceRegistration(CXios::defaultPoolId, CXios::defaultWriterId) ; } }