Commit 546d81a8 by John Eskew

Always create an asset metadata collection in the Mongo modulestore.

If no collection name is specified, use a default name.
https://openedx.atlassian.net/browse/PLAT-294
parent 600e7bf3
...@@ -436,6 +436,10 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -436,6 +436,10 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
""" """
A Mongodb backed ModuleStore A Mongodb backed ModuleStore
""" """
# If no name is specified for the asset metadata collection, this name is used.
DEFAULT_ASSET_COLLECTION_NAME = 'assetstore'
# TODO (cpennington): Enable non-filesystem filestores # TODO (cpennington): Enable non-filesystem filestores
# pylint: disable=C0103 # pylint: disable=C0103
# pylint: disable=W0201 # pylint: disable=W0201
...@@ -474,9 +478,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -474,9 +478,9 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
self.collection = self.database[collection] self.collection = self.database[collection]
# Collection which stores asset metadata. # Collection which stores asset metadata.
self.asset_collection = None if asset_collection is None:
if asset_collection is not None: asset_collection = self.DEFAULT_ASSET_COLLECTION_NAME
self.asset_collection = self.database[asset_collection] self.asset_collection = self.database[asset_collection]
if user is not None and password is not None: if user is not None and password is not None:
self.database.authenticate(user, password) self.database.authenticate(user, password)
...@@ -1465,9 +1469,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -1465,9 +1469,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
Returns: Returns:
Asset info for the course Asset info for the course
""" """
if self.asset_collection is None:
return None
# Using the course_key, find or insert the course asset metadata document. # Using the course_key, find or insert the course asset metadata document.
# A single document exists per course to store the course asset metadata. # A single document exists per course to store the course asset metadata.
course_key = self.fill_in_run(course_key) course_key = self.fill_in_run(course_key)
...@@ -1493,9 +1494,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -1493,9 +1494,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
Returns: Returns:
True if info save was successful, else False True if info save was successful, else False
""" """
if self.asset_collection is None:
return False
course_assets, asset_idx = self._find_course_asset(asset_metadata.asset_id) course_assets, asset_idx = self._find_course_asset(asset_metadata.asset_id)
all_assets = SortedListWithKey([], key=itemgetter('filename')) all_assets = SortedListWithKey([], key=itemgetter('filename'))
# Assets should be pre-sorted, so add them efficiently without sorting. # Assets should be pre-sorted, so add them efficiently without sorting.
...@@ -1552,9 +1550,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -1552,9 +1550,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
ItemNotFoundError if no such item exists ItemNotFoundError if no such item exists
AttributeError is attr is one of the build in attrs. AttributeError is attr is one of the build in attrs.
""" """
if self.asset_collection is None:
return
course_assets, asset_idx = self._find_course_asset(asset_key) course_assets, asset_idx = self._find_course_asset(asset_key)
if asset_idx is None: if asset_idx is None:
raise ItemNotFoundError(asset_key) raise ItemNotFoundError(asset_key)
...@@ -1581,9 +1576,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -1581,9 +1576,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
Returns: Returns:
Number of asset metadata entries deleted (0 or 1) Number of asset metadata entries deleted (0 or 1)
""" """
if self.asset_collection is None:
return 0
course_assets, asset_idx = self._find_course_asset(asset_key) course_assets, asset_idx = self._find_course_asset(asset_key)
if asset_idx is None: if asset_idx is None:
return 0 return 0
...@@ -1607,9 +1599,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -1607,9 +1599,6 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
Arguments: Arguments:
course_key (CourseKey): course_identifier course_key (CourseKey): course_identifier
""" """
if self.asset_collection is None:
return
# Using the course_id, find the course asset metadata document. # Using the course_id, find the course asset metadata document.
# A single document exists per course to store the course asset metadata. # A single document exists per course to store the course asset metadata.
course_assets = self._find_course_assets(course_key) course_assets = self._find_course_assets(course_key)
......
...@@ -93,10 +93,6 @@ class MongoConnection(object): ...@@ -93,10 +93,6 @@ class MongoConnection(object):
wait_time=retry_wait_time wait_time=retry_wait_time
) )
# Remove when adding official Split support for asset metadata storage.
if asset_collection:
pass
if user is not None and password is not None: if user is not None and password is not None:
self.database.authenticate(user, password) self.database.authenticate(user, password)
......
...@@ -685,8 +685,8 @@ class TestMongoModuleStoreWithNoAssetCollection(TestMongoModuleStore): ...@@ -685,8 +685,8 @@ class TestMongoModuleStoreWithNoAssetCollection(TestMongoModuleStore):
def test_no_asset_collection(self): def test_no_asset_collection(self):
courses = self.draft_store.get_courses() courses = self.draft_store.get_courses()
course = courses[0] course = courses[0]
# Confirm that no asset collection means no asset metadata. # Confirm that no specified asset collection name means empty asset metadata.
self.assertEquals(self.draft_store.get_all_asset_metadata(course.id, 'asset'), None) self.assertEquals(self.draft_store.get_all_asset_metadata(course.id, 'asset'), [])
class TestMongoKeyValueStore(object): class TestMongoKeyValueStore(object):
......
...@@ -570,7 +570,9 @@ DOC_STORE_CONFIG = { ...@@ -570,7 +570,9 @@ DOC_STORE_CONFIG = {
'host': 'localhost', 'host': 'localhost',
'db': 'xmodule', 'db': 'xmodule',
'collection': 'modulestore', 'collection': 'modulestore',
'asset_collection': 'assetstore', # If 'asset_collection' defined, it'll be used
# as the collection name for asset metadata.
# Otherwise, a default collection name will be used.
} }
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment