X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fredis%2Fasyncdatabasediscovery.cpp;h=b57955e049c60fc28ac8d37166c2c118d72095c5;hb=refs%2Fchanges%2F25%2F9925%2F1;hp=63f2f12cfc49b1dd6d6d3d11db98d3b4788bffb6;hpb=8324d029ce006509ddbc605446d05987c17e0368;p=ric-plt%2Fsdl.git diff --git a/src/redis/asyncdatabasediscovery.cpp b/src/redis/asyncdatabasediscovery.cpp index 63f2f12..b57955e 100644 --- a/src/redis/asyncdatabasediscovery.cpp +++ b/src/redis/asyncdatabasediscovery.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2018-2019 Nokia. + Copyright (c) 2018-2022 Nokia. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,27 +14,31 @@ limitations under the License. */ -#include "private/redis/asyncdatabasediscovery.hpp" -#include "private/databaseconfiguration.hpp" -#include "private/logger.hpp" +/* + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). +*/ + #include #include "config.h" +#include "private/abort.hpp" +#include "private/databaseconfiguration.hpp" +#include "private/logger.hpp" +#include "private/redis/asyncdatabasediscovery.hpp" #if HAVE_HIREDIS #include "private/redis/asynchiredisdatabasediscovery.hpp" #endif -#if HAVE_SENTINEL #include "private/redis/asyncsentineldatabasediscovery.hpp" -#endif -#include "private/abort.hpp" using namespace shareddatalayer::redis; std::shared_ptr AsyncDatabaseDiscovery::create(std::shared_ptr engine, const boost::optional& ns, const DatabaseConfiguration& staticDatabaseConfiguration, + const boost::optional& addressIndex, std::shared_ptr logger) { - auto staticAddresses(staticDatabaseConfiguration.getServerAddresses()); + auto staticAddresses(staticDatabaseConfiguration.getServerAddresses(addressIndex)); if (staticAddresses.empty()) staticAddresses = staticDatabaseConfiguration.getDefaultServerAddresses(); @@ -54,17 +58,28 @@ std::shared_ptr AsyncDatabaseDiscovery::create(std::shar else { #if HAVE_HIREDIS -#if HAVE_SENTINEL - static_cast(ns); - return std::make_shared(engine, - logger); -#else - return std::make_shared(engine, - ns, - DatabaseInfo::Type::SINGLE, - staticAddresses, - logger); -#endif + if (staticDbType == DatabaseConfiguration::DbType::REDIS_SENTINEL || + staticDbType == DatabaseConfiguration::DbType::SDL_SENTINEL_CLUSTER) + { + auto sentinelAddress(staticDatabaseConfiguration.getSentinelAddress(addressIndex)); + auto sentinelMasterName(staticDatabaseConfiguration.getSentinelMasterName(addressIndex)); + + if (sentinelAddress) + return std::make_shared(engine, + logger, + *sentinelAddress, + sentinelMasterName); + else + SHAREDDATALAYER_ABORT("Sentinel address not configured."); + } + else + { + return std::make_shared(engine, + ns, + DatabaseInfo::Type::SINGLE, + staticAddresses, + logger); + } #else static_cast(logger); SHAREDDATALAYER_ABORT("No Hiredis");