Beispiel #1
0
def get_all_builds(request):
    name = request.GET.get('name')
    branch = request.GET.get('branch')
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', common.DEFAULT_BUILD_SIZE))
    builds = builds_helper.get_builds_and_tags(request, name=name, branch=branch, pageIndex=index,
                                      pageSize=size)
    scm_url = systems_helper.get_scm_url(request)
    deploy_state = None
    current_build_id = request.GET.get('current_build_id', None)
    override_policy = request.GET.get('override_policy')
    deploy_id = request.GET.get('deploy_id')
    current_build = None
    if current_build_id:
        current_build = builds_helper.get_build_and_tag(request, current_build_id)
        current_build = current_build.get('build')
    if deploy_id:
        deploy_config = deploys_helper.get(request, deploy_id)
        if deploy_config:
            deploy_state = deploy_config.get('state', None)

    html = render_to_string('builds/pick_a_build.tmpl', {
        "builds": builds,
        "current_build": current_build,
        "scm_url": scm_url,
        "buildName": name,
        "branch": branch,
        "pageIndex": index,
        "pageSize": common.DEFAULT_BUILD_SIZE,
        "disablePrevious": index <= 1,
        "disableNext": len(builds) < common.DEFAULT_BUILD_SIZE,
        "overridePolicy": override_policy,
        "deployState": deploy_state,
    })
    return HttpResponse(html)
Beispiel #2
0
def tag_build(request, id):
    if request.method == "POST":
        build_info = builds_helper.get_build_and_tag(request, id)
        current_tag = build_info.get("tag")

        if current_tag:
            tagged_build = json.loads(current_tag["metaInfo"])
            if tagged_build["id"] == id:
                log.info(
                    "There is already a tag associated with the build. Remove it"
                )
                builds_helper.del_build_tag(request, current_tag["id"])
        tag = {
            "targetId": id,
            "targetType": "Build",
            "comments": request.POST["comments"]
        }
        value = request.POST["tag_value"]
        if value.lower() == "good":
            tag["value"] = tags_helper.TagValue.GOOD_BUILD
        elif value.lower() == "bad":
            tag["value"] = tags_helper.TagValue.BAD_BUILD
        else:
            return HttpResponse(status=400)
        builds_helper.set_build_tag(request, tag)
        return redirect("/builds/{0}/".format(id))
    else:
        return HttpResponse(status=405)
Beispiel #3
0
def get_all_builds(request):
    name = request.GET.get('name')
    branch = request.GET.get('branch')
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', common.DEFAULT_BUILD_SIZE))
    builds = builds_helper.get_builds_and_tags(request, name=name, branch=branch, pageIndex=index,
                                      pageSize=size)
    scm_url = systems_helper.get_scm_url(request)
    current_build_id = request.GET.get('current_build_id', None)
    current_build = None
    if current_build_id:
        current_build = builds_helper.get_build_and_tag(request, current_build_id)

    html = render_to_string('builds/pick_a_build.tmpl', {
        "builds": builds,
        "current_build": current_build['build'],
        "scm_url": scm_url,
        "buildName": name,
        "branch": branch,
        "pageIndex": index,
        "pageSize": common.DEFAULT_BUILD_SIZE,
        "disablePrevious": index <= 1,
        "disableNext": len(builds) < common.DEFAULT_BUILD_SIZE,
    })
    return HttpResponse(html)
Beispiel #4
0
def get_all_builds(request):
    name = request.GET.get('name')
    branch = request.GET.get('branch')
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', common.DEFAULT_BUILD_SIZE))
    builds = builds_helper.get_builds_and_tags(request,
                                               name=name,
                                               branch=branch,
                                               pageIndex=index,
                                               pageSize=size)
    scm_url = systems_helper.get_scm_url(request)
    current_build_id = request.GET.get('current_build_id', None)
    current_build = None
    if current_build_id:
        current_build = builds_helper.get_build_and_tag(
            request, current_build_id)

    html = render_to_string(
        'builds/pick_a_build.tmpl', {
            "builds": builds,
            "current_build": current_build['build'],
            "scm_url": scm_url,
            "buildName": name,
            "branch": branch,
            "pageIndex": index,
            "pageSize": common.DEFAULT_BUILD_SIZE,
            "disablePrevious": index <= 1,
            "disableNext": len(builds) < common.DEFAULT_BUILD_SIZE,
        })
    return HttpResponse(html)
Beispiel #5
0
def get_build(request, id):
    info = builds_helper.get_build_and_tag(request, id)
    tag = info.get("tag")
    if tag:
        tag["build"]=json.loads(tag["metaInfo"])
    return render(request, 'builds/build_details.html', {
        "build": info["build"],
        "tag": tag
    })
Beispiel #6
0
def get_build(request, id):
    info = builds_helper.get_build_and_tag(request, id)
    tag = info.get("tag")
    if tag:
        tag["build"] = json.loads(tag["metaInfo"])
    return render(request, 'builds/build_details.html', {
        "build": info["build"],
        "tag": tag
    })
Beispiel #7
0
def gen_report(request, env, progress, sortByStatus="false"):
    agentStats = []
    firstTimeAgentStats = []
    deployStats = {}
    deprecatedDeployStats = []

    # always set the current
    deploy = deploys_helper.get(request, env['deployId'])
    build_info = builds_helper.get_build_and_tag(request, deploy["buildId"])
    stageDistMap = genStageDistMap()
    stateDistMap = genStateDistMap()
    currentDeployStat = DeployStatistics(deploy=deploy,
                                         build=build_info['build'],
                                         stageDistMap=stageDistMap,
                                         stateDistMap=stateDistMap,
                                         buildTag=build_info.get('tag'))
    deployStats[env['deployId']] = currentDeployStat

    for agent in progress["agents"]:
        if agent["firstDeploy"]:
            firstTimeAgentStats.append(
                addToEnvReport(request, deployStats, agent, env))
        else:
            agentStats.append(addToEnvReport(request, deployStats, agent, env))

    if sortByStatus == "true":
        agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y))

    for key, value in deployStats.iteritems():
        if key != env['deployId']:
            deprecatedDeployStats.append(value)

    provisioning_hosts = progress["provisioningHosts"]
    if IS_PINTEREST:
        basic_cluster_info = clusters_helper.get_cluster(
            request, env.get('clusterName'))
        if basic_cluster_info and basic_cluster_info.get('capacity'):
            hosts_in_cluster = clusters_helper.get_host_ids(
                request, env.get('clusterName'))
            num_to_fake = basic_cluster_info.get('capacity') - len(
                hosts_in_cluster)
            for i in range(num_to_fake):
                faked_host = {}
                faked_host['hostName'] = 'UNKNOWN'
                faked_host['hostId'] = 'UNKNOWN'
                faked_host['state'] = 'PROVISIONED'
                provisioning_hosts.append(faked_host)

    return AgentReport(firstTimeAgentStats=firstTimeAgentStats,
                       agentStats=agentStats,
                       currentDeployStat=currentDeployStat,
                       deprecatedDeployStats=deprecatedDeployStats,
                       missingHosts=progress["missingHosts"],
                       provisioningHosts=provisioning_hosts,
                       envName=env['envName'],
                       stageName=env['stageName'])
Beispiel #8
0
def warn_for_deploy(request, name, stage, buildId):
    """ Returns a warning message if:
    1. The build has been tagged as build build
    2. a build doesn't have a successful deploy on the preceding stage.

    TODO: we would have call backend twice since the getAllDeploys call does not support filtering on multiple states;
    Also, getAllDeploys return all deploys with commits after the specific commit, it would be good if there is options
    to return the exact matched deploys.
    """
    build_info = builds_helper.get_build_and_tag(request, buildId)
    build = build_info["build"]
    tag = build_info.get("tag")

    if tag is not None and tag["value"] == tags_helper.TagValue.BAD_BUILD:
        html = render_to_string('warn_deploy_bad_build.tmpl', {
            'tag': tag,
        })
        return HttpResponse(html)

    env_promote = environs_helper.get_env_promotes_config(request, name, stage)
    pred_stage = env_promote.get('predStageName')
    if not pred_stage or pred_stage == BUILD_STAGE:
        return HttpResponse("")

    pred_env = environs_helper.get_env_by_stage(request, name, pred_stage)

    filter = {}
    filter['envId'] = [pred_env['id']]
    filter['commit'] = build['commit']
    filter['repo'] = build['repo']
    filter['oldestFirst'] = True
    filter['deployState'] = "SUCCEEDING"
    filter['pageIndex'] = 1
    filter['pageSize'] = 1
    result = deploys_helper.get_all(request, **filter)
    succeeding_deploys = result['deploys']

    if succeeding_deploys:
        return HttpResponse("")

    filter['deployState'] = "SUCCEEDED"
    result = deploys_helper.get_all(request, **filter)
    succeeded_deploys = result['deploys']

    if succeeded_deploys:
        return HttpResponse("")

    html = render_to_string('warn_no_success_deploy_in_pred.tmpl', {
        'envName': name,
        'predStageName': pred_stage,
    })

    return HttpResponse(html)
Beispiel #9
0
def _gen_deploy_summary(request, deploys, for_env=None):
    deploy_summaries = []
    for deploy in deploys:
        if for_env:
            env = for_env
        else:
            env = environs_helper.get(request, deploy['envId'])
        build_with_tag = builds_helper.get_build_and_tag(request, deploy['buildId'])
        summary = {}
        summary['deploy'] = deploy
        summary['env'] = env
        summary['build'] = build_with_tag['build']
        summary['buildTag'] = build_with_tag['tag']
        deploy_summaries.append(summary)
    return deploy_summaries
Beispiel #10
0
def gen_report(request, env, progress, sortByStatus="false"):
    agentStats = []
    firstTimeAgentStats = []
    deployStats = {}
    deprecatedDeployStats = []

    # always set the current
    deploy = deploys_helper.get(request, env['deployId'])
    build_info = builds_helper.get_build_and_tag(request, deploy["buildId"])
    stageDistMap = genStageDistMap()
    stateDistMap = genStateDistMap()
    currentDeployStat = DeployStatistics(deploy=deploy, build=build_info['build'], stageDistMap=stageDistMap,
                                         stateDistMap=stateDistMap, buildTag=build_info.get('tag'))
    deployStats[env['deployId']] = currentDeployStat

    for agent in progress["agents"]:
        if agent["firstDeploy"]:
            firstTimeAgentStats.append(addToEnvReport(request, deployStats, agent, env))
        else:
            agentStats.append(addToEnvReport(request, deployStats, agent, env))

    if sortByStatus == "true":
        agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y))

    for key, value in deployStats.iteritems():
        if key != env['deployId']:
            deprecatedDeployStats.append(value)

    provisioning_hosts = progress["provisioningHosts"]
    if IS_PINTEREST:
        basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
        if basic_cluster_info and basic_cluster_info.get('capacity'):
            hosts_in_cluster = clusters_helper.get_host_ids(request, env.get('clusterName'))
            num_to_fake = basic_cluster_info.get('capacity') - len(hosts_in_cluster)
            for i in range(num_to_fake):
                faked_host = {}
                faked_host['hostName'] = 'UNKNOWN'
                faked_host['hostId'] = 'UNKNOWN'
                faked_host['state'] = 'PROVISIONED'
                provisioning_hosts.append(faked_host)

    return AgentReport(firstTimeAgentStats=firstTimeAgentStats,
                       agentStats=agentStats,
                       currentDeployStat=currentDeployStat,
                       deprecatedDeployStats=deprecatedDeployStats,
                       missingHosts=progress["missingHosts"],
                       provisioningHosts=provisioning_hosts,
                       envName=env['envName'], stageName=env['stageName'])
Beispiel #11
0
def rollback(request, name, stage):
    query_dict = request.GET
    to_deploy_id = query_dict.get('to_deploy_id', None)
    envs = environs_helper.get_all_env_stages(request, name)
    stages, env = common.get_all_stages(envs, stage)
    result = deploys_helper.get_all(request, envId=[env['id']], pageIndex=1,
                                    pageSize=DEFAULT_ROLLBACK_DEPLOY_NUM)
    deploys = result.get("deploys")

    # remove the first deploy if exists
    if deploys:
        deploys.pop(0)

    # append the build info
    deploy_summaries = []
    branch = None
    commit = None
    build_id = None
    for deploy in deploys:
        build_info = builds_helper.get_build_and_tag(request, deploy['buildId'])
        build = build_info["build"]
        tag = build_info.get("tag", None)
        summary = {}
        summary['deploy'] = deploy
        summary['build'] = build
        summary['tag'] = tag
        if not to_deploy_id and deploy['state'] == 'SUCCEEDED':
            to_deploy_id = deploy['id']
        if to_deploy_id and to_deploy_id == deploy['id']:
            branch = build['branch']
            commit = build['commitShort']
            build_id = build['id']
        deploy_summaries.append(summary)

    html = render_to_string("environs/env_rollback.html", {
        "envs": envs,
        "stages": stages,
        "envs": envs,
        "env": env,
        "deploy_summaries": deploy_summaries,
        "to_deploy_id": to_deploy_id,
        "branch": branch,
        "commit": commit,
        "build_id": build_id,
        "csrf_token": get_token(request),
    })
    return HttpResponse(html)
Beispiel #12
0
def gen_report(request, env, progress, sortByStatus="false"):
    agentStats = []
    firstTimeAgentStats = []
    deployStats = {}
    deprecatedDeployStats = []

    # always set the current
    deploy = deploys_helper.get(request, env['deployId'])
    build_info = builds_helper.get_build_and_tag(request, deploy["buildId"])
    stageDistMap = genStageDistMap()
    stateDistMap = genStateDistMap()
    currentDeployStat = DeployStatistics(deploy=deploy,
                                         build=build_info['build'],
                                         stageDistMap=stageDistMap,
                                         stateDistMap=stateDistMap,
                                         buildTag=build_info.get('tag'))
    deployStats[env['deployId']] = currentDeployStat

    for agent in progress["agents"]:
        if agent["firstDeploy"]:
            firstTimeAgentStats.append(
                addToEnvReport(request, deployStats, agent, env))
        else:
            agentStats.append(addToEnvReport(request, deployStats, agent, env))

    if sortByStatus == "true":
        agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y))

    for key, value in deployStats.iteritems():
        if key != env['deployId']:
            deprecatedDeployStats.append(value)

    provisioning_hosts = progress["provisioningHosts"]

    return AgentReport(firstTimeAgentStats=firstTimeAgentStats,
                       agentStats=agentStats,
                       currentDeployStat=currentDeployStat,
                       deprecatedDeployStats=deprecatedDeployStats,
                       missingHosts=progress["missingHosts"],
                       provisioningHosts=provisioning_hosts,
                       envName=env['envName'],
                       stageName=env['stageName'])
Beispiel #13
0
def deploy_build(request, name, stage, build_id):
    env = environs_helper.get_env_by_stage(request, name, stage)
    current_build = None
    if env.get('deployId'):
        current_deploy = deploys_helper.get(request, env['deployId'])
        current_build = builds_helper.get_build(request, current_deploy['buildId'])
    build = builds_helper.get_build_and_tag(request, build_id)
    builds = [build]
    scm_url = systems_helper.get_scm_url(request)

    html = render_to_string('deploys/deploy_build.html', {
        "env": env,
        "builds": builds,
        "current_build": current_build,
        "scm_url": scm_url,
        "buildName": env.get('buildName'),
        "branch": env.get('branch'),
        "csrf_token": get_token(request),
    })
    return HttpResponse(html)
Beispiel #14
0
def get_all_builds(request):
    name = request.GET.get('name')
    branch = request.GET.get('branch')
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', common.DEFAULT_BUILD_SIZE))
    builds = builds_helper.get_builds_and_tags(request,
                                               name=name,
                                               branch=branch,
                                               pageIndex=index,
                                               pageSize=size)
    scm_url = systems_helper.get_scm_url(request)
    deploy_state = None
    current_build_id = request.GET.get('current_build_id', None)
    override_policy = request.GET.get('override_policy')
    deploy_id = request.GET.get('deploy_id')
    current_build = None
    if current_build_id:
        current_build = builds_helper.get_build_and_tag(
            request, current_build_id)
        current_build = current_build.get('build')
    if deploy_id:
        deploy_config = deploys_helper.get(request, deploy_id)
        if deploy_config:
            deploy_state = deploy_config.get('state', None)

    html = render_to_string(
        'builds/pick_a_build.tmpl', {
            "builds": builds,
            "current_build": current_build,
            "scm_url": scm_url,
            "buildName": name,
            "branch": branch,
            "pageIndex": index,
            "pageSize": common.DEFAULT_BUILD_SIZE,
            "disablePrevious": index <= 1,
            "disableNext": len(builds) < common.DEFAULT_BUILD_SIZE,
            "overridePolicy": override_policy,
            "deployState": deploy_state,
        })
    return HttpResponse(html)
Beispiel #15
0
def tag_build(request, id):
    if request.method == "POST":
        build_info = builds_helper.get_build_and_tag(request, id)
        current_tag = build_info.get("tag")

        if current_tag:
            tagged_build = json.loads(current_tag["metaInfo"])
            if tagged_build["id"] == id:
                log.info("There is already a tag associated with the build. Remove it")
                builds_helper.del_build_tag(request, current_tag["id"])
        tag = {"targetId":id, "targetType":"Build", "comments":request.POST["comments"]}
        value = request.POST["tag_value"]
        if value.lower() == "good":
            tag["value"] = tags_helper.TagValue.GOOD_BUILD
        elif value.lower()=="bad":
            tag["value"] = tags_helper.TagValue.BAD_BUILD
        else:
            return HttpResponse(status=400)
        builds_helper.set_build_tag(request, tag)
        return redirect("/builds/{0}/".format(id))
    else:
        return HttpResponse(status=405)
Beispiel #16
0
def gen_report(request, env, progress, sortByStatus="false"):
    agentStats = []
    firstTimeAgentStats = []
    deployStats = {}
    deprecatedDeployStats = []

    # always set the current
    deploy = deploys_helper.get(request, env['deployId'])
    build_info = builds_helper.get_build_and_tag(request, deploy["buildId"])
    stageDistMap = genStageDistMap()
    stateDistMap = genStateDistMap()
    currentDeployStat = DeployStatistics(deploy=deploy, build=build_info['build'], stageDistMap=stageDistMap,
                                         stateDistMap=stateDistMap, buildTag=build_info.get('tag'))
    deployStats[env['deployId']] = currentDeployStat

    for agent in progress["agents"]:
        if agent["firstDeploy"]:
            firstTimeAgentStats.append(addToEnvReport(request, deployStats, agent, env))
        else:
            agentStats.append(addToEnvReport(request, deployStats, agent, env))

    if sortByStatus == "true":
        agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y))

    for key, value in deployStats.iteritems():
        if key != env['deployId']:
            deprecatedDeployStats.append(value)

    provisioning_hosts = progress["provisioningHosts"]

    return AgentReport(firstTimeAgentStats=firstTimeAgentStats,
                       agentStats=agentStats,
                       currentDeployStat=currentDeployStat,
                       deprecatedDeployStats=deprecatedDeployStats,
                       missingHosts=progress["missingHosts"],
                       provisioningHosts=provisioning_hosts,
                       envName=env['envName'], stageName=env['stageName'])