Example #1
0
def get_partial(identifier):
    """ Function to return a generated partial """
    if not cache.exists('partial', identifier):
        resp = flask.Response(
            json.dumps({
                "result":
                "Partial with identifier %s not found" % identifier,
            }),
            status=404,
        )
        return resp

    if cache.is_blank_file('partial', identifier):
        log.debug('Record found, status: IN PROGRESS')
        resp = flask.Response(json.dumps({"result": "wait"}), status=202)
    else:
        log.debug('Record found, status: COMPLETED')
        if flask.request.method == 'HEAD':
            url = flask.url_for('get_partial', identifier=identifier)
            resp = flask.Response(json.dumps({"result": url}),
                                  status=200,
                                  mimetype='application/json')
        else:
            resp = cache.retrieve_or_redirect('partial', identifier)

    return resp
Example #2
0
def get_patch(sha_from, sha_to):
    """ Function to return a patch from cache """
    identifier = _get_identifier(sha_from, sha_to)

    log.debug('Looking up record with identifier %s', identifier)
    if not cache.exists('patch', identifier):
        log.info('Invalid partial request')
        resp = flask.Response(
            json.dumps(
                {"result": "Patch with identifier %s not found" % identifier}),
            status=404,
        )
        return resp

    log.info('Patch found, retrieving ...')
    return cache.retrieve_or_redirect('patch', identifier)
Example #3
0
def get_patch(sha_from, sha_to):
    """ Function to return a patch from cache """
    identifier = _get_identifier(sha_from, sha_to)

    log.debug('Looking up record with identifier %s', identifier)
    if not cache.exists('patch', identifier):
        log.info('Invalid partial request')
        resp = flask.Response(
            json.dumps({
                "result": "Patch with identifier %s not found" % identifier
            }),
            status=404,
        )
        return resp

    log.info('Patch found, retrieving ...')
    return cache.retrieve_or_redirect('patch', identifier)
Example #4
0
def trigger_partial():
    """ Function to trigger a  partial generation """
    required_params = (
        'mar_from', 'sha_from',
        'mar_to', 'sha_to',
        'channel_id', 'product_version')
    form = flask.request.form
    if not all(p in form.keys() for p in required_params):
        log.info('Missing parameters from POST form call')
        flask.abort(400)

    mar_from = form['mar_from']
    sha_from = form['sha_from']
    mar_to = form['mar_to']
    sha_to = form['sha_to']
    channel_id = form['channel_id']
    product_version = form['product_version']

    identifier = _get_identifier(sha_from, sha_to)
    url = flask.url_for('get_partial', identifier=identifier)

    if cache.exists('partial', identifier):
        log.info('Partial has already been triggered/generated')
        return flask.Response(json.dumps({"result": url}), status=201,
                              mimetype='application/json')
    try:
        cache.save_blank_file('partial', identifier)
    except:
        log.error('Error processing trigger request for URL: %s\n', url)
        return flask.Response(
            json.dumps({"result": "Error while processing request %s" % url}),
            status=500,
            mimetypge='application/json'
        )

    tasks.build_partial_mar.delay(mar_to, sha_to, mar_from, sha_from,
                                  identifier, channel_id, product_version)
    log.debug("Task submitted")
    return flask.Response(
        json.dumps({"result": url}),
        status=202,
        mimetype='application/json'
    )
Example #5
0
def trigger_partial():
    """ Function to trigger a  partial generation """
    required_params = ('mar_from', 'sha_from', 'mar_to', 'sha_to',
                       'channel_id', 'product_version')
    form = flask.request.form
    if not all(p in form.keys() for p in required_params):
        log.info('Missing parameters from POST form call')
        flask.abort(400)

    mar_from = form['mar_from']
    sha_from = form['sha_from']
    mar_to = form['mar_to']
    sha_to = form['sha_to']
    channel_id = form['channel_id']
    product_version = form['product_version']

    identifier = _get_identifier(sha_from, sha_to)
    url = flask.url_for('get_partial', identifier=identifier)

    if cache.exists('partial', identifier):
        log.info('Partial has already been triggered/generated')
        return flask.Response(json.dumps({"result": url}),
                              status=201,
                              mimetype='application/json')
    try:
        cache.save_blank_file('partial', identifier)
    except:
        log.error('Error processing trigger request for URL: %s\n', url)
        return flask.Response(json.dumps(
            {"result": "Error while processing request %s" % url}),
                              status=500,
                              mimetypge='application/json')

    tasks.build_partial_mar.delay(mar_to, sha_to, mar_from, sha_from,
                                  identifier, channel_id, product_version)
    log.debug("Task submitted")
    return flask.Response(json.dumps({"result": url}),
                          status=202,
                          mimetype='application/json')
Example #6
0
def get_partial(identifier):
    """ Function to return a generated partial """
    if not cache.exists('partial', identifier):
        resp = flask.Response(
            json.dumps({
                "result": "Partial with identifier %s not found" % identifier,
            }),
            status=404,
        )
        return resp

    if cache.is_blank_file('partial', identifier):
        log.debug('Record found, status: IN PROGRESS')
        resp = flask.Response(json.dumps({"result": "wait"}), status=202)
    else:
        log.debug('Record found, status: COMPLETED')
        if flask.request.method == 'HEAD':
            url = flask.url_for('get_partial', identifier=identifier)
            resp = flask.Response(json.dumps({"result": url}), status=200,
                                  mimetype='application/json')
        else:
            resp = cache.retrieve_or_redirect('partial', identifier)

    return resp