예제 #1
0
    def Query(self, request, context):
        """Score 의 invoke 로 생성된 data 에 대한 query 를 수행한다."""
        channel_name = conf.LOOPCHAIN_DEFAULT_CHANNEL if request.channel == '' else request.channel

        # TODO 입력값 오류를 검사하는 방법을 고려해본다, 현재는 json string 여부만 확인
        if util.check_is_json_string(request.params):
            logging.debug(f'Query request with {request.params}')
            try:
                response_from_score_service = \
                    self.peer_service.channel_manager.get_score_container_stub(channel_name).call(
                        method_name="Request",
                        message=loopchain_pb2.Message(code=message_code.Request.score_query, meta=request.params),
                        timeout=conf.SCORE_QUERY_TIMEOUT,
                        is_raise=True
                    )
                response = response_from_score_service.meta

                util.apm_event(
                    self.peer_service.peer_id, {
                        'event_type': 'Query',
                        'peer_id': self.peer_service.peer_id,
                        'data': {
                            'score_query': json.loads(request.params)
                        }
                    })

            except Exception as e:
                logging.error(f'Execute Query Error : {e}')
                if isinstance(e, _Rendezvous):
                    # timeout 일 경우
                    if e.code() == grpc.StatusCode.DEADLINE_EXCEEDED:
                        return loopchain_pb2.QueryReply(
                            response_code=message_code.Response.timeout_exceed,
                            response="")
                return loopchain_pb2.QueryReply(
                    response_code=message_code.Response.fail, response="")
        else:
            return loopchain_pb2.QueryReply(
                response_code=message_code.Response.fail_validate_params,
                response="")

        if util.check_is_json_string(response):
            # TODO 응답값 오류를 검사하는 방법을 고려해본다, 현재는 json string 여부만 확인
            response_code = message_code.Response.success
        else:
            response_code = message_code.Response.fail

        return loopchain_pb2.QueryReply(response_code=response_code,
                                        response=response)
예제 #2
0
    def Query(self, request, context):
        """Score 의 invoke 로 생성된 data 에 대한 query 를 수행한다."""
        channel_name = conf.LOOPCHAIN_DEFAULT_CHANNEL if request.channel == '' else request.channel

        score_stub = StubCollection().score_stubs[channel_name]
        response_code, response = score_stub.sync_task().query(request.params)

        return loopchain_pb2.QueryReply(response_code=response_code, response=response)
예제 #3
0
    def Query(self, request, context):
        """Score 의 invoke 로 생성된 data 에 대한 query 를 수행한다.

        """
        # TODO 입력값 오류를 검사하는 방법을 고려해본다, 현재는 json string 여부만 확인
        if util.check_is_json_string(request.params):
            logging.debug(f'Query request with {request.params}')
            try:
                response_from_score_service = self.peer_service.stub_to_score_service.call(
                    method_name="Request",
                    message=loopchain_pb2.Message(
                        code=message_code.Request.score_query,
                        meta=request.params),
                    timeout=conf.SCORE_QUERY_TIMEOUT,
                    is_raise=True)
                response = response_from_score_service.meta
            except Exception as e:
                logging.error(f'Execute Query Error : {e}')
                if isinstance(e, _Rendezvous):
                    # timeout 일 경우
                    if e.code() == grpc.StatusCode.DEADLINE_EXCEEDED:
                        return loopchain_pb2.QueryReply(
                            response_code=message_code.Response.timeout_exceed,
                            response="")
                return loopchain_pb2.QueryReply(
                    response_code=message_code.Response.fail, response="")
        else:
            return loopchain_pb2.QueryReply(
                response_code=message_code.Response.fail_validate_params,
                response="")

        if util.check_is_json_string(response):
            # TODO 응답값 오류를 검사하는 방법을 고려해본다, 현재는 json string 여부만 확인
            response_code = message_code.Response.success
        else:
            response_code = message_code.Response.fail

        return loopchain_pb2.QueryReply(response_code=response_code,
                                        response=response)