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
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 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()
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 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 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
def main(argv=None): opts, args = getopt.getopt(argv, "e:a:u:p:i:t:") output_path = "" url = "" portal_username = "" portal_password = "" interval = 0 num = 50 if len(opts) < 3: print("Please input required parameters first!!! \n") print( '[requied] -a : The portal url address, eg: -a https://yourhost.domain.com/portal' ) print( '[requied] -u : The portal administrator user name, eg: -u arcgis') print('[requied] -p: The portal administrator password, eg: -p 123456') print( '[options] -e : The directory of stored check result file. The default value is create a new directory with name "be_check" relative to current path. \n' ) print( '[options] -i : The interval of requests, unit - (s), the default value is 0 seconds' ) print('[options] -t: The request times, the default value is 20 times') print('\n') return for op, value in opts: if op == "-e": output_path = value elif op == "-a": if value != "": url = value else: print("Please input required parameter -a ") return elif op == "-u": if value != "": portal_username = value else: print("Please input required parameter -u ") return elif op == "-p": if value != "": portal_password = value else: print("Please input required parameter -p ") return elif op == "-i": if value != "": interval = int(value) elif op == "-t": if value != "": num = int(value) export_file_p = create_result_file(output_path, "be_test_", 'json') export_file_h = create_result_file(output_path, "be_test_", 'txt') print(common_utils.printSplitLine('Start testing......')) # url = r'https://123linux106.esrichina.com/portal' # portal_username = '******' # portal_password = '******' test_key = 'owner:' + portal_username #1 登陆portal token = check_login(export_file_h, url, portal_username, portal_password) if token != 'failed': # 获取服务列表 item_list = random_portal_searh_engine(export_file_h, url, token, test_key) if len(item_list) > 0: # 返回各类服务列表 fs_list, ss_list, ms_list, wmts_list = classify_items(item_list) # 随机抽检hosting feature service健康状态 fs_dict = random_test_hosting_feature_service( export_file_h, token, fs_list, num, interval) # 随机抽检map service健康状态 ms_dict = random_test_map_service(export_file_h, token, ms_list, num, interval) # 随机抽检scene service健康状态 ss_dict = random_test_scene_service(export_file_h, token, ss_list, num, interval) # 随机抽检WMTS服务健康状态 ws_dict = random_test_wmts_service(export_file_h, token, wmts_list, num, interval) # 将结果写入json export_json = { "feature_service": fs_dict, "map_service": ms_dict, "scene_service": ss_dict, "wmts_service": ws_dict } json_file_write_format(export_file_p, export_json)
def main(argv=None): opts, args = getopt.getopt(argv, "e:a:u:p:n:") output_path = "" url = "" portal_username = "" portal_password = "" num = 3 if len(opts) < 3: print("Please input required parameters first!!! \n") print('[requied] -a : The portal url address, eg: -a https://yourhost.domain.com/portal') print('[requied] -u : The portal administrator user name, eg: -u arcgis') print('[requied] -p: The portal administrator password, eg: -p 123456') print( '[options] -e : The directory of stored check result file. The default value is create a new directory with name "be_check" relative to current path. \n') print('[options] -n: The numbers for select services to check from portal content, the default value is 10') print('\n') return for op, value in opts: if op == "-e": output_path = value elif op == "-a": if value != "": url = value else: print("Please input required parameter -a ") return elif op == "-u": if value != "": portal_username = value else: print("Please input required parameter -u ") return elif op == "-p": if value != "": portal_password = value else: print("Please input required parameter -p ") return elif op == "-n": if value != "": num = int(value) # export_file_p = create_result_file(output_path, "beall",'json') export_file_h = create_result_file(output_path, "be_check_", 'txt') print(common_utils.printSplitLine('开始检测......')) # url = r'https://123linux106.esrichina.com/portal' # portal_username = '******' # portal_password = '******' test_key = 'owner:'+ portal_username #1 检测portal是否可以成功登陆 token = check_login(export_file_h, url, portal_username, portal_password) if token != 'failed': #2 检测portal健康状态 check_portal_health(export_file_h, url, token) # 3 检测hosting server健康状态 hosting_server_url = check_hosting_server_status(export_file_h, url, token) if hosting_server_url != "": # 4 检测关系型数据库的健康状态 check_relational_db_status(export_file_h, hosting_server_url,token) # 5 检测portal搜索引擎的健康状态 item_list = random_portal_searh_engine(export_file_h, url, token, test_key) # i = 0 # for item in item_list: # i += 1 # print(i, " " ,item) if len(item_list) > 0: # 返回各类服务列表 fs_list, ss_list, ms_list, wmts_list = classify_items(item_list) # print("fs_len:", len(fs_list)) # print("ss_len:", len(ss_list)) # print("ms_len:", len(ms_list)) # print("wmts_len:", len(wmts_list)) # 随机抽检hosting feature service健康状态 random_check_hosting_feature_service(export_file_h, token, fs_list, num) # 随机抽检map service健康状态 random_check_map_service(export_file_h, token, ms_list, num) # 随机抽检scene service健康状态 random_check_scene_service(export_file_h, token, ss_list, num) # 随机抽检WMTS服务健康状态 random_check_wmts_service(export_file_h, token, wmts_list, num)
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()
def main(argv=None): opts, args = getopt.getopt(argv, "e:a:u:p:") output_path = "" url = "" username = "" password = "" repair_times = 3 if len(opts) < 3: print("Please input required parameters first!!! \n") print( '[requied] -a : The arcgis server url address, eg: -a https://yourhost.domain.com:6443/arcgis' ) print( '[requied] -u : The arcgis server administrator user name, eg: -u arcgis' ) print( '[requied] -p: The arcgis server administrator password, eg: -p 123456' ) print( '[options] -e : The directory of stored check result file. The default value is create a new directory with name "as_check" relative to current path. \n' ) print('[options] -t: Repair times, the default value is 3 times') print('\n') return for op, value in opts: if op == "-e": output_path = value elif op == "-a": if value != "": url = value else: print("Please input required parameter -a ") return elif op == "-u": if value != "": username = value else: print("Please input required parameter -u ") return elif op == "-p": if value != "": password = value else: print("Please input required parameter -p ") return elif op == "-t": if value != "": repair_times = int(value) # export_file_p = create_result_file(output_path, "as_check_", 'json') export_file_h = create_result_file(output_path, "as_check_", 'txt') print(common_utils.printSplitLine('Start testing......')) current_path = os.getcwd() server_config = current_path + os.sep + 'ags_pms.conf' token = check_login(export_file_h, url, username, password) service_count, full_services_list, folders = get_services_list( export_file_h, url, token) check_service_status(export_file_h, url, token, full_services_list, int(repair_times)) check_instance_statistics(export_file_h, url, token, full_services_list, int(repair_times))
def main(argv=None): opts, args = getopt.getopt(argv, "e:a:u:p:i:t:") output_path = "" url = "" server_username = "" server_password = "" interval = 0 num = 20 if len(opts) < 3: print("Please input required parameters first!!! \n") print( '[requied] -a : The arcgis server url address, eg: -a https://yourhost.domain.com:6443/arcgis' ) print( '[requied] -u : The arcgis server administrator user name, eg: -u arcgis' ) print( '[requied] -p: The arcgis server administrator password, eg: -p 123456' ) print( '[options] -e : The directory of stored check result file. The default value is create a new directory with name "be_check" relative to current path. \n' ) print( '[options] -i : The interval of requests, unit - (s), the default value is 0 seconds' ) print('[options] -t: The request times, the default value is 20 times') print('\n') return for op, value in opts: if op == "-e": output_path = value elif op == "-a": if value != "": url = value else: print("Please input required parameter -a ") return elif op == "-u": if value != "": server_username = value else: print("Please input required parameter -u ") return elif op == "-p": if value != "": server_password = value else: print("Please input required parameter -p ") return elif op == "-i": if value != "": interval = int(value) elif op == "-t": if value != "": num = int(value) export_file_p = create_result_file(output_path, "as_test_", 'json') export_file_h = create_result_file(output_path, "as_test_", 'txt') print(common_utils.printSplitLine('Start testing......')) #1 登陆server token = check_login(export_file_h, url, server_username, server_password) if token != 'failed': # 获取服务列表 service_count, full_services_list, folders = get_services_list( export_file_h, url, token) dynamic_list, cache_list = classify_services(url, full_services_list, token) dynamic_dict = {} cache_dict = {} if len(dynamic_list) > 0: dynamic_dict = random_test_map_service(export_file_h, url, token, "Dynamic Map Service", dynamic_list, num, interval) # print(dynamic_dict) if len(cache_list) > 0: cache_dict = random_test_cache_service(export_file_h, url, token, "Cache Map Service", cache_list, num, interval) # 将结果写入json export_json = { "dynamic_service": dynamic_dict, "cache_service": cache_dict } json_file_write_format(export_file_p, export_json)