def update_service_properties_by_folder(export_file, url, token,service,update_properties):
    try:
        file = open(export_file, 'a+')
        service_name = service['serviceName']

        common_utils.file_write_format(file, common_utils.printSplitLine('updating service: ' + str(service_name)))
        # file.write(printSplitLine('updating service: ' + str(service_name)))

        fullSvcName = service['serviceName'] + "." + service['type']
        folder = service['folderName']
        time0,properties = get_service_properties(export_file,url, token, folder, fullSvcName)

        for key in update_properties.keys():
            common_utils.file_write_format(file, "update property:" + str(key) + "=" + str(properties[key]))
            properties[key] = update_properties[key]

        jsonProp = json.dumps(properties)
        time1,status = update_service_properties(url, token, folder, fullSvcName, jsonProp)

        common_utils.file_write_format(file, "edit result:" + status['status'])
        t = str(float(time0[:-1]) + float(time1[:-1])) + "s"

        common_utils.file_write_format(file, "response time: " + str(t))
        file.close()

    except:
        common_utils.file_write_format(file, "update service properties failed!")
        file.close()
        return
def loop_services(export_file,url,token,full_services_list, services_list, properties,folder,service_name_prefix):
    file = open(export_file, 'a+')
    for service in full_services_list:
        service_name = service['serviceName']
        if len(services_list) != 0:
            for update_service_name in services_list:
                if service_name == update_service_name:
                    update_service_properties_by_folder(export_file,url, token, service, properties)
        else:
            if (service['folderName'] == folder or folder == "") and str(service_name).__contains__(service_name_prefix):
                update_service_properties_by_folder(export_file,url,token,service,properties)

    common_utils.file_write_format(file, common_utils.printSplitLine("update finished!"))
    file.close()
def delete_service(export_file, url, token, service):
    try:
        file = open(export_file, 'a+')
        service_name = service['serviceName']
        folder = service['folderName']

        if folder != "/":
            service_url = url + "/admin/services/" + folder + "/" + service_name + "." + service[
                'type'] + "/delete"
        else:
            service_url = url + "/admin/services/" + service_name + "." + service[
                'type'] + "/delete"

        common_utils.file_write_format(file, "service_url:" + str(service_url))

        params = {'token': token, 'f': 'json'}

        result = common_utils.submit_request(service_url, params)

        common_utils.file_write_format(file,
                                       "response time: " + str(result[0]))
        common_utils.file_write_format(
            file, "delete result:" + str(result[1]) + "\n")
        file.close()
    except:
        common_utils.file_write_format(
            file, "delete service" + service_name + "failed!")
        file.close()
        return
示例#4
0
def initialize_parameters(export_file,server_config):
    file = open(export_file,'a+')
    common_utils.file_write_format(file, "ags_pms.conf: " + str(server_config))
    file.write("\n")
    print("")

    conns = common_utils.get_server_conns_params(server_config)

    common_utils.file_write_format(file, "conns:" + str(conns))

    if conns != None:
        url = conns['url']
        username = conns['username']
        password = conns['password']


    settings = common_utils.get_config_params(server_config)

    common_utils.file_write_format(file, "settins:" + str(settings))

    if settings != None:
        repair_times = settings['repair_times']

    file.close()
    return url,username,password,repair_times
def initialize_parameters(export_file, server_config):
    file = open(export_file, 'a+')
    common_utils.file_write_format(file, "ags_pms.conf: " + str(server_config))
    file.write("\n")
    print("")

    conns = common_utils.get_server_conns_params(server_config)

    common_utils.file_write_format(file, "conns:" + str(conns))

    if conns != None:
        url = conns['url']
        username = conns['username']
        password = conns['password']

    # settings = common_utils.get_config_params(server_config)
    settings = common_utils.get_config_params(server_config)

    if settings != None:
        folder = settings['folder']
        start_num = settings['start_num']
        service_count = settings['service_count']
        service_name_prefix = settings['service_name_prefix']

    common_utils.file_write_format(file, "settings:" + str(settings))

    file.close()
    return url, username, password, folder, start_num, service_count, service_name_prefix
def delete_services(export_file, url, token, full_services_list, services_list,
                    folder, service_name_prefix):
    file = open(export_file, 'a+')
    common_utils.file_write_format(
        file, common_utils.printSplitLine("start delete service"))
    file.close()
    for service in full_services_list:
        service_name = service['serviceName']
        if len(services_list) != 0:
            for delete_service_name in services_list:
                if service_name == delete_service_name:
                    delete_service(export_file, url, token, service)

        else:
            if (service['folderName'] == folder or folder == ""
                ) and str(service_name).__contains__(service_name_prefix):
                delete_service(export_file, url, token, service)

    file = open(export_file, 'a+')
    common_utils.file_write_format(
        file, common_utils.printSplitLine("task finished!"))
    file.close()
示例#7
0
def check_instance_statistics(export_file,url,token,service_list,repair_times):
    try:
        file = open(export_file, 'a+')

        error_log = "位于{0}目录下的服务{1}在服务器{2}创建实例异常: 应创建最小实例数:{3}, 实际创建实例数:{4}。\n服务地址:{5} \n"

        error_services = {}

        common_utils.file_write_format(file, common_utils.printSplitLine("start checking instance statistics"))


        for service in service_list:
            folder = service['folderName']
            serviceName = service['serviceName']
            type = service['type']

            if folder == "/":
                base_url = url + "/admin/services/"
            else:
                base_url = url + "/admin/services/" + folder + "/"

            params = {'token': token, 'f': 'json'}

            service_url = base_url + serviceName + "." + type

            common_utils.file_write_format(file, "checking service: " + service_url)

            responsetime, service_detail = common_utils.submit_request(service_url,params)

            # print(service_detail)

            min_instance_config = service_detail['minInstancesPerNode']

            stat_url = service_url + "/statistics"

            response = common_utils.submit_request(stat_url, params)

            statistics = response[1]
            summary = statistics['summary']
            machines = statistics['perMachine']
            m_count = len(machines)

            for machine in machines:
                machineName = machine['machineName']
                if machine['isStatisticsAvailable']:
                    # print(machine)
                    running_ins = int(machine['free']) + int(machine['busy'])

                    if running_ins < min_instance_config:
                        common_utils.file_write_format(file, error_log.format(folder, serviceName, machineName, min_instance_config, running_ins,
                                               service_url) + "\n")


                        error_services[serviceName] = service_url
                    else:
                        common_utils.file_write_format(file, "check " + machineName +" result : normal" )

        file.close()

        if len(error_services.keys()) > 0 :
            file = open(export_file, "a+")
            common_utils.file_write_format(file, common_utils.printSplitLine("check finished,continue to repair the instances"))

            for service in error_services.keys():
                serviceName = service
                service_url = error_services[service]
                common_utils.file_write_format(file, "repairing service :" + service_url)

                result = repair_bugs(repair_times,serviceName,service_url,token)

                common_utils.file_write_format(file, "repair result :" + str(result))

            common_utils.file_write_format("repair instance status finished!")

            file.close()

        file = open(export_file, "a+")

        common_utils.file_write_format(file, common_utils.printSplitLine("check finished!"))

        file.close()


    except:
        common_utils.file_write_format(file, "check instanse failed!")
        file.close()
        return
示例#8
0
def check_service_status(export_file,url,token,service_list,repair_times):
    try:
        error_log = "位于{0}目录下的服务{1}启动异常: 配置状态:{2}, 实际状态:{3}。\n服务地址:{4} \n"

        file = open(export_file, 'a+')

        common_utils.file_write_format(file, common_utils.printSplitLine('start checking service status'))

        i = 0

        for service in service_list:
            folder = service['folderName']
            serviceName = service['serviceName']
            type = service['type']

            if folder == "/":
                base_url = url + "/admin/services/"
            else:
                base_url = url + "/admin/services/" + folder + "/"

            service_url = base_url + serviceName + "." + type

            common_utils.file_write_format(file, "checking service :" + service_url)

            check_url = service_url + "/status"

            params = {'token': token, 'f': 'json'}

            response = common_utils.submit_request(check_url,params)

            status = response[1]

            configuredState = status['configuredState']
            realTimeState = status['realTimeState']

            if configuredState != realTimeState:
                common_utils.file_write_format(file, error_log.format(folder, serviceName, configuredState, realTimeState, service_url))
                common_utils.file_write_format(file, "repairing service ..." )
                # restart service if check found the start status is abnormal
                repair_bugs(export_file,repair_times,serviceName,service_url,token)
            else:
                common_utils.file_write_format(file, "check result : normal")


        common_utils.file_write_format(file, 'check and repair service start status finished!')
        file.close()

    except:
        common_utils.file_write_format(file, "check arcgis server service start status failed!")
        file.close()
        return
def create_new_folder(export_file, url, token, folder, folders):
    try:
        file = open(export_file, 'a+')
        exist = False
        for f in folders:
            if f == folder:
                common_utils.file_write_format(file, f + " folder exist")
                exist = True
                return
        if exist:
            common_utils.file_write_format(
                file, common_utils.printSplitLine("creating new folder"))
            create_folder_url = url + "/admin/services/createFolder"
            params = {
                'folderName': folder,
                'description': folder,
                'f': 'json',
                'token': token
            }

            common_utils.file_write_format(
                file,
                common_utils.printSplitLine("create new folder : " + folder))
            common_utils.file_write_format(file,
                                           "request url:" + create_folder_url)

            response = common_utils.submit_request(create_folder_url, params)
            common_utils.file_write_format(file,
                                           "response result: " + response)
            file.close()
    except:
        print("create new folder failed!")
        common_utils.file_write_format(file, "create new folder failed!")
        file.close()
        return
def publish_map_services(export_file, url, token, config_file, folder,
                         service_name_prefix, start_num, service_count):
    file = open(export_file, "a+")
    if folder == "/":
        service_url = url + "/admin/services/"
    else:
        service_url = url + "/admin/services/" + folder + "/"

    create_service_url = service_url + "createService"

    try:
        for i in range(service_count):
            service_name = service_name_prefix + str(start_num + i)
            service_params = set_params(config_file, "serviceName",
                                        service_name)
            params = {'service': service_params, 'f': 'json', 'token': token}
            common_utils.file_write_format(
                file,
                common_utils.printSplitLine(
                    "publish and start map service : " + service_name))
            common_utils.file_write_format(file, "publishing service ...")
            common_utils.file_write_format(file,
                                           "request url:" + create_service_url)

            response = common_utils.submit_request(create_service_url, params)
            common_utils.file_write_format(
                file, "response time: " + str(response[0]))
            common_utils.file_write_format(
                file, "response result: " + str(response[1]))

            if response != None:
                common_utils.file_write_format(file, "starting service ...")
                start_service_url = service_url + service_name + ".MapServer/start"
                common_utils.file_write_format(
                    file, "request url:" + start_service_url)
                params1 = {'token': token, 'f': 'json'}
                response = common_utils.submit_request(start_service_url,
                                                       params1)
                common_utils.file_write_format(
                    file, "response time: " + str(response[0]))
                common_utils.file_write_format(
                    file, "response result: " + str(response[1]))

        common_utils.file_write_format(
            file, common_utils.printSplitLine("task finished!"))
        file.close()
    except:
        common_utils.file_write_format(file, "publishing service failed!")
        file.close()
        return
示例#11
0
def request_services(export_file, url, token, count, service_list, interval,
                     times):
    file = open(export_file, 'a+')
    common_utils.file_write_format(
        file, common_utils.printSplitLine("start testing"))
    response_str = ""
    total_time = 0.0
    mean_time = 0.0
    request_num = 0
    try:
        for i in range(times):
            s = random.randint(0, count - 1)
            service = service_list[s]
            common_utils.file_write_format(file,
                                           "selected service:" + str(service))

            if service['folderName'] == '/':
                service_url = url + "/rest/services/" + service[
                    'serviceName'] + "/" + service['type']
            else:
                service_url = url + "/rest/services/" + service[
                    'folderName'] + "/" + service[
                        'serviceName'] + "/" + service['type']

            if service['type'] == 'MapServer':
                service_url += '/export'
                bbox = get_initialExtents(service_url, token)
                # print(bbox)
                if bbox == 'failed':
                    continue

                else:
                    random_bbox = generate_random_bbox(bbox)

                    common_utils.file_write_format(
                        file, 'param_bbox:' + str(random_bbox))
                    params = get_export_map_parameters(token, random_bbox)
                    response = common_utils.submit_request(service_url, params)
                    elapse = str_conv_float(response[0])
                    total_time += elapse
                    request_num += 1

                    common_utils.file_write_format(
                        file, 'response duration: ' + str(response[0]) +
                        ' \n' + 'response content: ' + str(response[1]))

            else:
                common_utils.file_write_format(
                    file, "skip %s now!" % service['type'])

                common_utils.file_write_format(
                    file, 'service url: ' + str(service_url) + '\n')
                time.sleep(interval)

            if int(request_num) == 0:
                mean_time = total_time
            else:
                mean_time = total_time / request_num
            common_utils.file_write_format(file, '\n')

        common_utils.file_write_format(
            file, common_utils.printSplitLine("Test task finished! "))

        common_utils.file_write_format(file,
                                       'Total test services: ' + str(times))

        common_utils.file_write_format(
            file,
            'All the requests consumed: ' + str("%.4f" % total_time) + 's')

        common_utils.file_write_format(
            file, 'Average response time: ' + str("%.4f" % mean_time) + 's')

    except:
        common_utils.file_write_format(file, "test failed!")

        file.close()