diff options
| author | Per Larsson <[email protected]> | 2022-03-19 10:41:08 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2022-03-19 10:41:08 +0100 |
| commit | 703c252710cdae35a35be700fade144e994777c0 (patch) | |
| tree | 03268a46ea32553c4777ee30cc617f140665938a /zenserver/zenserver.cpp | |
| parent | Minor cleanup. (diff) | |
| parent | Suppress C4305 in third party includes (diff) | |
| download | zen-703c252710cdae35a35be700fade144e994777c0.tar.xz zen-703c252710cdae35a35be700fade144e994777c0.zip | |
Merge branch 'main' into streamapi
Diffstat (limited to 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 149 |
1 files changed, 133 insertions, 16 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 3c7f9004d..110800315 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -106,7 +106,7 @@ ZEN_THIRD_PARTY_INCLUDES_END #include "cache/structuredcachestore.h" #include "compute/apply.h" #include "diag/diagsvcs.h" -#include "experimental/frontend.h" +#include "frontend/frontend.h" #include "experimental/usnjournal.h" #include "monitoring/httpstats.h" #include "monitoring/httpstatus.h" @@ -279,15 +279,20 @@ public: #endif #if ZEN_WITH_COMPUTE_SERVICES - ZEN_INFO("instantiating compute services"); + if (ServerOptions.ComputeServiceEnabled) + { + ZEN_INFO("instantiating compute services"); - std::filesystem::path SandboxDir = m_DataRoot / "exec" / "sandbox"; - zen::CreateDirectories(SandboxDir); - m_HttpLaunchService = std::make_unique<zen::HttpLaunchService>(*m_CasStore, SandboxDir); + std::filesystem::path SandboxDir = m_DataRoot / "exec" / "sandbox"; + zen::CreateDirectories(SandboxDir); + m_HttpLaunchService = std::make_unique<zen::HttpLaunchService>(*m_CasStore, SandboxDir); - std::filesystem::path ApplySandboxDir = m_DataRoot / "exec" / "apply"; - zen::CreateDirectories(ApplySandboxDir); - m_HttpFunctionService = std::make_unique<zen::HttpFunctionService>(*m_CasStore, *m_CidStore, ApplySandboxDir); + InitializeCompute(ServerOptions); + } + else + { + ZEN_INFO("NOT instantiating compute services"); + } #endif // ZEN_WITH_COMPUTE_SERVICES if (ServerOptions.StructuredCacheEnabled) @@ -327,14 +332,14 @@ public: m_Http->RegisterService(m_CasService); #if ZEN_WITH_COMPUTE_SERVICES - if (m_HttpLaunchService) + if (ServerOptions.ComputeServiceEnabled) { m_Http->RegisterService(*m_HttpLaunchService); - } - if (m_HttpFunctionService) - { - m_Http->RegisterService(*m_HttpFunctionService); + if (m_HttpFunctionService != nullptr) + { + m_Http->RegisterService(*m_HttpFunctionService); + } } #endif // ZEN_WITH_COMPUTE_SERVICES @@ -360,6 +365,9 @@ public: void InitializeState(const ZenServerOptions& ServerOptions); void InitializeStructuredCache(const ZenServerOptions& ServerOptions); +#if ZEN_WITH_COMPUTE_SERVICES + void InitializeCompute(const ZenServerOptions& ServerOptions); +#endif #if ZEN_ENABLE_MESH void StartMesh(int BasePort) @@ -826,6 +834,59 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions) } } +#if ZEN_WITH_COMPUTE_SERVICES +void +ZenServer::InitializeCompute(const ZenServerOptions& ServerOptions) +{ + ServerOptions; + const ZenUpstreamCacheConfig& UpstreamConfig = ServerOptions.UpstreamCacheConfig; + + // Horde compute upstream + if (UpstreamConfig.HordeConfig.Url.empty() == false && UpstreamConfig.HordeConfig.Url.empty() == false) + { + std::string_view EndpointName = UpstreamConfig.HordeConfig.Name.empty() ? "Horde"sv : UpstreamConfig.HordeConfig.Name; + + auto ComputeOptions = + zen::CloudCacheClientOptions{.Name = EndpointName, + .ServiceUrl = UpstreamConfig.HordeConfig.Url, + .ComputeCluster = UpstreamConfig.HordeConfig.Cluster, + .ConnectTimeout = std::chrono::milliseconds(UpstreamConfig.ConnectTimeoutMilliseconds), + .Timeout = std::chrono::milliseconds(UpstreamConfig.TimeoutMilliseconds), + .UseLegacyDdc = false}; + + auto ComputeAuthConfig = zen::UpstreamAuthConfig{.OAuthUrl = UpstreamConfig.HordeConfig.OAuthUrl, + .OAuthClientId = UpstreamConfig.HordeConfig.OAuthClientId, + .OAuthClientSecret = UpstreamConfig.HordeConfig.OAuthClientSecret, + .OpenIdProvider = UpstreamConfig.HordeConfig.OpenIdProvider, + .AccessToken = UpstreamConfig.HordeConfig.AccessToken}; + + auto StorageOptions = + zen::CloudCacheClientOptions{.Name = EndpointName, + .ServiceUrl = UpstreamConfig.JupiterConfig.Url, + .BlobStoreNamespace = UpstreamConfig.HordeConfig.Namespace, + .ConnectTimeout = std::chrono::milliseconds(UpstreamConfig.ConnectTimeoutMilliseconds), + .Timeout = std::chrono::milliseconds(UpstreamConfig.TimeoutMilliseconds)}; + + auto StorageAuthConfig = zen::UpstreamAuthConfig{.OAuthUrl = UpstreamConfig.JupiterConfig.OAuthUrl, + .OAuthClientId = UpstreamConfig.JupiterConfig.OAuthClientId, + .OAuthClientSecret = UpstreamConfig.JupiterConfig.OAuthClientSecret, + .OpenIdProvider = UpstreamConfig.JupiterConfig.OpenIdProvider, + .AccessToken = UpstreamConfig.JupiterConfig.AccessToken}; + + std::filesystem::path ApplySandboxDir = m_DataRoot / "exec" / "apply"; + zen::CreateDirectories(ApplySandboxDir); + m_HttpFunctionService = std::make_unique<zen::HttpFunctionService>(*m_CasStore, + *m_CidStore, + ApplySandboxDir, + ComputeOptions, + StorageOptions, + ComputeAuthConfig, + StorageAuthConfig, + *m_AuthMgr); + } +} +#endif + //////////////////////////////////////////////////////////////////////////////// class ZenEntryPoint @@ -845,19 +906,75 @@ ZenEntryPoint::ZenEntryPoint(ZenServerOptions& ServerOptions) : m_ServerOptions( { } +#if ZEN_USE_SENTRY +static void +SentryLogFunction(sentry_level_t Level, const char* Message, va_list Args, [[maybe_unused]] void* Userdata) +{ + char LogMessageBuffer[160]; + std::string LogMessage; + const char* MessagePtr = LogMessageBuffer; + + int n = vsnprintf(LogMessageBuffer, sizeof LogMessageBuffer, Message, Args); + + if (n >= int(sizeof LogMessageBuffer)) + { + LogMessage.resize(n + 1); + + n = vsnprintf(LogMessage.data(), LogMessage.size(), Message, Args); + + MessagePtr = LogMessage.c_str(); + } + + switch (Level) + { + case SENTRY_LEVEL_DEBUG: + ConsoleLog().debug("sentry: {}", MessagePtr); + break; + + case SENTRY_LEVEL_INFO: + ConsoleLog().info("sentry: {}", MessagePtr); + break; + + case SENTRY_LEVEL_WARNING: + ConsoleLog().warn("sentry: {}", MessagePtr); + break; + + case SENTRY_LEVEL_ERROR: + ConsoleLog().error("sentry: {}", MessagePtr); + break; + + case SENTRY_LEVEL_FATAL: + ConsoleLog().critical("sentry: {}", MessagePtr); + break; + } +} +#endif + int ZenEntryPoint::Run() { #if ZEN_USE_SENTRY + std::string SentryDatabasePath = PathToUtf8(m_ServerOptions.DataDir / ".sentry-native"); + if (m_ServerOptions.NoSentry == false) { sentry_options_t* SentryOptions = sentry_options_new(); sentry_options_set_dsn(SentryOptions, "https://[email protected]/5919284"); - sentry_options_set_database_path(SentryOptions, PathToUtf8(m_ServerOptions.DataDir / ".sentry-native").c_str()); - sentry_init(SentryOptions); + sentry_options_set_database_path(SentryOptions, SentryDatabasePath.c_str()); + sentry_options_set_logger(SentryOptions, SentryLogFunction, this); + // sentry_options_set_debug(SentryOptions, 1); - auto _ = zen::MakeGuard([] { sentry_close(); }); + if (int ErrorCode = sentry_init(SentryOptions); ErrorCode == 0) + { + printf("sentry initialized"); + } + else + { + printf("sentry_init returned failure!"); + } } + + auto _ = zen::MakeGuard([] { sentry_close(); }); #endif auto& ServerOptions = m_ServerOptions; |