def verify_test_param(source_id, param_value): """测试SQL参数""" if not source_id: abort(400, **make_result(status=400, msg='数据源不得为空')) if not param_value: abort(400, **make_result(status=400, msg='参数值不得为空')) return Response(source_id=source_id, param_value=param_value)
def verify_update_job_id(job_id, interface_id, job_name, job_desc, server_id, server_dir, server_script, old_prep, job_prep, user_id, is_deleted): """修改任务""" if not job_id: abort(400, **make_result(status=400, msg='任务id不存在')) if not interface_id: abort(400, **make_result(status=400, msg='接口id不存在')) if not user_id: abort(400, **make_result(status=400, msg='用户不存在')) if not server_id: abort(400, **make_result(status=400, msg='执行服务器id不存在')) if is_deleted < 0 or is_deleted > 1: abort(400, **make_result(status=400, msg='是否删除参数错误')) return Response(job_id=job_id, interface_id=interface_id, job_name=job_name, job_desc=job_desc, server_id=server_id, server_dir=server_dir, server_script=server_script, old_prep=old_prep, job_prep=job_prep, user_id=user_id, is_deleted=is_deleted)
def verify_execute_job(job_id, user_id): """立即执行任务""" if not job_id: abort(400, **make_result(status=400, msg='任务id不存在')) if not user_id: abort(400, **make_result(status=400, msg='用户不存在')) return Response(job_id=job_id, user_id=user_id)
def verify_add_interface(interface_name, interface_desc, retry, user_id): """新增接口请求""" if not interface_name: abort(400, **make_result(status=400, msg='接口名称不存在')) if retry < 0 or retry > 10: abort(400, **make_result(status=400, msg='重试次数请限制在0-10之内')) return Response(interface_name=interface_name, interface_desc=interface_desc, retry=retry, user_id=user_id)
def verify_add_datasource_detail(source_name, source_type, auth_type, source_host, source_port, source_database, source_user, source_password, source_desc, user_id): """新增数据源""" if not source_name: abort(400, **make_result(status=400, msg='数据源名称不存在')) if source_type < 1 or source_type > 5: abort(400, **make_result(status=400, msg='数据库类型错误')) if auth_type < 0 or auth_type > 4: abort(400, **make_result(status=400, msg='认证方式类型错误')) if not source_host: abort(400, **make_result(status=400, msg='数据库ip或域名不存在')) if not source_port: abort(400, **make_result(status=400, msg='数据库端口不存在')) return Response(source_name=source_name, source_type=source_type, auth_type=auth_type, source_host=source_host, source_port=source_port, source_database=source_database, source_user=source_user, source_password=source_password, source_desc=source_desc, user_id=user_id)
def verify_login_data(username, password): if not username: abort(400, **make_result(status=400, msg='用户名不能为空')) if not password: abort(400, **make_result(status=400, msg='密码不能为空')) return Response(username=username, password=password)
def verify_get_interface_graph(interface_id, graph_type): """获取任务流拓扑结构""" if not interface_id: abort(400, **make_result(status=400, msg='任务流不存在')) if graph_type < 1 or graph_type > 3: abort(400, **make_result(status=400, msg='图表类型错误')) return Response(interface_id=interface_id, graph_type=graph_type)
def verify_callback(exec_id, status): """验证回调函数""" if not exec_id: abort(400, **make_result(status=400, msg='执行id不存在')) if not status: abort(400, **make_result(status=400, msg='任务状态')) return Response(exec_id=exec_id, status=status)
def update_params_detail(param_id, param_type, param_name, param_index, source_id, param_value, param_desc, is_deleted, user_id): """修改参数详情""" # 参数名称查重 param_detail = ParamsModel.get_params_detail_by_name( db.etl_db, param_name) if param_detail and param_detail['param_id'] != param_id: abort(400, **make_result(status=400, msg='参数名称重复, 已存在数据库中')) # 修改参数 if is_deleted == 1: param_detail = ParamsModel.get_params_detail_not_delete( db.etl_db, param_id) if param_detail['param_type'] == 2: abort( 400, **make_result(status=400, msg='参数ID: [%s]为上下文参数, 不能删除' % param_id)) if param_detail['job_id']: abort( 400, **make_result(status=400, msg='参数ID: [%s], 在任务: [%s]调用中, 请停止调用后删除' % (param_id, param_detail['job_id']))) ParamsModel.update_params_detail(db.etl_db, param_id, param_type, param_name, param_index, source_id, param_value, param_desc, is_deleted, user_id) return Response(param_id=param_id)
def delete(): """登出""" try: session.login_out() return make_result(200, msg='成功'), 200 except Exception as e: log.error('用户登出出错 [ERROR: %s]' % e, exc_info=True) abort(400, **make_result(status=400, msg='无用户登陆信息'))
def verify_action_dispatch(dispatch_id, action, user_id): """暂停/恢复调度任务""" if not dispatch_id: abort(400, **make_result(status=400, msg='调度id不存在')) if action < 1 or action > 2: abort(400, **make_result(status=400, msg='请求参数错误')) return Response(dispatch_id=dispatch_id, action=action, user_id=user_id)
def verify_action_ftp_event(ftp_event_id, action, user_id): """暂停/恢复调度事件""" if not ftp_event_id: abort(400, **make_result(status=400, msg='调度事件id不存在')) if action < 1 or action > 2: abort(400, **make_result(status=400, msg='请求参数错误')) return Response(ftp_event_id=ftp_event_id, action=action, user_id=user_id)
def verify_get_execute_list(interface_id, start_time, end_time, exec_type, page, limit): """获取执行列表""" if start_time and end_time and start_time >= end_time: abort(400, **make_result(status=400, msg='创建开始时间大于创建结束时间')) if exec_type < 0 or exec_type > 2: abort(400, **make_result(status=400, msg='执行类型错误')) return Response(interface_id=interface_id, start_time=start_time, end_time=end_time, exec_type=exec_type, page=page, limit=limit)
def verify_add_exec_host(server_host, server_name, user_id): """新增执行服务器""" if not server_host: abort(400, **make_result(status=400, msg='执行服务器ip不存在')) if not server_name: abort(400, **make_result(status=400, msg='执行服务器名称不存在')) return Response(server_host=server_host, server_name=server_name, user_id=user_id)
def verify_get_params_list(param_type, param_name, param_index, source_id, is_deleted, page, limit): """获取参数列表""" param_index = param_index.split(',') if param_index else [] if param_type < 0 or param_type > 3: abort(400, **make_result(status=400, msg='参数类型错误')) if is_deleted < 0 or is_deleted > 1: abort(400, **make_result(status=400, msg='状态参数错误')) return Response(param_type=param_type, param_name=param_name, param_index=param_index, source_id=source_id, is_deleted=is_deleted, page=page, limit=limit)
def verify_get_interface_list(interface_name, start_time, end_time, interface_type, is_deleted, page, limit): """获取接口列表""" if start_time and end_time and start_time >= end_time: abort(400, **make_result(status=400, msg='创建开始时间大于创建结束时间')) if is_deleted > 2: abort(400, **make_result(status=400, msg='接口使用参数错误')) if interface_type > 5: abort(400, **make_result(status=400, msg='接口类型参数错误')) return Response(interface_name=interface_name, start_time=start_time, end_time=end_time, interface_type=interface_type, is_deleted=is_deleted, page=page, limit=limit)
def verify_get_interface_list(interface_name, interface_index, start_time, end_time, is_deleted, page, limit): """获取任务流列表""" # 任务流目录 interface_index = interface_index.split(',') if interface_index else [] # 创建时间 if start_time and end_time and start_time >= end_time: abort(400, **make_result(status=400, msg='创建开始时间大于创建结束时间')) if is_deleted > 2: abort(400, **make_result(status=400, msg='任务流使用参数错误')) return Response(interface_name=interface_name, interface_index=interface_index, start_time=start_time, end_time=end_time, is_deleted=is_deleted, page=page, limit=limit)
def verify_update_interface_detail(interface_id, interface_name, interface_desc, retry, user_id, is_deleted): """修改接口详情""" if not interface_id: abort(400, **make_result(status=400, msg='接口id不存在')) if not interface_name: abort(400, **make_result(status=400, msg='接口名称不存在')) if retry < 0 or retry > 10: abort(400, **make_result(status=400, msg='重试次数请限制在0-10之内')) if is_deleted < 0 or is_deleted > 1: abort(400, **make_result(status=400, msg='是否删除参数错误')) return Response(interface_id=interface_id, interface_name=interface_name, interface_desc=interface_desc, retry=retry, user_id=user_id, is_deleted=is_deleted)
def verify_get_alert_conf_list(alert_channel, conf_name, is_deleted, page, limit): """获取预警配置列表""" if alert_channel < 0 or alert_channel > 2: abort(400, **make_result(status=400, msg='预警渠道参数错误')) if is_deleted < 0 or is_deleted > 2: abort(400, **make_result(status=400, msg='是否删除参数错误')) return Response(alert_channel=alert_channel, conf_name=conf_name, is_deleted=is_deleted, page=page, limit=limit)
def verify_test_ftp_event_link(ftp_id, ftp_type, ftp_host, ftp_port, ftp_user, ftp_passwd, data_path): """测试FTP文件目录是否存在""" if not data_path: abort(400, **make_result(status=400, msg='文件路径不得为空')) if not ftp_id and (not ftp_type and not ftp_host and not ftp_port): abort(400, **make_result(status=400, msg='FTP配置项缺失')) return Response(ftp_id=ftp_id, ftp_type=ftp_type, ftp_host=ftp_host, ftp_port=ftp_port, ftp_user=ftp_user, ftp_passwd=ftp_passwd, data_path=data_path)
def verify_add_job_id(job_name, interface_id, job_desc, job_index, server_id, job_prep, job_params, server_dir, server_script, user_id, return_code): """新增任务""" if not job_name: abort(400, **make_result(status=400, msg='任务名称不存在')) if not job_index: abort(400, **make_result(status=400, msg='任务目录不存在')) elif re.findall(',', job_index): abort(400, **make_result(status=400, msg='任务目录中不得出现逗号字符","')) if not interface_id: abort(400, **make_result(status=400, msg='任务流id不存在')) if not server_id: abort(400, **make_result(status=400, msg='执行服务器id不存在')) if not server_script: abort(400, **make_result(status=400, msg='脚本命令不存在')) if not user_id: abort(400, **make_result(status=400, msg='用户不存在')) if return_code < 0: abort(400, **make_result(status=400, msg='返回状态码应大于等于0')) return Response(job_name=job_name, interface_id=interface_id, job_desc=job_desc, job_index=job_index, server_id=server_id, job_prep=job_prep, job_params=job_params, server_dir=server_dir, server_script=server_script, user_id=user_id, return_code=return_code)
def verify_get_execute_flow_history(dispatch_id, run_date, run_status, page, limit): """获取任务流历史日志""" # 调度ID if not dispatch_id: abort(400, **make_result(status=400, msg='调度ID缺失')) if run_status < 0 or run_status > 5: abort(400, **make_result(status=400, msg='运行状态错误')) return Response(dispatch_id=dispatch_id, run_date=run_date, run_status=run_status, page=page, limit=limit)
def verify_get_execute_job_log_list(job_id, start_time, end_time, run_status, page, limit): """获取手动执行任务日志""" # 执行时间 if start_time and end_time and start_time >= end_time: abort(400, **make_result(status=400, msg='执行开始时间大于创建结束时间')) if run_status < 0 or run_status > 5: abort(400, **make_result(status=400, msg='运行状态错误')) return Response(job_id=job_id, start_time=start_time, end_time=end_time, run_status=run_status, page=page, limit=limit)
def verify_get_datasource_list(source_name, source_type, source_host, is_deleted, page, limit): """获取数据源列表""" if source_type < 0 or source_type > 5: abort(400, **make_result(status=400, msg='数据库类型错误')) if is_deleted < 0 or is_deleted > 1: abort(400, **make_result(status=400, msg='状态参数错误')) return Response(source_name=source_name, source_type=source_type, source_host=source_host, is_deleted=is_deleted, page=page, limit=limit)
def verify_get_ftp_list(ftp_name, ftp_type, ftp_host, is_deleted, page, limit): """获取FTP配置列表""" if ftp_type < 0 or ftp_type > 2: abort(400, **make_result(status=400, msg='FTP类型错误')) if is_deleted < 0 or is_deleted > 1: abort(400, **make_result(status=400, msg='状态参数错误')) return Response(ftp_name=ftp_name, ftp_type=ftp_type, ftp_host=ftp_host, is_deleted=is_deleted, page=page, limit=limit)
def update_interface_detail(interface_id, interface_name, interface_desc, interface_index, old_parent, parent_interface, run_time, retry, user_id, is_deleted): """修改任务流详情""" # 任务流名称查重 interface_detail = InterfaceModel.get_interface_detail_by_name( db.etl_db, interface_name) if interface_detail and interface_detail[ 'interface_id'] != interface_id: abort(400, **make_result(status=400, msg='任务流名称重复, 已存在数据库中')) # 调度查重 if is_deleted == 1: if InterfaceModel.get_schedule_detail(db.etl_db, interface_id): abort(400, **make_result(status=400, msg='任务流在调度任务中, 不能设置失效')) # 修改任务流 if not run_time: run_time = (date.today() + timedelta(days=-1)).strftime('%Y-%m-%d') InterfaceModel.update_interface_detail(db.etl_db, interface_id, interface_name, interface_desc, interface_index, run_time, retry, user_id, is_deleted) # 修改任务流前置 old_parent = set() if not old_parent else set(old_parent) parent_interface = set() if not parent_interface else set( parent_interface) # 删 del_data = [] for parent_id in old_parent - parent_interface: del_data.append({ 'interface_id': interface_id, 'parent_id': parent_id, 'user_id': user_id, 'update_time': int(time.time()) }) InterfaceModel.delete_job_parent(db.etl_db, del_data) if del_data else None # 增 add_data = [] for parent_id in parent_interface - old_parent: add_data.append({ 'interface_id': interface_id, 'parent_id': parent_id, 'user_id': user_id, 'insert_time': int(time.time()), 'update_time': int(time.time()) }) InterfaceModel.add_job_parent(db.etl_db, add_data) if add_data else None return Response(interface_id=interface_id)
def verify_get_job_list(job_name, start_time, end_time, interface_id, is_deleted, page, limit): """获取任务列表""" if start_time and end_time and start_time >= end_time: abort(400, **make_result(status=400, msg='创建开始时间大于创建结束时间')) if is_deleted < 0 or is_deleted > 1: abort(400, **make_result(status=400, msg='任务状态参数错误')) return Response(job_name=job_name, start_time=start_time, end_time=end_time, interface_id=interface_id, is_deleted=is_deleted, page=page, limit=limit)
def verify_get_execute_job_history(job_id, exec_type, start_time, end_time, run_status, page, limit): """获取任务历史日志列表""" # 执行时间 if start_time and end_time and start_time >= end_time: abort(400, **make_result(status=400, msg='执行开始时间大于创建结束时间')) if exec_type < 0 or exec_type > 2: abort(400, **make_result(status=400, msg='执行类型参数错误')) return Response(job_id=job_id, exec_type=exec_type, start_time=start_time, end_time=end_time, run_status=run_status, page=page, limit=limit)
def verify_add_alert_conf(alert_channel, conf_name, param_config, param_host, param_pass, user_id): """新增预警配置""" if alert_channel < 1 or alert_channel > 2: abort(400, **make_result(status=400, msg='预警渠道参数错误')) if not conf_name: abort(400, **make_result(status=400, msg='配置名称参数错误')) if not param_config: abort(400, **make_result(status=400, msg='参数配置不得为空')) return Response(alert_channel=alert_channel, conf_name=conf_name, param_config=param_config, param_host=param_host, param_pass=param_pass, user_id=user_id)
def get_payload_bit_list_int(key, default=None): value = request.json.get(key, default) if not isinstance(value, list): abort( HTTPStatus.BadRequest, **make_result(status=APIStatus.BadRequest, msg='参数 %s 不是 list' % (key, ))) if not value: return 0 for i in value: if (not str(i).isdigit()) or (int(i) > 2 and i % 2 == 1) or (i == 0): abort( HTTPStatus.BadRequest, **make_result(status=APIStatus.BadRequest, msg='参数 %s 中(%s) 错误' % (key, i))) return reduce(lambda x, y: x | y, value)