diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 28ab0459d..1fca07b5c 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -3,6 +3,7 @@ #include "cli/daemoncommand.hpp" #include "cli/daemonutility.hpp" #include "remote/apilistener.hpp" +#include "remote/configobjectslock.hpp" #include "remote/configobjectutility.hpp" #include "config/configcompiler.hpp" #include "config/configcompilercontext.hpp" @@ -801,6 +802,10 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vectorGetName() + " is already acknowledged."); } + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + return ApiActions::CreateResult(503, "Icinga is reloading."); + } + Comment::AddComment(checkable, CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), persistent, timestamp, sticky == AcknowledgementSticky); checkable->AcknowledgeProblem(HttpUtility::GetLastParameter(params, "author"), @@ -272,6 +279,12 @@ Dictionary::Ptr ApiActions::RemoveAcknowledgement(const ConfigObject::Ptr& objec "Cannot remove acknowledgement for non-existent checkable object " + object->GetName() + "."); + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + return ApiActions::CreateResult(503, "Icinga is reloading."); + } + String removedBy (HttpUtility::GetLastParameter(params, "author")); checkable->ClearAcknowledgement(removedBy); @@ -297,6 +310,12 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object, timestamp = HttpUtility::GetLastParameter(params, "expiry"); } + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + return ApiActions::CreateResult(503, "Icinga is reloading."); + } + String commentName = Comment::AddComment(checkable, CommentUser, HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), false, timestamp); @@ -316,6 +335,12 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object, Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params) { + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + return ApiActions::CreateResult(503, "Icinga is reloading."); + } + auto author (HttpUtility::GetLastParameter(params, "author")); Checkable::Ptr checkable = dynamic_pointer_cast(object); @@ -388,6 +413,12 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object, } } + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + return ApiActions::CreateResult(503, "Icinga is reloading."); + } + Downtime::Ptr downtime = Downtime::AddDowntime(checkable, author, comment, startTime, endTime, fixed, triggerName, duration); String downtimeName = downtime->GetName(); @@ -500,6 +531,12 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object, Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params) { + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + return ApiActions::CreateResult(503, "Icinga is reloading."); + } + auto author (HttpUtility::GetLastParameter(params, "author")); Checkable::Ptr checkable = dynamic_pointer_cast(object); diff --git a/lib/remote/createobjecthandler.cpp b/lib/remote/createobjecthandler.cpp index c01b23641..598eeec3b 100644 --- a/lib/remote/createobjecthandler.cpp +++ b/lib/remote/createobjecthandler.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "remote/createobjecthandler.hpp" +#include "remote/configobjectslock.hpp" #include "remote/configobjectutility.hpp" #include "remote/httputility.hpp" #include "remote/jsonrpcconnection.hpp" @@ -94,6 +95,13 @@ bool CreateObjectHandler::HandleRequest( if (params) verbose = HttpUtility::GetLastParameter(params, "verbose"); + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading"); + return true; + } + /* Object creation can cause multiple errors and optionally diagnostic information. * We can't use SendJsonError() here. */ diff --git a/lib/remote/deleteobjecthandler.cpp b/lib/remote/deleteobjecthandler.cpp index 2edb0e455..a4fd98d9a 100644 --- a/lib/remote/deleteobjecthandler.cpp +++ b/lib/remote/deleteobjecthandler.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "remote/deleteobjecthandler.hpp" +#include "remote/configobjectslock.hpp" #include "remote/configobjectutility.hpp" #include "remote/httputility.hpp" #include "remote/filterutility.hpp" @@ -66,6 +67,13 @@ bool DeleteObjectHandler::HandleRequest( bool cascade = HttpUtility::GetLastParameter(params, "cascade"); bool verbose = HttpUtility::GetLastParameter(params, "verbose"); + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading"); + return true; + } + ArrayData results; bool success = true; diff --git a/lib/remote/modifyobjecthandler.cpp b/lib/remote/modifyobjecthandler.cpp index cc008b90c..d9a215f5f 100644 --- a/lib/remote/modifyobjecthandler.cpp +++ b/lib/remote/modifyobjecthandler.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "remote/modifyobjecthandler.hpp" +#include "remote/configobjectslock.hpp" #include "remote/httputility.hpp" #include "remote/filterutility.hpp" #include "remote/apiaction.hpp" @@ -77,6 +78,13 @@ bool ModifyObjectHandler::HandleRequest( if (params) verbose = HttpUtility::GetLastParameter(params, "verbose"); + ConfigObjectsSharedLock lock (std::try_to_lock); + + if (!lock) { + HttpUtility::SendJsonError(response, params, 503, "Icinga is reloading"); + return true; + } + ArrayData results; for (const ConfigObject::Ptr& obj : objs) {