diff options
| author | Per Larsson <[email protected]> | 2022-02-03 15:40:04 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2022-02-03 15:40:04 +0100 |
| commit | d6741139e1ea3c6bb1462da61a81c42a80ac6e59 (patch) | |
| tree | a422d3f591c954e9f5a20c6a28f60bd08923185e /zenserver/upstream/upstreamcache.cpp | |
| parent | Merge branch 'main' into auth (diff) | |
| download | zen-d6741139e1ea3c6bb1462da61a81c42a80ac6e59.tar.xz zen-d6741139e1ea3c6bb1462da61a81c42a80ac6e59.zip | |
Minor cleanup of free functions.
Diffstat (limited to 'zenserver/upstream/upstreamcache.cpp')
| -rw-r--r-- | zenserver/upstream/upstreamcache.cpp | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp index 7466af1d2..5990536a9 100644 --- a/zenserver/upstream/upstreamcache.cpp +++ b/zenserver/upstream/upstreamcache.cpp @@ -18,8 +18,8 @@ #include <zenstore/cas.h> #include <zenstore/cidstore.h> -#include "cache/structuredcache.h" #include <auth/authmgr.h> +#include "cache/structuredcache.h" #include "cache/structuredcachestore.h" #include "diag/logging.h" @@ -99,22 +99,23 @@ namespace detail { if (AuthConfig.OAuthUrl.empty() == false) { - TokenProvider = CloudCacheTokenProvider::MakeFromOAuthClientCredentials( + TokenProvider = CloudCacheTokenProvider::CreateFromOAuthClientCredentials( {.Url = AuthConfig.OAuthUrl, .ClientId = AuthConfig.OAuthClientId, .ClientSecret = AuthConfig.OAuthClientSecret}); } else if (AuthConfig.OpenIdProvider.empty() == false) { - TokenProvider = CloudCacheTokenProvider::MakeFromCallback([this, ProviderName = std::string(AuthConfig.OpenIdProvider)]() { - AuthMgr::OpenIdAccessToken Token = m_AuthMgr.GetOpenIdAccessToken(ProviderName); - return CloudCacheAccessToken{.Value = Token.AccessToken, .ExpireTime = Token.ExpireTime}; - }); + TokenProvider = + CloudCacheTokenProvider::CreateFromCallback([this, ProviderName = std::string(AuthConfig.OpenIdProvider)]() { + AuthMgr::OpenIdAccessToken Token = m_AuthMgr.GetOpenIdAccessToken(ProviderName); + return CloudCacheAccessToken{.Value = Token.AccessToken, .ExpireTime = Token.ExpireTime}; + }); } else { CloudCacheAccessToken AccessToken{.Value = std::string(AuthConfig.AccessToken), .ExpireTime = CloudCacheAccessToken::TimePoint::max()}; - TokenProvider = CloudCacheTokenProvider::MakeFromStaticToken(AccessToken); + TokenProvider = CloudCacheTokenProvider::CreateFromStaticToken(AccessToken); } m_Client = new CloudCacheClient(Options, std::move(TokenProvider)); @@ -1040,10 +1041,10 @@ namespace detail { ////////////////////////////////////////////////////////////////////////// -class DefaultUpstreamCache final : public UpstreamCache +class UpstreamCacheImpl final : public UpstreamCache { public: - DefaultUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) + UpstreamCacheImpl(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) : m_Log(logging::Get("upstream")) , m_Options(Options) , m_CacheStore(CacheStore) @@ -1051,16 +1052,16 @@ public: { } - virtual ~DefaultUpstreamCache() { Shutdown(); } + virtual ~UpstreamCacheImpl() { Shutdown(); } virtual void Initialize() override { for (uint32_t Idx = 0; Idx < m_Options.ThreadCount; Idx++) { - m_UpstreamThreads.emplace_back(&DefaultUpstreamCache::ProcessUpstreamQueue, this); + m_UpstreamThreads.emplace_back(&UpstreamCacheImpl::ProcessUpstreamQueue, this); } - m_EndpointMonitorThread = std::thread(&DefaultUpstreamCache::MonitorEndpoints, this); + m_EndpointMonitorThread = std::thread(&UpstreamCacheImpl::MonitorEndpoints, this); m_RunState.IsRunning = true; } @@ -1069,7 +1070,14 @@ public: const UpstreamEndpointStatus Status = Endpoint->Initialize(); const UpstreamEndpointInfo& Info = Endpoint->GetEndpointInfo(); - ZEN_INFO("register endpoint '{} - {}' {}", Info.Name, Info.Url, ToString(Status.State)); + if (Status.State == UpstreamEndpointState::kOk) + { + ZEN_INFO("register endpoint '{} - {}' {}", Info.Name, Info.Url, ToString(Status.State)); + } + else + { + ZEN_WARN("register endpoint '{} - {}' {}", Info.Name, Info.Url, ToString(Status.State)); + } // Register endpoint even if it fails, the health monitor thread will probe failing endpoint(s) std::unique_lock<std::shared_mutex> _(m_EndpointsMutex); @@ -1562,22 +1570,22 @@ private: ////////////////////////////////////////////////////////////////////////// -std::unique_ptr<UpstreamCache> -MakeUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) +std::unique_ptr<UpstreamEndpoint> +UpstreamEndpoint::CreateZenEndpoint(const ZenStructuredCacheClientOptions& Options) { - return std::make_unique<DefaultUpstreamCache>(Options, CacheStore, CidStore); + return std::make_unique<detail::ZenUpstreamEndpoint>(Options); } std::unique_ptr<UpstreamEndpoint> -MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options, const UpstreamAuthConfig& AuthConfig, AuthMgr& Mgr) +UpstreamEndpoint::CreateJupiterEndpoint(const CloudCacheClientOptions& Options, const UpstreamAuthConfig& AuthConfig, AuthMgr& Mgr) { return std::make_unique<detail::JupiterUpstreamEndpoint>(Options, AuthConfig, Mgr); } -std::unique_ptr<UpstreamEndpoint> -MakeZenUpstreamEndpoint(const ZenStructuredCacheClientOptions& Options) +std::unique_ptr<UpstreamCache> +UpstreamCache::Create(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) { - return std::make_unique<detail::ZenUpstreamEndpoint>(Options); + return std::make_unique<UpstreamCacheImpl>(Options, CacheStore, CidStore); } } // namespace zen |