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,20 +411,27 @@ 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
{ {
ValidateServicesCache(); if (name.IsScalar()) {
ValidateServicesCache();
map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()]; map<String, weak_ptr<Service> >& services = m_ServicesCache[GetName()];
map<String, weak_ptr<Service> >::iterator it = services.find(name); map<String, weak_ptr<Service> >::iterator it = services.find(name);
if (it != services.end()) { if (it != services.end()) {
Service::Ptr service = it->second.lock(); Service::Ptr service = it->second.lock();
assert(service); assert(service);
return service; return service;
}
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."));
} }
return Service::GetByName(name);
} }
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;