Merge "Replaces methods deprecated in pymongo3.0"
This commit is contained in:
commit
ab98a80a57
@ -58,7 +58,7 @@ class Connection(base.Connection):
|
|||||||
'trait_type': trait.dtype,
|
'trait_type': trait.dtype,
|
||||||
'trait_value': trait.value})
|
'trait_value': trait.value})
|
||||||
try:
|
try:
|
||||||
self.db.event.insert(
|
self.db.event.insert_one(
|
||||||
{'_id': event_model.message_id,
|
{'_id': event_model.message_id,
|
||||||
'event_type': event_model.event_type,
|
'event_type': event_model.event_type,
|
||||||
'timestamp': event_model.generated,
|
'timestamp': event_model.generated,
|
||||||
|
@ -179,13 +179,13 @@ class Connection(pymongo_base.Connection):
|
|||||||
# for their ENV.
|
# for their ENV.
|
||||||
resource_id = self._generate_random_str(
|
resource_id = self._generate_random_str(
|
||||||
cfg.CONF.database.db2nosql_resource_id_maxlen)
|
cfg.CONF.database.db2nosql_resource_id_maxlen)
|
||||||
self.db.resource.insert({'_id': resource_id,
|
self.db.resource.insert_one({'_id': resource_id,
|
||||||
'no_key': resource_id})
|
'no_key': resource_id})
|
||||||
meter_id = str(bson.objectid.ObjectId())
|
meter_id = str(bson.objectid.ObjectId())
|
||||||
timestamp = timeutils.utcnow()
|
timestamp = timeutils.utcnow()
|
||||||
self.db.meter.insert({'_id': meter_id,
|
self.db.meter.insert_one({'_id': meter_id,
|
||||||
'no_key': meter_id,
|
'no_key': meter_id,
|
||||||
'timestamp': timestamp})
|
'timestamp': timestamp})
|
||||||
|
|
||||||
self.db.resource.create_index([
|
self.db.resource.create_index([
|
||||||
('user_id', pymongo.ASCENDING),
|
('user_id', pymongo.ASCENDING),
|
||||||
@ -228,7 +228,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
data = copy.deepcopy(data)
|
data = copy.deepcopy(data)
|
||||||
data['resource_metadata'] = pymongo_utils.improve_keys(
|
data['resource_metadata'] = pymongo_utils.improve_keys(
|
||||||
data.pop('resource_metadata'))
|
data.pop('resource_metadata'))
|
||||||
self.db.resource.update(
|
self.db.resource.update_one(
|
||||||
{'_id': data['resource_id']},
|
{'_id': data['resource_id']},
|
||||||
{'$set': {'project_id': data['project_id'],
|
{'$set': {'project_id': data['project_id'],
|
||||||
'user_id': data['user_id'] or 'null',
|
'user_id': data['user_id'] or 'null',
|
||||||
@ -253,7 +253,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
# automatically.
|
# automatically.
|
||||||
if record.get('_id') is None:
|
if record.get('_id') is None:
|
||||||
record['_id'] = str(bson.objectid.ObjectId())
|
record['_id'] = str(bson.objectid.ObjectId())
|
||||||
self.db.meter.insert(record)
|
self.db.meter.insert_one(record)
|
||||||
|
|
||||||
def get_resources(self, user=None, project=None, source=None,
|
def get_resources(self, user=None, project=None, source=None,
|
||||||
start_timestamp=None, start_timestamp_op=None,
|
start_timestamp=None, start_timestamp_op=None,
|
||||||
|
@ -498,7 +498,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
data = copy.deepcopy(data)
|
data = copy.deepcopy(data)
|
||||||
data['resource_metadata'] = pymongo_utils.improve_keys(
|
data['resource_metadata'] = pymongo_utils.improve_keys(
|
||||||
data.pop('resource_metadata'))
|
data.pop('resource_metadata'))
|
||||||
resource = self.db.resource.find_and_modify(
|
resource = self.db.resource.find_one_and_update(
|
||||||
{'_id': data['resource_id']},
|
{'_id': data['resource_id']},
|
||||||
{'$set': {'project_id': data['project_id'],
|
{'$set': {'project_id': data['project_id'],
|
||||||
'user_id': data['user_id'],
|
'user_id': data['user_id'],
|
||||||
@ -515,7 +515,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
upsert=True,
|
upsert=True,
|
||||||
new=True,
|
return_document=pymongo.ReturnDocument.AFTER,
|
||||||
)
|
)
|
||||||
|
|
||||||
# only update last sample timestamp if actually later (the usual
|
# only update last sample timestamp if actually later (the usual
|
||||||
@ -523,7 +523,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
last_sample_timestamp = resource.get('last_sample_timestamp')
|
last_sample_timestamp = resource.get('last_sample_timestamp')
|
||||||
if (last_sample_timestamp is None or
|
if (last_sample_timestamp is None or
|
||||||
last_sample_timestamp <= data['timestamp']):
|
last_sample_timestamp <= data['timestamp']):
|
||||||
self.db.resource.update(
|
self.db.resource.update_one(
|
||||||
{'_id': data['resource_id']},
|
{'_id': data['resource_id']},
|
||||||
{'$set': {'metadata': data['resource_metadata'],
|
{'$set': {'metadata': data['resource_metadata'],
|
||||||
'last_sample_timestamp': data['timestamp']}}
|
'last_sample_timestamp': data['timestamp']}}
|
||||||
@ -537,7 +537,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
first_sample_timestamp = resource.get('first_sample_timestamp')
|
first_sample_timestamp = resource.get('first_sample_timestamp')
|
||||||
if (first_sample_timestamp is not None and
|
if (first_sample_timestamp is not None and
|
||||||
first_sample_timestamp > data['timestamp']):
|
first_sample_timestamp > data['timestamp']):
|
||||||
self.db.resource.update(
|
self.db.resource.update_one(
|
||||||
{'_id': data['resource_id']},
|
{'_id': data['resource_id']},
|
||||||
{'$set': {'first_sample_timestamp': data['timestamp']}}
|
{'$set': {'first_sample_timestamp': data['timestamp']}}
|
||||||
)
|
)
|
||||||
@ -547,7 +547,7 @@ class Connection(pymongo_base.Connection):
|
|||||||
# a new key '_id').
|
# a new key '_id').
|
||||||
record = copy.copy(data)
|
record = copy.copy(data)
|
||||||
record['recorded_at'] = timeutils.utcnow()
|
record['recorded_at'] = timeutils.utcnow()
|
||||||
self.db.meter.insert(record)
|
self.db.meter.insert_one(record)
|
||||||
|
|
||||||
def clear_expired_metering_data(self, ttl):
|
def clear_expired_metering_data(self, ttl):
|
||||||
"""Clear expired data from the backend storage system.
|
"""Clear expired data from the backend storage system.
|
||||||
|
@ -253,13 +253,11 @@ class ConnectionPool(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _mongo_connect(url):
|
def _mongo_connect(url):
|
||||||
try:
|
try:
|
||||||
if cfg.CONF.database.mongodb_replica_set:
|
client = MongoProxy(
|
||||||
client = MongoProxy(
|
pymongo.MongoClient(
|
||||||
pymongo.MongoReplicaSetClient(
|
url, replicaSet=cfg.CONF.database.mongodb_replica_set
|
||||||
url,
|
)
|
||||||
replicaSet=cfg.CONF.database.mongodb_replica_set))
|
)
|
||||||
else:
|
|
||||||
client = MongoProxy(pymongo.MongoClient(url))
|
|
||||||
return client
|
return client
|
||||||
except pymongo.errors.ConnectionFailure as e:
|
except pymongo.errors.ConnectionFailure as e:
|
||||||
LOG.warn(_('Unable to connect to the database server: '
|
LOG.warn(_('Unable to connect to the database server: '
|
||||||
|
@ -114,10 +114,10 @@ class ConnectionTest(test_base.BaseTestCase):
|
|||||||
group='database')
|
group='database')
|
||||||
impl_db2.Connection('db2://user:pwd@localhost:27017/ceilodb2')
|
impl_db2.Connection('db2://user:pwd@localhost:27017/ceilodb2')
|
||||||
resource_id = 'wew' * 247 + 'x' * 3
|
resource_id = 'wew' * 247 + 'x' * 3
|
||||||
conn_mock.ceilodb2.resource.insert.assert_called_with(
|
conn_mock.ceilodb2.resource.insert_one.assert_called_with(
|
||||||
{'_id': resource_id,
|
{'_id': resource_id,
|
||||||
'no_key': resource_id})
|
'no_key': resource_id})
|
||||||
conn_mock.ceilodb2.meter.insert.assert_called_with(
|
conn_mock.ceilodb2.meter.insert_one.assert_called_with(
|
||||||
{'_id': '54b8860d75bfe43b54e84ce7',
|
{'_id': '54b8860d75bfe43b54e84ce7',
|
||||||
'no_key': '54b8860d75bfe43b54e84ce7',
|
'no_key': '54b8860d75bfe43b54e84ce7',
|
||||||
'timestamp': 'timestamp'})
|
'timestamp': 'timestamp'})
|
||||||
|
Loading…
Reference in New Issue
Block a user