mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 14:14:45 +02:00
ApiListener: merge new config validation and actication functions
Merge AsyncTryActivateZonesStage and TryActivateZonesStageCallback and name the result TryActivateZonesStage. The old split was a leftover from the one being a callback function with no actual meaningful separation.
This commit is contained in:
parent
e4610e7dbd
commit
70c9d49ebc
@ -538,7 +538,7 @@ void ApiListener::HandleConfigUpdate(const MessageOrigin::Ptr& origin, const Dic
|
|||||||
Log(LogInformation, "ApiListener")
|
Log(LogInformation, "ApiListener")
|
||||||
<< "Received configuration updates (" << count << ") from endpoint '" << fromEndpointName
|
<< "Received configuration updates (" << count << ") from endpoint '" << fromEndpointName
|
||||||
<< "' are different to production, triggering validation and reload.";
|
<< "' are different to production, triggering validation and reload.";
|
||||||
AsyncTryActivateZonesStage(relativePaths);
|
TryActivateZonesStage(relativePaths);
|
||||||
} else {
|
} else {
|
||||||
Log(LogInformation, "ApiListener")
|
Log(LogInformation, "ApiListener")
|
||||||
<< "Received configuration updates (" << count << ") from endpoint '" << fromEndpointName
|
<< "Received configuration updates (" << count << ") from endpoint '" << fromEndpointName
|
||||||
@ -548,17 +548,44 @@ void ApiListener::HandleConfigUpdate(const MessageOrigin::Ptr& origin, const Dic
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for stage config validation.
|
* Spawns a new validation process with 'System.ZonesStageVarDir' set to override the config validation zone dirs with
|
||||||
* When validation was successful, the configuration is copied from
|
* our current stage. Then waits for the validation result and if it was successful, the configuration is copied from
|
||||||
* stage to production and a restart is triggered.
|
* stage to production and a restart is triggered. On validation failure, there is no restart and this is logged.
|
||||||
* On failure, there's no restart and this is logged.
|
*
|
||||||
|
* The caller of this function must hold m_ConfigSyncStageLock.
|
||||||
*
|
*
|
||||||
* @param pr Result of the validation process.
|
|
||||||
* @param relativePaths Collected paths including the zone name, which are copied from stage to current directories.
|
* @param relativePaths Collected paths including the zone name, which are copied from stage to current directories.
|
||||||
*/
|
*/
|
||||||
void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr,
|
void ApiListener::TryActivateZonesStage(const std::vector<String>& relativePaths)
|
||||||
const std::vector<String>& relativePaths)
|
|
||||||
{
|
{
|
||||||
|
VERIFY(Application::GetArgC() >= 1);
|
||||||
|
|
||||||
|
/* Inherit parent process args. */
|
||||||
|
Array::Ptr args = new Array({
|
||||||
|
Application::GetExePath(Application::GetArgV()[0]),
|
||||||
|
});
|
||||||
|
|
||||||
|
for (int i = 1; i < Application::GetArgC(); i++) {
|
||||||
|
String argV = Application::GetArgV()[i];
|
||||||
|
|
||||||
|
if (argV == "-d" || argV == "--daemonize")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
args->Add(argV);
|
||||||
|
}
|
||||||
|
|
||||||
|
args->Add("--validate");
|
||||||
|
|
||||||
|
// Set the ZonesStageDir. This creates our own local chroot without any additional automated zone includes.
|
||||||
|
args->Add("--define");
|
||||||
|
args->Add("System.ZonesStageVarDir=" + GetApiZonesStageDir());
|
||||||
|
|
||||||
|
Process::Ptr process = new Process(Process::PrepareCommand(args));
|
||||||
|
process->SetTimeout(Application::GetReloadTimeout());
|
||||||
|
|
||||||
|
process->Run();
|
||||||
|
const ProcessResult& pr = process->WaitForResult();
|
||||||
|
|
||||||
String apiZonesDir = GetApiZonesDir();
|
String apiZonesDir = GetApiZonesDir();
|
||||||
String apiZonesStageDir = GetApiZonesStageDir();
|
String apiZonesStageDir = GetApiZonesStageDir();
|
||||||
|
|
||||||
@ -622,44 +649,6 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr,
|
|||||||
listener->UpdateLastFailedZonesStageValidation(pr.Output);
|
listener->UpdateLastFailedZonesStageValidation(pr.Output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Spawns a new validation process and waits for its output.
|
|
||||||
* Sets 'System.ZonesStageVarDir' to override the config validation zone dirs with our current stage.
|
|
||||||
*
|
|
||||||
* @param relativePaths Required for later file operations in the callback. Provides the zone name plus path in a list.
|
|
||||||
*/
|
|
||||||
void ApiListener::AsyncTryActivateZonesStage(const std::vector<String>& relativePaths)
|
|
||||||
{
|
|
||||||
VERIFY(Application::GetArgC() >= 1);
|
|
||||||
|
|
||||||
/* Inherit parent process args. */
|
|
||||||
Array::Ptr args = new Array({
|
|
||||||
Application::GetExePath(Application::GetArgV()[0]),
|
|
||||||
});
|
|
||||||
|
|
||||||
for (int i = 1; i < Application::GetArgC(); i++) {
|
|
||||||
String argV = Application::GetArgV()[i];
|
|
||||||
|
|
||||||
if (argV == "-d" || argV == "--daemonize")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
args->Add(argV);
|
|
||||||
}
|
|
||||||
|
|
||||||
args->Add("--validate");
|
|
||||||
|
|
||||||
// Set the ZonesStageDir. This creates our own local chroot without any additional automated zone includes.
|
|
||||||
args->Add("--define");
|
|
||||||
args->Add("System.ZonesStageVarDir=" + GetApiZonesStageDir());
|
|
||||||
|
|
||||||
Process::Ptr process = new Process(Process::PrepareCommand(args));
|
|
||||||
process->SetTimeout(Application::GetReloadTimeout());
|
|
||||||
|
|
||||||
process->Run();
|
|
||||||
const ProcessResult& pr = process->WaitForResult();
|
|
||||||
TryActivateZonesStageCallback(pr, relativePaths);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the structure from the last failed validation output.
|
* Update the structure from the last failed validation output.
|
||||||
* Uses the current timestamp.
|
* Uses the current timestamp.
|
||||||
|
@ -199,9 +199,7 @@ private:
|
|||||||
static ConfigDirInformation LoadConfigDir(const String& dir);
|
static ConfigDirInformation LoadConfigDir(const String& dir);
|
||||||
static void ConfigGlobHandler(ConfigDirInformation& config, const String& path, const String& file);
|
static void ConfigGlobHandler(ConfigDirInformation& config, const String& path, const String& file);
|
||||||
|
|
||||||
static void TryActivateZonesStageCallback(const ProcessResult& pr,
|
static void TryActivateZonesStage(const std::vector<String>& relativePaths);
|
||||||
const std::vector<String>& relativePaths);
|
|
||||||
static void AsyncTryActivateZonesStage(const std::vector<String>& relativePaths);
|
|
||||||
|
|
||||||
static String GetChecksum(const String& content);
|
static String GetChecksum(const String& content);
|
||||||
static bool CheckConfigChange(const ConfigDirInformation& oldConfig, const ConfigDirInformation& newConfig);
|
static bool CheckConfigChange(const ConfigDirInformation& oldConfig, const ConfigDirInformation& newConfig);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user