Example #1
0
    def _get_db(self, collection):
        c = self.db['collections'].find_one({"_id": collection})
        if not c:
            raise DatastoreException(
                'Collection {0} not found'.format(collection))

        return self.db[collection]
Example #2
0
 def tail(self, cur):
     try:
         for i in cur:
             i['id'] = i.pop('_id')
             yield i
     except (pymongo.errors.OperationFailure,
             pymongo.errors.AutoReconnect) as err:
         raise DatastoreException(str(err))
Example #3
0
    def _get_db(self, collection):
        c = self.db['collections'].find_one({"_id": collection})
        if not c:
            raise DatastoreException(
                'Collection {0} not found'.format(collection))

        typ = c['attributes'].get('type', 'config')

        if typ == 'log':
            return self.log_db[collection]

        return self.db[collection]
Example #4
0
    def wrapped(*args, **kwargs):
        for i in range(0, 15):
            self = args[0]
            if not self.connected:
                time.sleep(1)
                continue

            try:
                return fn(*args, **kwargs)
            except (pymongo.errors.AutoReconnect,
                    pymongo.errors.ConnectionFailure,
                    pymongo.errors.OperationFailure):
                time.sleep(1)

        raise DatastoreException('Cannot connect to MongoDB instance')
Example #5
0
 def __init__(self, datastore):
     self.__datastore = datastore
     if not self.__datastore.collection_exists('config'):
         raise DatastoreException("'config' collection doesn't exist")