示例#1
0
def ensure_database_indexes():
    """
    Ensure that the minimal required indexes have been created for all collections.

    Gratuitously create MongoEngine based models indexes if they do not already exist.
    """

    model.Importer.ensure_indexes()
    model.RepositoryContentUnit.ensure_indexes()
    model.Repository.ensure_indexes()
    model.ReservedResource.ensure_indexes()
    model.TaskStatus.ensure_indexes()
    model.Worker.ensure_indexes()
    model.CeleryBeatLock.ensure_indexes()
    model.ResourceManagerLock.ensure_indexes()
    model.LazyCatalogEntry.ensure_indexes()
    model.DeferredDownload.ensure_indexes()
    model.Distributor.ensure_indexes()

    # Load all the model classes that the server knows about and ensure their indexes as well
    plugin_manager = PluginManager()
    for unit_type, model_class in plugin_manager.unit_models.items():
        unit_key_index = {'fields': model_class.unit_key_fields, 'unique': True}
        for index in model_class._meta['indexes']:
            if isinstance(index, dict) and 'fields' in index:
                if list(index['fields']) == list(unit_key_index['fields']):
                    raise ValueError("Content unit type '%s' explicitly defines an index for its "
                                     "unit key. This is not allowed because the platform handles"
                                     "it for you." % unit_type)
        model_class._meta['indexes'].append(unit_key_index)
        model_class._meta['index_specs'] = \
            model_class._build_index_specs(model_class._meta['indexes'])
        model_class.ensure_indexes()
示例#2
0
def ensure_database_indexes():
    """
    Ensure that the minimal required indexes have been created for all collections.

    Gratuitiously create MongoEngine based models indexes if they do not already exist.
    """

    model.RepositoryContentUnit.ensure_indexes()
    model.Repository.ensure_indexes()
    model.ReservedResource.ensure_indexes()
    model.TaskStatus.ensure_indexes()
    model.Worker.ensure_indexes()
    model.CeleryBeatLock.ensure_indexes()

    # Load all the model classes that the server knows about and ensure their inexes as well
    plugin_manager = PluginManager()
    for model_class in plugin_manager.unit_models.itervalues():
        model_class.ensure_indexes()
示例#3
0
def ensure_database_indexes():
    """
    Ensure that the minimal required indexes have been created for all collections.

    Pre-mongoengine collections are updated by the base model class every time they are initialized.
    MongoEngine based models require a manual check as they will only create indexes if the
    collection does not already exist.
    """

    _ensure_indexes(model.RepositoryContentUnit)
    _ensure_indexes(model.Repository)
    _ensure_indexes(model.ReservedResource)
    _ensure_indexes(model.TaskStatus)
    _ensure_indexes(model.Worker)

    # Load all the model classes that the server knows about and ensure their inexes as well
    plugin_manager = PluginManager()
    for model_class in plugin_manager.unit_models.itervalues():
        _ensure_indexes(model_class)
示例#4
0
def _generate_plugin_definitions():
    """
    Use entry points to get the information about available content unit types

    :return: A list of content unit types
    :rtype:  list of TypeDefinition
    """
    definitions = []
    plugin_manager = PluginManager()
    for unit_type, model_class in plugin_manager.unit_models.items():
        content_type_id = unit_type
        display_name = getattr(model_class, 'unit_display_name', unit_type)
        description = getattr(model_class, 'unit_description', '')
        referenced_types = getattr(model_class, 'unit_referenced_types', [])
        unit_key = list(getattr(model_class, 'unit_key_fields', []))
        search_indexes = list(model_class._meta.get('indexes', []))
        definition = TypeDefinition(content_type_id, display_name, description,
                                    unit_key, search_indexes, referenced_types)
        definitions.append(definition)
    return definitions
示例#5
0
文件: api.py 项目: beav/pulp
def _create_manager():
    global _MANAGER
    _MANAGER = PluginManager()