aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2026-03-03 21:13:13 +0100
committerDan Engelbrecht <[email protected]>2026-03-03 21:13:13 +0100
commit792477584c562a8f0d25b7ef77c55a99d5045dcb (patch)
treeab225d09d5501e1cdf44f12eb0ff5bb651a1ea10
parentinitial implementation from (diff)
downloadzen-de/consul-support.tar.xz
zen-de/consul-support.zip
remove consul knowledge from StorageServerInstancede/consul-support
-rw-r--r--src/zenserver/hub/hubservice.cpp87
1 files changed, 40 insertions, 47 deletions
diff --git a/src/zenserver/hub/hubservice.cpp b/src/zenserver/hub/hubservice.cpp
index cc34e86bb..ee8c4d1e6 100644
--- a/src/zenserver/hub/hubservice.cpp
+++ b/src/zenserver/hub/hubservice.cpp
@@ -135,8 +135,7 @@ struct StorageServerInstance
StorageServerInstance(ZenServerEnvironment& RunEnvironment,
std::string_view ModuleId,
std::filesystem::path FileHydrationPath,
- std::filesystem::path HydrationTempPath,
- consul::ConsulClient* ConsulClient = nullptr);
+ std::filesystem::path HydrationTempPath);
~StorageServerInstance();
void Provision();
@@ -170,7 +169,6 @@ private:
#if ZEN_PLATFORM_WINDOWS
JobObject* m_JobObject = nullptr;
#endif
- consul::ConsulClient* m_ConsulClient;
void SpawnServerProcess();
@@ -181,12 +179,10 @@ private:
StorageServerInstance::StorageServerInstance(ZenServerEnvironment& RunEnvironment,
std::string_view ModuleId,
std::filesystem::path FileHydrationPath,
- std::filesystem::path HydrationTempPath,
- consul::ConsulClient* ConsulClient)
+ std::filesystem::path HydrationTempPath)
: m_ModuleId(ModuleId)
, m_ServerInstance(RunEnvironment, ZenServerInstance::ServerMode::kStorageServer)
, m_HydrationPath(FileHydrationPath)
-, m_ConsulClient(ConsulClient)
{
m_BaseDir = RunEnvironment.CreateChildDir(ModuleId);
m_TempDir = HydrationTempPath / ModuleId;
@@ -238,28 +234,6 @@ StorageServerInstance::Provision()
SpawnServerProcess();
}
- // Register with Consul if client is available
- if (m_ConsulClient != nullptr)
- {
- consul::ServiceRegistrationInfo Info;
- Info.ServiceId = m_ModuleId;
- Info.ServiceName = "zen-service";
- Info.Address = "localhost";
- Info.Port = GetBasePort();
- Info.HealthEndpoint = "health";
- Info.HealthIntervalSeconds = 10;
- Info.DeregisterAfterSeconds = 30;
-
- if (!m_ConsulClient->RegisterService(Info))
- {
- ZEN_WARN("Failed to register storage server instance for module '{}' with Consul, continuing anyway", m_ModuleId);
- }
- else
- {
- ZEN_INFO("Registered storage server instance for module '{}' with Consul as '{}'", m_ModuleId, Info.ServiceName);
- }
- }
-
m_IsProvisioned = true;
}
@@ -277,19 +251,6 @@ StorageServerInstance::Deprovision()
ZEN_INFO("Deprovisioning storage server instance for module '{}'", m_ModuleId);
- // Deregister from Consul before shutdown
- if (m_ConsulClient != nullptr)
- {
- if (!m_ConsulClient->DeregisterService(m_ModuleId))
- {
- ZEN_WARN("Failed to deregister storage server instance for module '{}' from Consul, continuing anyway", m_ModuleId);
- }
- else
- {
- ZEN_INFO("Deregistered storage server instance for module '{}' from Consul", m_ModuleId);
- }
- }
-
m_ServerInstance.Shutdown();
Dehydrate();
@@ -484,12 +445,9 @@ struct HttpHubService::Impl
return false;
}
- IsNewInstance = true;
- auto NewInstance = std::make_unique<StorageServerInstance>(m_RunEnvironment,
- ModuleId,
- m_FileHydrationPath,
- m_HydrationTempPath,
- m_ConsulClient);
+ IsNewInstance = true;
+ auto NewInstance =
+ std::make_unique<StorageServerInstance>(m_RunEnvironment, ModuleId, m_FileHydrationPath, m_HydrationTempPath);
#if ZEN_PLATFORM_WINDOWS
if (m_JobObject.IsValid())
{
@@ -541,6 +499,28 @@ struct HttpHubService::Impl
OutInfo.Port = Instance->GetBasePort();
+ // Register with Consul if client is available
+ if (m_ConsulClient != nullptr)
+ {
+ consul::ServiceRegistrationInfo Info;
+ Info.ServiceId = ModuleId;
+ Info.ServiceName = "zen-service";
+ Info.Address = "localhost";
+ Info.Port = OutInfo.Port;
+ Info.HealthEndpoint = "health";
+ Info.HealthIntervalSeconds = 10;
+ Info.DeregisterAfterSeconds = 30;
+
+ if (!m_ConsulClient->RegisterService(Info))
+ {
+ ZEN_WARN("Failed to register storage server instance for module '{}' with Consul, continuing anyway", ModuleId);
+ }
+ else
+ {
+ ZEN_INFO("Registered storage server instance for module '{}' with Consul as '{}'", ModuleId, Info.ServiceName);
+ }
+ }
+
// TODO: base URI? Would need to know what host name / IP to use
return true;
@@ -595,6 +575,19 @@ struct HttpHubService::Impl
m_DeprovisioningModules.erase(ModuleId);
});
+ // Deregister from Consul before shutdown
+ if (m_ConsulClient != nullptr)
+ {
+ if (!m_ConsulClient->DeregisterService(ModuleId))
+ {
+ ZEN_WARN("Failed to deregister storage server instance for module '{}' from Consul, continuing anyway", ModuleId);
+ }
+ else
+ {
+ ZEN_INFO("Deregistered storage server instance for module '{}' from Consul", ModuleId);
+ }
+ }
+
Instance->Deprovision();
return true;