mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-20 12:14:44 +02:00
Make sure the dependency graph is properly updated when adding and removing objects
fixes #11686 fixes #11374
This commit is contained in:
parent
65e91ed96b
commit
d82db2ae6c
@ -34,7 +34,20 @@ void DependencyGraph::AddDependency(Object *parent, Object *child)
|
|||||||
void DependencyGraph::RemoveDependency(Object *parent, Object *child)
|
void DependencyGraph::RemoveDependency(Object *parent, Object *child)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
m_Dependencies[child][parent]--;
|
|
||||||
|
std::map<Object *, int>& refs = m_Dependencies[child];
|
||||||
|
std::map<Object *, int>::iterator it = refs.find(parent);
|
||||||
|
|
||||||
|
if (it == refs.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
it->second--;
|
||||||
|
|
||||||
|
if (it->second == 0)
|
||||||
|
refs.erase(it);
|
||||||
|
|
||||||
|
if (refs.empty())
|
||||||
|
m_Dependencies.erase(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)
|
std::vector<Object::Ptr> DependencyGraph::GetParents(const Object::Ptr& child)
|
||||||
|
@ -67,7 +67,7 @@ class Comment : ConfigObject < CommentNameComposer
|
|||||||
|
|
||||||
if (!newValue.IsEmpty()) {
|
if (!newValue.IsEmpty()) {
|
||||||
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
||||||
DependencyGraph::RemoveDependency(this, service.get());
|
DependencyGraph::AddDependency(this, service.get());
|
||||||
}
|
}
|
||||||
}}}
|
}}}
|
||||||
navigate {{{
|
navigate {{{
|
||||||
|
@ -55,7 +55,7 @@ class Dependency : CustomVarObject < DependencyNameComposer
|
|||||||
|
|
||||||
if (!newValue.IsEmpty()) {
|
if (!newValue.IsEmpty()) {
|
||||||
Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
|
Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
|
||||||
DependencyGraph::RemoveDependency(this, service.get());
|
DependencyGraph::AddDependency(this, service.get());
|
||||||
}
|
}
|
||||||
}}}
|
}}}
|
||||||
navigate {{{
|
navigate {{{
|
||||||
@ -82,7 +82,7 @@ class Dependency : CustomVarObject < DependencyNameComposer
|
|||||||
|
|
||||||
if (!newValue.IsEmpty()) {
|
if (!newValue.IsEmpty()) {
|
||||||
Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
|
Service::Ptr service = Service::GetByNamePair(GetParentHostName(), newValue);
|
||||||
DependencyGraph::RemoveDependency(this, service.get());
|
DependencyGraph::AddDependency(this, service.get());
|
||||||
}
|
}
|
||||||
}}}
|
}}}
|
||||||
navigate {{{
|
navigate {{{
|
||||||
|
@ -54,7 +54,7 @@ class Downtime : ConfigObject < DowntimeNameComposer
|
|||||||
|
|
||||||
if (!newValue.IsEmpty()) {
|
if (!newValue.IsEmpty()) {
|
||||||
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
||||||
DependencyGraph::RemoveDependency(this, service.get());
|
DependencyGraph::AddDependency(this, service.get());
|
||||||
}
|
}
|
||||||
}}}
|
}}}
|
||||||
navigate {{{
|
navigate {{{
|
||||||
|
@ -74,7 +74,7 @@ class Notification : CustomVarObject < NotificationNameComposer
|
|||||||
|
|
||||||
if (!newValue.IsEmpty()) {
|
if (!newValue.IsEmpty()) {
|
||||||
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
||||||
DependencyGraph::RemoveDependency(this, service.get());
|
DependencyGraph::AddDependency(this, service.get());
|
||||||
}
|
}
|
||||||
}}}
|
}}}
|
||||||
navigate {{{
|
navigate {{{
|
||||||
|
@ -53,7 +53,7 @@ class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
|
|||||||
|
|
||||||
if (!newValue.IsEmpty()) {
|
if (!newValue.IsEmpty()) {
|
||||||
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
|
||||||
DependencyGraph::RemoveDependency(this, service.get());
|
DependencyGraph::AddDependency(this, service.get());
|
||||||
}
|
}
|
||||||
}}}
|
}}}
|
||||||
navigate {{{
|
navigate {{{
|
||||||
|
@ -901,7 +901,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
|
|||||||
<< "\t" << klass.Parent << "::Start(runtimeCreated);" << std::endl << std::endl;
|
<< "\t" << klass.Parent << "::Start(runtimeCreated);" << std::endl << std::endl;
|
||||||
|
|
||||||
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
||||||
if (!(it->Type.IsName))
|
if (!it->Type.IsName && it->TrackAccessor.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Empty, Get" << it->GetFriendlyName() << "());" << std::endl;
|
m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Empty, Get" << it->GetFriendlyName() << "());" << std::endl;
|
||||||
@ -913,7 +913,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
|
|||||||
<< "\t" << klass.Parent << "::Stop(runtimeRemoved);" << std::endl << std::endl;
|
<< "\t" << klass.Parent << "::Stop(runtimeRemoved);" << std::endl << std::endl;
|
||||||
|
|
||||||
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
||||||
if (!(it->Type.IsName))
|
if (!it->Type.IsName && it->TrackAccessor.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Get" << it->GetFriendlyName() << "(), Empty);" << std::endl;
|
m_Impl << "\t" << "Track" << it->GetFriendlyName() << "(Get" << it->GetFriendlyName() << "(), Empty);" << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user