Router selector and proxy modifications due to Route struct changes.

This commit is contained in:
Milos Gajdos 2019-07-09 16:45:31 +01:00
parent 23cb811f60
commit 6cf8bde612
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
5 changed files with 74 additions and 138 deletions

View File

@ -45,7 +45,7 @@ func (r *routerSelector) getRoutes(service string) ([]table.Route, error) {
if !r.remote {
// lookup router for routes for the service
return r.r.Table().Lookup(table.NewQuery(
table.QueryDestination(service),
table.QueryService(service),
))
}
@ -83,7 +83,7 @@ func (r *routerSelector) getRoutes(service string) ([]table.Route, error) {
// call the router
pbRoutes, err = r.rs.Lookup(context.Background(), &pb.LookupRequest{
Query: &pb.Query{
Destination: service,
Service: service,
},
}, client.WithAddress(addr))
if err != nil {
@ -107,11 +107,12 @@ func (r *routerSelector) getRoutes(service string) ([]table.Route, error) {
// convert from pb to []*router.Route
for _, r := range pbRoutes.Routes {
routes = append(routes, table.Route{
Destination: r.Destination,
Gateway: r.Gateway,
Router: r.Router,
Network: r.Network,
Metric: int(r.Metric),
Service: r.Service,
Address: r.Address,
Gateway: r.Gateway,
Network: r.Network,
Link: r.Link,
Metric: int(r.Metric),
})
}

View File

@ -107,7 +107,7 @@ func (p *Proxy) getRoute(service string) ([]string, error) {
if p.Router != nil {
// lookup the router
routes, err := p.Router.Table().Lookup(
table.NewQuery(table.QueryDestination(service)),
table.NewQuery(table.QueryService(service)),
)
if err != nil {
return nil, err
@ -180,7 +180,7 @@ func (p *Proxy) getRoute(service string) ([]string, error) {
// call the router
proutes, err := p.RouterService.Lookup(context.Background(), &pb.LookupRequest{
Query: &pb.Query{
Destination: service,
Service: service,
},
}, client.WithAddress(addr))
if err != nil {
@ -205,11 +205,12 @@ func (p *Proxy) getRoute(service string) ([]string, error) {
// convert from pb to []*router.Route
for _, r := range pbRoutes.Routes {
routes = append(routes, table.Route{
Destination: r.Destination,
Gateway: r.Gateway,
Router: r.Router,
Network: r.Network,
Metric: int(r.Metric),
Service: r.Service,
Address: r.Address,
Gateway: r.Gateway,
Network: r.Network,
Link: r.Link,
Metric: int(r.Metric),
})
}

View File

@ -1,5 +1,5 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: go-micro/network/router/proto/router.proto
// source: router.proto
package router

View File

@ -1,13 +1,11 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: go-micro/network/router/proto/router.proto
// source: router.proto
package router
import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
math "math"
)
@ -34,7 +32,7 @@ func (m *LookupRequest) Reset() { *m = LookupRequest{} }
func (m *LookupRequest) String() string { return proto.CompactTextString(m) }
func (*LookupRequest) ProtoMessage() {}
func (*LookupRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_fc08514fc6dadd29, []int{0}
return fileDescriptor_367072455c71aedc, []int{0}
}
func (m *LookupRequest) XXX_Unmarshal(b []byte) error {
@ -74,7 +72,7 @@ func (m *LookupResponse) Reset() { *m = LookupResponse{} }
func (m *LookupResponse) String() string { return proto.CompactTextString(m) }
func (*LookupResponse) ProtoMessage() {}
func (*LookupResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_fc08514fc6dadd29, []int{1}
return fileDescriptor_367072455c71aedc, []int{1}
}
func (m *LookupResponse) XXX_Unmarshal(b []byte) error {
@ -104,8 +102,8 @@ func (m *LookupResponse) GetRoutes() []*Route {
// Query is passed in a LookupRequest
type Query struct {
// destination to lookup
Destination string `protobuf:"bytes,1,opt,name=destination,proto3" json:"destination,omitempty"`
// service to lookup
Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -115,7 +113,7 @@ func (m *Query) Reset() { *m = Query{} }
func (m *Query) String() string { return proto.CompactTextString(m) }
func (*Query) ProtoMessage() {}
func (*Query) Descriptor() ([]byte, []int) {
return fileDescriptor_fc08514fc6dadd29, []int{2}
return fileDescriptor_367072455c71aedc, []int{2}
}
func (m *Query) XXX_Unmarshal(b []byte) error {
@ -136,9 +134,9 @@ func (m *Query) XXX_DiscardUnknown() {
var xxx_messageInfo_Query proto.InternalMessageInfo
func (m *Query) GetDestination() string {
func (m *Query) GetService() string {
if m != nil {
return m.Destination
return m.Service
}
return ""
}
@ -146,15 +144,17 @@ func (m *Query) GetDestination() string {
// Route is a service route
type Route struct {
// service for the route
Destination string `protobuf:"bytes,1,opt,name=destination,proto3" json:"destination,omitempty"`
Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
// the address that advertise this route
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
// gateway as the next hop
Gateway string `protobuf:"bytes,2,opt,name=gateway,proto3" json:"gateway,omitempty"`
// the router that advertise this route
Router string `protobuf:"bytes,3,opt,name=router,proto3" json:"router,omitempty"`
Gateway string `protobuf:"bytes,3,opt,name=gateway,proto3" json:"gateway,omitempty"`
// the network for this destination
Network string `protobuf:"bytes,4,opt,name=network,proto3" json:"network,omitempty"`
// the network link
Link string `protobuf:"bytes,5,opt,name=link,proto3" json:"link,omitempty"`
// the metric / score of this route
Metric int64 `protobuf:"varint,5,opt,name=metric,proto3" json:"metric,omitempty"`
Metric int64 `protobuf:"varint,6,opt,name=metric,proto3" json:"metric,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -164,7 +164,7 @@ func (m *Route) Reset() { *m = Route{} }
func (m *Route) String() string { return proto.CompactTextString(m) }
func (*Route) ProtoMessage() {}
func (*Route) Descriptor() ([]byte, []int) {
return fileDescriptor_fc08514fc6dadd29, []int{3}
return fileDescriptor_367072455c71aedc, []int{3}
}
func (m *Route) XXX_Unmarshal(b []byte) error {
@ -185,9 +185,16 @@ func (m *Route) XXX_DiscardUnknown() {
var xxx_messageInfo_Route proto.InternalMessageInfo
func (m *Route) GetDestination() string {
func (m *Route) GetService() string {
if m != nil {
return m.Destination
return m.Service
}
return ""
}
func (m *Route) GetAddress() string {
if m != nil {
return m.Address
}
return ""
}
@ -199,16 +206,16 @@ func (m *Route) GetGateway() string {
return ""
}
func (m *Route) GetRouter() string {
func (m *Route) GetNetwork() string {
if m != nil {
return m.Router
return m.Network
}
return ""
}
func (m *Route) GetNetwork() string {
func (m *Route) GetLink() string {
if m != nil {
return m.Network
return m.Link
}
return ""
}
@ -227,98 +234,23 @@ func init() {
proto.RegisterType((*Route)(nil), "Route")
}
func init() {
proto.RegisterFile("go-micro/network/router/proto/router.proto", fileDescriptor_fc08514fc6dadd29)
}
var fileDescriptor_fc08514fc6dadd29 = []byte{
// 242 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0xc1, 0x4a, 0xc3, 0x40,
0x10, 0x86, 0x5d, 0x63, 0x56, 0x9c, 0x62, 0x85, 0x3d, 0xc8, 0x22, 0x22, 0x61, 0x4f, 0x55, 0x69,
0x22, 0x15, 0xdf, 0xc2, 0x8b, 0xfb, 0x06, 0xb1, 0x0e, 0x25, 0x94, 0x66, 0xd2, 0xdd, 0x09, 0xa5,
0x0f, 0xe1, 0x3b, 0x4b, 0x26, 0x5b, 0x30, 0xa7, 0x1e, 0xbf, 0x99, 0xf9, 0x7e, 0x76, 0x7f, 0x78,
0xd9, 0xd0, 0x72, 0xd7, 0xac, 0x03, 0x55, 0x2d, 0xf2, 0x81, 0xc2, 0xb6, 0x0a, 0xd4, 0x33, 0x86,
0xaa, 0x0b, 0xc4, 0x94, 0xa0, 0x14, 0x70, 0x4b, 0xb8, 0xfd, 0x24, 0xda, 0xf6, 0x9d, 0xc7, 0x7d,
0x8f, 0x91, 0xcd, 0x23, 0xe4, 0xfb, 0x1e, 0xc3, 0xd1, 0xaa, 0x42, 0x2d, 0x66, 0x2b, 0x5d, 0x7e,
0x0d, 0xe4, 0xc7, 0xa1, 0x7b, 0x83, 0xf9, 0xe9, 0x3c, 0x76, 0xd4, 0x46, 0x34, 0x4f, 0xa0, 0x25,
0x30, 0x5a, 0x55, 0x64, 0x22, 0xf8, 0x01, 0x7d, 0x9a, 0xba, 0x67, 0xc8, 0x25, 0xc1, 0x14, 0x30,
0xfb, 0xc1, 0xc8, 0x4d, 0x5b, 0x73, 0x43, 0xad, 0xc4, 0xdf, 0xf8, 0xff, 0x23, 0xf7, 0xab, 0x20,
0x17, 0xf9, 0xfc, 0xad, 0xb1, 0x70, 0xbd, 0xa9, 0x19, 0x0f, 0xf5, 0xd1, 0x5e, 0xca, 0xf6, 0x84,
0xe6, 0x3e, 0x3d, 0x28, 0xd8, 0x4c, 0x16, 0x89, 0x06, 0x23, 0xd5, 0x61, 0xaf, 0x46, 0x23, 0xe1,
0x60, 0xec, 0x90, 0x43, 0xb3, 0xb6, 0x79, 0xa1, 0x16, 0x99, 0x4f, 0xb4, 0xfa, 0x00, 0xed, 0x47,
0xf7, 0x15, 0xf4, 0xf8, 0x6d, 0x33, 0x2f, 0x27, 0x75, 0x3d, 0xdc, 0x95, 0xd3, 0x3e, 0xdc, 0xc5,
0xb7, 0x96, 0x66, 0xdf, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x4d, 0x73, 0x18, 0x9e, 0x87, 0x01,
0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// RouterClient is the client API for Router service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type RouterClient interface {
Lookup(ctx context.Context, in *LookupRequest, opts ...grpc.CallOption) (*LookupResponse, error)
}
type routerClient struct {
cc *grpc.ClientConn
}
func NewRouterClient(cc *grpc.ClientConn) RouterClient {
return &routerClient{cc}
}
func (c *routerClient) Lookup(ctx context.Context, in *LookupRequest, opts ...grpc.CallOption) (*LookupResponse, error) {
out := new(LookupResponse)
err := c.cc.Invoke(ctx, "/Router/Lookup", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// RouterServer is the server API for Router service.
type RouterServer interface {
Lookup(context.Context, *LookupRequest) (*LookupResponse, error)
}
func RegisterRouterServer(s *grpc.Server, srv RouterServer) {
s.RegisterService(&_Router_serviceDesc, srv)
}
func _Router_Lookup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LookupRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RouterServer).Lookup(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/Router/Lookup",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RouterServer).Lookup(ctx, req.(*LookupRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Router_serviceDesc = grpc.ServiceDesc{
ServiceName: "Router",
HandlerType: (*RouterServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Lookup",
Handler: _Router_Lookup_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "go-micro/network/router/proto/router.proto",
func init() { proto.RegisterFile("router.proto", fileDescriptor_367072455c71aedc) }
var fileDescriptor_367072455c71aedc = []byte{
// 238 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xc1, 0x4a, 0xc4, 0x30,
0x10, 0x86, 0x8d, 0xdd, 0x46, 0x1c, 0x75, 0x85, 0x1c, 0x24, 0x88, 0x48, 0xcd, 0x69, 0x41, 0x2c,
0xb2, 0xe2, 0x5b, 0x78, 0x31, 0x6f, 0x50, 0x77, 0x07, 0x29, 0xd5, 0xa6, 0x3b, 0x49, 0x5c, 0xf6,
0x59, 0x7c, 0x59, 0xc9, 0x24, 0x7b, 0xe8, 0xc1, 0x5b, 0xb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20 +17,22 @@ message LookupResponse {
// Query is passed in a LookupRequest
message Query {
// destination to lookup
string destination = 1;
// service to lookup
string service = 1;
}
// Route is a service route
message Route {
// service for the route
string destination = 1;
string service = 1;
// the address that advertise this route
string address = 2;
// gateway as the next hop
string gateway = 2;
// the router that advertise this route
string router = 3;
string gateway = 3;
// the network for this destination
string network = 4;
// the network link
string link = 5;
// the metric / score of this route
int64 metric = 5;
int64 metric = 6;
}