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

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

Merge XIOS_FILE_SERVICE dev branch into trunk

YM

  • Property svn:executable set to *
File size: 3.6 KB
Line 
1#include "service_node.hpp"
2
3namespace 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)
13  { /* Ne rien faire de plus */ }
14
15
16  void CServiceNode::parse(xml::CXMLNode & node)
17  {
18    SuperClass::parse(node);
19  }
20
21  void CServiceNode::allocateRessources(const string& poolId)
22  {
23    int nonEmpty=0 ;
24    if (!nprocs.isEmpty()) nonEmpty++ ;
25    if (!global_fraction.isEmpty()) nonEmpty++ ;
26    if (!remain_fraction.isEmpty()) nonEmpty++ ;
27    if (!remain.isEmpty()) nonEmpty++ ;
28    if (nonEmpty==0) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"A number a ressource for allocate service must be specified." 
29                           <<"At least attributes, <nprocs> or <global_fraction> or <remain_fraction> or <remain> must be specified")
30    else if (nonEmpty>1) ERROR("void void CServiceNode::allocateRessources(const string& poolId)",<<"Only one of these attributes : <nprocs> or <global_fraction>"
31                               <<" or <remain_fraction> or <remain> must be specified to determine allocated ressources."
32                               <<" More than one is currently specified")
33    auto servicesManager=CXios::getServicesManager() ;
34    auto ressourcesManager=CXios::getRessourcesManager() ;
35    int nbRessources ;
36    int globalRessources ;
37    ressourcesManager->getPoolSize(poolId, globalRessources) ;
38    int freeRessources ;
39    ressourcesManager->getPoolFreeSize(poolId, freeRessources ) ;
40    if (!nprocs.isEmpty()) nbRessources = nprocs ;
41    if (!global_fraction.isEmpty()) nbRessources = std::round(globalRessources * global_fraction) ;
42    if (!remain_fraction.isEmpty()) nbRessources = std::round(freeRessources * remain_fraction) ;
43    if (!remain.isEmpty()) nbRessources = freeRessources ;
44    if (nbRessources>freeRessources)
45      ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Cannot allocate required ressources for the service."
46                                                       <<"  Required is : "<<nbRessources<<"  but free ressource is currently : "<<freeRessources)
47    if (nb_partitions.isEmpty()) nb_partitions=1 ;
48    if (nb_partitions > nbRessources) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Cannot allocate required ressources for the service."
49                                                       <<"  The number of service partition : < nb_partitions = "<<nb_partitions<<" > "
50                                                       <<"is greater than the required ressources required < nbRessources = "<<nbRessources<<" >")
51   
52    int serviceType ;
53    if (type.isEmpty()) ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Service type must be specified")
54    if (type.getValue() == type_attr::writer) serviceType=CServicesManager::WRITER ;
55    else if (type.getValue() == type_attr::reader) serviceType=CServicesManager::READER ;
56    else if (type.getValue() == type_attr::gatherer) serviceType=CServicesManager::GATHERER ;
57
58    string serviceId ;
59    if (!name.isEmpty()) serviceId=name ;
60    else if (!hasAutoGeneratedId() ) serviceId=getId() ;
61    else ERROR("void CServiceNode::allocateRessources(const string& poolId)",<<"Service has no name or id, attributes <id> or <name> must be specified")
62    servicesManager->createServices(poolId, serviceId, serviceType, nbRessources, nb_partitions, true) ;
63  }
64
65}
Note: See TracBrowser for help on using the repository browser.