Пример #1
0
    def _get_downloader(self, request, entry):
        """
        Get the configured downloader.

        :param request: The original twisted client HTTP request being handled by the streamer.
        :type  request: twisted.web.server.Request
        :param entry: A catalog entry.
        :type  entry: LazyCatalogEntry
        :return: The configured downloader.
        :rtype:  nectar.downloaders.base.Downloader
        :raise: PluginNotFound: when plugin not found.
        :raise: DoesNotExist: when importer not found.
        """
        try:
            importer, config, model = \
                repo_controller.get_importer_by_id(entry.importer_id)
            model.config = config.flatten()
            downloader = importer.get_downloader_for_db_importer(
                model, entry.url, working_dir='/tmp', stream=True)
            listener = DownloadListener(self, request)
            downloader.event_listener = listener
            downloader.session = self.session_cache.get_or_create(
                request.uri, downloader)
            return downloader
        except (PluginNotFound, DoesNotExist):
            msg = _('Plugin not-found: referenced by catalog entry for {path}')
            logger.error(msg.format(path=entry.path))
            raise
Пример #2
0
    def _download(self, catalog_entry, request, responder):
        """
        Build a nectar downloader and download the content from the catalog entry.
        The download is performed by the alternate content container, so it is possible
        to use the streamer in conjunction with alternate content sources.

        :param catalog_entry:   The catalog entry to download.
        :type  catalog_entry:   pulp.server.db.model.LazyCatalogEntry
        :param request:         The client content request.
        :type  request:         twisted.web.server.Request
        :param responder:       The file-like object that nectar should write to.
        :type  responder:       Responder
        """
        # Configure the primary downloader for alternate content sources
        plugin_importer, config, db_importer = repo_controller.get_importer_by_id(
            catalog_entry.importer_id)
        primary_downloader = plugin_importer.get_downloader_for_db_importer(
            db_importer, catalog_entry.url, working_dir='/tmp')
        pulp_request = request.getHeader(PULP_STREAM_REQUEST_HEADER)
        listener = StreamerListener(request, self.config, catalog_entry,
                                    pulp_request)
        primary_downloader.session = self.session
        primary_downloader.event_listener = listener

        # Build the alternate content source download request
        unit_model = plugins_api.get_unit_model_by_id(
            catalog_entry.unit_type_id)
        qs = unit_model.objects.filter(id=catalog_entry.unit_id).only(
            *unit_model.unit_key_fields)
        try:
            unit = qs.get()
            download_request = content_models.Request(
                catalog_entry.unit_type_id,
                unit.unit_key,
                catalog_entry.url,
                responder,
            )

            alt_content_container = content_container.ContentContainer(
                threaded=False)
            alt_content_container.download(primary_downloader,
                                           [download_request], listener)
        except DoesNotExist:
            # A catalog entry is referencing a unit that doesn't exist which is bad.
            msg = _(
                'The catalog entry for {path} references {unit_type}:{id}, but '
                'that unit is not in the database.')
            logger.error(
                msg.format(path=catalog_entry.path,
                           unit_type=catalog_entry.unit_type_id,
                           id=catalog_entry.unit_id))
            request.setResponseCode(NOT_FOUND)
        finally:
            primary_downloader.config.finalize()
Пример #3
0
    def _download(self, catalog_entry, request, responder):
        """
        Build a nectar downloader and download the content from the catalog entry.
        The download is performed by the alternate content container, so it is possible
        to use the streamer in conjunction with alternate content sources.

        :param catalog_entry:   The catalog entry to download.
        :type  catalog_entry:   pulp.server.db.model.LazyCatalogEntry
        :param request:         The client content request.
        :type  request:         twisted.web.server.Request
        :param responder:       The file-like object that nectar should write to.
        :type  responder:       Responder
        """
        # Configure the primary downloader for alternate content sources
        plugin_importer, config, db_importer = repo_controller.get_importer_by_id(
            catalog_entry.importer_id)
        # There is an unfortunate mess of configuration classes and attributes, and
        # multiple "models" floating around. The MongoEngine class that corresponds
        # to the database entry only contains the repository config. The ``config``
        # variable above contains the repository configuration _and_ the plugin-wide
        # configuration, so here we override the db_importer.config because it doesn't
        # have the whole config. In the future the importer object should seemlessly
        # load and apply the plugin-wide configuration.
        db_importer.config = config.flatten()
        primary_downloader = plugin_importer.get_downloader_for_db_importer(
            db_importer, catalog_entry.url, working_dir='/tmp')
        pulp_request = request.getHeader(PULP_STREAM_REQUEST_HEADER)
        listener = StreamerListener(request, self.config, catalog_entry, pulp_request)
        primary_downloader.session = self.session
        primary_downloader.event_listener = listener

        # Build the alternate content source download request
        unit_model = plugins_api.get_unit_model_by_id(catalog_entry.unit_type_id)
        qs = unit_model.objects.filter(id=catalog_entry.unit_id).only(*unit_model.unit_key_fields)
        try:
            unit = qs.get()
            download_request = content_models.Request(
                catalog_entry.unit_type_id,
                unit.unit_key,
                catalog_entry.url,
                responder,
            )

            alt_content_container = content_container.ContentContainer(threaded=False)
            alt_content_container.download(primary_downloader, [download_request], listener)
        except DoesNotExist:
            # A catalog entry is referencing a unit that doesn't exist which is bad.
            msg = _('The catalog entry for {path} references {unit_type}:{id}, but '
                    'that unit is not in the database.')
            logger.error(msg.format(path=catalog_entry.path, unit_type=catalog_entry.unit_type_id,
                                    id=catalog_entry.unit_id))
            request.setResponseCode(NOT_FOUND)
        finally:
            primary_downloader.config.finalize()
Пример #4
0
    def _download(self, catalog_entry, request, responder):
        """
        Build a nectar downloader and download the content from the catalog entry.
        The download is performed by the alternate content container, so it is possible
        to use the streamer in conjunction with alternate content sources.

        :param catalog_entry:   The catalog entry to download.
        :type  catalog_entry:   pulp.server.db.model.LazyCatalogEntry
        :param request:         The client content request.
        :type  request:         twisted.web.server.Request
        :param responder:       The file-like object that nectar should write to.
        :type  responder:       Responder
        """
        # Configure the primary downloader for alternate content sources
        plugin_importer, config, db_importer = repo_controller.get_importer_by_id(
            catalog_entry.importer_id)
        primary_downloader = plugin_importer.get_downloader_for_db_importer(
            db_importer, catalog_entry.url, working_dir='/tmp')
        pulp_request = request.getHeader(PULP_STREAM_REQUEST_HEADER)
        listener = StreamerListener(request, self.config, catalog_entry, pulp_request)
        primary_downloader.session = self.session
        primary_downloader.event_listener = listener

        # Build the alternate content source download request
        unit_model = plugins_api.get_unit_model_by_id(catalog_entry.unit_type_id)
        qs = unit_model.objects.filter(id=catalog_entry.unit_id).only(*unit_model.unit_key_fields)
        try:
            unit = qs.get()
            download_request = content_models.Request(
                catalog_entry.unit_type_id,
                unit.unit_key,
                catalog_entry.url,
                responder,
            )

            alt_content_container = content_container.ContentContainer(threaded=False)
            alt_content_container.download(primary_downloader, [download_request], listener)
        except DoesNotExist:
            # A catalog entry is referencing a unit that doesn't exist which is bad.
            msg = _('The catalog entry for {path} references {unit_type}:{id}, but '
                    'that unit is not in the database.')
            logger.error(msg.format(path=catalog_entry.path, unit_type=catalog_entry.unit_type_id,
                                    id=catalog_entry.unit_id))
            request.setResponseCode(NOT_FOUND)
        finally:
            primary_downloader.config.finalize()
Пример #5
0
    def _download(self, catalog_entry, request, responder):
        """
        Build a nectar downloader and download the content from the catalog entry.
        The download is performed by the alternate content container, so it is possible
        to use the streamer in conjunction with alternate content sources.

        :param catalog_entry:   The catalog entry to download.
        :type  catalog_entry:   pulp.server.db.model.LazyCatalogEntry
        :param request:         The client content request.
        :type  request:         twisted.web.server.Request
        :param responder:       The file-like object that nectar should write to.
        :type  responder:       Responder
        """
        importer, config = repo_controller.get_importer_by_id(catalog_entry.importer_id)
        data = {'catalog_entry': catalog_entry, 'client_request': request}
        download_request = nectar_request.DownloadRequest(catalog_entry.url, responder, data=data)
        downloader = importer.get_downloader(config, catalog_entry.url,
                                             **catalog_entry.data)
        downloader.event_listener = StreamerListener(request, self.config)
        downloader.download_one(download_request, events=True)
        downloader.config.finalize()
Пример #6
0
    def _download(self, catalog_entry, request, responder):
        """
        Build a nectar downloader and download the content from the catalog entry.
        The download is performed by the alternate content container, so it is possible
        to use the streamer in conjunction with alternate content sources.

        :param catalog_entry:   The catalog entry to download.
        :type  catalog_entry:   pulp.server.db.model.LazyCatalogEntry
        :param request:         The client content request.
        :type  request:         twisted.web.server.Request
        :param responder:       The file-like object that nectar should write to.
        :type  responder:       Responder
        """
        # Configure the primary downloader for alternate content sources
        importer, config = repo_controller.get_importer_by_id(catalog_entry.importer_id)
        primary_downloader = importer.get_downloader(config, catalog_entry.url,
                                                     **catalog_entry.data)
        pulp_request = request.getHeader(PULP_STREAM_REQUEST_HEADER)
        listener = StreamerListener(request, self.config, catalog_entry, pulp_request)
        primary_downloader.session = self.session
        primary_downloader.event_listener = listener

        # Build the alternate content source download request
        unit_model = plugins_api.get_unit_model_by_id(catalog_entry.unit_type_id)
        qs = unit_model.objects.filter(id=catalog_entry.unit_id).only(*unit_model.unit_key_fields)
        unit = qs.get()
        download_request = content_models.Request(
            catalog_entry.unit_type_id,
            unit.unit_key,
            catalog_entry.url,
            responder
        )

        alt_content_container = content_container.ContentContainer(threaded=False)
        alt_content_container.download(primary_downloader, [download_request], listener)
        primary_downloader.config.finalize()
Пример #7
0
    def _download(self, catalog_entry, request, responder):
        """
        Build a nectar downloader and download the content from the catalog entry.
        The download is performed by the alternate content container, so it is possible
        to use the streamer in conjunction with alternate content sources.

        :param catalog_entry:   The catalog entry to download.
        :type  catalog_entry:   pulp.server.db.model.LazyCatalogEntry
        :param request:         The client content request.
        :type  request:         twisted.web.server.Request
        :param responder:       The file-like object that nectar should write to.
        :type  responder:       Responder
        """
        # Configure the primary downloader for alternate content sources
        plugin_importer, config, db_importer = repo_controller.get_importer_by_id(
            catalog_entry.importer_id)
        # There is an unfortunate mess of configuration classes and attributes, and
        # multiple "models" floating around. The MongoEngine class that corresponds
        # to the database entry only contains the repository config. The ``config``
        # variable above contains the repository configuration _and_ the plugin-wide
        # configuration, so here we override the db_importer.config because it doesn't
        # have the whole config. In the future the importer object should seemlessly
        # load and apply the plugin-wide configuration.
        db_importer.config = config.flatten()
        primary_downloader = plugin_importer.get_downloader_for_db_importer(
            db_importer, catalog_entry.url, working_dir='/tmp')
        pulp_request = request.getHeader(PULP_STREAM_REQUEST_HEADER)
        listener = StreamerListener(request, self.config, catalog_entry,
                                    pulp_request)
        primary_downloader.session = self.session
        primary_downloader.event_listener = listener

        # Build the alternate content source download request
        unit_model = plugins_api.get_unit_model_by_id(
            catalog_entry.unit_type_id)
        qs = unit_model.objects.filter(id=catalog_entry.unit_id).only(
            *unit_model.unit_key_fields)
        try:
            unit = qs.get()
            download_request = content_models.Request(
                catalog_entry.unit_type_id,
                unit.unit_key,
                catalog_entry.url,
                responder,
            )

            alt_content_container = content_container.ContentContainer(
                threaded=False)
            alt_content_container.download(primary_downloader,
                                           [download_request], listener)
        except DoesNotExist:
            # A catalog entry is referencing a unit that doesn't exist which is bad.
            msg = _(
                'The catalog entry for {path} references {unit_type}:{id}, but '
                'that unit is not in the database.')
            logger.error(
                msg.format(path=catalog_entry.path,
                           unit_type=catalog_entry.unit_type_id,
                           id=catalog_entry.unit_id))
            request.setResponseCode(NOT_FOUND)
        finally:
            primary_downloader.config.finalize()