Implement dictionary-based host/service name pairs.

This commit is contained in:
Gunnar Beutner 2013-02-08 21:30:14 +01:00
parent 580f2e1fcc
commit e443b77a56
3 changed files with 24 additions and 17 deletions

View File

@ -411,8 +411,9 @@ void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector<V
task->FinishResult(Empty); task->FinishResult(Empty);
} }
Service::Ptr Host::GetServiceByShortName(const String& name) const Service::Ptr Host::GetServiceByShortName(const Value& name) const
{ {
if (name.IsScalar()) {
ValidateServicesCache(); ValidateServicesCache();
map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()]; map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()];
@ -425,6 +426,12 @@ Service::Ptr Host::GetServiceByShortName(const String& name) const
} }
return Service::GetByName(name); return Service::GetByName(name);
} else if (name.IsObjectType<Dictionary>()) {
Dictionary::Ptr dict = name;
return GetByName(dict->Get("host"))->GetServiceByShortName(dict->Get("service"));
} else {
BOOST_THROW_EXCEPTION(invalid_argument("Host/Service name pair is invalid."));
}
} }
set<Host::Ptr> Host::GetParentHosts(void) const set<Host::Ptr> Host::GetParentHosts(void) const
@ -464,9 +471,9 @@ set<Service::Ptr> Host::GetParentServices(void) const
if (dependencies) { if (dependencies) {
String key; String key;
BOOST_FOREACH(tie(key, tuples::ignore), dependencies) { Value value;
// TODO(#3660): look up { host = "name", service = "name" } pairs BOOST_FOREACH(tie(key, value), dependencies) {
parents.insert(GetServiceByShortName(key)); parents.insert(GetServiceByShortName(value));
} }
} }

View File

@ -67,7 +67,7 @@ public:
bool IsInDowntime(void) const; bool IsInDowntime(void) const;
bool IsUp(void) const; bool IsUp(void) const;
shared_ptr<Service> GetServiceByShortName(const String& name) const; shared_ptr<Service> GetServiceByShortName(const Value& name) const;
set<shared_ptr<Service> > GetServices(void) const; set<shared_ptr<Service> > GetServices(void) const;
static void InvalidateServicesCache(void); static void InvalidateServicesCache(void);

View File

@ -777,9 +777,9 @@ set<Service::Ptr> Service::GetParentServices(void) const
if (dependencies) { if (dependencies) {
String key; String key;
BOOST_FOREACH(tie(key, tuples::ignore), dependencies) { Value value;
// TODO(#3660): look up { host = "name", service = "name" } pairs BOOST_FOREACH(tie(key, value), dependencies) {
Service::Ptr service = GetHost()->GetServiceByShortName(key); Service::Ptr service = GetHost()->GetServiceByShortName(value);
if (service->GetName() == GetName()) if (service->GetName() == GetName())
continue; continue;