mirror of https://github.com/Icinga/icinga2.git
Merge pull request #9594 from Icinga/8834
ConfigObjectUtility::GetObjectConfigPath(): just return paths of existing objects
This commit is contained in:
commit
0294c174a4
|
@ -332,17 +332,7 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
|
||||||
params->Set("zone", zoneName);
|
params->Set("zone", zoneName);
|
||||||
|
|
||||||
if (object->GetPackage() == "_api") {
|
if (object->GetPackage() == "_api") {
|
||||||
String file;
|
std::ifstream fp(ConfigObjectUtility::GetExistingObjectConfigPath(object).CStr(), std::ifstream::binary);
|
||||||
|
|
||||||
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);
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ String ConfigObjectUtility::GetConfigDir()
|
||||||
return prefix + activeStage;
|
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();
|
String typeDir = type->GetPluralName();
|
||||||
boost::algorithm::to_lower(typeDir);
|
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
|
* 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
|
* 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.
|
* 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;
|
return longPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +62,11 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str
|
||||||
return prefix + Utility::TruncateUsingHash<80+3+40>(escapedName) + ".conf";
|
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)
|
void ConfigObjectUtility::RepairPackage(const String& package)
|
||||||
{
|
{
|
||||||
/* Try to fix the active stage, whenever we find a directory in there.
|
/* 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;
|
String path;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
path = GetObjectConfigPath(type, fullName);
|
path = ComputeNewObjectConfigPath(type, fullName);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
errors->Add("Config package broken: " + DiagnosticInformation(ex, false));
|
errors->Add("Config package broken: " + DiagnosticInformation(ex, false));
|
||||||
return false;
|
return false;
|
||||||
|
@ -346,17 +353,10 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path;
|
if (object->GetPackage() == "_api") {
|
||||||
|
Utility::Remove(GetExistingObjectConfigPath(object));
|
||||||
try {
|
|
||||||
path = GetObjectConfigPath(object->GetReflectionType(), name);
|
|
||||||
} catch (const std::exception& ex) {
|
|
||||||
errors->Add("Config package broken: " + DiagnosticInformation(ex, false));
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utility::Remove(path);
|
|
||||||
|
|
||||||
Log(LogInformation, "ConfigObjectUtility")
|
Log(LogInformation, "ConfigObjectUtility")
|
||||||
<< "Deleted object '" << name << "' of type '" << type->GetName() << "'.";
|
<< "Deleted object '" << name << "' of type '" << type->GetName() << "'.";
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ class ConfigObjectUtility
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static String GetConfigDir();
|
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 RepairPackage(const String& package);
|
||||||
static void CreateStorage();
|
static void CreateStorage();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue