Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr/triple reflect support #1603

Merged
merged 4 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/rpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type ReferencedRPCService interface {
Reference() string
}

// RPCService the type alias of interface{}
type TriplePBService interface {
XXX_InterfaceName() string
}

// GetReference return the reference id of the service.
// If the service implemented the ReferencedRPCService interface,
// it will call the Reference method. If not, it will
Expand Down
20 changes: 18 additions & 2 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config/generic"
Expand Down Expand Up @@ -74,8 +75,23 @@ func (cc *ConsumerConfig) Init(rc *RootConfig) error {
break
}
}
for _, reference := range cc.References {
if err := reference.Init(rc); err != nil {
for key, referenceConfig := range cc.References {
if referenceConfig.InterfaceName == "" {
reference := GetConsumerService(key)
// try to use interface name defined by pb
supportPBPackagerNameReference, ok := reference.(common.TriplePBService)
LaurenceLiZhixin marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
logger.Errorf("Reference with reference = %s is not support read interface name from it."+
LaurenceLiZhixin marked this conversation as resolved.
Show resolved Hide resolved
"Please run go install github.com/dubbogo/tools/cmd/protoc-gen-go-triple@latest to update your "+
"protoc-gen-go-triple and re-generate your pb file again."+
"If you are not using pb serialization, please set 'interface' field in reference config.", key)
continue
} else {
// use interface name defined by pb
referenceConfig.InterfaceName = supportPBPackagerNameReference.XXX_InterfaceName()
}
}
if err := referenceConfig.Init(rc); err != nil {
return err
}
}
Expand Down
36 changes: 34 additions & 2 deletions config/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import (

import (
"github.com/creasty/defaults"

tripleConstant "github.com/dubbogo/triple/pkg/common/constant"
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/logger"
)
Expand Down Expand Up @@ -75,11 +78,40 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
break
}
}
for _, service := range c.Services {
if err := service.Init(rc); err != nil {
for key, serviceConfig := range c.Services {
if serviceConfig.Interface == "" {
service := GetProviderService(key)
// try to use interface name defined by pb
supportPBPackagerNameSerivce, ok := service.(common.TriplePBService)
if !ok {
logger.Errorf("Service with reference = %s is not support read interface name from it."+
"Please run go install github.com/dubbogo/tools/cmd/protoc-gen-go-triple@latest to update your "+
"protoc-gen-go-triple and re-generate your pb file again."+
"If you are not using pb serialization, please set 'interface' field in service config.", key)
continue
} else {
// use interface name defined by pb
serviceConfig.Interface = supportPBPackagerNameSerivce.XXX_InterfaceName()
}
}
if err := serviceConfig.Init(rc); err != nil {
return err
}
}

for k, v := range rc.Protocols {
if v.Name == tripleConstant.TRIPLE {
tripleReflectionService := NewServiceConfigBuilder().
SetProtocolIDs(k).
SetInterface("grpc.reflection.v1alpha.ServerReflection").
Build()
if err := tripleReflectionService.Init(rc); err != nil {
return err
}
c.Services["XXX_serverReflectionServer"] = tripleReflectionService
}
}

if err := c.check(); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
type ReferenceConfig struct {
pxy *proxy.Proxy
id string
InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"`
InterfaceName string `yaml:"interface" json:"interface,omitempty" property:"interface"`
Check *bool `yaml:"check" json:"check,omitempty" property:"check"`
URL string `yaml:"url" json:"url,omitempty" property:"url"`
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
Expand Down
2 changes: 1 addition & 1 deletion config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type ServiceConfig struct {
id string
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
ProtocolIDs []string `yaml:"protocol-ids" json:"protocol-ids,omitempty" property:"protocol-ids"` // multi protocolIDs support, split by ','
Interface string `validate:"required" yaml:"interface" json:"interface,omitempty" property:"interface"`
LaurenceLiZhixin marked this conversation as resolved.
Show resolved Hide resolved
Interface string `yaml:"interface" json:"interface,omitempty" property:"interface"`
RegistryIDs []string `yaml:"registry-ids" json:"registry-ids,omitempty" property:"registry-ids"`
Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty" property:"cluster"`
Loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"`
Expand Down
1 change: 1 addition & 0 deletions config_center/zookeeper/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

import (
"github.com/dubbogo/go-zookeeper/zk"

gxset "github.com/dubbogo/gost/container/set"
gxzookeeper "github.com/dubbogo/gost/database/kv/zk"

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/dubbogo/go-zookeeper v1.0.3
github.com/dubbogo/gost v1.11.20-0.20211116110728-26777ca61b4a
github.com/dubbogo/grpc-go v1.42.6-triple
github.com/dubbogo/triple v1.1.5
github.com/dubbogo/triple v1.1.6-0.20211119123944-4ad68a0d048e
github.com/emicklei/go-restful/v3 v3.7.1
github.com/fsnotify/fsnotify v1.5.1
github.com/ghodss/yaml v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ github.com/dubbogo/grpc-go v1.42.6-triple/go.mod h1:F1T9hnUvYGW4JLK1QNriavpOkhus
github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc=
github.com/dubbogo/triple v1.0.9/go.mod h1:1t9me4j4CTvNDcsMZy6/OGarbRyAUSY0tFXGXHCp7Iw=
github.com/dubbogo/triple v1.1.5 h1:obLSzyJWawOBrah9PeFqLDRom5jVQGVuzs4NO4YzuS8=
github.com/dubbogo/triple v1.1.5/go.mod h1:5lGslNo9Tq8KR8+tSSSJkhypNaREYZCKCk0Owx40Cx4=
github.com/dubbogo/triple v1.1.6-0.20211119123944-4ad68a0d048e h1:GJDV0dOaKwSP/4i8eaDNJ/FpH3sW9czArA0MGj4BZ8Q=
github.com/dubbogo/triple v1.1.6-0.20211119123944-4ad68a0d048e/go.mod h1:5lGslNo9Tq8KR8+tSSSJkhypNaREYZCKCk0Owx40Cx4=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down
1 change: 1 addition & 0 deletions imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
_ "dubbo.apache.org/dubbo-go/v3/metrics/prometheus"
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo3"
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo3/reflection"
_ "dubbo.apache.org/dubbo-go/v3/protocol/grpc"
_ "dubbo.apache.org/dubbo-go/v3/protocol/jsonrpc"
_ "dubbo.apache.org/dubbo-go/v3/protocol/rest"
Expand Down
5 changes: 4 additions & 1 deletion protocol/dubbo3/dubbo3_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func (dp *DubboProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
if serializationType == constant.ProtobufSerialization {
m, ok := reflect.TypeOf(service).MethodByName("XXX_SetProxyImpl")
if !ok {
panic("method XXX_SetProxyImpl is necessary for triple service")
logger.Errorf("PB service with key = %s is not support XXX_SetProxyImpl to pb."+
"Please run go install github.com/dubbogo/tools/cmd/protoc-gen-go-triple@latest to update your "+
"protoc-gen-go-triple and re-generate your pb file again.", key)
return nil
}
if invoker == nil {
panic(fmt.Sprintf("no invoker found for servicekey: %v", url.ServiceKey()))
Expand Down
Loading