Esempio n. 1
0
 def retrieve(cls):
     try:
         return pickle.loads(Cache.get(cls.cache_key))
     except KeyError:
         Log.warning(
             "Attempted to retrieve '%s' but it was empty. Repopulating..."
             % cls.cache_key)
         cls.populate()
         return pickle.loads(Cache.get(cls.cache_key))
Esempio n. 2
0
 def init(self):
     """
     Re-initialize all indexes. This calls rebuild on every registered
     index class. There be dragons here.
     :return: None
     """
     for name in self._indexes.keys():
         Log.debug("Init on %s" % name)
         try:
             self.rebuild(self._indexes.get(name))
         except NotFoundError or KeyError or AttributeError as e:
             Log.warning("Error re-initing index %s: %s" % (name, e))
Esempio n. 3
0
 def rebuild(self, index_class):
     """
     Re-create an index. This deletes the entire index (not just the contents,
     but the Whole Damn Thing(tm). and re-creates it.
     :param index_class: elasticsearch_dsl.Document child representing this index.
     :return: None
     """
     try:
         index_class._index.delete()
         index_class.init()
         Log.info("Successfully rebuilt index %s" % index_class.Index.name)
     except NotFoundError:
         Log.warning("Index %s did not exist." % index_class.Index.name)
Esempio n. 4
0
 def retrieve(cls):
     """
     Retrieve the cache's value
     :return: Various
     """
     try:
         return Cache.get(cls.cache_key)
     except KeyError:
         Log.warning(
             "Attempted to retrieve '%s' but it was empty. Repopulating..."
             % cls.cache_key)
         cls.populate()
         return Cache.get(cls.cache_key)
Esempio n. 5
0
 def delete(cocktail_object):
     try:
         indexables = CocktailFactory.obj_to_index(cocktail_object,
                                                   RecipeIndex)
         for indexable in indexables:
             try:
                 RecipeIndex.delete(indexable)
             except NotFoundError:
                 Log.warning("No cache entry found for %s" % indexable)
     except KeyError as e:
         # Since this is a DELETE situation we don't particularly care to correct
         # the problem, but if we're creating or some other thing that could be
         # more problematic.
         Log.error("Recipe has bad data: %s" % e)
Esempio n. 6
0
    def _connect(self):
        if not hasattr(self, 'zk'):
            self.zk = KazooClient(hosts=self.hosts,
                                  read_only=self.read_only,
                                  timeout=5,
                                  connection_retry=self._get_retry())
        elif self.zk.state != KazooState.CONNECTED:
            Log.warning("ZooKeeper state is %s" % self.zk.state)
            pass
        elif self.zk.state == KazooState.CONNECTED:
            return
        else:
            raise Exception("We in a weird state. %s" % self.zk.state)

        try:
            return self.zk.start()
        except KazooTimeoutError as e:
            raise FatalException("Timeout connecting to ZooKeeper (%s)" % e)