Exemplo n.º 1
0
    def unaryCall(self, _request, context):
        packet = _request
        header = packet.header
        _suffix = packet.body.key
        param_bytes = packet.body.value
        param = bytes.decode(param_bytes)
        job_id = header.task.taskId
        src = header.src
        dst = header.dst
        method = header.operator
        param_dict = json.loads(param)
        param_dict['src_party_id'] = str(src.partyId)
        try:
            nodes_check(param_dict.get('src_party_id'), param_dict.get('_src_role'), param_dict.get('appKey'),
                        param_dict.get('appSecret'), str(dst.partyId))
        except Exception as e:
            resp_json = {
                "retcode": 100,
                "retmsg": str(e)
            }
            return wrap_grpc_packet(resp_json, method, _suffix, dst.partyId, src.partyId, job_id)
        param = bytes.decode(bytes(json.dumps(param_dict), 'utf-8'))

        action = getattr(requests, method.lower(), None)
        audit_logger(job_id).info('rpc receive: {}'.format(packet))
        if action:
            audit_logger(job_id).info("rpc receive: {} {}".format(get_url(_suffix), param))
            resp = action(url=get_url(_suffix), data=param, headers=HEADERS)
        else:
            pass
        resp_json = resp.json()
        return wrap_grpc_packet(resp_json, method, _suffix, dst.partyId, src.partyId, job_id)
Exemplo n.º 2
0
def remote_api(job_id,
               method,
               endpoint,
               src_party_id,
               dest_party_id,
               src_role,
               json_body,
               overall_timeout=DEFAULT_GRPC_OVERALL_TIMEOUT):
    json_body['src_role'] = src_role
    if CHECK_NODES_IDENTITY:
        get_node_identity(json_body, src_party_id)
    _packet = wrap_grpc_packet(json_body,
                               method,
                               endpoint,
                               src_party_id,
                               dest_party_id,
                               job_id,
                               overall_timeout=overall_timeout)
    try:
        channel, stub = get_proxy_data_channel()
        _return = stub.unaryCall(_packet)
        audit_logger(job_id).info("grpc api response: {}".format(_return))
        channel.close()
        json_body = json.loads(_return.body.value)
        return json_body
    except Exception as e:
        tips = ''
        if 'Error received from peer' in str(e):
            tips = 'Please check if the fate flow server of the other party is started. '
        if 'failed to connect to all addresses' in str(e):
            tips = 'Please check whether the rollsite service(port: 9370) is started. '
        raise Exception('{}rpc request error: {}'.format(tips, e))
Exemplo n.º 3
0
def request_execute_server(request, execute_host):
    try:
        endpoint = request.base_url.replace(request.host_url, '')
        method = request.method
        url = "http://{}/{}".format(execute_host, endpoint)
        audit_logger().info('sub request: {}'.format(url))
        action = getattr(requests, method.lower(), None)
        response = action(url=url, json=request.json, headers=HEADERS)
        return jsonify(response.json())
    except requests.exceptions.ConnectionError as e:
        return get_json_result(retcode=999, retmsg='please start fate flow server: {}'.format(execute_host))
    except Exception as e:
        raise Exception('local request error: {}'.format(e))
Exemplo n.º 4
0
def local_api(method, endpoint, json_body, job_id=None):
    try:
        url = "http://{}{}".format(RuntimeConfig.JOB_SERVER_HOST, endpoint)
        audit_logger(job_id).info('local api request: {}'.format(url))
        action = getattr(requests, method.lower(), None)
        response = action(url=url, json=json_body, headers=HEADERS)
        audit_logger(job_id).info(response.text)
        response_json_body = response.json()
        audit_logger(job_id).info('local api response: {} {}'.format(endpoint, response_json_body))
        return response_json_body
    except Exception as e:
        raise Exception('local request error: {}'.format(e))
Exemplo n.º 5
0
SERVINGS_ZK_PATH = '/FATE-SERVICES/serving/online/publishLoad/providers'
FATE_FLOW_ZK_PATH = '/FATE-SERVICES/flow/online/transfer/providers'
FATE_FLOW_MODEL_TRANSFER_PATH = '/v1/model/transfer'
# fate-manager
FATE_MANAGER_GET_NODE_INFO = '/node/info'
FATE_MANAGER_NODE_CHECK = '/node/management/check'

# logger
log_utils.LoggerFactory.LEVEL = 10
# {CRITICAL: 50, FATAL:50, ERROR:40, WARNING:30, WARN:30, INFO:20, DEBUG:10, NOTSET:0}
log_utils.LoggerFactory.set_directory(
    os.path.join(file_utils.get_project_base_directory(), 'logs', 'fate_flow'))
stat_logger = log_utils.getLogger("fate_flow_stat")
detect_logger = log_utils.getLogger("fate_flow_detect")
access_logger = log_utils.getLogger("fate_flow_access")
audit_logger = log_utils.audit_logger()
"""
Services 
"""
IP = get_base_config("fate_flow", {}).get("host", "0.0.0.0")
HTTP_PORT = get_base_config("fate_flow", {}).get("http_port")
GRPC_PORT = get_base_config("fate_flow", {}).get("grpc_port")

# standalone job will be send to the standalone job server when FATE-Flow work on cluster deploy mode,
# but not the port for FATE-Flow on standalone deploy mode.
CLUSTER_STANDALONE_JOB_SERVER_PORT = 9381

# services ip and port
SERVER_CONF_PATH = 'arch/conf/server_conf.json'
SERVING_PATH = '/servers/servings'
server_conf = file_utils.load_json_conf(SERVER_CONF_PATH)