mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
Just get paths from existing objects for modification and deletion
instead of computing from scratch if they're in the _api package. For now this changes literally nothing as paths of existing objects still follow the scheme of paths of new objects which didn't change. Now Icinga only doesn't expect existing objects at particular paths. However, with the latter in v2.14+ (agent, satellite) we can just change the path scheme of new objects in v2.16+ (master) as we wish. The child nodes will just follow the new scheme of paths of new objects.
This commit is contained in:
parent
f855cfa155
commit
145ee890df
@ -332,17 +332,7 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
|
||||
params->Set("zone", zoneName);
|
||||
|
||||
if (object->GetPackage() == "_api") {
|
||||
String file;
|
||||
|
||||
try {
|
||||
file = ConfigObjectUtility::GetObjectConfigPath(object->GetReflectionType(), object->GetName());
|
||||
} catch (const std::exception& ex) {
|
||||
Log(LogNotice, "ApiListener")
|
||||
<< "Cannot sync object '" << object->GetName() << "': " << ex.what();
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream fp(file.CStr(), std::ifstream::binary);
|
||||
std::ifstream fp(ConfigObjectUtility::GetExistingObjectConfigPath(object).CStr(), std::ifstream::binary);
|
||||
if (!fp)
|
||||
return;
|
||||
|
||||
|
@ -29,7 +29,7 @@ String ConfigObjectUtility::GetConfigDir()
|
||||
return prefix + activeStage;
|
||||
}
|
||||
|
||||
String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const String& fullName)
|
||||
String ConfigObjectUtility::ComputeNewObjectConfigPath(const Type::Ptr& type, const String& fullName)
|
||||
{
|
||||
String typeDir = type->GetPluralName();
|
||||
boost::algorithm::to_lower(typeDir);
|
||||
@ -51,8 +51,10 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str
|
||||
* be able to schedule a downtime or add an acknowledgement, which is not feasible) and the impact of not syncing
|
||||
* these objects through the whole cluster is limited. For other object types, we currently prefer to fail the
|
||||
* creation early so that configuration inconsistencies throughout the cluster are avoided.
|
||||
*
|
||||
* TODO: Remove this in v2.16 and truncate all.
|
||||
*/
|
||||
if ((type->GetName() != "Comment" && type->GetName() != "Downtime") || Utility::PathExists(longPath)) {
|
||||
if (type->GetName() != "Comment" && type->GetName() != "Downtime") {
|
||||
return longPath;
|
||||
}
|
||||
|
||||
@ -60,6 +62,11 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str
|
||||
return prefix + Utility::TruncateUsingHash<80+3+40>(escapedName) + ".conf";
|
||||
}
|
||||
|
||||
String ConfigObjectUtility::GetExistingObjectConfigPath(const ConfigObject::Ptr& object)
|
||||
{
|
||||
return object->GetDebugInfo().Path;
|
||||
}
|
||||
|
||||
void ConfigObjectUtility::RepairPackage(const String& package)
|
||||
{
|
||||
/* Try to fix the active stage, whenever we find a directory in there.
|
||||
@ -185,7 +192,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
||||
String path;
|
||||
|
||||
try {
|
||||
path = GetObjectConfigPath(type, fullName);
|
||||
path = ComputeNewObjectConfigPath(type, fullName);
|
||||
} catch (const std::exception& ex) {
|
||||
errors->Add("Config package broken: " + DiagnosticInformation(ex, false));
|
||||
return false;
|
||||
@ -346,16 +353,7 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
|
||||
return false;
|
||||
}
|
||||
|
||||
String path;
|
||||
|
||||
try {
|
||||
path = GetObjectConfigPath(object->GetReflectionType(), name);
|
||||
} catch (const std::exception& ex) {
|
||||
errors->Add("Config package broken: " + DiagnosticInformation(ex, false));
|
||||
return false;
|
||||
}
|
||||
|
||||
Utility::Remove(path);
|
||||
Utility::Remove(GetExistingObjectConfigPath(object));
|
||||
|
||||
Log(LogInformation, "ConfigObjectUtility")
|
||||
<< "Deleted object '" << name << "' of type '" << type->GetName() << "'.";
|
||||
|
@ -22,7 +22,8 @@ class ConfigObjectUtility
|
||||
|
||||
public:
|
||||
static String GetConfigDir();
|
||||
static String GetObjectConfigPath(const Type::Ptr& type, const String& fullName);
|
||||
static String ComputeNewObjectConfigPath(const Type::Ptr& type, const String& fullName);
|
||||
static String GetExistingObjectConfigPath(const ConfigObject::Ptr& object);
|
||||
static void RepairPackage(const String& package);
|
||||
static void CreateStorage();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user