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]
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))
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]
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')
def __init__(self, datastore): self.__datastore = datastore if not self.__datastore.collection_exists('config'): raise DatastoreException("'config' collection doesn't exist")