def get_genesis(): target_id = request.args.get('target_id') if not target_id: return result_dto(False, 401, 'args missing', '') # logger.info('target_id: ' + target_id) return result_dto(True, 200, 'genesis', system_service.read_genesis(target_id))
def do_delete(): try: args = request.args logger.info(args) if not args.get('peerName'): return result_dto(False, 401, '参数错误', '') # 删除节点 move_service.do_delete(args.get('peerName')) return result_dto(True, 200, '删除成功', '') except Exception as e: logger.error(e) return result_dto(False, 501, 'server failed', str(e))
def do_adjust(): try: args = request.get_json() logger.info(args) if not args.get('peer_id') or not args.get('chain_id'): return result_dto(False, 401, '参数错误', '') # 执行分片移动 system_service.do_move(args.get('peer_id'), args.get('chain_id')) return result_dto(True, 200, 'success', '') except Exception as e: logger.error(e) return result_dto(False, 501, 'server failed', str(e))
def move_peer(): # args = json_util.un_marshal(request.get_data(as_text=True)) args = request.get_json() logger.info(args) if not args.get('peer_id') or not args.get('chain_id'): return result_dto(False, 401, "参数错误", "") # 转发移动分片的请求 try: peer_service.transfer_move_req(args.get('peer_id'), args.get('chain_id')) return result_dto(True, 200, "成功", "") except Exception as e: logger.error("分片调整失败" + str(e)) return result_dto(False, 500, "失败", str(e))
def do_create(): try: args = request.get_json() logger.info(args) if not args.get('peerName') or not args.get( 'newPeerName' ): #or not args.get('genesis') or not args.get('neighbors'): return result_dto(False, 401, '参数错误', '') # 创建节点 move_service.do_create(args.get('peerName'), args.get('newPeerName'), args.get('genesis'), args.get('neighbors')) return result_dto(True, 200, '创建节点成功', '') except Exception as e: logger.error(e) return result_dto(False, 501, 'server failed', str(e))
def error_500(error): logger.error(error) return jsonify(result_dto(False, 500, 'server failed', str(error))), 500