]> granicus.if.org Git - icinga2/commitdiff
Implement the __commit function
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 19 Dec 2014 12:08:46 +0000 (13:08 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 19 Dec 2014 12:08:46 +0000 (13:08 +0100)
refs #8127

lib/config/configitem.cpp
lib/config/configitem.hpp

index 81f699ecca58742a2772654c8edaa93b01d55183..c3b87f85750fe3a286767d068d4bc5270bbce9a8 100644 (file)
@@ -35,6 +35,7 @@
 #include "base/serializer.hpp"
 #include "base/json.hpp"
 #include "base/exception.hpp"
+#include "base/scriptfunction.hpp"
 #include <sstream>
 #include <fstream>
 #include <boost/foreach.hpp>
@@ -46,6 +47,8 @@ ConfigItem::TypeMap ConfigItem::m_Items;
 ConfigItem::ItemList ConfigItem::m_UnnamedItems;
 ConfigItem::ItemList ConfigItem::m_CommittedItems;
 
+REGISTER_SCRIPTFUNCTION(__commit, &ConfigItem::ScriptCommit);
+
 /**
  * Constructor for the ConfigItem class.
  *
@@ -392,6 +395,29 @@ bool ConfigItem::ActivateItems(void)
        return true;
 }
 
+bool ConfigItem::ScriptCommit(void)
+{
+       WorkQueue upq(25000, Application::GetConcurrency());
+
+       if (!CommitNewItems(upq))
+               return false;
+
+       BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
+               BOOST_FOREACH(const DynamicObject::Ptr& object, type->GetObjects()) {
+                       if (object->IsActive())
+                               continue;
+
+#ifdef I2_DEBUG
+       Log(LogDebug, "ConfigItem")
+           << "Activating object '" << object->GetName() << "' of type '" << object->GetType()->GetName() << "'";
+#endif /* I2_DEBUG */
+               upq.Enqueue(boost::bind(&DynamicObject::Activate, object));
+               }
+       }
+
+       return true;
+}
+
 std::vector<ConfigItem::Ptr> ConfigItem::GetItems(const String& type)
 {
        std::vector<ConfigItem::Ptr> items;
index a31def4f6660a780993119cb229dace0d7aa9bae..af383877c349a63b75474d8b11249d7efed4ad26 100644 (file)
@@ -67,6 +67,8 @@ public:
        static bool CommitItems(void);
        static bool ActivateItems(void);
 
+       static bool ScriptCommit(void);
+
        static std::vector<ConfigItem::Ptr> GetItems(const String& type);
 
 private: