def create_sync_schedule(self, repo_id, importer_id, sync_options, schedule_data): """ Create a new sync schedule for a given repository using the given importer. @param repo_id: @param importer_id: @param sync_options: @param schedule_data: @return: """ # validate the input self._validate_importer(repo_id, importer_id) schedule_utils.validate_keys(sync_options, _SYNC_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) # build the sync call request args = [repo_id] kwargs = {'overrides': sync_options['override_config']} call_request = CallRequest(sync_with_auto_publish_itinerary, args, kwargs, weight=0) # schedule the sync scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) importer_manager = managers_factory.repo_importer_manager() importer_manager.add_sync_schedule(repo_id, schedule_id) return schedule_id
def create_publish_schedule(self, repo_id, distributor_id, publish_options, schedule_data): """ Create a new scheduled publish for the given repository and distributor. @param repo_id: @param distributor_id: @param publish_options: @param schedule_data: @return: """ # validate the input self._validate_distributor(repo_id, distributor_id) schedule_utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) # build the publish call args = [repo_id, distributor_id] kwargs = {'overrides': publish_options['override_config']} call_request = CallRequest(publish_itinerary, args, kwargs, weight=0) # schedule the publish scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) distributor_manager = managers_factory.repo_distributor_manager() distributor_manager.add_publish_schedule(repo_id, distributor_id, schedule_id) return schedule_id
def create_sync_schedule(self, repo_id, importer_id, sync_options, schedule_data): """ Create a new sync schedule for a given repository using the given importer. @param repo_id: @param importer_id: @param sync_options: @param schedule_data: @return: """ # validate the input self._validate_importer(repo_id, importer_id) schedule_utils.validate_keys(sync_options, _SYNC_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) # build the sync call request sync_manager = managers_factory.repo_sync_manager() args = [repo_id] kwargs = {'sync_config_override': sync_options['override_config']} weight = pulp_config.config.getint('tasks', 'sync_weight') tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id)] call_request = CallRequest(sync_manager.sync, args, kwargs, weight=weight, tags=tags, archive=True) call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id) call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, sync_manager.prep_sync) # schedule the sync scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) importer_manager = managers_factory.repo_importer_manager() importer_manager.add_sync_schedule(repo_id, schedule_id) return schedule_id
def create_publish_schedule(self, repo_id, distributor_id, publish_options, schedule_data): """ Create a new scheduled publish for the given repository and distributor. @param repo_id: @param distributor_id: @param publish_options: @param schedule_data: @return: """ # validate the input self._validate_distributor(repo_id, distributor_id) schedule_utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) # build the publish call publish_manager = managers_factory.repo_publish_manager() args = [repo_id, distributor_id] kwargs = {'publish_config_override': publish_options['override_config']} weight = pulp_config.config.getint('tasks', 'publish_weight') tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)] call_request = CallRequest(publish_manager.publish, args, kwargs, weight=weight, tags=tags, archive=True) call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id) call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) call_request.add_life_cycle_callback(dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK, publish_manager.prep_publish) # schedule the publish scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) distributor_manager = managers_factory.repo_distributor_manager() distributor_manager.add_publish_schedule(repo_id, distributor_id, schedule_id) return schedule_id
def test_validate_valid_keys(self): valid_keys = ('one', 'two', 'three') options = {'one': 1, 'two': 2, 'three': 3} schedule_manager = AggregateScheduleManager() try: schedule_utils.validate_keys(options, valid_keys) except Exception, e: self.fail(str(e))
def create(cls, repo_id, distributor_id, publish_options, schedule, failure_threshold=None, enabled=True): """ Create a new scheduled publish for the given repository and distributor. :param repo_id: unique ID for a repository :type repo_id: basestring :param distributor_id: unique ID for a distributor :type distributor_id: basestring :param publish_options: dictionary that contains the key 'override_config', whose value should be passed as the 'overrides' parameter to the publish task. This wasn't originally documented, so it isn't clear why overrides value couldn't be passed directly. :type sync_options: dict :param schedule_data: dictionary that contains the key 'schedule', whose value is an ISO8601 string. This wasn't originally documented, so it isn't clear why the string itself couldn't have been passed directly. :type schedule_data: dict :return: new schedule instance :rtype: pulp.server.db.model.dispatch.ScheduledCall """ dist = model.Distributor.objects.get_or_404( repo_id=repo_id, distributor_id=distributor_id) utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS) utils.validate_initial_schedule_options(schedule, failure_threshold, enabled) task = repo_controller.queue_publish.name args = [repo_id, distributor_id] kwargs = {'overrides': publish_options['override_config']} schedule = ScheduledCall(schedule, task, args=args, kwargs=kwargs, resource=dist.resource_tag, failure_threshold=failure_threshold, enabled=enabled) schedule.save() try: model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id) except exceptions.MissingResource: # back out of this whole thing, since the distributor disappeared utils.delete(schedule.id) raise return schedule
def create(cls, repo_id, importer_id, sync_options, schedule, failure_threshold=None, enabled=True): """ Create a new sync schedule for a given repository using the given importer. :param repo_id: unique ID for a repository :type repo_id: basestring :param importer_id: unique ID for an importer :type importer_id: basestring :param sync_options: dictionary that contains the key 'override_config', whose value should be passed as the 'overrides' parameter to the sync task. This wasn't originally documented, so it isn't clear why overrides value couldn't be passed directly. :type sync_options: dict :param schedule_data: dictionary that contains the key 'schedule', whose value is an ISO8601 string. This wasn't originally documented, so it isn't clear why the string itself couldn't have been passed directly. :type schedule_data: dict :return: new schedule instance :rtype: pulp.server.db.model.dispatch.ScheduledCall """ # validate the input importer_controller.get_valid_importer(repo_id, importer_id) utils.validate_keys(sync_options, _SYNC_OPTION_KEYS) utils.validate_initial_schedule_options(schedule, failure_threshold, enabled) task = repo_controller.queue_sync_with_auto_publish.name args = [repo_id] kwargs = {'overrides': sync_options['override_config']} resource = importer_controller.build_resource_tag(repo_id, importer_id) schedule = ScheduledCall(schedule, task, args=args, kwargs=kwargs, resource=resource, failure_threshold=failure_threshold, enabled=enabled) schedule.save() try: importer_controller.get_valid_importer(repo_id, importer_id) except exceptions.MissingResource: # back out of this whole thing, since the importer disappeared utils.delete(schedule.id) raise return schedule
def create(cls, repo_id, importer_id, sync_options, schedule, failure_threshold=None, enabled=True): """ Create a new sync schedule for a given repository using the given importer. :param repo_id: unique ID for a repository :type repo_id: basestring :param importer_id: unique ID for an importer :type importer_id: basestring :param sync_options: dictionary that contains the key 'override_config', whose value should be passed as the 'overrides' parameter to the sync task. This wasn't originally documented, so it isn't clear why overrides value couldn't be passed directly. :type sync_options: dict :param schedule_data: dictionary that contains the key 'schedule', whose value is an ISO8601 string. This wasn't originally documented, so it isn't clear why the string itself couldn't have been passed directly. :type schedule_data: dict :return: new schedule instance :rtype: pulp.server.db.model.dispatch.ScheduledCall """ # validate the input importer_controller.get_valid_importer(repo_id, importer_id) utils.validate_keys(sync_options, _SYNC_OPTION_KEYS) utils.validate_initial_schedule_options(schedule, failure_threshold, enabled) task = repo_controller.queue_sync_with_auto_publish.name args = [repo_id] kwargs = {"overrides": sync_options["override_config"]} resource = importer_controller.build_resource_tag(repo_id, importer_id) schedule = ScheduledCall( schedule, task, args=args, kwargs=kwargs, resource=resource, failure_threshold=failure_threshold, enabled=enabled, ) schedule.save() try: importer_controller.get_valid_importer(repo_id, importer_id) except exceptions.MissingResource: # back out of this whole thing, since the importer disappeared utils.delete(schedule.id) raise return schedule
def create(cls, repo_id, distributor_id, publish_options, schedule, failure_threshold=None, enabled=True): """ Create a new scheduled publish for the given repository and distributor. :param repo_id: unique ID for a repository :type repo_id: basestring :param distributor_id: unique ID for a distributor :type distributor_id: basestring :param publish_options: dictionary that contains the key 'override_config', whose value should be passed as the 'overrides' parameter to the publish task. This wasn't originally documented, so it isn't clear why overrides value couldn't be passed directly. :type sync_options: dict :param schedule_data: dictionary that contains the key 'schedule', whose value is an ISO8601 string. This wasn't originally documented, so it isn't clear why the string itself couldn't have been passed directly. :type schedule_data: dict :return: new schedule instance :rtype: pulp.server.db.model.dispatch.ScheduledCall """ dist = model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id) utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS) utils.validate_initial_schedule_options(schedule, failure_threshold, enabled) task = repo_controller.queue_publish.name args = [repo_id, distributor_id] kwargs = {"overrides": publish_options["override_config"]} schedule = ScheduledCall( schedule, task, args=args, kwargs=kwargs, resource=dist.resource_tag, failure_threshold=failure_threshold, enabled=enabled, ) schedule.save() try: model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id) except exceptions.MissingResource: # back out of this whole thing, since the distributor disappeared utils.delete(schedule.id) raise return schedule
def _create_schedule(self, management_method, management_action_name, consumer_id, units, options, schedule_data): self._validate_consumer(consumer_id) schedule_utils.validate_keys(options, _UNIT_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) args = [consumer_id] kwargs = {'units': units, 'options': options.get('options', {})} weight = pulp_config.config.getint('tasks', 'consumer_content_weight') tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id), action_tag(management_action_name), action_tag('scheduled_' + management_action_name)] call_request = CallRequest(management_method, args, kwargs, weight=weight, tags=tags, archive=True) call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id) scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) return schedule_id
def _create_schedule(self, itinerary_method, action_name, consumer_id, units, options, schedule_data): self._validate_consumer(consumer_id) schedule_utils.validate_keys(options, _UNIT_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) args = [consumer_id] kwargs = {'units': units, 'options': options.get('options', {})} tags = [ resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id), action_tag(action_name) ] call_request = CallRequest(itinerary_method, args, kwargs, weight=0, tags=tags) scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) return schedule_id