def do_get_repo_units(repo_id, criteria, exception_class): """ Performs a repo unit association query. This is split apart so we can have custom mixins with different signatures. """ try: association_query_manager = manager_factory.repo_unit_association_query_manager() units = association_query_manager.get_units(repo_id, criteria=criteria) all_units = [] # Load all type definitions in use so we don't hammer the database unique_type_defs = set([u['unit_type_id'] for u in units]) type_defs = {} for def_id in unique_type_defs: type_def = types_db.type_definition(def_id) type_defs[def_id] = type_def # Convert to transfer object for unit in units: type_id = unit['unit_type_id'] u = common_utils.to_plugin_associated_unit(unit, type_defs[type_id]) all_units.append(u) return all_units except Exception, e: _LOG.exception('Exception from server requesting all content units for repository [%s]' % repo_id) raise exception_class(e), None, sys.exc_info()[2]
def do_get_repo_units(repo_id, criteria, exception_class): """ Performs a repo unit association query. This is split apart so we can have custom mixins with different signatures. """ try: association_query_manager = manager_factory.repo_unit_association_query_manager( ) units = association_query_manager.get_units(repo_id, criteria=criteria) all_units = [] # Load all type definitions in use so we don't hammer the database unique_type_defs = set([u['unit_type_id'] for u in units]) type_defs = {} for def_id in unique_type_defs: type_def = types_db.type_definition(def_id) type_defs[def_id] = type_def # Convert to transfer object for unit in units: type_id = unit['unit_type_id'] u = common_utils.to_plugin_associated_unit(unit, type_defs[type_id]) all_units.append(u) return all_units except Exception, e: _LOG.exception( 'Exception from server requesting all content units for repository [%s]' % repo_id) raise exception_class(e), None, sys.exc_info()[2]
def resolve_dependencies_by_units(repo_id, units, options): """ Calculates dependencies for the given set of units in the given repository. :param repo_id: identifies the repository :type repo_id: str :param units: list of database representations of units to resolve dependencies for :type units: list :param options: dict of options to pass the importer to drive the resolution :type options: dict or None :return: report from the plugin :rtype: object :raise MissingResource: if the repo does not exist or does not have an importer """ # Validation repo_query_manager = manager_factory.repo_query_manager() importer_manager = manager_factory.repo_importer_manager() # The following will raise MissingResource as appropriate repo = repo_query_manager.get_repository(repo_id) repo_importer = importer_manager.get_importer(repo_id) try: importer_instance, plugin_config = plugin_api.get_importer_by_id( repo_importer['importer_type_id']) except plugin_exceptions.PluginNotFound: raise MissingResource(repo_id), None, sys.exc_info()[2] # Package for the importer call call_config = PluginCallConfiguration(plugin_config, repo_importer['config'], options) transfer_repo = common_utils.to_transfer_repo(repo) conduit = DependencyResolutionConduit(repo_id, repo_importer['id']) # Convert all of the units into the plugin standard representation transfer_units = [] # Preload all the type defs so we don't hammer the database unnecessarily type_defs = {} all_type_def_ids = set([u['unit_type_id'] for u in units]) for def_id in all_type_def_ids: type_def = types_db.type_definition(def_id) type_defs[def_id] = type_def for unit in units: type_id = unit['unit_type_id'] u = conduit_common_utils.to_plugin_associated_unit(unit, type_defs[type_id]) transfer_units.append(u) # Invoke the importer try: dep_report = importer_instance.resolve_dependencies(transfer_repo, transfer_units, conduit, call_config) except Exception: raise PulpExecutionException(), None, sys.exc_info()[2] return dep_report
def resolve_dependencies_by_units(repo_id, units, options): """ Calculates dependencies for the given set of units in the given repository. :param repo_id: identifies the repository :type repo_id: str :param units: list of database representations of units to resolve dependencies for :type units: list :param options: dict of options to pass the importer to drive the resolution :type options: dict or None :return: report from the plugin :rtype: object :raise MissingResource: if the repo does not exist or does not have an importer """ # Validation repo_query_manager = manager_factory.repo_query_manager() importer_manager = manager_factory.repo_importer_manager() # The following will raise MissingResource as appropriate repo = repo_query_manager.get_repository(repo_id) repo_importer = importer_manager.get_importer(repo_id) try: importer_instance, plugin_config = plugin_api.get_importer_by_id( repo_importer['importer_type_id']) except plugin_exceptions.PluginNotFound: raise MissingResource(repo_id), None, sys.exc_info()[2] # Package for the importer call call_config = PluginCallConfiguration(plugin_config, repo_importer['config'], options) transfer_repo = common_utils.to_transfer_repo(repo) transfer_repo.working_dir = common_utils.importer_working_dir( repo_importer['importer_type_id'], repo_id, mkdir=True) conduit = DependencyResolutionConduit(repo_id, repo_importer['id']) # Convert all of the units into the plugin standard representation transfer_units = [] # Preload all the type defs so we don't hammer the database unnecessarily type_defs = {} all_type_def_ids = set([u['unit_type_id'] for u in units]) for def_id in all_type_def_ids: type_def = types_db.type_definition(def_id) type_defs[def_id] = type_def for unit in units: type_id = unit['unit_type_id'] u = conduit_common_utils.to_plugin_associated_unit(unit, type_defs[type_id]) transfer_units.append(u) # Invoke the importer try: dep_report = importer_instance.resolve_dependencies(transfer_repo, transfer_units, conduit, call_config) except Exception, e: raise PulpExecutionException(), None, sys.exc_info()[2]
def _transfer_object_generator(): unit_key_fields_cache = {} for u in units: type_id = u['unit_type_id'] if type_id not in unit_key_fields_cache: fields = units_controller.get_unit_key_fields_for_type(type_id) unit_key_fields_cache[type_id] = fields yield common_utils.to_plugin_associated_unit(u, type_id, unit_key_fields_cache[type_id])
def create_transfer_units(associate_units): unit_key_fields = {} transfer_units = [] for unit in associate_units: type_id = unit['unit_type_id'] if type_id not in unit_key_fields: unit_key_fields[type_id] = units_controller.get_unit_key_fields_for_type(type_id) u = conduit_common_utils.to_plugin_associated_unit(unit, type_id, unit_key_fields[type_id]) transfer_units.append(u) return transfer_units
def create_transfer_units(associate_units): unit_key_fields = {} transfer_units = [] for unit in associate_units: type_id = unit['unit_type_id'] if type_id not in unit_key_fields: unit_key_fields[type_id] = units_controller.get_unit_key_fields_for_type(type_id) u = conduit_common_utils.to_plugin_associated_unit(unit, type_id, unit_key_fields[type_id]) transfer_units.append(u) return transfer_units
def create_transfer_units(associate_units, associated_unit_type_ids): type_defs = {} for def_id in associated_unit_type_ids: type_def = types_db.type_definition(def_id) type_defs[def_id] = type_def transfer_units = [] for unit in associate_units: type_id = unit['unit_type_id'] u = conduit_common_utils.to_plugin_associated_unit(unit, type_defs[type_id]) transfer_units.append(u) return transfer_units
def create_transfer_units(associate_units, associated_unit_type_ids): type_defs = {} for def_id in associated_unit_type_ids: type_def = types_db.type_definition(def_id) type_defs[def_id] = type_def transfer_units = [] for unit in associate_units: type_id = unit['unit_type_id'] u = conduit_common_utils.to_plugin_associated_unit(unit, type_defs[type_id]) transfer_units.append(u) return transfer_units
def get_source_units(self, criteria=None): """ Returns the collection of content units associated with the source repository for a unit import. Units returned from this call will have the id field populated and are useable in any calls in this conduit that require the id field. @param criteria: used to scope the returned results or the data within; the Criteria class can be imported from this module @type criteria: L{Criteria} @return: list of unit instances @rtype: list of L{AssociatedUnit} """ try: units = self.__association_query_manager.get_units_across_types(self.source_repo_id, criteria=criteria) all_units = [] # Load all type definitions in use so we don't hammer the database unique_type_defs = set([u['unit_type_id'] for u in units]) type_defs = {} for def_id in unique_type_defs: type_def = types_db.type_definition(def_id) type_defs[def_id] = type_def # Convert to transfer object for unit in units: type_id = unit['unit_type_id'] u = common_utils.to_plugin_associated_unit(unit, type_defs[type_id]) all_units.append(u) return all_units except Exception, e: _LOG.exception('Exception from server requesting all content units for repository [%s]' % self.repo_id) raise UnitImportConduitException(e), None, sys.exc_info()[2]
def _transfer_object_generator(): for u in units: yield common_utils.to_plugin_associated_unit( u, type_defs[u['unit_type_id']])
def _transfer_object_generator(): for u in units: yield common_utils.to_plugin_associated_unit(u, type_defs[u['unit_type_id']])