From efc22891787dfa6abf8a8886f8931d4513ac2d37 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 24 Oct 2018 17:06:17 +0200 Subject: [PATCH] Remove duplicated validation paths in function signatures --- lib/remote/apilistener-filesync.cpp | 33 ++++++++++++----------------- lib/remote/apilistener.hpp | 4 +--- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index 4b31673f6..17951a39f 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -446,7 +446,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D /* Spawn a validation process. On success, move the staged configuration * into production and restart. */ - AsyncTryActivateZonesStage(GetApiZonesStageDir(), GetApiZonesDir(), relativePaths); + AsyncTryActivateZonesStage(relativePaths); } return Empty; @@ -459,20 +459,20 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D * On failure, there's no restart and this is logged. * * @param pr Result of the validation process. - * @param stageConfigDir TODO - * @param currentConfigDir TODO - * @param relativePaths Collected paths which are copied from stage to current. + * @param relativePaths Collected paths including the zone name, which are copied from stage to current directories. */ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, - const String& stageConfigDir, const String& currentConfigDir, const std::vector& relativePaths) { - String logFile = GetApiZonesStageDir() + "/startup.log"; + String apiZonesDir = GetApiZonesDir(); + String apiZonesStageDir = GetApiZonesStageDir(); + + String logFile = apiZonesStageDir + "/startup.log"; std::ofstream fpLog(logFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc); fpLog << pr.Output; fpLog.close(); - String statusFile = GetApiZonesStageDir() + "/status"; + String statusFile = apiZonesStageDir + "/status"; std::ofstream fpStatus(statusFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc); fpStatus << pr.ExitStatus; fpStatus.close(); @@ -480,9 +480,7 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, /* validation went fine, copy stage and reload */ if (pr.ExitStatus == 0) { Log(LogInformation, "ApiListener") - << "Config validation for stage '" << GetApiZonesStageDir() << "' was OK, replacing into '" << GetApiZonesDir() << "' and triggering reload."; - - String apiZonesDir = GetApiZonesDir(); + << "Config validation for stage '" << apiZonesStageDir << "' was OK, replacing into '" << apiZonesDir << "' and triggering reload."; /* Purge production before copying stage. */ if (Utility::PathExists(apiZonesDir)) @@ -495,8 +493,8 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, Log(LogNotice, "ApiListener") << "Copying file '" << path << "' from config sync staging to production zones directory."; - String stagePath = GetApiZonesStageDir() + path; - String currentPath = GetApiZonesDir() + path; + String stagePath = apiZonesStageDir + path; + String currentPath = apiZonesDir + path; Utility::MkDirP(Utility::DirName(currentPath), 0700); @@ -515,7 +513,7 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, /* Error case. */ Log(LogCritical, "ApiListener") - << "Config validation failed for staged cluster config sync in '" << GetApiZonesStageDir() + << "Config validation failed for staged cluster config sync in '" << apiZonesStageDir << "'. Aborting. Logs: '" << logFile << "'"; ApiListener::Ptr listener = ApiListener::GetInstance(); @@ -528,12 +526,9 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, * 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 stageConfigDir TODO - * @param currentConfigDir TODO - * @param relativePaths Required for later file operations in the callback. + * @param relativePaths Required for later file operations in the callback. Provides the zone name plus path in a list. */ -void ApiListener::AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir, - const std::vector& relativePaths) +void ApiListener::AsyncTryActivateZonesStage(const std::vector& relativePaths) { VERIFY(Application::GetArgC() >= 1); @@ -559,7 +554,7 @@ void ApiListener::AsyncTryActivateZonesStage(const String& stageConfigDir, const Process::Ptr process = new Process(Process::PrepareCommand(args)); process->SetTimeout(300); - process->Run(std::bind(&TryActivateZonesStageCallback, _1, stageConfigDir, currentConfigDir, relativePaths)); + process->Run(std::bind(&TryActivateZonesStageCallback, _1, relativePaths)); } /** diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 59e73ec96..3d1082444 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -182,10 +182,8 @@ private: void SendConfigUpdate(const JsonRpcConnection::Ptr& aclient); static void TryActivateZonesStageCallback(const ProcessResult& pr, - const String& stageConfigDir, const String& currentConfigDir, - const std::vector& relativePaths); - static void AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir, const std::vector& relativePaths); + static void AsyncTryActivateZonesStage(const std::vector& relativePaths); void UpdateLastFailedZonesStageValidation(const String& log); void ClearLastFailedZonesStageValidation();