// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "zenserver.h" #if ZEN_WITH_COMPUTE_SERVICES # include namespace cxxopts { class Options; } namespace zen::LuaConfig { struct Options; } namespace zen::compute { class HttpFunctionService; } namespace zen { class CidStore; class HttpApiService; class HttpComputeService; struct ZenComputeServerConfig : public ZenServerConfig { std::string UpstreamNotificationEndpoint; std::string InstanceId; // For use in notifications }; struct ZenComputeServerConfigurator : public ZenServerConfiguratorBase { ZenComputeServerConfigurator(ZenComputeServerConfig& ServerOptions) : ZenServerConfiguratorBase(ServerOptions) , m_ServerOptions(ServerOptions) { } ~ZenComputeServerConfigurator() = default; private: virtual void AddCliOptions(cxxopts::Options& Options) override; virtual void AddConfigOptions(LuaConfig::Options& Options) override; virtual void ApplyOptions(cxxopts::Options& Options) override; virtual void OnConfigFileParsed(LuaConfig::Options& LuaOptions) override; virtual void ValidateOptions() override; ZenComputeServerConfig& m_ServerOptions; }; class ZenComputeServerMain : public ZenServerMain { public: ZenComputeServerMain(ZenComputeServerConfig& ServerOptions); virtual void DoRun(ZenServerState::ZenServerEntry* Entry) override; ZenComputeServerMain(const ZenComputeServerMain&) = delete; ZenComputeServerMain& operator=(const ZenComputeServerMain&) = delete; typedef ZenComputeServerConfig Config; typedef ZenComputeServerConfigurator Configurator; private: ZenComputeServerConfig& m_ServerOptions; }; /** * The compute server handles DDC build function execution requests * only. It's intended to be used on a pure compute resource and does * not handle any storage tasks. The actual scheduling happens upstream * in a storage server instance. */ class ZenComputeServer : public ZenServerBase { ZenComputeServer& operator=(ZenComputeServer&&) = delete; ZenComputeServer(ZenComputeServer&&) = delete; public: ZenComputeServer(); ~ZenComputeServer(); int Initialize(const ZenComputeServerConfig& ServerConfig, ZenServerState::ZenServerEntry* ServerEntry); void Run(); void Cleanup(); private: HttpStatsService m_StatsService; GcManager m_GcManager; GcScheduler m_GcScheduler{m_GcManager}; std::unique_ptr m_CidStore; std::unique_ptr m_ComputeService; std::unique_ptr m_ApiService; std::unique_ptr m_FunctionService; void InitializeState(const ZenComputeServerConfig& ServerConfig); void InitializeServices(const ZenComputeServerConfig& ServerConfig); void RegisterServices(const ZenComputeServerConfig& ServerConfig); }; } // namespace zen #endif // ZEN_WITH_COMPUTE_SERVICES