// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #include #include #include #include ZEN_THIRD_PARTY_INCLUDES_START #include ZEN_THIRD_PARTY_INCLUDES_END ////////////////////////////////////////////////////////////////////////// // Services // #include #include #include #include #include #include #include #include "admin/admin.h" #include "buildstore/httpbuildstore.h" #include "cache/httpstructuredcache.h" #include "diag/diagsvcs.h" #include "frontend/frontend.h" #include "objectstore/objectstore.h" #include "projectstore/httpprojectstore.h" #include "projectstore/projectstore.h" #include "stats/statsreporter.h" #include "upstream/upstream.h" #include "vfs/vfsservice.h" #include "workspaces/httpworkspaces.h" #ifndef ZEN_APP_NAME # define ZEN_APP_NAME "Unreal Zen Storage Server" #endif namespace zen { struct ZenServerOptions; class ZenServer : public IHttpStatusProvider { ZenServer& operator=(ZenServer&&) = delete; ZenServer(ZenServer&&) = delete; public: ZenServer(); ~ZenServer(); int Initialize(const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry); void InitializeState(const ZenServerOptions& ServerOptions); void InitializeStructuredCache(const ZenServerOptions& ServerOptions); void Run(); void RequestExit(int ExitCode); void Cleanup(); void SetDedicatedMode(bool State) { m_IsDedicatedMode = State; } void SetTestMode(bool State) { m_TestMode = State; } void SetDataRoot(std::filesystem::path Root) { m_DataRoot = Root; } void SetContentRoot(std::filesystem::path Root) { m_ContentRoot = Root; } std::function m_IsReadyFunc; void SetIsReadyFunc(std::function&& IsReadyFunc) { m_IsReadyFunc = std::move(IsReadyFunc); } void OnReady(); void EnsureIoRunner(); void EnqueueProcessMonitorTimer(); void EnqueueStateMarkerTimer(); void EnqueueSigIntTimer(); void EnqueueStateExitFlagTimer(); void EnqueueStatsReportingTimer(); void CheckStateMarker(); void CheckSigInt(); void CheckStateExitFlag(); void CheckOwnerPid(); bool UpdateProcessMonitor(); void Flush(); virtual void HandleStatusRequest(HttpServerRequest& Request) override; private: ZenServerState::ZenServerEntry* m_ServerEntry = nullptr; bool m_IsDedicatedMode = false; bool m_TestMode = false; bool m_IsPowerCycle = false; CbObject m_RootManifest; std::filesystem::path m_DataRoot; std::filesystem::path m_ContentRoot; std::thread m_IoRunner; asio::io_context m_IoContext; asio::steady_timer m_PidCheckTimer{m_IoContext}; asio::steady_timer m_StateMakerTimer{m_IoContext}; asio::steady_timer m_StateExitFlagTimer{m_IoContext}; asio::steady_timer m_SigIntTimer{m_IoContext}; asio::steady_timer m_StatsReportingTimer{m_IoContext}; ProcessMonitor m_ProcessMonitor; NamedMutex m_ServerMutex; bool m_FoundNoActiveSponsors = false; enum ServerState { kInitializing, kRunning, kShuttingDown } m_CurrentState = kInitializing; inline void SetNewState(ServerState NewState) { m_CurrentState = NewState; } static std::string_view ToString(ServerState Value); StatsReporter m_StatsReporter; Ref m_Http; std::unique_ptr m_AuthMgr; std::unique_ptr m_AuthService; HttpStatusService m_StatusService; HttpStatsService m_StatsService; GcManager m_GcManager; GcScheduler m_GcScheduler{m_GcManager}; tsl::robin_map> m_CidStores; Ref m_CacheStore; std::unique_ptr m_OpenProcessCache; HttpTestService m_TestService; std::unique_ptr m_BuildCidStore; std::unique_ptr m_BuildStore; #if ZEN_WITH_TESTS HttpTestingService m_TestingService; #endif RefPtr m_ProjectStore; std::unique_ptr m_HttpProjectService; std::unique_ptr m_Workspaces; std::unique_ptr m_HttpWorkspacesService; std::unique_ptr m_UpstreamCache; std::unique_ptr m_UpstreamService; std::unique_ptr m_StructuredCacheService; HttpHealthService m_HealthService; std::unique_ptr m_FrontendService; std::unique_ptr m_ObjStoreService; std::unique_ptr m_BuildStoreService; std::unique_ptr m_VfsService; std::unique_ptr m_JobQueue; std::unique_ptr m_AdminService; bool m_DebugOptionForcedCrash = false; bool m_UseSentry = false; std::string m_StartupScrubOptions; }; void zenserver_forcelinktests(); } // namespace zen