Improve logging and code quality

This commit is contained in:
Michael Friedrich 2018-09-28 11:26:47 +02:00
parent fb367e12cc
commit 86108e6a1e
3 changed files with 14 additions and 16 deletions

View File

@ -145,14 +145,14 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
if (!success) if (!success)
return false; return false;
/* Load cluster synchronized configuration files. This can be disabled for staged sync validations. */ /* Load cluster synchronized configuration files. This can be overridden for staged sync validations. */
String zonesVarDir = Configuration::DataDir + "/api/zones"; String zonesVarDir = Configuration::DataDir + "/api/zones";
/* Cluster config sync stage validation needs this. */ /* Cluster config sync stage validation needs this. */
if (systemNS->Contains("ZonesStageVarDir")) { if (systemNS->Contains("ZonesStageVarDir")) {
zonesVarDir = systemNS->Get("ZonesStageVarDir"); zonesVarDir = systemNS->Get("ZonesStageVarDir");
Log(LogInformation, "DaemonUtility") Log(LogNotice, "DaemonUtility")
<< "Overriding zones var directory with '" << zonesVarDir << "' for cluster config sync staging."; << "Overriding zones var directory with '" << zonesVarDir << "' for cluster config sync staging.";
} }

View File

@ -342,7 +342,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
/* Spawn a validation process. On success, move the staged configuration /* Spawn a validation process. On success, move the staged configuration
* into production and restart. * into production and restart.
*/ */
AsyncTryActivateZonesStage(GetApiZonesStageDir(), GetApiZonesDir(), relativePaths, true); AsyncTryActivateZonesStage(GetApiZonesStageDir(), GetApiZonesDir(), relativePaths);
} }
return Empty; return Empty;
@ -350,7 +350,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr,
const String& stageConfigDir, const String& currentConfigDir, const String& stageConfigDir, const String& currentConfigDir,
const std::vector<String>& relativePaths, bool reload) const std::vector<String>& relativePaths)
{ {
String logFile = GetApiZonesStageDir() + "/startup.log"; String logFile = GetApiZonesStageDir() + "/startup.log";
std::ofstream fpLog(logFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc); std::ofstream fpLog(logFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
@ -365,12 +365,11 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr,
/* validation went fine, copy stage and reload */ /* validation went fine, copy stage and reload */
if (pr.ExitStatus == 0) { if (pr.ExitStatus == 0) {
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Config validation for stage '" << GetApiZonesStageDir() << "' was OK, triggering reload."; << "Config validation for stage '" << GetApiZonesStageDir() << "' was OK, copying into '" << GetApiZonesDir() << "' and triggering reload.";
for (const String& path : relativePaths) { for (const String& path : relativePaths) {
/* TODO: Better error handling with existing files. */ Log(LogNotice, "ApiListener")
Log(LogCritical, "ApiListener") << "Copying file '" << path << "' from config sync staging to production zones directory.";
<< "Copying file '" << path << "' from config sync staging to production directory.";
String stagePath = GetApiZonesStageDir() + path; String stagePath = GetApiZonesStageDir() + path;
String currentPath = GetApiZonesDir() + path; String currentPath = GetApiZonesDir() + path;
@ -380,12 +379,11 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr,
Utility::CopyFile(stagePath, currentPath); Utility::CopyFile(stagePath, currentPath);
} }
if (reload) Application::RequestRestart();
Application::RequestRestart();
} else { } else {
Log(LogCritical, "ApiListener") Log(LogCritical, "ApiListener")
<< "Config validation failed for staged cluster config sync. Aborting. Logs: '" << "Config validation failed for staged cluster config sync in '" << GetApiZonesStageDir()
<< logFile << "'"; << "'. Aborting. Logs: '" << logFile << "'";
ApiListener::Ptr listener = ApiListener::GetInstance(); ApiListener::Ptr listener = ApiListener::GetInstance();
@ -395,7 +393,7 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr,
} }
void ApiListener::AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir, void ApiListener::AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir,
const std::vector<String>& relativePaths, bool reload) const std::vector<String>& relativePaths)
{ {
VERIFY(Application::GetArgC() >= 1); VERIFY(Application::GetArgC() >= 1);
@ -419,7 +417,7 @@ void ApiListener::AsyncTryActivateZonesStage(const String& stageConfigDir, const
Process::Ptr process = new Process(Process::PrepareCommand(args)); Process::Ptr process = new Process(Process::PrepareCommand(args));
process->SetTimeout(300); process->SetTimeout(300);
process->Run(std::bind(&TryActivateZonesStageCallback, _1, stageConfigDir, currentConfigDir, relativePaths, reload)); process->Run(std::bind(&TryActivateZonesStageCallback, _1, stageConfigDir, currentConfigDir, relativePaths));
} }
void ApiListener::UpdateLastFailedZonesStageValidation(const String& log) void ApiListener::UpdateLastFailedZonesStageValidation(const String& log)

View File

@ -183,9 +183,9 @@ private:
static void TryActivateZonesStageCallback(const ProcessResult& pr, static void TryActivateZonesStageCallback(const ProcessResult& pr,
const String& stageConfigDir, const String& currentConfigDir, const String& stageConfigDir, const String& currentConfigDir,
const std::vector<String>& relativePaths, bool reload); const std::vector<String>& relativePaths);
static void AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir, static void AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir,
const std::vector<String>& relativePaths, bool reload); const std::vector<String>& relativePaths);
void UpdateLastFailedZonesStageValidation(const String& log); void UpdateLastFailedZonesStageValidation(const String& log);