Пример #1
0
    def post(self, request, name, stage):
        query_dict = request.POST
        data = {}
        if "notify_author" in query_dict:
            data["notifyAuthors"] = True
        else:
            data["notifyAuthors"] = False
        self._set_parallel(data, query_dict)
        data["priority"] = query_dict["priority"]
        data["stuckThreshold"] = int(query_dict["stuckThreshold"])
        data["successThreshold"] = float(query_dict["successThreshold"]) * 100
        data["description"] = query_dict.get("description")
        data["acceptanceType"] = query_dict["acceptanceType"]
        data["chatroom"] = query_dict.get("chatroom")
        data["buildName"] = query_dict["buildName"]
        data["branch"] = query_dict["branch"]
        data["emailRecipients"] = query_dict["email_recipients"]
        data["watchRecipients"] = query_dict["watch_recipients"]
        data["maxDeployNum"] = int(query_dict["maxDeployNum"])
        data["maxDeployDay"] = int(query_dict["maxDeployDay"])
        data["maxParallelRp"] = int(query_dict["maxParallelRp"])
        data["overridePolicy"] = query_dict["overridePolicy"]

        environs_helper.update_env_basic_config(request, name, stage, data=data)
        return self.get(request, name, stage)
Пример #2
0
def update_cluster(request, name, stage):
    params = request.POST
    cluster_info = {}
    cluster_info['capacity'] = params['capacity']
    cluster_info['base_image_id'] = params['baseImageId']
    cluster_info['provider'] = params['provider']
    cluster_info['host_type_id'] = params['hostTypeId']
    cluster_info['security_zone_id'] = params['securityZoneId']
    cluster_info['placement_id'] = ",".join(params.getlist('placementId'))
    cluster_info['config_id'] = params['configId']

    user_data_configs = parse_configs(params)
    if 'assignPublicIp' in params:
        user_data_configs['cmp_public_ip'] = 'yes'

    if 'role' in params and params['role'] != '':
        user_data_configs['cmp_role'] = params['role']

    if user_data_configs:
        clusters_helper.update_advanced_configs(request, name, stage, user_data_configs)
    clusters_helper.update_cluster(request, name, stage, cluster_info)

    env_info = {}
    if 'isDocker' in params:
        env_info['isDocker'] = True
    else:
        env_info['isDocker'] = False
    environs_helper.update_env_basic_config(request, name, stage, data=env_info)
    return get_basic_cluster(request, name, stage)
Пример #3
0
    def post(self, request, name, stage):
        log.info("Post to capacity with data {0}".format(request.body))
        try:
            cluster_name = '{}-{}'.format(name, stage)
            cluster_info = json.loads(request.body)

            log.info("Create Capacity in the provider")
            clusters_helper.create_cluster_with_env(request, cluster_name, name, stage, cluster_info)

            log.info("Associate cluster_name to environment")
            # Update cluster info
            environs_helper.update_env_basic_config(
                request, name, stage, data={"clusterName": cluster_name})

            log.info("Update capacity to the environment")
            # set up env and group relationship
            environs_helper.add_env_capacity(
                request, name, stage, capacity_type="GROUP", data=cluster_name)
            return HttpResponse("{}", content_type="application/json")
        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("Have an error {}".format(e))
            return HttpResponse(e, status=500, content_type="application/json")
Пример #4
0
def update_env_priority(request, env_name):
    if env_name == NGAPP_A:
        curr_env = NGAPP_A
        prev_env = NGAPP_B
    else:
        curr_env = NGAPP_B
        prev_env = NGAPP_A

    curr_data = {"priority": "HIGH"}
    prev_data = {"priority": "NORMAL"}
    environs_helper.update_env_basic_config(request, curr_env, "prod", data=curr_data)
    environs_helper.update_env_basic_config(request, prev_env, "prod", data=prev_data)
Пример #5
0
def delete_cluster(request, name, stage):
    cluster_name = common.get_cluster_name(request, name, stage)
    clusters_helper.delete_cluster(request, cluster_name)

    # Update isDocker and cluster name in
    env_info = {}
    env_info['clusterName'] = ''
    env_info['isDocker'] = False
    environs_helper.update_env_basic_config(request, name, stage, data=env_info)

    # Remove group and env relationship
    environs_helper.remove_env_capacity(request, name, stage, capacity_type="GROUP", data=cluster_name)
    return redirect('/env/{}/{}/config/capacity/'.format(name, stage))
Пример #6
0
    def post(self, request, name, stage):
        log.info("Post to capacity with data {0}".format(request.body))
        try:
            cluster_name = '{}-{}'.format(name, stage)
            cluster_info = json.loads(request.body)

            log.info("Create Capacity in the provider")
            clusters_helper.create_cluster(request, cluster_name, cluster_info)

            log.info("Update cluster_name to environment")
            # Update environment
            environs_helper.update_env_basic_config(request, name, stage,
                                                    data={"clusterName": cluster_name, "IsDocker": True})

            return HttpResponse("{}", content_type="application/json")
        except Exception as e:
            log.info("Have an error {}", e)
            return HttpResponse(e, status=500, content_type="application/json")
Пример #7
0
def parse_cluster_info(request, env_name, env_stage, cluster_name):
    params = request.POST
    cluster_info = {}
    cluster_info['capacity'] = params['capacity']
    cluster_info['baseImageId'] = params['baseImageId']
    cluster_info['provider'] = params['provider']
    cluster_info['hostType'] = params['hostTypeId']
    cluster_info['securityZone'] = params['securityZoneId']
    cluster_info['placement'] = ",".join(params.getlist('placementId'))

    # Update cluster name and isDocker in env
    env_info = {}
    env_info['clusterName'] = cluster_name
    if 'isDocker' in params:
        env_info['isDocker'] = True
    else:
        env_info['isDocker'] = False
    environs_helper.update_env_basic_config(request, env_name, env_stage, data=env_info)
    return cluster_info
Пример #8
0
def parse_cluster_info(request, env_name, env_stage, cluster_name):
    params = request.POST
    cluster_info = {}
    cluster_info["capacity"] = params["capacity"]
    cluster_info["baseImageId"] = params["baseImageId"]
    cluster_info["provider"] = params["provider"]
    cluster_info["hostType"] = params["hostTypeId"]
    cluster_info["securityZone"] = params["securityZoneId"]
    cluster_info["placement"] = ",".join(params.getlist("placementId"))

    # Update cluster name and isDocker in env
    env_info = {}
    env_info["clusterName"] = cluster_name
    if "isDocker" in params:
        env_info["isDocker"] = True
    else:
        env_info["isDocker"] = False
    environs_helper.update_env_basic_config(request, env_name, env_stage, data=env_info)
    return cluster_info
Пример #9
0
def update_env_priority(request, env_name):
    try:
        if env_name == NGAPP_A:
            curr_env = NGAPP_A
            prev_env = NGAPP_B
        else:
            curr_env = NGAPP_B
            prev_env = NGAPP_A

        # we only update env priority once
        if Ngapp2DeployUtils().get_finish_message_flag("prod") != "True":
            return

        curr_data = {"priority": "HIGH"}
        prev_data = {"priority": "NORMAL"}
        environs_helper.update_env_basic_config(request, curr_env, "prod", data=curr_data)
        environs_helper.update_env_basic_config(request, prev_env, "prod", data=prev_data)
    except:
        logger.error("Failed change ngapp2 deploy priority")

        # send message to the auto scaling channel
        message = "Failed to switch ngapp2 deploy priority after deploy. This may lead to health check failure. Please take actions."
        systems_helper.send_chat_message(request, "system", "autoscaling", message)
Пример #10
0
def update_env_priority(request, env_name):
    try:
        if env_name == NGAPP_A:
            curr_env = NGAPP_A
            prev_env = NGAPP_B
        else:
            curr_env = NGAPP_B
            prev_env = NGAPP_A

        # we only update env priority once
        if Ngapp2DeployUtils().get_finish_message_flag("prod") != "True":
            return

        curr_data = {"priority": "HIGH"}
        prev_data = {"priority": "NORMAL"}
        environs_helper.update_env_basic_config(request, curr_env, "prod", data=curr_data)
        environs_helper.update_env_basic_config(request, prev_env, "prod", data=prev_data)
    except:
        logger.error("Failed change ngapp2 deploy priority")

        # send message to the auto scaling channel
        message = "Failed to switch ngapp2 deploy priority after deploy. This may lead to health check failure. Please take actions."
        systems_helper.send_chat_message(request, "system", "autoscaling", message)
Пример #11
0
    def post(self, request, name, stage):
        query_dict = request.POST
        data = {}
        if "notify_author" in query_dict:
            data["notifyAuthors"] = True
        else:
            data["notifyAuthors"] = False
        data["maxParallel"] = int(query_dict["maxParallelHosts"])
        data["priority"] = query_dict["priority"]
        data["stuckThreshold"] = int(query_dict["stuckThreshold"])
        data["successThreshold"] = float(query_dict["successThreshold"]) * 100
        data["description"] = query_dict.get("description")
        data["acceptanceType"] = query_dict["acceptanceType"]
        data["chatroom"] = query_dict.get("chatroom")
        data["buildName"] = query_dict["buildName"]
        data["branch"] = query_dict["branch"]
        data["emailRecipients"] = query_dict["email_recipients"]
        data["watchRecipients"] = query_dict["watch_recipients"]
        data["maxDeployNum"] = int(query_dict["maxDeployNum"])
        data["maxDeployDay"] = int(query_dict["maxDeployDay"])

        environs_helper.update_env_basic_config(request, name, stage, data=data)
        return self.get(request, name, stage)
    def post(self, request, name, stage):
        log.info("Post to capacity with data {0}".format(request.body))
        try:
            cluster_name = '{}-{}'.format(name, stage)
            cluster_info = json.loads(request.body)

            log.info("Create Capacity in the provider")
            if 'configs' in cluster_info:
                if 'spiffe_id' in cluster_info['configs']:
                    log.error(
                        "Teletraan does not support user to change spiffe_id %s"
                        % cluster_info['spiffe_id'])
                    raise TeletraanException(
                        "Teletraan does not support user to create spiffe_id")

            clusters_helper.create_cluster_with_env(request, cluster_name,
                                                    name, stage, cluster_info)

            log.info("Associate cluster_name to environment")
            # Update cluster info
            environs_helper.update_env_basic_config(
                request, name, stage, data={"clusterName": cluster_name})

            log.info("Update capacity to the environment")
            # set up env and group relationship
            environs_helper.add_env_capacity(request,
                                             name,
                                             stage,
                                             capacity_type="GROUP",
                                             data=cluster_name)
            return HttpResponse("{}", content_type="application/json")
        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("Have an error {}".format(e))
            return HttpResponse(e, status=500, content_type="application/json")
Пример #13
0
    def post(self, request, name, stage):
        log.info("Post to capacity with data {0}".format(request.body))
        try:
            cluster_name = '{}-{}'.format(name, stage)
            cluster_info = json.loads(request.body)

            log.info("Create Capacity in the provider")
            clusters_helper.create_cluster(request, cluster_name, cluster_info)

            log.info("Update cluster_name to environment")
            # Update environment
            environs_helper.update_env_basic_config(request,
                                                    name,
                                                    stage,
                                                    data={
                                                        "clusterName":
                                                        cluster_name,
                                                        "IsDocker": True
                                                    })

            return HttpResponse("{}", content_type="application/json")
        except Exception as e:
            log.info("Have an error {}", e)
            return HttpResponse(e, status=500, content_type="application/json")
def clone_cluster(request, src_name, src_stage):
    try:
        params = request.POST
        dest_name = params.get('new_environment', src_name)
        dest_stage = params.get('new_stage', src_stage + '_clone')

        src_cluster_name = '{}-{}'.format(src_name, src_stage)
        dest_cluster_name = '{}-{}'.format(dest_name, dest_stage)

        ##0. teletraan service get src env buildName
        src_env = environs_helper.get_env_by_stage(request, src_name,
                                                   src_stage)
        build_name = src_env.get('buildName', None)
        external_id = src_env.get('externalId', None)

        ##1. teletraan service create a new env
        dest_env = environs_helper.create_env(
            request, {
                'envName': dest_name,
                'stageName': dest_stage,
                'buildName': build_name,
                'externalId': external_id
            })
        log.info('clone_cluster, created a new env %s' % dest_env)

        ##2. rodimus service get src_cluster config
        src_cluster_info = clusters_helper.get_cluster(request,
                                                       src_cluster_name)
        log.info('clone_cluster, src cluster info %s' % src_cluster_info)
        configs = src_cluster_info.get('configs')
        if configs:
            cmp_group = configs.get('cmp_group')
            if cmp_group:
                cmp_groups_set = set(cmp_group.split(','))
                cmp_groups_set.remove(src_cluster_name)
                cmp_groups_set.remove('CMP')
                cmp_groups_set.add(dest_cluster_name)
                # CMP needs to be the first in the list
                configs['cmp_group'] = ','.join(['CMP'] + list(cmp_groups_set))
                src_cluster_info['configs'] = configs

        ##3. rodimus service post create cluster
        src_cluster_info['clusterName'] = dest_cluster_name
        src_cluster_info['capacity'] = 0
        log.info('clone_cluster, request clone cluster info %s' %
                 src_cluster_info)
        dest_cluster_info = clusters_helper.create_cluster_with_env(
            request, dest_cluster_name, dest_name, dest_stage,
            src_cluster_info)
        log.info('clone_cluster, cloned cluster info %s' % dest_cluster_info)

        ##4. teletraan service update_env_basic_config
        environs_helper.update_env_basic_config(
            request,
            dest_name,
            dest_stage,
            data={"clusterName": dest_cluster_name})
        ##5. teletraan service set up env and group relationship
        environs_helper.update_env_capacity(request,
                                            dest_name,
                                            dest_stage,
                                            capacity_type="GROUP",
                                            data=[dest_cluster_name])

        ##6. get src script_config
        src_script_configs = environs_helper.get_env_script_config(
            request, src_name, src_stage)
        src_agent_configs = environs_helper.get_env_agent_config(
            request, src_name, src_stage)
        src_alarms_configs = environs_helper.get_env_alarms_config(
            request, src_name, src_stage)
        src_metrics_configs = environs_helper.get_env_metrics_config(
            request, src_name, src_stage)
        src_webhooks_configs = environs_helper.get_env_hooks_config(
            request, src_name, src_stage)

        ##8. clone all the extra configs
        if src_agent_configs:
            environs_helper.update_env_agent_config(request, dest_name,
                                                    dest_stage,
                                                    src_agent_configs)
        if src_script_configs:
            environs_helper.update_env_script_config(request, dest_name,
                                                     dest_stage,
                                                     src_script_configs)
        if src_alarms_configs:
            environs_helper.update_env_alarms_config(request, dest_name,
                                                     dest_stage,
                                                     src_alarms_configs)
        if src_metrics_configs:
            environs_helper.update_env_metrics_config(request, dest_name,
                                                      dest_stage,
                                                      src_metrics_configs)
        if src_webhooks_configs:
            environs_helper.update_env_hooks_config(request, dest_name,
                                                    dest_stage,
                                                    src_webhooks_configs)

        return HttpResponse(json.dumps(src_cluster_info),
                            content_type="application/json")
    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("Failed to clone cluster env_name: %s, stage_name: %s" %
                  (src_name, src_stage))
        log.error(traceback.format_exc())
        return HttpResponse(e, status=500, content_type="application/json")
Пример #15
0
def clone_cluster(request, src_name, src_stage):
    try:
        params = request.POST
        dest_name = params.get('new_environment', src_name)
        dest_stage = params.get('new_stage', src_stage + '_clone')

        src_cluster_name = '{}-{}'.format(src_name, src_stage)
        dest_cluster_name = '{}-{}'.format(dest_name, dest_stage)

        ##0. teletraan service get src env buildName
        src_env = environs_helper.get_env_by_stage(request, src_name, src_stage)
        build_name = src_env.get('buildName', None)

        ##1. teletraan service create a new env
        dest_env = environs_helper.create_env(request, {
            'envName': dest_name,
            'stageName': dest_stage,
            'buildName': build_name
        })
        log.info('clone_cluster, created a new env %s' % dest_env)

        ##2. rodimus service get src_cluster config
        src_cluster_info = clusters_helper.get_cluster(request, src_cluster_name)
        log.info('clone_cluster, src cluster info %s' % src_cluster_info)
        configs = src_cluster_info.get('configs')
        if configs:
            cmp_group = configs.get('cmp_group')
            if cmp_group:
                cmp_groups_set = set(cmp_group.split(','))
                cmp_groups_set.remove(src_cluster_name)
                cmp_groups_set.remove('CMP')
                cmp_groups_set.add(dest_cluster_name)
                # CMP needs to be the first in the list
                configs['cmp_group'] = ','.join(['CMP'] + list(cmp_groups_set))
                src_cluster_info['configs'] = configs

        ##3. rodimus service post create cluster
        src_cluster_info['clusterName'] = dest_cluster_name
        src_cluster_info['capacity'] = 0
        log.info('clone_cluster, request clone cluster info %s' % src_cluster_info)
        dest_cluster_info = clusters_helper.create_cluster(request, dest_cluster_name, src_cluster_info)
        log.info('clone_cluster, cloned cluster info %s' % dest_cluster_info)

        ##4. teletraan service update_env_basic_config
        environs_helper.update_env_basic_config(request, dest_name, dest_stage,
                                                data={"clusterName": dest_cluster_name}
                                                )
        ##5. teletraan service set up env and group relationship
        environs_helper.update_env_capacity(request, dest_name, dest_stage, capacity_type="GROUP",
                                            data=[dest_cluster_name])

        ##6. get src script_config
        src_script_configs = environs_helper.get_env_script_config(request, src_name, src_stage)
        src_agent_configs = environs_helper.get_env_agent_config(request, src_name, src_stage)
        src_alarms_configs = environs_helper.get_env_alarms_config(request, src_name, src_stage)
        src_metrics_configs = environs_helper.get_env_metrics_config(request, src_name, src_stage)
        src_webhooks_configs = environs_helper.get_env_hooks_config(request, src_name, src_stage)

        ##8. clone all the extra configs
        if src_agent_configs:
            environs_helper.update_env_agent_config(request, dest_name, dest_stage, src_agent_configs)
        if src_script_configs:
            environs_helper.update_env_script_config(request, dest_name, dest_stage, src_script_configs)
        if src_alarms_configs:
            environs_helper.update_env_alarms_config(request, dest_name, dest_stage, src_alarms_configs)
        if src_metrics_configs:
            environs_helper.update_env_metrics_config(request, dest_name, dest_stage, src_metrics_configs)
        if src_webhooks_configs:
            environs_helper.update_env_hooks_config(request, dest_name, dest_stage, src_webhooks_configs)

        return HttpResponse(json.dumps(src_cluster_info), content_type="application/json")
    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("Failed to clone cluster env_name: %s, stage_name: %s" % (src_name, src_stage))
        log.error(traceback.format_exc())
        return HttpResponse(e, status=500, content_type="application/json")