Ejemplo n.º 1
0
    def Ping(self, request, context):

        print("received request:{request}\n".format(request=request))
        hi_msg = request.msg

        if (self.proxy_name == None or self.proxy_port == None):
            return model_pb2.response(status="ProxyNotSet")

        r = "This is %s \n" % (self.model_name)

        return model_pb2.response(status=r)
Ejemplo n.º 2
0
    def Ping(self, request, context):

        print("received request:{request}\n".format(request=request))
        hi_msg = request.msg

        if (self.model_name == None or self.model_port == None):
            return model_pb2.response(status="ModelNotSet")
        '''
        Connect to model 
        '''
        channel = grpc.insecure_channel('{model_name}:{model_port}'.format(
            model_name=self.model_name, model_port=self.model_port))

        stub = model_pb2_grpc.PredictServiceStub(channel)
        response = stub.Ping(
            model_pb2.hi(msg="This is %s \n" % (self.proxy_name)))

        r = response.status

        print("finished ping model")

        for proxy in self.post_list:
            print("started ping proxy %s" % (proxy))
            channel = grpc.insecure_channel('{proxy_name}:{proxy_port}'.format(
                proxy_name=proxy, proxy_port=self.proxy_port))
            stub = proxy_pb2_grpc.ProxyServiceStub(channel)
            response = stub.Ping(
                proxy_pb2.hi(msg=" This is %s \n" % (self.proxy_name)))

            r = r + response.status

        print("return ping request")
        r = "This is %s \n" % (self.proxy_name) + r
        return proxy_pb2.response(status=r)
Ejemplo n.º 3
0
    def SetProxy(self, request, context):
        print("[SetProxy]{request}\n".format(request=request))

        self.proxy_name = request.proxyName
        self.proxy_port = request.proxyPort

        return model_pb2.response(status = "SetProxy Sucessful")
Ejemplo n.º 4
0
    def Predict(self, request, context):

        print("received request:{request}\n".format(request=request))
        #        input_type = request.inputType
        #        input_stream = request.inputStream

        #        output = predict_fn.predict(input_stream)

        #        print("goes here")

        #        return test_pb2.response(status = output)

        if (self.model_name == None or self.model_port == None):
            return model_pb2.response(status="ModelNotSet")

        channel = grpc.insecure_channel('{model_name}:{model_port}'.format(
            model_name=self.model_name, model_port=self.model_port))
        stub = model_pb2_grpc.PredictServiceStub(channel)
        response = stub.Predict(
            model_pb2.input(inputType=request.inputType,
                            inputStream=request.inputStream))
        print(
            'Prediction request [{request}] sent to {model}:{response}'.format(
                request=request,
                model=self.model_name,
                response=response.status))

        input_type = request.inputType
        input_stream = response.status

        reply = "============Output From Model%s ============\n%s\n" % (
            self.model_name, response.status)

        for proxy in self.post_list:
            channel = grpc.insecure_channel('{proxy_name}:{proxy_port}'.format(
                proxy_name=proxy, proxy_port=self.proxy_port))
            stub = proxy_pb2_grpc.ProxyServiceStub(channel)
            response = stub.Predict(
                proxy_pb2.input(inputType=input_type,
                                inputStream=input_stream))
            print('Prediction request [{request}] sent to {proxy}:{response}'.
                  format(request=request,
                         proxy=proxy,
                         response=response.status))

            reply = reply + response.status

        return proxy_pb2.response(status=reply)