Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete this module - Duplication with mod-pickle-retention-file-generic #3

Open
titilambert opened this issue Oct 13, 2014 · 0 comments

Comments

@titilambert
Copy link
Member

Hello !

I made a diff between mod-pickle-retention-file-generic and mod-pickle-retention-file-scheduler.
I don't see any diff.
Could you confirm it ? and if you are OK, could we delete this module ?

Thanks !

diff -Naur mod-pickle-retention-file-generic/module/module.py mod-pickle-retention-file-scheduler/module/module.py 
--- mod-pickle-retention-file-generic/module/module.py  2014-10-13 01:17:26.193866705 -0400
+++ mod-pickle-retention-file-scheduler/module/module.py    2014-10-13 01:17:19.165917819 -0400
@@ -22,26 +22,24 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Shinken.  If not, see <http://www.gnu.org/licenses/>.

-
 # This Class is an example of an Scheduler module
 # Here for the configuration phase AND running one

 import cPickle
 import shutil
-import traceback

 from shinken.basemodule import BaseModule
 from shinken.log import logger

-# Hack for making 0.5 retention file load in a 0.6 version
+# Hack to make 0.5 retention file loading in a 0.6 version
 # because the commandCall class was moved
 import shinken
 from shinken.commandcall import CommandCall
 shinken.objects.command.CommandCall = CommandCall

 properties = {
-    'daemons': ['broker', 'arbiter', 'scheduler'],
-    'type': 'pickle_retention_file_generic',
+    'daemons': ['scheduler'],
+    'type': 'pickle_retention_file',
     'external': False,
     }

@@ -50,13 +48,13 @@
     """
     Called by the plugin manager to get a broker
     """
-    logger.debug("Get a pickle retention generic module for plugin %s" % plugin.get_name())
+    logger.debug("Get a pickle retention scheduler module for plugin %s" % plugin.get_name())
     path = plugin.path
-    instance = Pickle_retention_generic(plugin, path)
+    instance = Pickle_retention_scheduler(plugin, path)
     return instance


-class Pickle_retention_generic(BaseModule):
+class Pickle_retention_scheduler(BaseModule):
     def __init__(self, modconf, path):
         BaseModule.__init__(self, modconf)
         self.path = path
@@ -65,33 +63,45 @@
         """
         main function that is called in the retention creation pass
         """
-        logger.debug("[PickleRetentionGeneric] asking me to update the retention objects")
+        self.update_retention_objects(daemon)

+    # The real function, this wall module will be soonly removed
+    def update_retention_objects(self, sched):
+        logger.debug("[PickleRetention] asking me to update the retention objects")
         # Now the flat file method
         try:
             # Open a file near the path, with .tmp extension
-            # so in case of a problem, we do not lost the old one
+            # so in case of a problem, we do not lose the old one
             f = open(self.path + '.tmp', 'wb')
+            # Just put hosts/services because checks and notifications
+            # are already link into
+            # all_data = {'hosts': sched.hosts, 'services': sched.services}
+
+            # We create a all_data dict with list of dict of retention useful
+            # data of our hosts and services
+            all_data = sched.get_retention_data()

-            # We get interesting retention data from the daemon it self
-            all_data = daemon.get_retention_data()
-
-            # And we save it on file :)
+            #s = cPickle.dumps(all_data)
+            #s_compress = zlib.compress(s)
             cPickle.dump(all_data, f, protocol=cPickle.HIGHEST_PROTOCOL)
+            #f.write(s_compress)
             f.close()
-
             # Now move the .tmp file to the real path
             shutil.move(self.path + '.tmp', self.path)
         except IOError, exp:
-            logger.error("Creating retention file failed %s" % str(exp))
+            logger.error("Retention file creation failed, %s" % str(exp))
             return
         logger.info("Updating retention_file %s" % self.path)

-    # Should return if it succeed in the retention load or not
     def hook_load_retention(self, daemon):
+        return self.load_retention_objects(daemon)
+
+    # Should return if it succeed in the retention load or not
+    def load_retention_objects(self, sched):
+        logger.debug("[PickleRetention] asking me to load the retention objects")

-        logger.debug("[PickleRetentionGeneric]Reading from retention_file %s" % self.path)
         # Now the old flat file way :(
+        logger.debug("[PickleRetention]Reading from retention_file %s" % self.path)
         try:
             f = open(self.path, 'rb')
             all_data = cPickle.load(f)
@@ -103,9 +113,9 @@
             logger.warning("Sorry, the resource file is not compatible")
             return False

-        # Ok, we send back the data to the daemon
-        daemon.restore_retention_data(all_data)
+        # call the scheduler helper function for restoring values
+        sched.restore_retention_data(all_data)

-        logger.info("[PickleRetentionGeneric] Retention objects loaded successfully.")
+        logger.info("[PickleRetention] Retention objects loaded successfully.")

         return True


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant