Example #1
0
def get_last_ngapp2_deploy(request, curr_env, stage):
    if curr_env == NGAPP_A:
        env = environs_helper.get_env_by_stage(request, NGAPP_B, stage)
    else:
        env = environs_helper.get_env_by_stage(request, NGAPP_A, stage)
    if env:
        return deploys_helper.get(request, env['deployId'])
Example #2
0
def get_last_ngapp2_deploy(request, curr_env, stage):
    if curr_env == NGAPP_A:
        env = environs_helper.get_env_by_stage(request, NGAPP_B, stage)
    else:
        env = environs_helper.get_env_by_stage(request, NGAPP_A, stage)
    if env:
        return deploys_helper.get(request, env['deployId'])
Example #3
0
def get_all_deploys(request):
    env_stage_a = environs_helper.get_env_by_stage(request, NGAPP_A, "prod")
    env_stage_b = environs_helper.get_env_by_stage(request, NGAPP_B, "prod")
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', '%d' % DEFAULT_PAGE_SIZE))
    filter = {}
    filter['envId'] = [env_stage_a['id'], env_stage_b['id']]
    filter['pageIndex'] = index
    filter['pageSize'] = size
    result = deploys_helper.get_all(request, **filter)
    deploy_summaries = []
    for deploy in result['deploys']:
        build = builds_helper.get_build(request, deploy['buildId'])
        summary = {}
        summary['deploy'] = deploy
        summary['build'] = build
        deploy_summaries.append(summary)

    return render(
        request, 'ngapp2/ngapp2_history.html', {
            "deploy_summaries": deploy_summaries,
            "pageIndex": index,
            "pageSize": DEFAULT_PAGE_SIZE,
            "disablePrevious": index <= 1,
            "disableNext": len(result['deploys']) < DEFAULT_PAGE_SIZE,
        })
Example #4
0
def get_all_deploys(request):
    env_stage_a = environs_helper.get_env_by_stage(request, NGAPP_A, "prod")
    env_stage_b = environs_helper.get_env_by_stage(request, NGAPP_B, "prod")
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', '%d' % DEFAULT_PAGE_SIZE))
    filter = {}
    filter['envId'] = [env_stage_a['id'], env_stage_b['id']]
    filter['pageIndex'] = index
    filter['pageSize'] = size
    result = deploys_helper.get_all(request, **filter)
    deploy_summaries = []
    for deploy in result['deploys']:
        build = builds_helper.get_build(request, deploy['buildId'])
        summary = {}
        summary['deploy'] = deploy
        summary['build'] = build
        deploy_summaries.append(summary)

    return render(request, 'ngapp2/ngapp2_history.html', {
        "deploy_summaries": deploy_summaries,
        "pageIndex": index,
        "pageSize": DEFAULT_PAGE_SIZE,
        "disablePrevious": index <= 1,
        "disableNext": len(result['deploys']) < DEFAULT_PAGE_SIZE,
    })
Example #5
0
def get_all_deploys(request):
    env_stage_a = environs_helper.get_env_by_stage(request, NGAPP_A, "prod")
    env_stage_b = environs_helper.get_env_by_stage(request, NGAPP_B, "prod")
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', '%d' % DEFAULT_PAGE_SIZE))
    filter = {}
    filter['envId'] = [env_stage_a['id'], env_stage_b['id']]
    filter['pageIndex'] = index
    filter['pageSize'] = size
    result = deploys_helper.get_all(request, **filter)
    deploy_summaries = []
    for deploy in result['deploys']:
        build = builds_helper.get_build(request, deploy['buildId'])
        summary = {}
        summary['deploy'] = deploy
        summary['build'] = build
        deploy_summaries.append(summary)

    # get the rollback history from S3 between the start_timestamp and end_timestamp
    #   from the current page, assumed the deploy_summaries is in descend order.
    #   if it is the first page, set the end_timestamp to now.
    if len(deploy_summaries):
        start_timestamp = deploy_summaries[-1]['deploy']['startDate']
        if index == 1:
            end_timestamp = time.time() * 1000
        else:
            end_timestamp = deploy_summaries[0]['deploy']['startDate']
    else:
        start_timestamp = 0
        end_timestamp = time.time() * 1000

    s3 = s3_helper.S3Helper(bucket_name=S3_INTERNAL_TOOLS_BUCKET_NAME)
    history_key = get_rollback_history_key()
    rollbacks = s3.list(history_key)
    for rollback in rollbacks:
        timestamp = rollback.name[len(history_key) + 1:]
        timestamp = float(timestamp)
        if start_timestamp <= timestamp and timestamp <= end_timestamp:
            summary = json.loads(s3.download_string(rollback.name))
            deploy_summaries.append(summary)

    # order the history by deploy.start_date descend
    deploy_summaries.sort(key=lambda summary: summary['deploy']['startDate'],
                          reverse=True)

    return render(
        request, 'ngapp2/ngapp2_history.html', {
            "deploy_summaries": deploy_summaries,
            "pageIndex": index,
            "pageSize": DEFAULT_PAGE_SIZE,
            "disablePrevious": index <= 1,
            "disableNext": len(result['deploys']) < DEFAULT_PAGE_SIZE,
        })
Example #6
0
def get_all_deploys(request):
    env_stage_a = environs_helper.get_env_by_stage(request, NGAPP_A, "prod")
    env_stage_b = environs_helper.get_env_by_stage(request, NGAPP_B, "prod")
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', '%d' % DEFAULT_PAGE_SIZE))
    filter = {}
    filter['envId'] = [env_stage_a['id'], env_stage_b['id']]
    filter['pageIndex'] = index
    filter['pageSize'] = size
    result = deploys_helper.get_all(request, **filter)
    deploy_summaries = []
    for deploy in result['deploys']:
        build = builds_helper.get_build(request, deploy['buildId'])
        summary = {}
        summary['deploy'] = deploy
        summary['build'] = build
        deploy_summaries.append(summary)

    # get the rollback history from S3 between the start_timestamp and end_timestamp
    #   from the current page, assumed the deploy_summaries is in descend order.
    #   if it is the first page, set the end_timestamp to now.
    if len(deploy_summaries):
        start_timestamp = deploy_summaries[-1]['deploy']['startDate']
        if index == 1:
            end_timestamp = time.time() * 1000
        else:
            end_timestamp = deploy_summaries[0]['deploy']['startDate']
    else:
        start_timestamp = 0
        end_timestamp = time.time() * 1000

    s3 = s3_helper.S3Helper(bucket_name=S3_INTERNAL_TOOLS_BUCKET_NAME)
    history_key = get_rollback_history_key()
    rollbacks = s3.list(history_key)
    for rollback in rollbacks:
        timestamp = rollback.name[len(history_key)+1:]
        timestamp = float(timestamp)
        if start_timestamp <= timestamp and timestamp <= end_timestamp:
            summary = json.loads(s3.download_string(rollback.name))
            deploy_summaries.append(summary)

    # order the history by deploy.start_date descend
    deploy_summaries.sort(key=lambda summary: summary['deploy']['startDate'], reverse=True)

    return render(request, 'ngapp2/ngapp2_history.html', {
        "deploy_summaries": deploy_summaries,
        "pageIndex": index,
        "pageSize": DEFAULT_PAGE_SIZE,
        "disablePrevious": index <= 1,
        "disableNext": len(result['deploys']) < DEFAULT_PAGE_SIZE,
    })
Example #7
0
    def get(self, request):
        ngapp2_deploy_utils = Ngapp2DeployUtils()
        ok_to_serve = ngapp2_deploy_utils.get_ok_to_serve()

        curr_build = ok_to_serve.get('default')
        ok_to_serve_version = ok_to_serve.get('versions')
        prev_build = ngapp2_deploy_utils.get_previous_build()

        env_stage_a = environs_helper.get_env_by_stage(request, NGAPP_A,
                                                       "prod")
        env_stage_b = environs_helper.get_env_by_stage(request, NGAPP_B,
                                                       "prod")
        deploy_a = None
        build_a = None
        deploy_b = None
        if env_stage_a.get('deployId'):
            deploy_a = deploys_helper.get(request, env_stage_a['deployId'])
            build_a = builds_helper.get_build(request, deploy_a['buildId'])
        if env_stage_b.get('deployId'):
            deploy_b = deploys_helper.get(request, env_stage_b['deployId'])

        stage = getattr(NgappDeployStep,
                        ngapp2_deploy_utils.get_status_from_zk().upper())
        if stage != NgappDeployStep.SERVING_BUILD:
            deploying_env = ngapp2_deploy_utils.get_deploying_env_from_zk()
        else:
            if build_a and build_a['commit'][:7] == curr_build[:7]:
                deploying_env = env_stage_b['envName']
            else:
                deploying_env = env_stage_a['envName']

            ngapp2_deploy_utils.set_deploying_env_to_zk(deploying_env)

        if deploying_env == env_stage_a['envName']:
            curr_env = EnvStatus(env_stage_b, deploy_b, curr_build)
            prev_env = EnvStatus(env_stage_a, deploy_a, prev_build)
        else:
            curr_env = EnvStatus(env_stage_a, deploy_a, curr_build)
            prev_env = EnvStatus(env_stage_b, deploy_b, prev_build)

        return render(
            request, 'ngapp2/ngapp2_deploy.html', {
                "prev_env": prev_env,
                "curr_env": curr_env,
                "deploy_stage": stage,
                "deploying_env": deploying_env,
                "serve_version_count": len(ok_to_serve_version)
            })
    def get(self, request, name, stage):
        flavor = request.GET.get('flavor', 'AC')
        if flavor == AC_FLAVOR:
            configs = environs_helper.get_env_agent_config(request, name, stage)
        else:
            configs = environs_helper.get_env_script_config(request, name, stage)
        if request.is_ajax():
            # return data for ajax calls
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string('configs/config_map.tmpl', {
                "env": env,
                "configs": configs,
                "customization": CUSTOMIZATION[flavor],
                "csrf_token": get_token(request),
            })
            return HttpResponse(json.dumps({'html': html}), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        return render(request, 'configs/config_map.html', {
            "envs": envs,
            "env": env,
            "stages": stages,
            "configs": configs,
            "customization": CUSTOMIZATION[flavor],
        })
Example #9
0
    def get(self, request, name, stage):
        host_types = hosttypes_helper.get_by_provider(request, DEFAULT_PROVIDER)
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        security_zones = securityzones_helper.get_by_provider(request, DEFAULT_PROVIDER)
        placements = placements_helper.get_by_provider(request, DEFAULT_PROVIDER)
        base_images = baseimages_helper.get_by_name(request, DEFAULT_CMP_IMAGE)
        base_images_names = baseimages_helper.get_image_names(request, DEFAULT_PROVIDER)

        env = environs_helper.get_env_by_stage(request, name, stage)
        provider_list = baseimages_helper.get_all_providers(request)

        capacity_creation_info = {
            'environment': env,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'defaultMappings': PINTEREST_SECURITY_GROUP_PLACEMENTMAPPING,
            'baseImages': base_images,
            'baseImageNames': base_images_names,
            'defaultBaseImage': DEFAULT_CMP_IMAGE,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'providerList': provider_list,
            'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE)
        }
        # cluster manager
        return render(request, 'configs/new_capacity_adv.html', {
            'env': env,
            'capacity_creation_info': json.dumps(capacity_creation_info)})
Example #10
0
    def get(self, request, name, stage):
        if request.is_ajax():
            env = environs_helper.get_env_by_stage(request, name, stage)
            environs_helper.set_active_max_parallel(env)
            html = render_to_string('configs/env_config.tmpl', {
                "env": env,
                "csrf_token": get_token(request),
            })
            return HttpResponse(json.dumps({'html': html}), content_type="application/json")

        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)

        # get capacity to decide if we need to show the remove stage button
        show_remove = True
        # if people have already specified host capacity or group capacity but do not have cluster config
        # show capacity config page; otherwise, show cluster config page
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        if hosts:
            show_remove = False
        else:
            groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP")
            if groups:
                show_remove = False

        environs_helper.set_active_max_parallel(env)

        return render(request, 'configs/env_config.html', {
            "envs": envs,
            "env": env,
            "stages": stages,
            "show_remove": show_remove,
            "pinterest": IS_PINTEREST,
        })
Example #11
0
    def get(self, request, name, stage):
        if request.is_ajax():
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string('configs/schedule_config.tmpl', {
                "env": env,
                "csrf_token": get_token(request),
            })
            return HttpResponse(json.dumps({'html': html}),
                                content_type="application/json")

        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        agent_count = agents_helper.get_agents_total_by_env(request, env["id"])
        schedule_id = env.get('scheduleId', None)
        if schedule_id != None:
            schedule = schedules_helper.get_schedule(request, name, stage,
                                                     schedule_id)
        else:
            schedule = None
        max_parallel_number = env["maxParallel"]
        return render(
            request, 'configs/schedule_config.html', {
                "env": env,
                "schedule": schedule,
                "agent_count": agent_count,
                "max_parallel_number": max_parallel_number,
            })
Example #12
0
    def get(self, request, name, stage):
        host_types = hosttypes_helper.get_by_provider(
            request, DEFAULT_PROVIDER)
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        security_zones = securityzones_helper.get_by_provider_and_cell_name(
            request, DEFAULT_PROVIDER, DEFAULT_CELL)
        placements = placements_helper.get_by_provider_and_cell_name(
            request, DEFAULT_PROVIDER, DEFAULT_CELL)
        default_base_image = get_base_image_info_by_name(request, DEFAULT_CMP_IMAGE, DEFAULT_CELL)
        env = environs_helper.get_env_by_stage(request, name, stage)

        capacity_creation_info = {
            'environment': env,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'baseImages': default_base_image,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'defaultHostType': DEFAULT_CMP_HOST_TYPE,
            'defaultSeurityZone': DEFAULT_PLACEMENT
        }
        # cluster manager
        return render(request, 'configs/new_capacity.html', {
            'env': env,
            'capacity_creation_info': json.dumps(capacity_creation_info)})
Example #13
0
 def post(self, request, name, stage):
     configs = self.parse_configs(request.POST)
     flavor = request.POST.get('flavor', 'AC')
     if flavor == AC_FLAVOR:
         environs_helper.update_env_agent_config(request,
                                                 name,
                                                 stage,
                                                 data=configs)
         configs = environs_helper.get_env_agent_config(
             request, name, stage)
     else:
         environs_helper.update_env_script_config(request,
                                                  name,
                                                  stage,
                                                  data=configs)
         configs = environs_helper.get_env_script_config(
             request, name, stage)
     env = environs_helper.get_env_by_stage(request, name, stage)
     html = render_to_string(
         'configs/config_map.tmpl', {
             "env": env,
             "configs": configs,
             "customization": CUSTOMIZATION[flavor],
             "csrf_token": get_token(request),
         })
     return HttpResponse(json.dumps({'html': html}),
                         content_type="application/json")
Example #14
0
def compare_deploys(request, name, stage):
    start_deploy_id = request.GET.get('start_deploy', None)
    start_deploy = deploys_helper.get(request, start_deploy_id)
    start_build = builds_helper.get_build(request, start_deploy['buildId'])
    startSha = start_build['commit']
    repo = start_build['repo']

    end_deploy_id = request.GET.get('end_deploy', None)
    if end_deploy_id:
        end_deploy = deploys_helper.get(request, end_deploy_id)
    else:
        env = environs_helper.get_env_by_stage(request, name, stage)
        end_deploy = common.get_previous_deploy(request, env, start_deploy)
        if not end_deploy:
            end_deploy = start_deploy
    end_build = builds_helper.get_build(request, end_deploy['buildId'])
    endSha = end_build['commit']

    commits, truncated, new_start_sha = common.get_commits_batch(
        request, repo, startSha, endSha, keep_first=True)

    html = render_to_string(
        'builds/commits.tmpl', {
            "commits": commits,
            "start_sha": new_start_sha,
            "end_sha": endSha,
            "repo": repo,
            "truncated": truncated,
            "show_checkbox": False,
        })

    return HttpResponse(html)
Example #15
0
    def get(self, request, name, stage):
        flavor = request.GET.get('flavor', 'AC')
        if flavor == AC_FLAVOR:
            configs = environs_helper.get_env_agent_config(
                request, name, stage)
        else:
            configs = environs_helper.get_env_script_config(
                request, name, stage)
        if request.is_ajax():
            # return data for ajax calls
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string(
                'configs/config_map.tmpl', {
                    "env": env,
                    "configs": configs,
                    "customization": CUSTOMIZATION[flavor],
                    "csrf_token": get_token(request),
                })
            return HttpResponse(json.dumps({'html': html}),
                                content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        return render(
            request, 'configs/config_map.html', {
                "env": env,
                "stages": stages,
                "configs": configs,
                "customization": CUSTOMIZATION[flavor],
            })
Example #16
0
def clone_from_stage_name(request, env_name, stage_name, from_env_name,
                          from_stage_name, description):
    from_stage = environs_helper.get_env_by_stage(request, from_env_name,
                                                  from_stage_name)
    agent_configs = environs_helper.get_env_agent_config(
        request, from_env_name, from_stage_name)
    script_configs = environs_helper.get_env_script_config(
        request, from_env_name, from_stage_name)
    alarms_configs = environs_helper.get_env_alarms_config(
        request, from_env_name, from_stage_name)
    metrics_configs = environs_helper.get_env_metrics_config(
        request, from_env_name, from_stage_name)
    webhooks_configs = environs_helper.get_env_hooks_config(
        request, from_env_name, from_stage_name)
    promotes_configs = environs_helper.get_env_promotes_config(
        request, from_env_name, from_stage_name)

    new_data = {}
    new_data['envName'] = env_name
    new_data['stageName'] = stage_name
    new_data['description'] = description
    new_data['buildName'] = from_stage['buildName']
    new_data['branch'] = from_stage['branch']
    new_data['chatroom'] = from_stage['chatroom']
    new_data['maxParallel'] = from_stage['maxParallel']
    new_data['priority'] = from_stage['priority']
    new_data['stuckThreshold'] = from_stage['stuckThreshold']
    new_data['successThreshold'] = from_stage['successThreshold']
    new_data['acceptanceType'] = from_stage['acceptanceType']
    new_data['emailRecipients'] = from_stage['emailRecipients']
    new_data['notifyAuthors'] = from_stage['notifyAuthors']
    new_data['watchRecipients'] = from_stage['watchRecipients']
    new_data['maxDeployNum'] = from_stage['maxDeployNum']
    new_data['maxDeployDay'] = from_stage['maxDeployDay']
    new_data['overridePolicy'] = from_stage['overridePolicy']

    new_stage = environs_helper.create_env(request, new_data)

    # now clone all the extra configs
    if agent_configs:
        environs_helper.update_env_agent_config(request, env_name, stage_name,
                                                agent_configs)
    if script_configs:
        environs_helper.update_env_script_config(request, env_name, stage_name,
                                                 script_configs)
    if alarms_configs:
        environs_helper.update_env_alarms_config(request, env_name, stage_name,
                                                 alarms_configs)
    if metrics_configs:
        environs_helper.update_env_metrics_config(request, env_name,
                                                  stage_name, metrics_configs)
    if webhooks_configs:
        environs_helper.update_env_hooks_config(request, env_name, stage_name,
                                                webhooks_configs)
    if promotes_configs:
        environs_helper.update_env_promotes_config(request, env_name,
                                                   stage_name,
                                                   promotes_configs)

    return new_stage
Example #17
0
def compare_deploys_2(request, name, stage):
    env = environs_helper.get_env_by_stage(request, name, stage)
    configs = {}
    for key, value in request.GET.iteritems():
        if key.startswith('chkbox_'):
            index = key[len('chkbox_'):]
            configs[index] = value
    indexes = configs.keys()
    start_build_id = configs[indexes[0]]
    end_build_id = configs[indexes[1]]
    if int(indexes[0]) > int(indexes[1]):
        start_build_id = configs[indexes[1]]
        end_build_id = configs[indexes[0]]

    start_build = builds_helper.get_build(request, start_build_id)
    startSha = start_build['commit']
    repo = start_build['repo']
    end_build = builds_helper.get_build(request, end_build_id)
    endSha = end_build['commit']
    scm_url = systems_helper.get_scm_url(request)
    diffUrl = "%s/%s/compare/%s...%s" % (scm_url, repo, endSha, startSha)
    return render(
        request, 'deploys/deploy_commits.html', {
            "env": env,
            "startSha": startSha,
            "endSha": endSha,
            "repo": repo,
            "title": "Commits between the two deploys",
            "diffUrl": diffUrl,
        })
Example #18
0
def cluster_replacement_progress(request, name, stage):
    env = environs_helper.get_env_by_stage(request, name, stage)

    cluster_name = '{}-{}'.format(name, stage)
    replacement_event = clusters_helper.get_latest_cluster_replacement_progress(
        request, cluster_name)
    if not replacement_event:
        log.info("There is no on-going replacement event for cluster %s." %
                 cluster_name)
        return HttpResponse("There is no on-going replacement.")

    # basic_cluster_info = clusters_helper.get_cluster(request, cluster_name)
    # capacity = basic_cluster_info.get("capacity")
    # should not respect the cluster capacity here, when min != max, the capacity is not a right number
    asg_summary = autoscaling_groups_helper.get_autoscaling_summary(request, cluster_name)
    desired_capacity = None
    if asg_summary:
        desired_capacity = asg_summary.get("desiredCapacity")
    if not desired_capacity:
        error_msg = "cluster %s has wrong desired_capacity: %s, asg_summary: %s" % \
                    (cluster_name, desired_capacity, asg_summary)
        log.error(error_msg)
        return HttpResponse(error_msg, status=500, content_type="application/json")

    replacement_progress = get_replacement_summary(
        request, cluster_name, replacement_event, desired_capacity)

    html = render_to_string('clusters/replace_progress.tmpl', {
        "env": env,
        "replace_progress_report": replacement_progress
    })
    response = HttpResponse(html)
    return response
Example #19
0
    def get(self, request, name, stage):
        if request.is_ajax():
            env = environs_helper.get_env_by_stage(request, name, stage)
            environs_helper.set_active_max_parallel(env)
            html = render_to_string('configs/env_config.tmpl', {
                "env": env,
                "csrf_token": get_token(request),
            })
            return HttpResponse(json.dumps({'html': html}), content_type="application/json")

        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)

        # get capacity to decide if we need to show the remove stage button
        show_remove = True
        # if people have already specified host capacity or group capacity but do not have cluster config
        # show capacity config page; otherwise, show cluster config page
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        if hosts:
            show_remove = False
        else:
            groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP")
            if groups:
                show_remove = False

        environs_helper.set_active_max_parallel(env)

        return render(request, 'configs/env_config.html', {
            "env": env,
            "stages": stages,
            "show_remove": show_remove,
            "pinterest": IS_PINTEREST,
        })
Example #20
0
    def post(self, request, name, stage):
        try:
            env = environs_helper.get_env_by_stage(request, name, stage)
            cluster_name = env.get('clusterName')
            cluster_info = json.loads(request.body)
            log.info("Update Cluster Configuration with {}", cluster_info)

            cluster_name = '{}-{}'.format(name, stage)
            current_cluster = clusters_helper.get_cluster(request, cluster_name)
            log.info("getting current Cluster Configuration is {}", current_cluster)
            if 'configs' in current_cluster and 'configs' in cluster_info:
                if 'spiffe_id' in current_cluster['configs'] and 'spiffe_id' in cluster_info['configs']:
                    if current_cluster['configs']['spiffe_id'] != cluster_info['configs']['spiffe_id']:
                       log.error("Teletraan does not support user to update spiffe_id %s" % cluster_info['spiffe_id'])
                       raise TeletraanException("Teletraan does not support user to update spiffe_id")

                if 'spiffe_id' in current_cluster['configs'] and 'spiffe_id' not in cluster_info['configs']:
                    log.error("Teletraan does not support user to remove spiffe_id %s" % cluster_info['spiffe_id'])
                    raise TeletraanException("Teletraan does not support user to remove spiffe_id")

            image = baseimages_helper.get_by_id(request, cluster_info['baseImageId'])
            clusters_helper.update_cluster(request, cluster_name, cluster_info)
        except NotAuthorizedException as e:
            log.error("Have an NotAuthorizedException error {}".format(e))
            return HttpResponse(e, status=403, content_type="application/json")
        except Exception as e:
            log.error("Post to cluster configuration view has an error {}", e)
            return HttpResponse(e, status=500, content_type="application/json")
        return HttpResponse(json.dumps(cluster_info), content_type="application/json")
Example #21
0
def get_new_commits(request, name, stage):
    env = environs_helper.get_env_by_stage(request, name, stage)
    current_deploy = deploys_helper.get(request, env['deployId'])
    current_build = builds_helper.get_build(request, current_deploy['buildId'])
    startSha = current_build['commit']
    repo = current_build['repo']
    scm_url = systems_helper.get_scm_url(request)
    diffUrl = "%s/%s/compare/%s...%s" % (scm_url, repo, startSha, startSha)
    last_deploy = common.get_last_completed_deploy(request, env)
    if not last_deploy:
        return render(request, 'deploys/deploy_commits.html', {
            "env": env,
            "title": "No previous deploy found!",
            "startSha": startSha,
            "endSha": startSha,
            "repo": repo,
            "diffUrl": diffUrl,
        })

    last_build = builds_helper.get_build(request, last_deploy['buildId'])
    endSha = last_build['commit']
    diffUrl = "%s/%s/compare/%s...%s" % (scm_url, repo, endSha, startSha)
    return render(request, 'deploys/deploy_commits.html', {
        "env": env,
        "startSha": startSha,
        "endSha": endSha,
        "repo": repo,
        "title": "Commits since last deploy",
        "diffUrl": diffUrl,
    })
Example #22
0
def cluster_replacement_progress(request, name, stage):
    env = environs_helper.get_env_by_stage(request, name, stage)

    cluster_name = '{}-{}'.format(name, stage)
    replacement_event = clusters_helper.get_latest_cluster_replacement_progress(
        request, cluster_name)
    if not replacement_event:
        log.info("There is no on-going replacement event for cluster %s." %
                 cluster_name)
        return HttpResponse("There is no on-going replacement.")

    # basic_cluster_info = clusters_helper.get_cluster(request, cluster_name)
    # capacity = basic_cluster_info.get("capacity")
    # should not respect the cluster capacity here, when min != max, the capacity is not a right number
    asg_summary = autoscaling_groups_helper.get_autoscaling_summary(request, cluster_name)
    desired_capacity = None
    if asg_summary:
        desired_capacity = asg_summary.get("desiredCapacity")
    if not desired_capacity:
        error_msg = "cluster %s has wrong desired_capacity: %s, asg_summary: %s" % \
                    (cluster_name, desired_capacity, asg_summary)
        log.error(error_msg)
        return HttpResponse(error_msg, status=500, content_type="application/json")

    replacement_progress = get_replacement_summary(
        request, cluster_name, replacement_event, desired_capacity)

    html = render_to_string('clusters/replace_progress.tmpl', {
        "env": env,
        "replace_progress_report": replacement_progress
    })
    response = HttpResponse(html)
    return response
Example #23
0
    def get(self, request, name, stage):
        if request.is_ajax():
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string('configs/env_config.tmpl', {
                "env": env,
                "csrf_token": get_token(request),
            })
            return HttpResponse(json.dumps({'html': html}), content_type="application/json")

        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)

        # get capacity to decide if we need to show the remove stage button
        show_remove = True
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        if hosts:
            show_remove = False
        else:
            groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP")
            if groups:
                show_remove = False

        return render(request, 'configs/env_config.html', {
            "env": env,
            "stages": stages,
            "show_remove": show_remove,
            "pinterest": IS_PINTEREST,
        })
Example #24
0
def update_deploy_progress(request, name, stage):
    env = environs_helper.get_env_by_stage(request, name, stage)
    progress = deploys_helper.update_progress(request, name, stage)
    showMode = _fetch_param_with_cookie(request, 'showMode', MODE_COOKIE_NAME,
                                        'complete')
    sortByStatus = _fetch_param_with_cookie(request, 'sortByStatus',
                                            STATUS_COOKIE_NAME, 'true')

    report = agent_report.gen_report(request,
                                     env,
                                     progress,
                                     sortByStatus=sortByStatus)

    report.showMode = showMode
    report.sortByStatus = sortByStatus
    html = render_to_string('deploys/deploy_progress.tmpl', {
        "report": report,
        "env": env,
    })

    response = HttpResponse(html)

    # save preferences
    response.set_cookie(MODE_COOKIE_NAME, showMode)
    response.set_cookie(STATUS_COOKIE_NAME, sortByStatus)

    return response
Example #25
0
def compare_deploys_2(request, name, stage):
    env = environs_helper.get_env_by_stage(request, name, stage)
    configs = {}
    for key, value in request.GET.iteritems():
        if key.startswith('chkbox_'):
            index = key[len('chkbox_'):]
            configs[index] = value
    indexes = configs.keys()
    start_build_id = configs[indexes[0]]
    end_build_id = configs[indexes[1]]
    if int(indexes[0]) > int(indexes[1]):
        start_build_id = configs[indexes[1]]
        end_build_id = configs[indexes[0]]

    start_build = builds_helper.get_build(request, start_build_id)
    startSha = start_build['commit']
    repo = start_build['repo']
    end_build = builds_helper.get_build(request, end_build_id)
    endSha = end_build['commit']
    scm_url = systems_helper.get_scm_url(request)
    diffUrl = "%s/%s/compare/%s...%s" % (scm_url, repo, endSha, startSha)
    return render(request, 'deploys/deploy_commits.html', {
        "env": env,
        "startSha": startSha,
        "endSha": endSha,
        "repo": repo,
        "title": "Commits between the two deploys",
        "diffUrl": diffUrl,
    })
Example #26
0
def compare_deploys(request, name, stage):
    start_deploy_id = request.GET.get('start_deploy', None)
    start_deploy = deploys_helper.get(request, start_deploy_id)
    start_build = builds_helper.get_build(request, start_deploy['buildId'])
    startSha = start_build['commit']
    repo = start_build['repo']

    end_deploy_id = request.GET.get('end_deploy', None)
    if end_deploy_id:
        end_deploy = deploys_helper.get(request, end_deploy_id)
    else:
        env = environs_helper.get_env_by_stage(request, name, stage)
        end_deploy = common.get_previous_deploy(request, env, start_deploy)
        if not end_deploy:
            end_deploy = start_deploy
    end_build = builds_helper.get_build(request, end_deploy['buildId'])
    endSha = end_build['commit']

    commits, truncated, new_start_sha = common.get_commits_batch(request, repo, startSha,
                                                                 endSha, keep_first=True)

    html = render_to_string('builds/commits.tmpl', {
        "commits": commits,
        "start_sha": new_start_sha,
        "end_sha": endSha,
        "repo": repo,
        "truncated": truncated,
        "show_checkbox": False,
    })

    return HttpResponse(html)
Example #27
0
    def get_deploy_status(self, request, name, stage):
        env = environs_helper.get_env_by_stage(request, name, stage)
        deploy = deploys_helper.get(request, env['deployId'])
        build = builds_helper.get_build(request, deploy['buildId'])
        canary_message = None
        if is_prod() and stage == "canary" and deploy['state'] == "SUCCEEDING":
            expected = build['commit']
            running_build = self.get_canary_version_internal()
            if expected[:7] == running_build[:7]:
                canary_message = \
                    "curl https://canary.pinterest.com. " \
                    "Canary host is running on the correct version: {}".format(expected[:7])
            else:
                canary_message = "curl https://canary.pinterest.com. Running version: {}, " \
                                 "Expect version: {}".format(running_build[:7], expected[:7])
                deploy['state'] = "RUNNING"

        if deploy['state'] == "SUCCEEDING" or deploy['state'] == "SUCCEEDED":
            state = "succeeding"
        elif deploy['state'] == "ABORTED" or deploy['state'] == "FAILING":
            state = "failing"
        else:
            state = "running"
        return state, render(
            request, 'ngapp2/ngapp2_deploy.tmpl', {
                "build": build,
                "env": env,
                "deploy": deploy,
                "canaryMessage": canary_message
            })
Example #28
0
    def get(self, request, name, stage):
        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
            groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP")
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string("configs/capacity.tmpl", {
                "env": env,
                "hosts": ','.join(hosts),
                "groups": ','.join(groups),
                "csrf_token": get_token(request),

            })
            return HttpResponse(json.dumps({'html': html}), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        groups = environs_helper.get_env_capacity(request, name, stage, capacity_type="GROUP")
        return render(request, 'configs/capacity.html', {
            "env": env,
            "stages": stages,
            "hosts": ','.join(hosts),
            "groups": ','.join(groups),
        })
Example #29
0
    def get(self, request, name, stage):
        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request,
                                                     name,
                                                     stage,
                                                     capacity_type="HOST")
            groups = common.get_non_cmp_group(request, name, stage)
            env = environs_helper.get_env_by_stage(request, name, stage)
            html = render_to_string(
                "configs/capacity.tmpl", {
                    "env": env,
                    "hosts": ','.join(hosts),
                    "groups": ','.join(groups),
                    "csrf_token": get_token(request),
                })
            return HttpResponse(json.dumps({'html': html}),
                                content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request,
                                                 name,
                                                 stage,
                                                 capacity_type="HOST")
        groups = common.get_non_cmp_group(request, name, stage)
        return render(
            request, 'configs/capacity.html', {
                "env": env,
                "stages": stages,
                "hosts": ','.join(hosts),
                "groups": ','.join(groups),
            })
Example #30
0
def get_new_commits(request, name, stage):
    env = environs_helper.get_env_by_stage(request, name, stage)
    current_deploy = deploys_helper.get(request, env['deployId'])
    current_build = builds_helper.get_build(request, current_deploy['buildId'])
    startSha = current_build['commit']
    repo = current_build['repo']
    scm_url = systems_helper.get_scm_url(request)
    diffUrl = "%s/%s/compare/%s...%s" % (scm_url, repo, startSha, startSha)
    last_deploy = common.get_last_completed_deploy(request, env)
    if not last_deploy:
        return render(
            request, 'deploys/deploy_commits.html', {
                "env": env,
                "title": "No previous deploy found!",
                "startSha": startSha,
                "endSha": startSha,
                "repo": repo,
                "diffUrl": diffUrl,
            })

    last_build = builds_helper.get_build(request, last_deploy['buildId'])
    endSha = last_build['commit']
    diffUrl = "%s/%s/compare/%s...%s" % (scm_url, repo, endSha, startSha)
    return render(
        request, 'deploys/deploy_commits.html', {
            "env": env,
            "startSha": startSha,
            "endSha": endSha,
            "repo": repo,
            "title": "Commits since last deploy",
            "diffUrl": diffUrl,
        })
Example #31
0
    def get_deploy_status(self, request, name, stage):
        env = environs_helper.get_env_by_stage(request, name, stage)
        deploy = deploys_helper.get(request, env['deployId'])
        build = builds_helper.get_build(request, deploy['buildId'])
        canary_message = None
        if is_prod() and stage == "canary" and deploy['state'] == "SUCCEEDING":
            expected = build['commit']
            running_build = self.get_canary_version_internal()
            if expected[:7] == running_build[:7]:
                canary_message = \
                    "curl https://canary.pinterest.com. " \
                    "Canary host is running on the correct version: {}".format(expected[:7])
            else:
                canary_message = "curl https://canary.pinterest.com. Running version: {}, " \
                                 "Expect version: {}".format(running_build[:7], expected[:7])
                deploy['state'] = "RUNNING"

        if deploy['state'] == "SUCCEEDING" or deploy['state'] == "SUCCEEDED":
            state = "succeeding"
        elif deploy['state'] == "ABORTED" or deploy['state'] == "FAILING":
            state = "failing"
        else:
            state = "running"
        return state, render(request, 'ngapp2/ngapp2_deploy.tmpl', {
            "build": build,
            "env": env,
            "deploy": deploy,
            "canaryMessage": canary_message
        })
Example #32
0
def get_deploy(request, name, stage, deploy_id):
    deploy = deploys_helper.get(request, deploy_id)
    build = builds_helper.get_build(request, deploy['buildId'])
    env = environs_helper.get_env_by_stage(request, name, stage)
    return render(request, 'environs/env_deploy_details.html', {
        "deploy": deploy,
        "build": build,
        "env": env,
    })
Example #33
0
def view_cluster_replacement_schedule(request, name, stage, replacement_id):
    env = environs_helper.get_env_by_stage(request, name, stage)
    cluster_name = '{}-{}'.format(name, stage)
    schedule = clusters_helper.get_cluster_replacement_schedule(
        request, cluster_name, replacement_id)
    return render(request, 'clusters/replace_schedule.html', {
        "env": env,
        "schedule": schedule
    })
def view_cluster_replacement_schedule(request, name, stage, replacement_id):
    env = environs_helper.get_env_by_stage(request, name, stage)
    cluster_name = '{}-{}'.format(name, stage)
    schedule = clusters_helper.get_cluster_replacement_schedule(
        request, cluster_name, replacement_id)
    return render(request, 'clusters/replace_schedule.html', {
        "env": env,
        "schedule": schedule
    })
Example #35
0
def get_deploy(request, name, stage, deploy_id):
    deploy = deploys_helper.get(request, deploy_id)
    build = builds_helper.get_build(request, deploy['buildId'])
    env = environs_helper.get_env_by_stage(request, name, stage)
    return render(request, 'environs/env_deploy_details.html', {
        "deploy": deploy,
        "build": build,
        "env": env,
    })
Example #36
0
    def get(self, request):
        ngapp2_deploy_utils = Ngapp2DeployUtils()
        ok_to_serve = ngapp2_deploy_utils.get_ok_to_serve()

        curr_build = ok_to_serve.get('default')
        ok_to_serve_version = ok_to_serve.get('versions')
        prev_build = ngapp2_deploy_utils.get_previous_build()

        env_stage_a = environs_helper.get_env_by_stage(request, NGAPP_A, "prod")
        env_stage_b = environs_helper.get_env_by_stage(request, NGAPP_B, "prod")
        deploy_a = None
        build_a = None
        deploy_b = None
        if env_stage_a.get('deployId'):
            deploy_a = deploys_helper.get(request, env_stage_a['deployId'])
            build_a = builds_helper.get_build(request, deploy_a['buildId'])
        if env_stage_b.get('deployId'):
            deploy_b = deploys_helper.get(request, env_stage_b['deployId'])

        stage = getattr(NgappDeployStep, ngapp2_deploy_utils.get_status_from_zk().upper())
        if stage != NgappDeployStep.SERVING_BUILD:
            deploying_env = ngapp2_deploy_utils.get_deploying_env_from_zk()
        else:
            if build_a and build_a['commit'][:7] == curr_build[:7]:
                deploying_env = env_stage_b['envName']
            else:
                deploying_env = env_stage_a['envName']

            ngapp2_deploy_utils.set_deploying_env_to_zk(deploying_env)

        if deploying_env == env_stage_a['envName']:
            curr_env = EnvStatus(env_stage_b, deploy_b, curr_build)
            prev_env = EnvStatus(env_stage_a, deploy_a, prev_build)
        else:
            curr_env = EnvStatus(env_stage_a, deploy_a, curr_build)
            prev_env = EnvStatus(env_stage_b, deploy_b, prev_build)

        return render(request, 'ngapp2/ngapp2_deploy.html', {
            "prev_env": prev_env,
            "curr_env": curr_env,
            "deploy_stage": stage,
            "deploying_env": deploying_env,
            "serve_version_count": len(ok_to_serve_version)
        })
Example #37
0
def get_pred_deploys(request, name, stage):
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', DEFAULT_PAGE_SIZE))
    env = environs_helper.get_env_by_stage(request, name, stage)
    env_promote = environs_helper.get_env_promotes_config(request, name, stage)

    show_lock = False
    predStage = env_promote.get('predStage')
    if env_promote['type'] != "MANUAL" and predStage:
        show_lock = True

    current_startDate = 0
    if not predStage or predStage == "BUILD":
        deploys = []
    else:
        pred_env = environs_helper.get_env_by_stage(request, name, predStage)
        result = deploys_helper.get_all(request,
                                        envId=[pred_env['id']],
                                        pageIndex=index,
                                        pageSize=size)
        deploys = result["deploys"]
        if env.get('deployId'):
            deploy = deploys_helper.get(request, env['deployId'])
            build = builds_helper.get_build(request, deploy['buildId'])
            current_startDate = build['publishDate']

    deploy_wrappers = []
    for deploy in deploys:
        build = builds_helper.get_build(request, deploy['buildId'])
        if build['publishDate'] > current_startDate:
            deploy_wrapper = {}
            deploy_wrapper['deploy'] = deploy
            deploy_wrapper['build'] = build
            deploy_wrappers.append(deploy_wrapper)

    html = render_to_string(
        'deploys/simple_pred_deploys.tmpl', {
            "deploy_wrappers": deploy_wrappers,
            "envName": name,
            "stageName": predStage,
            "show_lock": show_lock,
            "current_startDate": current_startDate,
        })
    return HttpResponse(html)
Example #38
0
    def get(self, request, name, stage):
        # cluster manager
        provider_list = None
        basic_cluster_info = None
        create_new = False
        adv = False
        env = environs_helper.get_env_by_stage(request, name, stage)
        if IS_PINTEREST:
            provider_list = baseimages_helper.get_all_providers(request)
            basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
            if basic_cluster_info:
                base_image_id = basic_cluster_info.get('baseImageId')
                base_image = baseimages_helper.get_by_id(request, base_image_id)
                if base_image.get('abstract_name') != 'CMP-DOCKER':
                    adv = True

            params = request.GET
            if params.get('adv'):
                adv = params.get('adv')
            if params.get('create_new'):
                create_new = params.get('create_new')

        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
            groups = common.get_non_cmp_group(request, name, stage)
            html = render_to_string("configs/capacity.tmpl", {
                "env": env,
                "hosts": ','.join(hosts),
                "groups": ','.join(groups),
                "csrf_token": get_token(request),
                'is_pinterest': IS_PINTEREST,
                'provider_list': provider_list,
                'basic_cluster_info': basic_cluster_info,
                'adv': adv,
                'create_new': create_new,
            })
            return HttpResponse(json.dumps({'html': html}), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        groups = common.get_non_cmp_group(request, name, stage)
        return render(request, 'configs/capacity.html', {
            "envs": envs,
            "env": env,
            "stages": stages,
            "hosts": ','.join(hosts),
            "groups": ','.join(groups),
            'is_pinterest': IS_PINTEREST,
            'provider_list': provider_list,
            'basic_cluster_info': basic_cluster_info,
            'adv': adv,
            'create_new': create_new,
        })
Example #39
0
def get_pred_deploys(request, name, stage):
    index = int(request.GET.get('page_index', '1'))
    size = int(request.GET.get('page_size', DEFAULT_PAGE_SIZE))
    env = environs_helper.get_env_by_stage(request, name, stage)
    env_promote = environs_helper.get_env_promotes_config(request, name, stage)

    show_lock = False
    predStage = env_promote.get('predStage')
    if env_promote['type'] != "MANUAL" and predStage:
        show_lock = True

    current_startDate = 0
    if not predStage or predStage == "BUILD":
        deploys = []
    else:
        pred_env = environs_helper.get_env_by_stage(request, name, predStage)
        result = deploys_helper.get_all(request, envId=[pred_env['id']], pageIndex=index,
                                        pageSize=size)
        deploys = result["deploys"]
        if env.get('deployId'):
            deploy = deploys_helper.get(request, env['deployId'])
            build = builds_helper.get_build(request, deploy['buildId'])
            current_startDate = build['publishDate']

    deploy_wrappers = []
    for deploy in deploys:
        build = builds_helper.get_build(request, deploy['buildId'])
        if build['publishDate'] > current_startDate:
            deploy_wrapper = {}
            deploy_wrapper['deploy'] = deploy
            deploy_wrapper['build'] = build
            deploy_wrappers.append(deploy_wrapper)

    html = render_to_string('deploys/simple_pred_deploys.tmpl', {
        "deploy_wrappers": deploy_wrappers,
        "envName": name,
        "stageName": predStage,
        "show_lock": show_lock,
        "current_startDate": current_startDate,
    })
    return HttpResponse(html)
Example #40
0
 def post(self, request, name, stage):
     try:
         env = environs_helper.get_env_by_stage(request, name, stage)
         cluster_name = env.get('clusterName')
         cluster_info = json.loads(request.body)
         log.info("Update Cluster Configuration with {}", cluster_info)
         image = baseimages_helper.get_by_id(request, cluster_info['baseImageId'])
         clusters_helper.update_cluster(request, cluster_name, cluster_info)
     except Exception as e:
         log.info("Post to cluster configuration view has an error {}", e)
         return HttpResponse(e, status=500, content_type="application/json")
     return HttpResponse(json.dumps(cluster_info), content_type="application/json")
Example #41
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)
Example #42
0
    def get(self, request, name, stage, hostname):
        agents = agents_helper.get_agents_by_host(request, hostname)
        env = environs_helper.get_env_by_stage(request, name, stage)
        host = environ_hosts_helper.get_host_by_env_and_hostname(
            request, name, stage, hostname)
        show_terminate = False
        asg = ''
        if host and host.get('hostId'):
            if host.get('state') != 'PENDING_TERMINATE' and host.get(
                    'state') != 'TERMINATING' and host.get(
                        'state') != 'TERMINATED':
                show_terminate = True

        cluster_provider = clusters_helper.get_cluster_provider(
            request, name, stage)
        if cluster_provider == 'null':
            cluster_provider = None

        # TODO deprecated it
        if host and host.get('groupName'):
            group_info = groups_helper.get_group_info(request,
                                                      host.get('groupName'))
            if group_info and group_info["asgStatus"] == "ENABLED":
                asg = host.get('groupName')

        # gather the env name and stage info
        agent_wrappers = []
        for agent in agents:
            agent_wrapper = {}
            agent_wrapper["agent"] = agent
            envId = agent['envId']
            agent_env = environs_helper.get(request, envId)
            agent_wrapper["env"] = env
            agent_wrapper["error"] = ""
            if agent.get('lastErrno', 0) != 0:
                agent_wrapper["error"] = agents_helper.get_agent_error(
                    request, agent_env['envName'], agent_env['stageName'],
                    hostname)
            agent_wrappers.append(agent_wrapper)

        return render(
            request, 'hosts/host_details.html', {
                'env_name': name,
                'stage_name': stage,
                'hostname': hostname,
                'host': host,
                'agent_wrappers': agent_wrappers,
                'show_terminate': show_terminate,
                'cluster_provider': cluster_provider,
                'asg_group': asg,
                'pinterest': IS_PINTEREST,
            })
Example #43
0
 def post(self, request, name, stage):
     try:
         env = environs_helper.get_env_by_stage(request, name, stage)
         cluster_name = env.get('clusterName')
         cluster_info = json.loads(request.body)
         log.info("Update Cluster Configuration with {}", cluster_info)
         image = baseimages_helper.get_by_id(
             request, cluster_info['baseImageId'])
         clusters_helper.update_cluster(request, cluster_name, cluster_info)
     except Exception as e:
         log.info("Post to cluster configuration view has an error {}", e)
         return HttpResponse(e, status=500, content_type="application/json")
     return HttpResponse(json.dumps(cluster_info), content_type="application/json")
Example #44
0
def clone_from_stage_name(request, env_name, stage_name, from_env_name, from_stage_name,
                          description, external_id):
    from_stage = environs_helper.get_env_by_stage(request, from_env_name, from_stage_name)
    agent_configs = environs_helper.get_env_agent_config(request, from_env_name, from_stage_name)
    script_configs = environs_helper.get_env_script_config(request, from_env_name, from_stage_name)
    alarms_configs = environs_helper.get_env_alarms_config(request, from_env_name, from_stage_name)
    metrics_configs = environs_helper.get_env_metrics_config(request, from_env_name,
                                                             from_stage_name)
    webhooks_configs = environs_helper.get_env_hooks_config(request, from_env_name, from_stage_name)
    promotes_configs = environs_helper.get_env_promotes_config(request, from_env_name,
                                                               from_stage_name)

    new_data = {}
    new_data['envName'] = env_name
    new_data['stageName'] = stage_name
    new_data['description'] = description
    new_data['buildName'] = from_stage['buildName']
    new_data['branch'] = from_stage['branch']
    new_data['chatroom'] = from_stage['chatroom']
    new_data['maxParallel'] = from_stage['maxParallel']
    new_data['priority'] = from_stage['priority']
    new_data['stuckThreshold'] = from_stage['stuckThreshold']
    new_data['successThreshold'] = from_stage['successThreshold']
    new_data['acceptanceType'] = from_stage['acceptanceType']
    new_data['emailRecipients'] = from_stage['emailRecipients']
    new_data['notifyAuthors'] = from_stage['notifyAuthors']
    new_data['watchRecipients'] = from_stage['watchRecipients']
    new_data['maxDeployNum'] = from_stage['maxDeployNum']
    new_data['maxDeployDay'] = from_stage['maxDeployDay']
    new_data['overridePolicy'] = from_stage['overridePolicy']
    new_data['externalId'] = external_id

    new_stage = environs_helper.create_env(request, new_data)

    # now clone all the extra configs
    if agent_configs:
        environs_helper.update_env_agent_config(request, env_name, stage_name, agent_configs)
    if script_configs:
        environs_helper.update_env_script_config(request, env_name, stage_name, script_configs)
    if alarms_configs:
        environs_helper.update_env_alarms_config(request, env_name, stage_name, alarms_configs)
    if metrics_configs:
        environs_helper.update_env_metrics_config(request, env_name, stage_name, metrics_configs)
    if webhooks_configs:
        environs_helper.update_env_hooks_config(request, env_name, stage_name, webhooks_configs)
    if promotes_configs:
        environs_helper.update_env_promotes_config(request, env_name, stage_name, promotes_configs)

    return new_stage
Example #45
0
def get_duplicate_commit_deploy_message(request, name, stage, buildId):
    env = environs_helper.get_env_by_stage(request, name, stage)
    if env.get('deployId') is None:
        return HttpResponse('')

    current_deploy = deploys_helper.get_current(request, name, stage)
    current_build = builds_helper.get_build(request, current_deploy['buildId'])
    current_commit = current_build['commit']

    next_build = builds_helper.get_build(request, buildId)
    next_commit = next_build['commit']

    if current_commit == next_commit:
        return render(request, 'deploys/duplicate_commit_deploy_message.tmpl',
                      {"commit": next_build['commitShort']})
    return HttpResponse('')
Example #46
0
    def get(self, request, name, stage):
        env = environs_helper.get_env_by_stage(request, name, stage)
        env_promote = environs_helper.get_env_promotes_config(request, name, stage)
        current_build = None
        if 'deployId' in env and env['deployId']:
            deploy = deploys_helper.get(request, env['deployId'])
            current_build = builds_helper.get_build(request, deploy['buildId'])

        return render(request, 'deploys/new_deploy.html', {
            "env": env,
            "env_promote": env_promote,
            "buildName": env['buildName'],
            "current_build": current_build,
            "pageIndex": 1,
            "pageSize": common.DEFAULT_BUILD_SIZE,
        })
Example #47
0
def get_duplicate_commit_deploy_message(request, name, stage, buildId):
    env = environs_helper.get_env_by_stage(request, name, stage)
    if env.get('deployId') is None:
        return HttpResponse('')

    current_deploy = deploys_helper.get_current(request, name, stage)
    current_build = builds_helper.get_build(request, current_deploy['buildId'])
    current_commit = current_build['commit']

    next_build = builds_helper.get_build(request, buildId)
    next_commit = next_build['commit']

    if current_commit == next_commit:
        return render(request, 'deploys/duplicate_commit_deploy_message.tmpl',{
                      "commit":next_build['commitShort']})
    return HttpResponse('')
 def post(self, request, name, stage):
     configs = self.parse_configs(request.POST)
     flavor = request.POST.get('flavor', 'AC')
     if flavor == AC_FLAVOR:
         environs_helper.update_env_agent_config(request, name, stage, data=configs)
         configs = environs_helper.get_env_agent_config(request, name, stage)
     else:
         environs_helper.update_env_script_config(request, name, stage, data=configs)
         configs = environs_helper.get_env_script_config(request, name, stage)
     env = environs_helper.get_env_by_stage(request, name, stage)
     html = render_to_string('configs/config_map.tmpl', {
         "env": env,
         "configs": configs,
         "customization": CUSTOMIZATION[flavor],
         "csrf_token": get_token(request),
     })
     return HttpResponse(json.dumps({'html': html}), content_type="application/json")
Example #49
0
    def get(self, request, name, stage):

        cluster_name = '{}-{}'.format(name, stage)
        current_cluster = clusters_helper.get_cluster(request, cluster_name)
        host_types = hosttypes_helper.get_by_provider(
            request, DEFAULT_PROVIDER)
        current_image = baseimages_helper.get_by_id(
            request, current_cluster['baseImageId'])
        current_cluster['baseImageName'] = current_image['abstract_name']
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        cells = cells_helper.get_by_provider(request, current_cluster['provider'])
        security_zones = securityzones_helper.get_by_provider_and_cell_name(
            request, current_cluster['provider'], current_cluster['cellName'])
        placements = placements_helper.get_by_provider_and_cell_name(
            request, current_cluster['provider'], current_cluster['cellName'])
        base_images = get_base_image_info_by_name(
            request, current_image['abstract_name'], current_cluster['cellName'])
        base_images_names = baseimages_helper.get_image_names(
            request, current_cluster['provider'], current_cluster['cellName'])

        env = environs_helper.get_env_by_stage(request, name, stage)
        provider_list = baseimages_helper.get_all_providers(request)

        capacity_creation_info = {
            'environment': env,
            'cells': cells,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'baseImages': base_images,
            'baseImageNames': base_images_names,
            'defaultBaseImage': DEFAULT_CMP_IMAGE,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'providerList': provider_list,
            'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE),
            'currentCluster': current_cluster
        }
        return render(request, 'clusters/cluster_configuration.html', {
            'env': env,
            'capacity_creation_info': json.dumps(capacity_creation_info),
            'user_data_config_settings_wiki': USER_DATA_CONFIG_SETTINGS_WIKI,
            'is_pinterest': IS_PINTEREST})
Example #50
0
    def get(self, request, name, stage, hostname):
        agents = agents_helper.get_agents_by_host(request, hostname)
        env = environs_helper.get_env_by_stage(request, name, stage)
        host = environ_hosts_helper.get_host_by_env_and_hostname(request, name, stage, hostname)
        show_terminate = False
        asg = ''
        if host and host.get('hostId'):
            if host.get('state') != 'PENDING_TERMINATE' and host.get('state') != 'TERMINATING' and host.get('state') != 'TERMINATED':
                show_terminate = True

        cluster_provider = clusters_helper.get_cluster_provider(request, name, stage)
        if cluster_provider == 'null':
            cluster_provider = None

        # TODO deprecated it
        if host and host.get('groupName'):
            group_info = groups_helper.get_group_info(request, host.get('groupName'))
            if group_info and group_info["asgStatus"] == "ENABLED":
                asg = host.get('groupName')

        # gather the env name and stage info
        agent_wrappers = []
        for agent in agents:
            agent_wrapper = {}
            agent_wrapper["agent"] = agent
            envId = agent['envId']
            agent_env = environs_helper.get(request, envId)
            agent_wrapper["env"] = env
            agent_wrapper["error"] = ""
            if agent.get('lastErrno', 0) != 0:
                agent_wrapper["error"] = agents_helper.get_agent_error(request, agent_env['envName'],
                                                                       agent_env['stageName'], hostname)
            agent_wrappers.append(agent_wrapper)

        return render(request, 'hosts/host_details.html', {
            'env_name': name,
            'stage_name': stage,
            'hostname': hostname,
            'host': host,
            'agent_wrappers': agent_wrappers,
            'show_terminate': show_terminate,
            'cluster_provider': cluster_provider,
            'asg_group': asg,
            'pinterest': IS_PINTEREST,
        })
    def get(self, request, name, stage):
        host_types = hosttypes_helper.get_by_provider(request,
                                                      DEFAULT_PROVIDER)
        for host_type in host_types:
            host_type['mem'] = float(host_type['mem']) / 1024

        security_zones = securityzones_helper.get_by_provider_and_cell_name(
            request, DEFAULT_PROVIDER, DEFAULT_CELL)
        placements = placements_helper.get_by_provider_and_cell_name(
            request, DEFAULT_PROVIDER, DEFAULT_CELL)
        cells = cells_helper.get_by_provider(request, DEFAULT_PROVIDER)
        base_images = get_base_image_info_by_name(request, DEFAULT_CMP_IMAGE,
                                                  DEFAULT_CELL)
        base_images_names = baseimages_helper.get_image_names(
            request, DEFAULT_PROVIDER, DEFAULT_CELL)

        env = environs_helper.get_env_by_stage(request, name, stage)
        provider_list = baseimages_helper.get_all_providers(request)

        capacity_creation_info = {
            'environment': env,
            'hostTypes': host_types,
            'securityZones': security_zones,
            'placements': placements,
            'cells': cells,
            'baseImages': base_images,
            'baseImageNames': base_images_names,
            'defaultBaseImage': DEFAULT_CMP_IMAGE,
            'defaultCMPConfigs': get_default_cmp_configs(name, stage),
            'defaultProvider': DEFAULT_PROVIDER,
            'defaultCell': DEFAULT_CELL,
            'defaultHostType': DEFAULT_CMP_HOST_TYPE,
            'defaultSeurityZone': DEFAULT_PLACEMENT,
            'providerList': provider_list,
            'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE)
        }
        # cluster manager
        return render(
            request, 'configs/new_capacity_adv.html', {
                'env': env,
                'capacity_creation_info': json.dumps(capacity_creation_info),
                'user_data_config_settings_wiki':
                USER_DATA_CONFIG_SETTINGS_WIKI,
                'is_pinterest': IS_PINTEREST
            })
Example #52
0
def get_hotfix(request, name, stage, id):
    env = environs_helper.get_env_by_stage(request, name, stage)
    hotfix = hotfixs_helper.get(request, id)
    deploy = deploys_helper.get(request, hotfix['baseDeployId'])
    build = builds_helper.get_build(request, deploy['buildId'])
    urlPattern = systems_helper.get_url_pattern(request)
    commits = []
    _create_commits(commits, urlPattern['template'], hotfix)
    jenkins_url = "%s/%s/%s" % (BUILD_URL, hotfix['jobName'],
                                hotfix['jobNum']) if hotfix['jobName'] and hotfix['jobNum'] else ''
    return render(request, 'hotfixs/hotfix_detail.html', {
        "env": env,
        "hotfix": hotfix,
        "commits": commits,
        "deploy": deploy,
        "build": build,
        "jenkins_url": jenkins_url
    })
Example #53
0
def sendStartMessage(request, user, envName, stageName, notifyAuthor):
    env = environs_helper.get_env_by_stage(request, envName, stageName)
    deploy = deploys_helper.get(request, env['deployId'])
    build = builds_helper.get_build(request, deploy['buildId'])
    branch = build['branch']
    Ngapp2DeployUtils().reset_finish_message_flag(stageName)
    message = "{}/{}: deploy of {}/{} started. See details <{}|here>.".format(
        envName, stageName, branch, build['commitShort'], get_deploy_url(envName, stageName))
    systems_helper.send_chat_message(request, user.name, get_slack_channel(), message)

    if not notifyAuthor:
        return

    author_msg = get_notify_authors_message(request, env, build)
    if author_msg and is_prod():
        systems_helper.send_chat_message(request, user.name, get_slack_channel(), author_msg)
    elif author_msg:
        logger.info("get author list message:{}".format(author_msg))
Example #54
0
def sendStartMessage(request, user, envName, stageName, notifyAuthor):
    env = environs_helper.get_env_by_stage(request, envName, stageName)
    deploy = deploys_helper.get(request, env['deployId'])
    build = builds_helper.get_build(request, deploy['buildId'])
    branch = build['branch']
    Ngapp2DeployUtils().reset_finish_message_flag(stageName)
    message = "{}/{}: deploy of {}/{} started. See details <{}|here>.".format(
        envName, stageName, branch, build['commitShort'], get_deploy_url(envName, stageName))
    systems_helper.send_chat_message(request, user.name, get_slack_channel(), message)

    if not notifyAuthor:
        return

    author_msg = get_notify_authors_message(request, env, build)
    if author_msg and is_prod():
        systems_helper.send_chat_message(request, user.name, get_slack_channel(), author_msg)
    elif author_msg:
        logger.info("get author list message:{}".format(author_msg))
Example #55
0
    def get(self, request, name, stage):
        env = environs_helper.get_env_by_stage(request, name, stage)
        env_promote = environs_helper.get_env_promotes_config(
            request, name, stage)
        current_build = None
        if 'deployId' in env and env['deployId']:
            deploy = deploys_helper.get(request, env['deployId'])
            current_build = builds_helper.get_build(request, deploy['buildId'])

        return render(
            request, 'deploys/new_deploy.html', {
                "env": env,
                "env_promote": env_promote,
                "buildName": env['buildName'],
                "current_build": current_build,
                "pageIndex": 1,
                "pageSize": common.DEFAULT_BUILD_SIZE,
            })
Example #56
0
def deploy_commit(request, name, stage, commit):
    env = environs_helper.get_env_by_stage(request, name, stage)
    builds = builds_helper.get_builds(request, commit=commit)
    current_build = None
    if env.get('deployId'):
        deploy = deploys_helper.get(request, env['deployId'])
        current_build = builds_helper.get_build(request, deploy['buildId'])
    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)