Exemplo n.º 1
0
def update(schedule_id, delta):
    """
    Updates the schedule with unique ID schedule_id. This only allows updating
    of fields in ScheduledCall.USER_UPDATE_FIELDS.

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    :param delta:       a dictionary of keys with values that should be modified
                        on the schedule.
    :type  delta:       dict

    :return:    instance of ScheduledCall representing the post-update state
    :rtype      ScheduledCall

    :raise  exceptions.UnsupportedValue
    :raise  exceptions.MissingResource
    """
    unknown_keys = set(delta.keys()) - ScheduledCall.USER_UPDATE_FIELDS
    if unknown_keys:
        raise exceptions.UnsupportedValue(list(unknown_keys))

    delta['last_updated'] = time.time()

    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        raise exceptions.InvalidValue(['schedule_id'])
    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, update={'$set': delta}, safe=True, new=True)
    if schedule is None:
        raise exceptions.MissingResource(schedule_id=schedule_id)
    return ScheduledCall.from_db(schedule)
Exemplo n.º 2
0
    def post(self, request, repo_id, distributor_id):
        """
        Create a new scheduled publish.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param distributor_id: id of the distributor
        :type  distributor_id: str

        :return: Response containing a dict for the new scheduled publish
        :rtype : django.http.HttpResponse
        :raises exceptions.UnsupportedValue: if unsupported fields are included in body
        """

        manager = manager_factory.repo_publish_schedule_manager()
        publish_options = {'override_config': request.body_as_json.pop('override_config', {})}
        schedule = request.body_as_json.pop('schedule', None)
        failure_threshold = request.body_as_json.pop('failure_threshold', None)
        enabled = request.body_as_json.pop('enabled', True)
        if request.body_as_json:
            raise exceptions.UnsupportedValue(request.body_as_json.keys())

        schedule = manager.create(repo_id, distributor_id, publish_options,
                                  schedule, failure_threshold, enabled)
        ret = schedule.for_display()
        ret['_href'] = reverse('repo_publish_schedule_resource', kwargs={
            'repo_id': repo_id, 'distributor_id': distributor_id, 'schedule_id': schedule.id
        })
        response = generate_json_response_with_pulp_encoder(ret)
        return generate_redirect_response(response, ret['_href'])
Exemplo n.º 3
0
def validate_updated_schedule_options(options):
    """
    Validate updated schedule options.

    :param options: updated options for a scheduled call
    :type  options: dict
    :raises: pulp.server.exceptions.UnsupportedValue if unsupported schedule options are passed in
    :raises: pulp.server.exceptions.InvalidValue if any of the options are invalid
    """

    unknown_options = _find_unknown_options(options, ScheduledCall.USER_UPDATE_FIELDS)

    if unknown_options:
        raise exceptions.UnsupportedValue(unknown_options)

    invalid_options = []

    if 'iso_schedule' in options and not _is_valid_schedule(options['iso_schedule']):
        invalid_options.append('iso_schedule')

    if 'failure_threshold' in options and not _is_valid_failure_threshold(
            options['failure_threshold']):
        invalid_options.append('failure_threshold')

    if 'remaining_runs' in options and not _is_valid_remaining_runs(options['remaining_runs']):
        invalid_options.append('remaining_runs')

    if 'enabled' in options and not _is_valid_enabled_flag(options['enabled']):
        invalid_options.append('enabled')

    if not invalid_options:
        return

    raise exceptions.InvalidValue(invalid_options)
Exemplo n.º 4
0
    def post(self, request, repo_id, importer_id):
        """
        Create a new scheduled sync.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param importer_id: create a new scheduled sync for this importer
        :type  importer_id: str

        :return: Response containing a serialized dict of the new  scheduled sync
        :rtype : django.http.HttpResponse
        :raises exceptions.UnsupportedValue: if there are unsupported request body params
        """

        manager = manager_factory.repo_sync_schedule_manager()
        sync_options = {'override_config': request.body_as_json.pop('override_config', {})}
        schedule = request.body_as_json.pop('schedule', None)
        failure_threshold = request.body_as_json.pop('failure_threshold', None)
        enabled = request.body_as_json.pop('enabled', True)
        if request.body_as_json:
            raise exceptions.UnsupportedValue(request.body_as_json.keys())

        scheduled_call = manager.create(repo_id, importer_id, sync_options,
                                        schedule, failure_threshold, enabled)
        display_call = scheduled_call.for_display()
        display_call['_href'] = reverse(
            'repo_sync_schedule_resource',
            kwargs={'repo_id': repo_id, 'importer_id': importer_id,
                    'schedule_id': scheduled_call['id']}
        )
        response = generate_json_response(display_call)
        return generate_redirect_response(response, display_call['_href'])
Exemplo n.º 5
0
def validate_schedule_updates(updates):
    """
    Validate the updates to an existing schedule
    @param updates:
    @return:
    """
    invalid_keys = get_invalid_keys(updates, SCHEDULE_MUTABLE_FIELDS)

    if invalid_keys:
        raise pulp_exceptions.UnsupportedValue(invalid_keys)

    invalid_values = []

    if 'schedule' in updates and not is_valid_schedule(updates['schedule']):
        invalid_values.append('schedule')

    if 'failure_threshold' in updates and not is_valid_failure_threshold(updates['failure_threshold']):
        invalid_values.append('failure_threshold')

    if 'remaining_runs' in updates and not is_valid_remaining_runs(updates['remaining_runs']):
        invalid_values.append('remaining_runs')

    if 'enabled' in updates and not is_valid_enabled(updates['enabled']):
        invalid_values.append('enabled')

    if not invalid_values:
        return

    raise pulp_exceptions.InvalidValue(invalid_values)
Exemplo n.º 6
0
def validate_schedule_options(schedule, options):
    """
    Validate the options for a new schedule.
    @param schedule: new schedule
    @type  schedule: basestring
    @param options: new schedule options
    @type  options: dict
    @raise: L{pulp_exceptions.UnsupportedValue}
    @raise: L{pulp_exceptions.InvalidValue}
    """
    invalid_keys = get_invalid_keys(options, SCHEDULE_OPTIONS_FIELDS)

    if invalid_keys:
        raise pulp_exceptions.UnsupportedValue(invalid_keys)

    invalid_values = []

    if not is_valid_schedule(schedule):
        invalid_values.append('schedule')

    if 'failure_threshold' in options and not is_valid_failure_threshold(options['failure_threshold']):
        invalid_values.append('failure_threshold')

    if 'enabled' in options and not is_valid_enabled(options['enabled']):
        invalid_values.append('enabled')

    if not invalid_values:
        return

    raise pulp_exceptions.InvalidValue(invalid_values)
Exemplo n.º 7
0
    def POST(self, repo_id, importer_id):
        manager = manager_factory.repo_sync_schedule_manager()

        params = self.params()
        sync_options = {'override_config': params.pop('override_config', {})}
        schedule = params.pop('schedule', None)
        failure_threshold = params.pop('failure_threshold', None)
        enabled = params.pop('enabled', True)
        if params:
            raise exceptions.UnsupportedValue(params.keys())

        scheduled_call = manager.create(repo_id, importer_id, sync_options,
                                        schedule, failure_threshold, enabled)

        ret = scheduled_call.for_display()
        ret.update(serialization.link.child_link_obj(scheduled_call.id))
        return self.created(ret['_href'], ret)
Exemplo n.º 8
0
def update(schedule_id, delta):
    """
    Updates the schedule with unique ID schedule_id. This only allows updating
    of fields in ScheduledCall.USER_UPDATE_FIELDS.

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    :param delta:       a dictionary of keys with values that should be modified
                        on the schedule.
    :type  delta:       dict

    :return:    instance of ScheduledCall representing the post-update state
    :rtype      ScheduledCall

    :raise  exceptions.UnsupportedValue
    :raise  exceptions.MissingResource
    """
    unknown_keys = set(delta.keys()) - ScheduledCall.USER_UPDATE_FIELDS
    if unknown_keys:
        raise exceptions.UnsupportedValue(list(unknown_keys))

    delta['last_updated'] = time.time()

    # bz 1139703 - if we update iso_schedule, update the pickled object as well
    if 'iso_schedule' in delta:
        interval, start_time, occurrences = dateutils.parse_iso8601_interval(
            delta['iso_schedule'])
        delta['schedule'] = pickle.dumps(CelerySchedule(interval))

        # set first_run and next_run so that the schedule update will take effect
        new_schedule_call = ScheduledCall(delta['iso_schedule'],
                                          'dummytaskname')
        delta['first_run'] = new_schedule_call.first_run
        delta['next_run'] = new_schedule_call.next_run

    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        # During schedule update, MissingResource should be raised even if
        # schedule_id is invalid object_id.
        raise exceptions.MissingResource(schedule_id=schedule_id)
    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, update={'$set': delta}, safe=True, new=True)
    if schedule is None:
        raise exceptions.MissingResource(schedule_id=schedule_id)
    return ScheduledCall.from_db(schedule)