Beispiel #1
0
            raise PulpExecutionException(e), None, sys.exc_info()[2]

        publish_end_timestamp = _now_timestamp()

        # Reload the distributor in case the scratchpad is changed by the plugin
        distributor = distributor_coll.find_one({'id' : distributor_id, 'repo_group_id' : group_id})
        distributor['last_publish'] = publish_end_timestamp
        distributor_coll.save(distributor)

        # Add a publish entry
        if report is not None and isinstance(report, PublishReport):
            summary = report.summary
            details = report.details
            if report.success_flag:
                result = RepoGroupPublishResult.expected_result(group_id, distributor_id,
                         distributor['distributor_type_id'], publish_start_timestamp,
                         publish_end_timestamp, summary, details)
            else:
                result = RepoGroupPublishResult.failed_result(group_id, distributor_id,
                         distributor['distributor_type_id'], publish_start_timestamp,
                         publish_end_timestamp, summary, details)
        else:
            _LOG.warn('Plugin type [%s] did not return a valid publish report' % distributor['distributor_type_id'])

            summary = details = _('Unknown')
            result = RepoGroupPublishResult.expected_result(group_id, distributor_id,
                     distributor['distributor_type_id'], publish_start_timestamp,
                     publish_end_timestamp, summary, details)

        publish_result_coll.save(result, safe=True)
        return result
Beispiel #2
0
class RepoGroupPublishManager(object):
    @staticmethod
    def publish(group_id, distributor_id, publish_config_override=None):
        """
        Requests the given distributor publish the repository group.

        :param group_id:                identifies the repo group
        :type  group_id:                str
        :param distributor_id:          identifies the group's distributor
        :type  distributor_id:          str
        :param publish_config_override: values to pass the plugin for this publish call alone
        :type  publish_config_override: dict
        """
        distributor_manager = manager_factory.repo_group_distributor_manager()
        distributor = distributor_manager.get_distributor(
            group_id, distributor_id)
        distributor_type_id = distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(
            distributor_type_id)

        group_query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = group_query_manager.get_group(group_id)
        distributor_type_id = distributor['distributor_type_id']

        # Assemble the data needed for publish
        conduit = RepoGroupPublishConduit(group_id, distributor)

        call_config = PluginCallConfiguration(plugin_config,
                                              distributor['config'],
                                              publish_config_override)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.get_working_directory()

        # TODO: Add events for group publish start/complete
        RepoGroupPublishManager._do_publish(transfer_group, distributor_id,
                                            distributor_instance, conduit,
                                            call_config)

    @staticmethod
    def _do_publish(group, distributor_id, distributor_instance, conduit,
                    call_config):

        distributor_coll = RepoGroupDistributor.get_collection()
        publish_result_coll = RepoGroupPublishResult.get_collection()
        group_id = group.id

        # Perform the publish
        publish_start_timestamp = _now_timestamp()
        try:
            report = distributor_instance.publish_group(
                group, conduit, call_config)
        except Exception, e:
            publish_end_timestamp = _now_timestamp()

            # Reload the distributor in case the scratchpad is changed by the plugin
            distributor = distributor_coll.find_one({
                'id': distributor_id,
                'repo_group_id': group_id
            })
            distributor['last_publish'] = publish_end_timestamp
            distributor_coll.save(distributor)

            # Add a publish history entry for the run
            result = RepoGroupPublishResult.error_result(
                group_id, distributor_id, distributor['distributor_type_id'],
                publish_start_timestamp, publish_end_timestamp, e,
                sys.exc_info()[2])
            publish_result_coll.save(result)

            raise

        publish_end_timestamp = _now_timestamp()

        # Reload the distributor in case the scratchpad is changed by the plugin
        distributor = distributor_coll.find_one({
            'id': distributor_id,
            'repo_group_id': group_id
        })
        distributor['last_publish'] = publish_end_timestamp
        distributor_coll.save(distributor)

        # Add a publish entry
        if report is not None and isinstance(report, PublishReport):
            summary = report.summary
            details = report.details
            if report.success_flag:
                result = RepoGroupPublishResult.expected_result(
                    group_id, distributor_id,
                    distributor['distributor_type_id'],
                    publish_start_timestamp, publish_end_timestamp, summary,
                    details)
            else:
                result = RepoGroupPublishResult.failed_result(
                    group_id, distributor_id,
                    distributor['distributor_type_id'],
                    publish_start_timestamp, publish_end_timestamp, summary,
                    details)
        else:
            msg = _(
                'Plugin type [%(t)s] did not return a valid publish report')
            msg = msg % {'t': distributor['distributor_type_id']}
            logger.warn(msg)

            summary = details = _('Unknown')
            result = RepoGroupPublishResult.expected_result(
                group_id, distributor_id, distributor['distributor_type_id'],
                publish_start_timestamp, publish_end_timestamp, summary,
                details)

        publish_result_coll.save(result)
        return result
Beispiel #3
0
        # Reload the distributor in case the scratchpad is changed by the plugin
        distributor = distributor_coll.find_one({
            'id': distributor_id,
            'repo_group_id': group_id
        })
        distributor['last_publish'] = publish_end_timestamp
        distributor_coll.save(distributor)

        # Add a publish entry
        if report is not None and isinstance(report, PublishReport):
            summary = report.summary
            details = report.details
            if report.success_flag:
                result = RepoGroupPublishResult.expected_result(
                    group_id, distributor_id,
                    distributor['distributor_type_id'],
                    publish_start_timestamp, publish_end_timestamp, summary,
                    details)
            else:
                result = RepoGroupPublishResult.failed_result(
                    group_id, distributor_id,
                    distributor['distributor_type_id'],
                    publish_start_timestamp, publish_end_timestamp, summary,
                    details)
        else:
            _LOG.warn(
                'Plugin type [%s] did not return a valid publish report' %
                distributor['distributor_type_id'])

            summary = details = _('Unknown')
            result = RepoGroupPublishResult.expected_result(