aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/hub
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2026-03-18 12:04:32 +0100
committerGitHub Enterprise <[email protected]>2026-03-18 12:04:32 +0100
commit85373257f39a00d1ac87350938296f2bf1c3ac4a (patch)
tree2257932fe75146e796a604edf68e525f8fe7fe18 /src/zenserver/hub
parentSimple S3 client (#836) (diff)
downloadzen-85373257f39a00d1ac87350938296f2bf1c3ac4a.tar.xz
zen-85373257f39a00d1ac87350938296f2bf1c3ac4a.zip
add --hub-instance-config option to set lua config path for hub instances (#854)
* add --hub-instance-config option to set lua config path for hub instances
Diffstat (limited to 'src/zenserver/hub')
-rw-r--r--src/zenserver/hub/hub.cpp43
-rw-r--r--src/zenserver/hub/hub.h5
-rw-r--r--src/zenserver/hub/storageserverinstance.cpp4
-rw-r--r--src/zenserver/hub/storageserverinstance.h1
-rw-r--r--src/zenserver/hub/zenhubserver.cpp10
-rw-r--r--src/zenserver/hub/zenhubserver.h19
6 files changed, 69 insertions, 13 deletions
diff --git a/src/zenserver/hub/hub.cpp b/src/zenserver/hub/hub.cpp
index 3c9f40eaa..2f3873884 100644
--- a/src/zenserver/hub/hub.cpp
+++ b/src/zenserver/hub/hub.cpp
@@ -20,6 +20,7 @@ ZEN_THIRD_PARTY_INCLUDES_END
# include <zencore/testing.h>
# include <zencore/testutils.h>
# include <zencore/workthreadpool.h>
+# include <zenhttp/httpclient.h>
#endif
#include <numeric>
@@ -232,7 +233,8 @@ Hub::Provision(std::string_view ModuleId, HubProvisionedInstanceInfo& OutInfo, s
.HydrationTempPath = m_HydrationTempPath,
.FileHydrationPath = m_FileHydrationPath,
.HttpThreadCount = m_Config.InstanceHttpThreadCount,
- .CoreLimit = m_Config.InstanceCoreLimit},
+ .CoreLimit = m_Config.InstanceCoreLimit,
+ .ConfigPath = m_Config.InstanceConfigPath},
ModuleId);
#if ZEN_PLATFORM_WINDOWS
if (m_JobObject.IsValid())
@@ -504,6 +506,45 @@ TEST_CASE("hub.provision_basic")
CHECK_FALSE(HubInstance->Find("module_a"));
}
+TEST_CASE("hub.provision_config")
+{
+ ScopedTemporaryDirectory TempDir;
+ CreateDirectories(TempDir.Path() / "hub");
+
+ std::string LuaConfig =
+ "server = {\n"
+ " buildstore = {\n"
+ " enabled = true,\n"
+ " }\n"
+ "}\n";
+
+ WriteFile(TempDir.Path() / "config.lua", IoBuffer(IoBuffer::Wrap, LuaConfig.data(), LuaConfig.length()));
+
+ std::unique_ptr<Hub> HubInstance =
+ hub_testutils::MakeHub(TempDir.Path() / "hub", Hub::Configuration{.InstanceConfigPath = TempDir.Path() / "config.lua"});
+
+ CHECK_EQ(HubInstance->GetInstanceCount(), 0);
+ CHECK_FALSE(HubInstance->Find("module_a"));
+
+ HubProvisionedInstanceInfo Info;
+ std::string Reason;
+ const bool ProvisionResult = HubInstance->Provision("module_a", Info, Reason);
+ REQUIRE_MESSAGE(ProvisionResult, Reason);
+ CHECK_NE(Info.Port, 0);
+ CHECK_EQ(HubInstance->GetInstanceCount(), 1);
+ CHECK(HubInstance->Find("module_a"));
+
+ HttpClient Client(fmt::format("http://127.0.0.1:{}{}", Info.Port, Info.BaseUri));
+ HttpClient::Response TestResponse = Client.Get("/status/builds");
+ CHECK(TestResponse.IsSuccess());
+ CHECK(TestResponse.AsObject()["ok"].AsBool());
+
+ const bool DeprovisionResult = HubInstance->Deprovision("module_a", Reason);
+ CHECK(DeprovisionResult);
+ CHECK_EQ(HubInstance->GetInstanceCount(), 0);
+ CHECK_FALSE(HubInstance->Find("module_a"));
+}
+
TEST_CASE("hub.provision_callbacks")
{
ScopedTemporaryDirectory TempDir;
diff --git a/src/zenserver/hub/hub.h b/src/zenserver/hub/hub.h
index 8a84a558b..78be3eda1 100644
--- a/src/zenserver/hub/hub.h
+++ b/src/zenserver/hub/hub.h
@@ -45,8 +45,9 @@ public:
int InstanceLimit = 1000;
- uint32_t InstanceHttpThreadCount = 0; // Deduce from core count
- int InstanceCoreLimit = 0; // Use hardware core count
+ uint32_t InstanceHttpThreadCount = 0; // Deduce from core count
+ int InstanceCoreLimit = 0; // Use hardware core count
+ std::filesystem::path InstanceConfigPath;
};
typedef std::function<void(std::string_view ModuleId, const HubProvisionedInstanceInfo& Info)> ProvisionModuleCallbackFunc;
diff --git a/src/zenserver/hub/storageserverinstance.cpp b/src/zenserver/hub/storageserverinstance.cpp
index 68de5e274..8e71e7aca 100644
--- a/src/zenserver/hub/storageserverinstance.cpp
+++ b/src/zenserver/hub/storageserverinstance.cpp
@@ -45,6 +45,10 @@ StorageServerInstance::SpawnServerProcess()
{
AdditionalOptions << " --corelimit=" << m_Config.CoreLimit;
}
+ if (!m_Config.ConfigPath.empty())
+ {
+ AdditionalOptions << " --config=\"" << MakeSafeAbsolutePath(m_Config.ConfigPath).string() << "\"";
+ }
m_ServerInstance.SpawnServerAndWaitUntilReady(m_Config.BasePort, AdditionalOptions.ToView());
ZEN_DEBUG("Storage server instance for module '{}' started, listening on port {}", m_ModuleId, m_Config.BasePort);
diff --git a/src/zenserver/hub/storageserverinstance.h b/src/zenserver/hub/storageserverinstance.h
index 23196d835..3b3cae385 100644
--- a/src/zenserver/hub/storageserverinstance.h
+++ b/src/zenserver/hub/storageserverinstance.h
@@ -28,6 +28,7 @@ public:
std::filesystem::path FileHydrationPath;
uint32_t HttpThreadCount = 0; // Deduce from core count
int CoreLimit = 0; // Use hardware core count
+ std::filesystem::path ConfigPath;
};
StorageServerInstance(ZenServerEnvironment& RunEnvironment, const Configuration& Config, std::string_view ModuleId);
diff --git a/src/zenserver/hub/zenhubserver.cpp b/src/zenserver/hub/zenhubserver.cpp
index 313be977c..b36a0778e 100644
--- a/src/zenserver/hub/zenhubserver.cpp
+++ b/src/zenserver/hub/zenhubserver.cpp
@@ -94,6 +94,13 @@ ZenHubServerConfigurator::AddCliOptions(cxxopts::Options& Options)
cxxopts::value(m_ServerOptions.HubInstanceCoreLimit),
"<instance core limit>");
+ Options.add_option("hub",
+ "",
+ "hub-instance-config",
+ "Path to Lua config file for provisioned instances",
+ cxxopts::value(m_ServerOptions.HubInstanceConfigPath),
+ "<instance config>");
+
#if ZEN_PLATFORM_WINDOWS
Options.add_option("hub",
"",
@@ -269,7 +276,8 @@ ZenHubServer::InitializeServices(const ZenHubServerConfig& ServerConfig)
.BasePortNumber = ServerConfig.HubBasePortNumber,
.InstanceLimit = ServerConfig.HubInstanceLimit,
.InstanceHttpThreadCount = ServerConfig.HubInstanceHttpThreadCount,
- .InstanceCoreLimit = ServerConfig.HubInstanceCoreLimit},
+ .InstanceCoreLimit = ServerConfig.HubInstanceCoreLimit,
+ .InstanceConfigPath = ServerConfig.HubInstanceConfigPath},
ZenServerEnvironment(ZenServerEnvironment::Hub,
ServerConfig.DataDir / "hub",
ServerConfig.DataDir / "servers",
diff --git a/src/zenserver/hub/zenhubserver.h b/src/zenserver/hub/zenhubserver.h
index 1036598bb..7e85159f1 100644
--- a/src/zenserver/hub/zenhubserver.h
+++ b/src/zenserver/hub/zenhubserver.h
@@ -21,15 +21,16 @@ class HttpHubService;
struct ZenHubServerConfig : public ZenServerConfig
{
- std::string UpstreamNotificationEndpoint;
- std::string InstanceId; // For use in notifications
- std::string ConsulEndpoint; // If set, enables Consul service registration
- uint16_t HubBasePortNumber = 21000;
- int HubInstanceLimit = 1000;
- bool HubUseJobObject = true;
- std::string HubInstanceHttpClass = "asio";
- uint32_t HubInstanceHttpThreadCount = 0; // Deduce from core count
- int HubInstanceCoreLimit = 0; // Use hardware core count
+ std::string UpstreamNotificationEndpoint;
+ std::string InstanceId; // For use in notifications
+ std::string ConsulEndpoint; // If set, enables Consul service registration
+ uint16_t HubBasePortNumber = 21000;
+ int HubInstanceLimit = 1000;
+ bool HubUseJobObject = true;
+ std::string HubInstanceHttpClass = "asio";
+ uint32_t HubInstanceHttpThreadCount = 0; // Deduce from core count
+ int HubInstanceCoreLimit = 0; // Use hardware core count
+ std::filesystem::path HubInstanceConfigPath; // Path to Lua config file
};
class Hub;