Ejemplo n.º 1
0
def add_cluster_server_components(request):
    cluster_name = request.data['cluster_name']
    role = request.data['role']
    ip = request.data['ip']
    hostname = request.data['hostname']
    username = request.data['username']
    password = request.data['password']
    cluster_dto = {"available":False, "cluster_name":cluster_name, "id":None, "message": None}
    existDTO = common.valid_single_server(ip, username, password)
    if(existDTO['available']==True):
        filter_server = server.objects.filter(ip=ip)
        if filter_server!=[] and len(filter_server)>0:
            cluster_dto['message'] = "IP已被使用!"
        else:
            server_obj = server(type='cluster', cluster_name=cluster_name, role=role, ip=ip, hostname=hostname, username=username, password=password)
            server_obj.save()
            items = request.data['components']
            for item in items:
                component_obj = component(server_id=server_obj, type=item['type'], port=item['port'], install_dir=item['install_dir'], data_dir=item['data_dir'], log_dir=item['log_dir'], install_bs=item['install_bs'],
                    db_username=item['db_username'], db_password=item['db_password'], web_service_name=item['web_service_name'],
                    es_memory_limit=item['es_memory_limit'], es_index_number_of_shards=item['es_index_number_of_shards'],
                    es_index_refresh_interval=item['es_index_refresh_interval'], storm_works_num_per_host=item['storm_works_num_per_host'],
                    storm_dataProcess_works_num=item['storm_dataProcess_works_num'], storm_dataIndex_works_num=item['storm_dataIndex_works_num'],
                    storm_spout_config_num =item['storm_spout_config_num'], storm_spout_dataprocess_num=item['storm_spout_dataprocess_num'],
                    storm_spout_dataindex_num=item['storm_spout_dataindex_num'], storm_bolt_default_num=item['storm_bolt_default_num'],
                    storm_bolt_rule_num=item['storm_bolt_rule_num'], storm_bolt_advanced_num=item['storm_bolt_advanced_num'],
                    storm_bolt_kafka_num=item['storm_bolt_kafka_num'], storm_bolt_es_num=item['storm_bolt_es_num'],frontend_service_name=item['frontend_service_name'],
                    es_path_data=item['es_path_data'], es_path_logs=item['es_path_logs'],storm_nimbs_bs=item['storm_nimbs_bs'])
                component_obj.save()
            cluster_dto['available'] = True
            cluster_dto['id'] = server_obj.id
    else:
        cluster_dto['message'] = existDTO['message']
    return Response(cluster_dto)
Ejemplo n.º 2
0
def add_single_server(request):
    # 输入参数 ip username password
    ip = request.data['ip']
    username = request.data['username']
    password = request.data['password']
    serverDTO = {"available":False, "id":None, "message":None, "component_bs":False, "install_bs":False}
    exist_server = server.objects.filter(type='single', ip=ip, username=username, password=password)
    if exist_server!=[] and len(exist_server)>0:
        serverDTO['available'] = True
        filter_server = json.loads(serializers.serialize("json", exist_server))[0]
        serverDTO['id'] = filter_server['pk']
        serverDTO['install_bs'] = filter_server['fields']['install_bs']
        filter_components = component.objects.filter(server_id = filter_server['pk'])
        serverDTO['component_bs'] = False
        if filter_components!=[] and len(filter_components)>0:
            serverDTO['component_bs'] = True
    else:
        existDTO = common.valid_single_server(ip, username, password)
        if(existDTO['available']==True):
            serverDTO['available'] = True
            server_obj = server(type='single', ip=ip, username=username, password=password, hostname=existDTO['hostname'])
            server_obj.save()
            serverDTO['id'] = server_obj.id
        else:
            serverDTO['message'] = existDTO['message']
    return Response(serverDTO)