示例#1
0
    def _put(self, release, changed_by, transaction):
        form = NewReleaseForm()
        if not form.validate():
            return Response(status=400, response=form.errors)

        retry(db.releases.addRelease, sleeptime=5, retry_exceptions=(SQLAlchemyError,), 
                kwargs=dict(name=release, product=form.product.data, version=form.version.data, blob=form.blob.data, changed_by=changed_by,  transaction=transaction))
        return Response(status=201)
示例#2
0
 def get(self, release):
     release = retry(db.releases.getReleases, sleeptime=5, retry_exceptions=(SQLAlchemyError,),
             kwargs=dict(name=release, limit=1))
     if not release:
         return Response(status=404)
     headers = {'X-Data-Version': release[0]['data_version']}
     headers.update(get_csrf_headers())
     return Response(response=render_template('fragments/release_row.html', row=release[0]), headers=headers)
示例#3
0
def changeRelease(release, changed_by, transaction, existsCallback, commitCallback, log):
    """Generic function to change an aspect of a release. It relies on a
       ReleaseForm existing and does some upfront work and checks before
       doing anything. It will, for the named release and any found in the
       'copyTo' field of the ReleaseForm:
        - Create the release if it doesn't already exist.
        - return a 400 Response if the release exists and old_data_version doesn't.
        - return a 400 Response if the product name in the form doesn't match the existing one.
        - update the version column of the release table if the one in the form doesn't match it.
        - if the release already exists, 'existsCallback' will be called. If
          that function returns True, a 201 Response will be returned upon
          successful completion. If that function returns False, a 200 Response
          will be returned instead.

      @type  release: string
      @param release: The primary release to update. Additional releases found
                      in the 'copyTo' field of the ReleaseForm will also be
                      updated.
      @type  changed_by: string
      @param changed_by: The username making the change.
      @type  transaction: AUSTransaction object
      @param transaction: The transaction object to be used for all database
                          operations.
      @type  existsCallback: callable
      @param existsCallback: The callable to call to determine whether to
                             consider this a "new" change or not. It must
                             receive 3 positional arguments:
                              - the name of the release
                              - the product name from the ReleaseForm
                              - the version from the ReleaseForm
      @type  commitCallback: callable
      @param commitCallback: The callable to call after all prerequisite checks
                             and updates are done. It must receive 6 positional
                             arguments:
                              - the name of the release
                              - the product name from the ReleaseForm
                              - the version from the ReleaseForm
                              - the data from the ReleaseForm
                              - the most recent version of the data for the
                                release from the database
                              - the old_data_version from the ReleaseForm
    """
    new = True
    form = ReleaseForm()
    if not form.validate():
        return Response(status=400, response=form.errors)
    product = form.product.data
    version = form.version.data
    incomingData = form.data.data
    copyTo = form.copyTo.data
    old_data_version = form.data_version.data

    allReleases = [release]
    if copyTo:
        allReleases += copyTo
    for rel in allReleases:
        try:
            releaseInfo = retry(db.releases.getReleases, kwargs=dict(name=rel, transaction=transaction))[0]
            if existsCallback(rel, product, version):
                new = False
            # "release" is the one named in the URL (as opposed to the
            # ones that can be provided in copyTo), and we treat it as
            # the "primary" one
            if rel == release:
                # Make sure that old_data_version is provided, because we need to verify it when updating.
                if not old_data_version:
                    return Response(status=400, response="Release exists, data_version must be provided")
                # If the product we're given doesn't match the one in the DB, panic.
                if product != releaseInfo['product']:
                    return Response(status=400, response="Product name '%s' doesn't match the one on the release object ('%s') for release '%s'" % (product, releaseInfo['product'], rel))
            # If this isn't the release in the URL...
            else:
                # Use the data_version we just grabbed from the db.
                old_data_version = releaseInfo['data_version']
        except IndexError:
            # If the release doesn't already exist, create it, and set old_data_version appropriately.
            releaseInfo = createRelease(rel, product, version, changed_by, transaction, dict(name=rel))
            old_data_version = 1

        # If the version doesn't match, just update it. This will be the case for nightlies
        # every time there's a version bump.
        if version != releaseInfo['version']:
            log.debug("database version for %s is %s, updating it to %s", rel, releaseInfo['version'], version)
            retry(db.releases.updateRelease, kwargs=dict(name=rel, version=version, changed_by=changed_by, old_data_version=old_data_version, transaction=transaction))
            old_data_version += 1

        commitCallback(rel, product, version, incomingData, releaseInfo['data'], old_data_version)

    new_data_version = db.releases.getReleases(name=release, transaction=transaction)[0]['data_version']
    if new:
        status = 201
    else:
        status = 200
    return make_response(json.dumps(dict(new_data_version=new_data_version)), status)
示例#4
0
 def commit(rel, product, version, newReleaseData, releaseData, old_data_version):
     releaseData.update(newReleaseData)
     return retry(db.releases.updateRelease, kwargs=dict(name=rel, blob=releaseData, changed_by=changed_by, old_data_version=old_data_version, transaction=transaction))
示例#5
0
 def get(self, release):
     release_blob = retry(db.releases.getReleaseBlob, sleeptime=5, retry_exceptions=(SQLAlchemyError,),
             kwargs=dict(name=release))
     return jsonify(release_blob)
示例#6
0
def createRelease(release, product, version, changed_by, transaction, releaseData):
    blob = ReleaseBlobV1(schema_version=CURRENT_SCHEMA_VERSION, **releaseData)
    retry(db.releases.addRelease, kwargs=dict(name=release, product=product, version=version, blob=blob, changed_by=changed_by, transaction=transaction))
    return retry(db.releases.getReleases, kwargs=dict(name=release, transaction=transaction))[0]
示例#7
0
 def commit(rel, product, version, localeData, releaseData, old_data_version):
     return retry(db.releases.addLocaleToRelease, kwargs=dict(name=rel, platform=platform, locale=locale, data=localeData, old_data_version=old_data_version, changed_by=changed_by, transaction=transaction))
示例#8
0
 def exists(rel, product, version):
     if rel == release:
         return retry(db.releases.localeExists, kwargs=dict(name=rel, platform=platform, locale=locale, transaction=transaction))
     return False