]> granicus.if.org Git - icinga2/commitdiff
Use adapters in the checker/delegation components.
authorGunnar Beutner <gunnar@beutner.name>
Sat, 16 Jun 2012 18:44:24 +0000 (20:44 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Sat, 16 Jun 2012 18:47:43 +0000 (20:47 +0200)
base/application.cpp
base/application.h
components/checker/checkercomponent.cpp
components/delegation/delegationcomponent.cpp
components/delegation/delegationcomponent.h
icinga/configobjectadapter.h
icinga/macroprocessor.cpp
icinga/macroprocessor.h
icinga/service.cpp
icinga/service.h

index 4ffe0e4f00535230c6bd7bb793b92b23645fd7f0..070d0b40ad4a5bac2062f67235c1f28902d596d1 100644 (file)
@@ -248,7 +248,7 @@ Component::Ptr Application::LoadComponent(const string& path,
  *
  * @param component The component.
  */
-void Application::RegisterComponent(Component::Ptr component)
+void Application::RegisterComponent(const Component::Ptr& component)
 {
        m_Components[component->GetName()] = component;
 
@@ -260,7 +260,7 @@ void Application::RegisterComponent(Component::Ptr component)
  *
  * @param component The component.
  */
-void Application::UnregisterComponent(Component::Ptr component)
+void Application::UnregisterComponent(const Component::Ptr& component)
 {
        string name = component->GetName();
 
index 56383b049c97b303b6d50f8d415b63cc09b38359..47ff8465a4a2bb21131185a715cd3b6ce646cb9e 100644 (file)
@@ -57,8 +57,8 @@ public:
 
        shared_ptr<Component> LoadComponent(const string& path,
            const ConfigObject::Ptr& componentConfig);
-       void RegisterComponent(shared_ptr<Component> component);
-       void UnregisterComponent(shared_ptr<Component> component);
+       void RegisterComponent(const shared_ptr<Component>& component);
+       void UnregisterComponent(const shared_ptr<Component>& component);
        shared_ptr<Component> GetComponent(const string& name) const;
        void AddComponentSearchDir(const string& componentDirectory);
 
index 97b8f4883283f11b7a805248ef1dedb8c2656f3e..6b6ae352970b745f7110351b3f513d49a32c9502 100644 (file)
@@ -48,7 +48,7 @@ void CheckerComponent::Start(void)
        ConfigObject::TMap::Range range = ConfigObject::GetObjects("service");
 
        for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
-               Service svc(it->second);
+               Service svc = it->second;
                CheckTask::Ptr ct = CheckTask::CreateTask(svc);
                CheckResult cr = ct->Execute();
        }
index 0a27018c3d1bb26bb8de9d7660a616bf62b9993d..f2a9de172c5b8325f7da655377abed40826c1db1 100644 (file)
@@ -53,47 +53,47 @@ void DelegationComponent::Stop(void)
                mgr->UnregisterEndpoint(m_DelegationEndpoint);
 }
 
-void DelegationComponent::NewServiceHandler(const ConfigObject::Ptr& object)
+void DelegationComponent::NewServiceHandler(const Service& object)
 {
        AssignService(object);
 }
 
-void DelegationComponent::RemovedServiceHandler(const ConfigObject::Ptr& object)
+void DelegationComponent::RemovedServiceHandler(const Service& object)
 {
        RevokeService(object);
 }
 
-void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
+void DelegationComponent::AssignService(const Service& service)
 {
        RequestMessage request;
        request.SetMethod("checker::AssignService");
 
        MessagePart params;
-       params.SetProperty("service", service->GetProperties());
+       params.SetProperty("service", service.GetConfigObject()->GetProperties());
        request.SetParams(params);
 
-       Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service->GetName() + "'");
+       Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service.GetName() + "'");
 
        GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
            boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _2, _5));
 }
 
-void DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut)
+void DelegationComponent::AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut)
 {
        if (timedOut) {
-               Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' timed out.");
+               Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' timed out.");
        } else {
-               service->SetTag("checker", sender->GetIdentity());
-               Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' was successful.");
+               service.SetChecker(sender->GetIdentity());
+               Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' was successful.");
        }
 }
 
-void DelegationComponent::RevokeService(const ConfigObject::Ptr& service)
+void DelegationComponent::RevokeService(const Service& service)
 {
 
 }
 
-void DelegationComponent::RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut)
+void DelegationComponent::RevokeServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut)
 {
 }
 
@@ -101,13 +101,13 @@ void DelegationComponent::DelegationTimerHandler(void)
 {
        ConfigObject::Set::Iterator it;
        for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
-               ConfigObject::Ptr object = *it;
+               Service service = *it;
 
-               string checker;
-               if (object->GetTag("checker", &checker) && GetEndpointManager()->GetEndpointByIdentity(checker))
+               string checker = service.GetChecker();
+               if (!checker.empty() && GetEndpointManager()->GetEndpointByIdentity(checker))
                        continue;
 
-               AssignService(object);
+               AssignService(service);
        }
 }
 
index d665fac73827fe4263d34befb3776878ac5b476e..d2559538bbfe47d19cbfe588370e438a1cfa7437 100644 (file)
@@ -38,16 +38,16 @@ private:
        ConfigObject::Set::Ptr m_AllServices;
        Timer::Ptr m_DelegationTimer;
 
-       void NewServiceHandler(const ConfigObject::Ptr& object);
-       void RemovedServiceHandler(const ConfigObject::Ptr& object);
+       void NewServiceHandler(const Service& object);
+       void RemovedServiceHandler(const Service& object);
 
-       void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
-       void RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
+       void AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
+       void RevokeServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
 
        void DelegationTimerHandler(void);
 
-       void AssignService(const ConfigObject::Ptr& service);
-       void RevokeService(const ConfigObject::Ptr& service);
+       void AssignService(const Service& service);
+       void RevokeService(const Service& service);
 };
 
 }
index 4ad327ddd94f78f5dc7a04c0e8db36e5d6f9eb24..b3cb41a937589bd8ec7c74b4f991b2db7043f73e 100644 (file)
@@ -16,7 +16,6 @@ public:
 
        bool IsLocal(void) const;
 
-protected:
        ConfigObject::Ptr GetConfigObject() const;
 
 private:
index e5dca2506de21571ed16f063777ab261ae0303ba..291161e781c46b3cc77300d5ba25675c1a561342 100644 (file)
@@ -2,27 +2,28 @@
 
 using namespace icinga;
 
-string MacroProcessor::ResolveMacros(string str, Dictionary::Ptr macros)
+string MacroProcessor::ResolveMacros(const string& str, const Dictionary::Ptr& macros)
 {
        string::size_type offset, pos_first, pos_second;
 
        offset = 0;
 
-       while ((pos_first = str.find_first_of('$', offset)) != string::npos) {
-               pos_second = str.find_first_of('$', pos_first + 1);
+       string result = str;
+       while ((pos_first = result.find_first_of('$', offset)) != string::npos) {
+               pos_second = result.find_first_of('$', pos_first + 1);
 
                if (pos_second == string::npos)
                        throw runtime_error("Closing $ not found in macro format string.");
 
-               string name = str.substr(pos_first + 1, pos_second - pos_first - 1);
+               string name = result.substr(pos_first + 1, pos_second - pos_first - 1);
                string value;
                if (!macros || !macros->GetProperty(name, &value))
                        throw runtime_error("Macro '" + name + "' is not defined.");
 
-               str.replace(pos_first, pos_second - pos_first + 1, value);
+               result.replace(pos_first, pos_second - pos_first + 1, value);
 
                offset = pos_first + value.size();
        }
 
-       return str;
+       return result;
 }
index 3af0c1555cf90975dde1af26dd39c929e46759c4..2bf5bc7f9fe7db1af507c545c0c6994b94f1e657 100644 (file)
@@ -7,7 +7,7 @@ namespace icinga
 class I2_ICINGA_API MacroProcessor
 {
 public:
-       static string ResolveMacros(string str, Dictionary::Ptr macros);
+       static string ResolveMacros(const string& str, const Dictionary::Ptr& macros);
 };
 
 }
index 6e8b606d7deea126a3ce941d7a4c0799bd141ffc..e60198673c8a44b629b0872976214d1c38bef35f 100644 (file)
@@ -74,3 +74,15 @@ time_t Service::GetNextCheck(void) const
        GetConfigObject()->GetTag("next_check", &value);
        return value;
 }
+
+void Service::SetChecker(string checker)
+{
+       GetConfigObject()->SetTag("checker", checker);
+}
+
+string Service::GetChecker(void) const
+{
+       string value;
+       GetConfigObject()->GetTag("checker", &value);
+       return value;
+}
index 4257ec764f0d964b30b53996774cc23656bf21f2..a2680dea44cd43487154146548d8bff5bf2931f9 100644 (file)
@@ -22,8 +22,10 @@ public:
 
        void SetNextCheck(time_t nextCheck);
        time_t GetNextCheck(void) const;
+       void SetChecker(string checker);
+       string GetChecker(void) const;
 };
 
 }
 
-#endif /* SERVICE_H */
\ No newline at end of file
+#endif /* SERVICE_H */