Пример #1
0
def get_apt_repos(project_version, session, is_ci=False):
    """
    Returns a list of all needed apt sources urls
    for the given project_version.

    Args:
        base_mirror (str): The base mirror name ("jessie-8.9").
        projectversion (ProjectVersion): The project_version.
        distribution (str): The distribution

    Returns:
        list: List of apt urls.
    """
    dep_ids = get_projectversion_deps(project_version.id, session)
    deps = (session.query(ProjectVersion).filter(
        ProjectVersion.id.in_(set(dep_ids))).all())

    urls = []

    if is_ci:
        urls.append(project_version.get_apt_repo(dist="unstable"))

    urls.append(project_version.get_apt_repo())
    for project_ver in deps:
        urls.append(project_ver.get_apt_repo())

    return urls
Пример #2
0
async def ScheduleBuilds():

    logger.info("scheduler: checking for pending builds")

    with Session() as session:

        needed_builds = (session.query(Build).filter(
            Build.buildstate == "needs_build", Build.buildtype == "deb").all())
        for build in needed_builds:
            if not chroot_ready(build, session):
                continue

            repo_id = build.sourcerepository_id
            for projectversion in build.buildconfiguration.projectversions:
                projectversion_id = projectversion.id
                # build.log_state("scheduler: projectversion %d, repo %d needs build" % (projectversion_id, repo_id))

                repo_deps = []
                if build.parent.build_after:
                    for build_after_repo in build.parent.build_after:
                        repo_deps.append(build_after_repo.id)
                else:
                    repo_deps_query = """
                    WITH RECURSIVE getparents(sourcerepository, dependency) AS (
                    SELECT s1.sourcerepository, s1.dependency
                      FROM buildorder s1
                      WHERE s1.sourcerepository = :repo_id
                    UNION ALL
                    SELECT s2.sourcerepository, s2.dependency
                      FROM
                        buildorder s2,
                        getparents s1
                      WHERE s2.sourcerepository = s1.dependency
                    )
                    SELECT * from getparents;
                    """
                    results = session.execute(repo_deps_query,
                                              {"repo_id": repo_id})
                    for row in results:
                        repo_deps.append(row[1])

                if not repo_deps:
                    # build.log_state("scheduler: no build order dependencies, scheduling...")
                    await schedule_build(build, session)
                    break

                pv_deps = get_projectversion_deps(projectversion.id, session)
                projectversion_ids = [projectversion_id]
                # FIXME: no mirrors
                projectversion_ids.extend(pv_deps)

                ready = True
                for dep_repo_id in repo_deps:
                    dep_repo = (session.query(SourceRepository).filter(
                        SourceRepository.id == dep_repo_id).first())
                    if not dep_repo:
                        logger.warning("scheduler: repo %d not found",
                                       dep_repo_id)
                        continue

                    # FIXME: buildconfig arch dependent!

                    # find running builds in the same and dependent projectversions
                    found_running = False
                    for pv_id in projectversion_ids:
                        # build.log_state("scheduler: trying to find running build order dependency in projectversion %d" % pv_id)

                        # check no build order dep is needs_build, building, publishing, ...
                        # FIXME: this needs maybe checking of source packages as well?
                        running_builds = (session.query(Build).join(
                            Build.buildconfiguration).filter(
                                or_(
                                    Build.buildstate == "new",
                                    Build.buildstate == "needs_build",
                                    Build.buildstate == "scheduled",
                                    Build.buildstate == "building",
                                    Build.buildstate == "needs_publish",
                                    Build.buildstate == "publishing",
                                ),
                                Build.buildtype == "deb",
                                Build.sourcerepository_id == dep_repo_id,
                                BuildConfiguration.projectversions.any(
                                    ProjectVersion.id == pv_id),
                            ).all())

                        if running_builds:
                            found_running = True

                            projectversion = (
                                session.query(ProjectVersion).filter(
                                    ProjectVersion.id == pv_id).first())
                            if not projectversion:
                                pvname = "unknown"
                                logger.warning(
                                    "scheduler: projectversion %d not found",
                                    pv_id)
                            else:
                                pvname = projectversion.fullname
                            builds = [str(b.id) for b in running_builds]
                            write_log(
                                build.id,
                                "W: waiting for repo {} to finish builds ({}) in projectversion {}\n"
                                .format(dep_repo.name, ", ".join(builds),
                                        pvname))
                            break

                    if found_running:
                        ready = False
                        break

                    # find successful builds in the same and dependent projectversions
                    found = False
                    for pv_id in projectversion_ids:
                        successful_builds = (session.query(Build).join(
                            Build.buildconfiguration).filter(
                                Build.buildstate == "successful",
                                Build.buildtype == "deb",
                                Build.sourcerepository_id == dep_repo_id,
                                BuildConfiguration.projectversions.any(
                                    ProjectVersion.id == pv_id),
                            ).all())

                        if successful_builds:
                            found = True
                            break
                    if not found:
                        ready = False
                        projectversion = (session.query(ProjectVersion).filter(
                            ProjectVersion.id == pv_id).first())
                        if not projectversion:
                            pvname = "unknown"
                            logger.warning(
                                "scheduler: projectversion %d not found",
                                pv_id)
                        else:
                            pvname = projectversion.fullname

                        write_log(
                            build.id,
                            "W: waiting for repo {} to be built in projectversion {}\n"
                            .format(dep_repo.name, pvname))
                        break

                if ready:
                    # build.log_state("scheduler: found all required build order dependencies, scheduling...")
                    await schedule_build(build, session)
Пример #3
0
async def post_projectversion_dependency(request):
    """
    Adds a projectversiondependency to a projectversion.

    ---
    description: Return the projectversion
    tags:
        - ProjectVersions
    consumes:
        - application/json
    parameters:
        - name: projectversion_id
          in: path
          required: true
          type: integer
        - name: body
          in: body
          required: true
          schema:
            type: object
            properties:
                dependency_id:
                    type: integer
    produces:
        - text/json
    responses:
        "200":
            description: successful
        "500":
            description: internal server error
    """
    params = await request.json()

    projectversion_id = parse_int(request.match_info["projectversion_id"])
    if not projectversion_id:
        return web.Response(text="Incorrect value for projectversion_id",
                            status=400)

    dependency_id = parse_int(params.get("dependency_id"))
    if not dependency_id:
        return web.Response(text="Incorrect value for dependency_id",
                            status=400)

    projectversion = (
        request.cirrina.db_session.query(ProjectVersion).filter(
            ProjectVersion.id == projectversion_id)  # pylint: disable=no-member
        .first())
    if not projectversion:
        return web.Response(status=400, text="Invalid data received.")

    if projectversion.is_locked:
        return web.Response(
            text="You can not add dependencies on a locked projectversion!",
            status=400)

    if dependency_id == projectversion_id:
        return web.Response(
            text=
            "You can not add a dependency of the same projectversion to itself!",
            status=400,
        )

    # check for dependency loops
    dep_ids = get_projectversion_deps(dependency_id,
                                      request.cirrina.db_session)
    if projectversion_id in dep_ids:
        return web.Response(
            text=
            "You can not add a dependency of a projectversion depending itself on this projectversion!",
            status=400,
        )

    dependency = (
        request.cirrina.db_session.query(ProjectVersion).filter(
            ProjectVersion.id == dependency_id)  # pylint: disable=no-member
        .first())
    if not dependency:
        return web.Response(status=400, text="Invalid data received.")

    projectversion.dependencies.append(dependency)
    request.cirrina.db_session.commit()

    return web.Response(status=200, text="Dependency added")