xige-16 09ae985daa Fix wrong error code in master_service_test.go
Signed-off-by: xige-16 <xi.ge@zilliz.com>
2021-03-10 22:06:22 +08:00

83 lines
2.4 KiB
Go

package grpcproxyserviceclient
import (
"context"
"time"
"github.com/zilliztech/milvus-distributed/internal/proto/milvuspb"
otgrpc "github.com/opentracing-contrib/go-grpc"
"github.com/opentracing/opentracing-go"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
"github.com/zilliztech/milvus-distributed/internal/proto/proxypb"
"github.com/zilliztech/milvus-distributed/internal/util/retry"
"google.golang.org/grpc"
)
type Client struct {
proxyServiceClient proxypb.ProxyServiceClient
address string
ctx context.Context
}
func (c *Client) Init() error {
tracer := opentracing.GlobalTracer()
connectGrpcFunc := func() error {
conn, err := grpc.DialContext(c.ctx, c.address, grpc.WithInsecure(), grpc.WithBlock(),
grpc.WithUnaryInterceptor(
otgrpc.OpenTracingClientInterceptor(tracer)),
grpc.WithStreamInterceptor(
otgrpc.OpenTracingStreamClientInterceptor(tracer)))
if err != nil {
return err
}
c.proxyServiceClient = proxypb.NewProxyServiceClient(conn)
return nil
}
err := retry.Retry(10, time.Millisecond*200, connectGrpcFunc)
if err != nil {
return err
}
return nil
}
func (c *Client) Start() error {
return nil
}
func (c *Client) Stop() error {
return nil
}
func (c *Client) RegisterNode(ctx context.Context, request *proxypb.RegisterNodeRequest) (*proxypb.RegisterNodeResponse, error) {
return c.proxyServiceClient.RegisterNode(ctx, request)
}
func (c *Client) InvalidateCollectionMetaCache(ctx context.Context, request *proxypb.InvalidateCollMetaCacheRequest) (*commonpb.Status, error) {
return c.proxyServiceClient.InvalidateCollectionMetaCache(ctx, request)
}
func (c *Client) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
return c.proxyServiceClient.GetTimeTickChannel(ctx, &commonpb.Empty{})
}
func (c *Client) GetComponentStates(ctx context.Context) (*internalpb2.ComponentStates, error) {
return c.proxyServiceClient.GetComponentStates(ctx, &commonpb.Empty{})
}
func (c *Client) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
return &milvuspb.StringResponse{
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_Success,
},
}, nil
}
func NewClient(address string) *Client {
return &Client{
address: address,
ctx: context.Background(),
}
}