[1761] | 1 | #include "daemons_manager.hpp" |
---|
| 2 | #include "services_manager.hpp" |
---|
| 3 | #include "ressources_manager.hpp" |
---|
| 4 | #include "cxios.hpp" |
---|
| 5 | #include "pool_ressource.hpp" |
---|
| 6 | #include "type.hpp" |
---|
| 7 | #include "server.hpp" |
---|
| 8 | #include "servers_ressource.hpp" |
---|
| 9 | |
---|
| 10 | namespace xios |
---|
| 11 | { |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | CServicesManager::CServicesManager(bool isXiosServer) |
---|
| 16 | { |
---|
| 17 | |
---|
| 18 | int commRank ; |
---|
| 19 | xiosComm_ = CXios::getXiosComm() ; |
---|
| 20 | MPI_Comm_rank(xiosComm_, &commRank) ; |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | // The global manager leader will be the process of rank 0 |
---|
| 24 | // By "xiosComm" communicator construction |
---|
| 25 | // - if servers exits it will be the root process of the servers communicator |
---|
| 26 | // - otherwise the root process of the first model |
---|
| 27 | |
---|
| 28 | managerGlobalLeader_ = 0 ; |
---|
| 29 | |
---|
| 30 | MPI_Comm_rank(xiosComm_, &commRank) ; |
---|
| 31 | winNotify_ = new CWindowManager(xiosComm_, maxBufferSize_) ; |
---|
| 32 | winNotify_->lockWindow(commRank,0) ; |
---|
| 33 | winNotify_->updateToWindow(commRank, this, &CServicesManager::notificationsDumpOut) ; |
---|
| 34 | winNotify_->unlockWindow(commRank,0) ; |
---|
| 35 | |
---|
| 36 | winServices_ = new CWindowManager(xiosComm_, maxBufferSize_) ; |
---|
| 37 | winServices_->lockWindow(commRank,0) ; |
---|
| 38 | winServices_->updateToWindow(commRank, this, &CServicesManager::servicesDumpOut) ; |
---|
| 39 | winServices_->unlockWindow(commRank,0) ; |
---|
| 40 | |
---|
| 41 | MPI_Barrier(xiosComm_) ; |
---|
| 42 | } |
---|
| 43 | |
---|
[1764] | 44 | CServicesManager::~CServicesManager() |
---|
| 45 | { |
---|
| 46 | delete winNotify_ ; |
---|
| 47 | delete winServices_ ; |
---|
| 48 | } |
---|
| 49 | |
---|
[1761] | 50 | bool CServicesManager::createServices(const std::string& poolId, const std::string& serviceId, |
---|
| 51 | int type, int size, int nbPartitions, bool wait) |
---|
| 52 | { |
---|
| 53 | |
---|
| 54 | int leader ; |
---|
| 55 | int poolSize ; |
---|
| 56 | |
---|
| 57 | bool ok=CXios::getRessourcesManager()->getPoolInfo(poolId, poolSize, leader) ; |
---|
| 58 | if (wait) |
---|
| 59 | { |
---|
| 60 | while (!ok) |
---|
| 61 | { |
---|
| 62 | CXios::getDaemonsManager()->eventLoop() ; |
---|
| 63 | ok=CXios::getRessourcesManager()->getPoolInfo(poolId, poolSize, leader) ; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if (ok) |
---|
| 68 | { |
---|
| 69 | createServicesNotify(leader, serviceId, type, size, nbPartitions) ; |
---|
| 70 | return true ; |
---|
| 71 | } |
---|
| 72 | else return false ; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | void CServicesManager::createServicesNotify(int rank, const string& serviceId, int type, int size, int nbPartitions) |
---|
| 77 | { |
---|
| 78 | winNotify_->lockWindow(rank,0) ; |
---|
| 79 | winNotify_->updateFromWindow(rank, this, &CServicesManager::notificationsDumpIn) ; |
---|
| 80 | notifications_.push_back(std::make_tuple(serviceId,type,size,nbPartitions)) ; |
---|
| 81 | winNotify_->updateToWindow(rank, this, &CServicesManager::notificationsDumpOut) ; |
---|
| 82 | winNotify_->unlockWindow(rank,0) ; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | void CServicesManager::checkCreateServicesNotification(void) |
---|
| 87 | { |
---|
| 88 | int commRank ; |
---|
| 89 | MPI_Comm_rank(xiosComm_,&commRank) ; |
---|
| 90 | winNotify_->lockWindow(commRank,0) ; |
---|
| 91 | winNotify_->updateFromWindow(commRank, this, &CServicesManager::notificationsDumpIn) ; |
---|
| 92 | |
---|
| 93 | if (!notifications_.empty()) |
---|
| 94 | { |
---|
| 95 | auto info = notifications_.front() ; |
---|
| 96 | CServer::getServersRessource()->getPoolRessource()->createService(get<0>(info), get<1>(info), get<2>(info), get<3>(info)) ; |
---|
| 97 | notifications_.pop_front() ; |
---|
| 98 | winNotify_->updateToWindow(commRank, this, &CServicesManager::notificationsDumpOut) ; |
---|
| 99 | } |
---|
| 100 | winNotify_->unlockWindow(commRank,0) ; |
---|
| 101 | |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | void CServicesManager::eventLoop(void) |
---|
| 105 | { |
---|
| 106 | checkCreateServicesNotification() ; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | void CServicesManager::notificationsDumpOut(CBufferOut& buffer) |
---|
| 111 | { |
---|
| 112 | |
---|
| 113 | buffer.realloc(maxBufferSize_) ; |
---|
| 114 | |
---|
| 115 | buffer<<(int)notifications_.size(); |
---|
| 116 | |
---|
| 117 | for(auto it=notifications_.begin();it!=notifications_.end(); ++it) |
---|
| 118 | buffer << std::get<0>(*it) << static_cast<int>(std::get<1>(*it))<< std::get<2>(*it) << std::get<3>(*it) ; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void CServicesManager::notificationsDumpIn(CBufferIn& buffer) |
---|
| 122 | { |
---|
| 123 | std::string id ; |
---|
| 124 | int type ; |
---|
| 125 | int size; |
---|
| 126 | int nbPartitions ; |
---|
| 127 | |
---|
| 128 | notifications_.clear() ; |
---|
| 129 | int nbNotifications ; |
---|
| 130 | buffer>>nbNotifications ; |
---|
| 131 | for(int i=0;i<nbNotifications;i++) |
---|
| 132 | { |
---|
| 133 | buffer>>id>>type>>size>>nbPartitions ; |
---|
| 134 | notifications_.push_back(std::make_tuple(id,type,size,nbPartitions)) ; |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | void CServicesManager::servicesDumpOut(CBufferOut& buffer) |
---|
| 140 | { |
---|
| 141 | |
---|
| 142 | buffer.realloc(maxBufferSize_) ; |
---|
| 143 | |
---|
| 144 | buffer<<(int)services_.size(); |
---|
| 145 | |
---|
| 146 | for(auto it=services_.begin();it!=services_.end(); ++it) |
---|
| 147 | { |
---|
| 148 | auto key = it->first ; |
---|
| 149 | auto val = it->second ; |
---|
| 150 | buffer << std::get<0>(key) << std::get<1>(key) << std::get<2>(key) |
---|
| 151 | << static_cast<int>(std::get<0>(val)) << std::get<1>(val) << std::get<2>(val) << std::get<3>(val) ; |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | void CServicesManager::servicesDumpIn(CBufferIn& buffer) |
---|
| 156 | { |
---|
| 157 | std::string poolId, serviceId ; |
---|
| 158 | int partitionId ; |
---|
| 159 | int type ; |
---|
| 160 | int size; |
---|
| 161 | int nbPartitions ; |
---|
| 162 | int leader ; |
---|
| 163 | |
---|
| 164 | services_.clear() ; |
---|
| 165 | int nbServices ; |
---|
| 166 | buffer>>nbServices ; |
---|
| 167 | for(int i=0;i<nbServices;i++) |
---|
| 168 | { |
---|
| 169 | buffer>>poolId>>serviceId>>partitionId>>type>>size>>nbPartitions>>leader ; |
---|
| 170 | services_[std::tuple<std::string,std::string,int>(poolId,serviceId,partitionId)]=std::make_tuple(type,size,nbPartitions,leader) ; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | void CServicesManager::registerService(const std::string& poolId, const std::string& serviceId, const int& partitionId, int type, |
---|
| 175 | int size, int nbPartitions, int leader) |
---|
| 176 | { |
---|
| 177 | |
---|
| 178 | winServices_->lockWindow(managerGlobalLeader_,0) ; |
---|
| 179 | winServices_->updateFromWindow(managerGlobalLeader_, this, &CServicesManager::servicesDumpIn) ; |
---|
| 180 | services_[std::tuple<std::string, std::string,int>(poolId,serviceId,partitionId)]=std::make_tuple(type,size,nbPartitions,leader) ; |
---|
| 181 | winServices_->updateToWindow(managerGlobalLeader_, this, &CServicesManager::servicesDumpOut) ; |
---|
| 182 | winServices_->unlockWindow(managerGlobalLeader_,0) ; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | bool CServicesManager::getServiceInfo(const std::string& poolId, const std::string& serviceId, const int& partitionId, int& type, |
---|
| 186 | int& size, int& nbPartitions, int& leader) |
---|
| 187 | { |
---|
| 188 | winServices_->lockWindow(managerGlobalLeader_,0) ; |
---|
| 189 | winServices_->updateFromWindow(managerGlobalLeader_, this, &CServicesManager::servicesDumpIn) ; |
---|
| 190 | winServices_->unlockWindow(managerGlobalLeader_,0) ; |
---|
| 191 | |
---|
| 192 | auto it=services_.find(std::tuple<std::string,std::string,int>(poolId,serviceId,partitionId)) ; |
---|
| 193 | if ( it == services_.end()) return false ; |
---|
| 194 | else |
---|
| 195 | { |
---|
| 196 | type= std::get<0>(it->second); |
---|
| 197 | size= std::get<1>(it->second); |
---|
| 198 | nbPartitions = std::get<2>(it->second); |
---|
| 199 | leader = std::get<3>(it->second); |
---|
| 200 | return true ; |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | bool CServicesManager::getServiceLeader(const std::string& poolId, const std::string& serviceId, const int& partitionId, int& leader) |
---|
| 205 | { |
---|
| 206 | int type; |
---|
| 207 | int size ; |
---|
| 208 | int nbPartitions; |
---|
| 209 | return getServiceInfo(poolId, serviceId, partitionId, type, size, nbPartitions, leader) ; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | bool CServicesManager::getServiceType(const std::string& poolId, const std::string& serviceId, const int& partitionId, int& type) |
---|
| 213 | { |
---|
| 214 | int size ; |
---|
| 215 | int nbPartitions; |
---|
| 216 | int leader; |
---|
| 217 | return getServiceInfo(poolId, serviceId, partitionId, type, size, nbPartitions, leader) ; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | bool CServicesManager::getServiceNbPartitions(const std::string& poolId, const std::string& serviceId, const int& partitionId, int& nbPartitions) |
---|
| 221 | { |
---|
| 222 | int size ; |
---|
| 223 | int type; |
---|
| 224 | int leader; |
---|
| 225 | return getServiceInfo(poolId, serviceId, partitionId, type, size, nbPartitions, leader) ; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | bool CServicesManager::hasService(const std::string& poolId, const std::string& serviceId, const int& partitionId) |
---|
| 229 | { |
---|
| 230 | winServices_->lockWindow(managerGlobalLeader_,0) ; |
---|
| 231 | winServices_->updateFromWindow(managerGlobalLeader_, this, &CServicesManager::servicesDumpIn) ; |
---|
| 232 | winServices_->unlockWindow(managerGlobalLeader_,0) ; |
---|
| 233 | auto it=services_.find(std::tuple<std::string, std::string, int>(poolId, serviceId, partitionId)) ; |
---|
| 234 | if ( it == services_.end()) return false ; |
---|
| 235 | else return true ; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | } |
---|