Skip to content
Snippets Groups Projects
Unverified Commit 370681af authored by Ming Deng's avatar Ming Deng Committed by GitHub
Browse files

Merge pull request #471 from hxmhlt/metadata_report

Add: Metadata report base
parents 422b6780 f595f501
No related branches found
No related tags found
No related merge requests found
Showing
with 384 additions and 163 deletions
......@@ -26,6 +26,7 @@ const (
VERSION_KEY = "version"
INTERFACE_KEY = "interface"
PATH_KEY = "path"
PROTOCOL_KEY = "protocol"
SERVICE_KEY = "service"
METHODS_KEY = "methods"
TIMEOUT_KEY = "timeout"
......
......@@ -18,20 +18,20 @@
package extension
import (
"github.com/apache/dubbo-go/metadata"
"github.com/apache/dubbo-go/metadata/report/factory"
)
var (
metaDataReportFactories = make(map[string]func() metadata.MetadataReportFactory, 8)
metaDataReportFactories = make(map[string]func() factory.MetadataReportFactory, 8)
)
// SetMetadataReportFactory ...
func SetMetadataReportFactory(name string, v func() metadata.MetadataReportFactory) {
func SetMetadataReportFactory(name string, v func() factory.MetadataReportFactory) {
metaDataReportFactories[name] = v
}
// GetMetadataReportFactory ...
func GetMetadataReportFactory(name string) metadata.MetadataReportFactory {
func GetMetadataReportFactory(name string) factory.MetadataReportFactory {
if metaDataReportFactories[name] == nil {
panic("metadata report for " + name + " is not existing, make sure you have import the package.")
}
......
......@@ -133,6 +133,11 @@ func (s *Service) Method() map[string]*MethodType {
return s.methods
}
// Name will return service name
func (s *Service) Name() string {
return s.name
}
// RcvrType ...
func (s *Service) RcvrType() reflect.Type {
return s.rcvrType
......
......@@ -53,15 +53,6 @@ func Test_refresh(t *testing.T) {
Owner: "dubbo",
Environment: "test"},
Registries: map[string]*RegistryConfig{
//"shanghai_reg1": {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
//},
"shanghai_reg2": {
Protocol: "mock",
TimeoutStr: "2s",
......@@ -156,15 +147,6 @@ func Test_appExternal_refresh(t *testing.T) {
Owner: "dubbo",
Environment: "test"},
Registries: map[string]*RegistryConfig{
//"shanghai_reg1": {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
//},
"shanghai_reg2": {
Protocol: "mock",
TimeoutStr: "2s",
......@@ -251,15 +233,6 @@ func Test_appExternalWithoutId_refresh(t *testing.T) {
Owner: "dubbo",
Environment: "test"},
Registries: map[string]*RegistryConfig{
//"shanghai_reg1": {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
//},
"shanghai_reg2": {
Protocol: "mock",
TimeoutStr: "2s",
......@@ -408,15 +381,6 @@ func Test_refreshProvider(t *testing.T) {
Owner: "dubbo",
Environment: "test"},
Registries: map[string]*RegistryConfig{
//"shanghai_reg1": {
// id: "shanghai_reg1",
// Protocol: "mock",
// TimeoutStr: "2s",
// Group: "shanghai_idc",
// Address: "127.0.0.1:2181",
// Username: "user1",
// Password: "pwd1",
//},
"shanghai_reg2": {
Protocol: "mock",
TimeoutStr: "2s",
......
......@@ -210,6 +210,7 @@ func Load() {
}
svs.id = key
svs.Implement(rpcService)
svs.Protocols = providerConfig.Protocols
if err := svs.Export(); err != nil {
panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
}
......
......@@ -24,6 +24,7 @@ import (
import (
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"
)
import (
......@@ -90,7 +91,7 @@ func TestLoad(t *testing.T) {
func TestLoadWithSingleReg(t *testing.T) {
doInitConsumerWithSingleRegistry()
doInitProviderWithSingleRegistry()
mockInitProviderWithSingleRegistry()
ms := &MockService{}
SetConsumerService(ms)
......@@ -233,3 +234,55 @@ func TestConfigLoaderWithConfigCenterSingleRegistry(t *testing.T) {
assert.Equal(t, "mock://127.0.0.1:2182", consumerConfig.Registries[constant.DEFAULT_KEY].Address)
}
// mockInitProviderWithSingleRegistry will init a mocked providerConfig
func mockInitProviderWithSingleRegistry() {
providerConfig = &ProviderConfig{
ApplicationConfig: &ApplicationConfig{
Organization: "dubbo_org",
Name: "dubbo",
Module: "module",
Version: "1.0.0",
Owner: "dubbo",
Environment: "test"},
Registry: &RegistryConfig{
Address: "mock://127.0.0.1:2181",
Username: "user1",
Password: "pwd1",
},
Registries: map[string]*RegistryConfig{},
Services: map[string]*ServiceConfig{
"MockService": {
InterfaceName: "com.MockService",
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
{
Name: "GetUser",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
{
Name: "GetUser1",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
},
exported: new(atomic.Bool),
},
},
Protocols: map[string]*ProtocolConfig{
"mock": {
Name: "mock",
Ip: "127.0.0.1",
Port: "20000",
},
},
}
}
......@@ -24,16 +24,16 @@ import (
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/metadata"
"github.com/apache/dubbo-go/metadata/report"
)
var (
instance metadata.MetadataReport
instance report.MetadataReport
once sync.Once
)
// GetMetadataReportInstance ...
func GetMetadataReportInstance(url *common.URL) metadata.MetadataReport {
func GetMetadataReportInstance(url *common.URL) report.MetadataReport {
once.Do(func() {
instance = extension.GetMetadataReportFactory(url.Protocol).CreateMetadataReport(url)
})
......
......@@ -71,11 +71,15 @@ type ServiceConfig struct {
ParamSign string `yaml:"param.sign" json:"param.sign,omitempty" property:"param.sign"`
Tag string `yaml:"tag" json:"tag,omitempty" property:"tag"`
Protocols map[string]*ProtocolConfig
unexported *atomic.Bool
exported *atomic.Bool
rpcService common.RPCService
cacheProtocol protocol.Protocol
cacheMutex sync.Mutex
cacheProtocol protocol.Protocol
exportersLock sync.Mutex
exporters []protocol.Exporter
}
// Prefix ...
......@@ -92,6 +96,8 @@ func (c *ServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal((*plain)(c)); err != nil {
return err
}
c.exported = atomic.NewBool(false)
c.unexported = atomic.NewBool(false)
return nil
}
......@@ -105,6 +111,16 @@ func NewServiceConfig(id string, context context.Context) *ServiceConfig {
}
}
// InitExported will set exported as false atom bool
func (c *ServiceConfig) InitExported() {
c.exported = atomic.NewBool(false)
}
// IsExport will return whether the service config is exported or not
func (c *ServiceConfig) IsExport() bool {
return c.exported.Load()
}
// Export ...
func (c *ServiceConfig) Export() error {
// TODO: config center start here
......@@ -122,7 +138,7 @@ func (c *ServiceConfig) Export() error {
regUrls := loadRegistries(c.Registry, providerConfig.Registries, common.PROVIDER)
urlMap := c.getUrlMap()
protocolConfigs := loadProtocol(c.Protocol, providerConfig.Protocols)
protocolConfigs := loadProtocol(c.Protocol, c.Protocols)
if len(protocolConfigs) == 0 {
logger.Warnf("The service %v's '%v' protocols don't has right protocolConfigs ", c.InterfaceName, c.Protocol)
return nil
......@@ -148,6 +164,9 @@ func (c *ServiceConfig) Export() error {
if len(c.Tag) > 0 {
ivkURL.AddParam(constant.Tagkey, c.Tag)
}
var exporter protocol.Exporter
if len(regUrls) > 0 {
for _, regUrl := range regUrls {
regUrl.SubURL = ivkURL
......@@ -160,22 +179,46 @@ func (c *ServiceConfig) Export() error {
c.cacheMutex.Unlock()
invoker := extension.GetProxyFactory(providerConfig.ProxyFactory).GetInvoker(*regUrl)
exporter := c.cacheProtocol.Export(invoker)
exporter = c.cacheProtocol.Export(invoker)
if exporter == nil {
panic(perrors.New(fmt.Sprintf("Registry protocol new exporter error,registry is {%v},url is {%v}", regUrl, ivkURL)))
}
}
} else {
invoker := extension.GetProxyFactory(providerConfig.ProxyFactory).GetInvoker(*ivkURL)
exporter := extension.GetProtocol(protocolwrapper.FILTER).Export(invoker)
exporter = extension.GetProtocol(protocolwrapper.FILTER).Export(invoker)
if exporter == nil {
panic(perrors.New(fmt.Sprintf("Filter protocol without registry new exporter error,url is {%v}", ivkURL)))
}
}
c.exporters = append(c.exporters, exporter)
}
c.exported.Store(true)
return nil
}
// Unexport will call unexport of all exporters service config exported
func (c *ServiceConfig) Unexport() {
if !c.exported.Load() {
return
}
if c.unexported.Load() {
return
}
func() {
c.exportersLock.Lock()
defer c.exportersLock.Unlock()
for _, exporter := range c.exporters {
exporter.Unexport()
}
c.exporters = nil
}()
c.exported.Store(false)
c.unexported.Store(true)
}
// Implement ...
func (c *ServiceConfig) Implement(s common.RPCService) {
c.rpcService = s
......@@ -245,3 +288,16 @@ func (c *ServiceConfig) getUrlMap() url.Values {
return urlMap
}
// GetExportedUrls will return the url in service config's exporter
func (c *ServiceConfig) GetExportedUrls() []*common.URL {
if c.exported.Load() {
var urls []*common.URL
for _, exporter := range c.exporters {
url := exporter.GetInvoker().GetUrl()
urls = append(urls, &url)
}
return urls
}
return nil
}
......@@ -21,6 +21,10 @@ import (
"testing"
)
import (
"go.uber.org/atomic"
)
import (
"github.com/apache/dubbo-go/common/extension"
)
......@@ -92,6 +96,7 @@ func doInitProvider() {
Weight: 200,
},
},
exported: new(atomic.Bool),
},
"MockServiceNoRightProtocol": {
InterfaceName: "com.MockService",
......@@ -116,56 +121,7 @@ func doInitProvider() {
Weight: 200,
},
},
},
},
Protocols: map[string]*ProtocolConfig{
"mock": {
Name: "mock",
Ip: "127.0.0.1",
Port: "20000",
},
},
}
}
func doInitProviderWithSingleRegistry() {
providerConfig = &ProviderConfig{
ApplicationConfig: &ApplicationConfig{
Organization: "dubbo_org",
Name: "dubbo",
Module: "module",
Version: "2.6.0",
Owner: "dubbo",
Environment: "test"},
Registry: &RegistryConfig{
Address: "mock://127.0.0.1:2181",
Username: "user1",
Password: "pwd1",
},
Registries: map[string]*RegistryConfig{},
Services: map[string]*ServiceConfig{
"MockService": {
InterfaceName: "com.MockService",
Protocol: "mock",
Cluster: "failover",
Loadbalance: "random",
Retries: "3",
Group: "huadong_idc",
Version: "1.0.0",
Methods: []*MethodConfig{
{
Name: "GetUser",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
{
Name: "GetUser1",
Retries: "2",
Loadbalance: "random",
Weight: 200,
},
},
exported: new(atomic.Bool),
},
},
Protocols: map[string]*ProtocolConfig{
......
module github.com/apache/dubbo-go
require (
github.com/Workiva/go-datastructures v1.0.50
github.com/Workiva/go-datastructures v1.0.52
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e // indirect
github.com/apache/dubbo-go-hessian2 v1.4.0
......
......@@ -27,8 +27,8 @@ github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc h1:LkkwnbY+S8Wmw
github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc/go.mod h1:ARgCUhI1MHQH+ONky/PAtmVHQrP5JlGY0F3poXOp/fA=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/Workiva/go-datastructures v1.0.50 h1:slDmfW6KCHcC7U+LP3DDBbm4fqTwZGn1beOFPfGaLvo=
github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9abU0yMQt0NI=
github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af h1:DBNMBMuMiWYu0b+8KMJuWmfCkcxl09JwdlqwDZZ6U14=
github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 h1:rFw4nCn9iMW+Vajsk51NtYIcwSTkXr+JGrMd36kTDJw=
......@@ -111,10 +111,7 @@ github.com/dubbogo/getty v1.3.3/go.mod h1:U92BDyJ6sW9Jpohr2Vlz8w2uUbIbNZ3d+6rJvF
github.com/dubbogo/go-zookeeper v1.0.0 h1:RsYdlGwhDW+iKXM3eIIcvt34P2swLdmQfuIJxsHlGoM=
github.com/dubbogo/go-zookeeper v1.0.0/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/gost v1.5.1/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.5.2 h1:ri/03971hdpnn3QeCU+4UZgnRNGDXLDGDucR/iozZm8=
github.com/dubbogo/gost v1.5.2/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.7.0 h1:lWNBIE2hk1Aj2be2uXkyRTpZG0RQZj0/xbXnkIq6EHE=
github.com/dubbogo/gost v1.7.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.8.0 h1:9ACbQe5OwMjqtinQcNJC5xp16kky27OsfSGw5L9A6vw=
github.com/dubbogo/gost v1.8.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74 h1:2MIhn2R6oXQbgW5yHfS+d6YqyMfXiu2L55rFZC4UD/M=
......@@ -385,8 +382,6 @@ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nacos-group/nacos-sdk-go v0.0.0-20190723125407-0242d42e3dbb h1:lbmvw8r9W55w+aQgWn35W1nuleRIECMoqUrmwAOAvoI=
github.com/nacos-group/nacos-sdk-go v0.0.0-20190723125407-0242d42e3dbb/go.mod h1:CEkSvEpoveoYjA81m4HNeYQ0sge0LFGKSEqO3JKHllo=
github.com/nacos-group/nacos-sdk-go v0.0.0-20191128082542-fe1b325b125c h1:WoCa3AvgQMVKNs+RIFlWPRgY9QVJwUxJDrGxHs0fcRo=
github.com/nacos-group/nacos-sdk-go v0.0.0-20191128082542-fe1b325b125c/go.mod h1:CEkSvEpoveoYjA81m4HNeYQ0sge0LFGKSEqO3JKHllo=
github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2 h1:BQ1HW7hr4IVovMwWg0E0PYcyW8CzqDcVmaew9cujU4s=
......
......@@ -17,6 +17,16 @@
package definition
import (
"bytes"
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
)
// ServiceDefinition is the describer of service definition
type ServiceDefinition struct {
CanonicalName string
CodeSource string
......@@ -24,6 +34,7 @@ type ServiceDefinition struct {
Types []TypeDefinition
}
// MethodDefinition is the describer of method definition
type MethodDefinition struct {
Name string
ParameterTypes []string
......@@ -31,6 +42,7 @@ type MethodDefinition struct {
Parameters []TypeDefinition
}
// TypeDefinition is the describer of type definition
type TypeDefinition struct {
Id string
Type string
......@@ -39,3 +51,39 @@ type TypeDefinition struct {
Properties map[string]TypeDefinition
TypeBuilderName string
}
// BuildServiceDefinition can build service definition which will be used to describe a service
func BuildServiceDefinition(service common.Service, url common.URL) ServiceDefinition {
sd := ServiceDefinition{}
sd.CanonicalName = url.Service()
for k, m := range service.Method() {
var paramTypes []string
for _, t := range m.ArgsType() {
paramTypes = append(paramTypes, t.Kind().String())
}
methodD := MethodDefinition{
Name: k,
ParameterTypes: paramTypes,
ReturnType: m.ReplyType().Kind().String(),
}
sd.Methods = append(sd.Methods, methodD)
}
return sd
}
// ServiceDescriperBuild: build the service key, format is `group/serviceName:version` which be same as URL's service key
func ServiceDescriperBuild(serviceName string, group string, version string) string {
buf := &bytes.Buffer{}
if group != "" {
buf.WriteString(group)
buf.WriteString(constant.PATH_SEPARATOR)
}
buf.WriteString(serviceName)
if version != "" && version != "0.0.0" {
buf.WriteString(constant.KEY_SEPARATOR)
buf.WriteString(version)
}
return buf.String()
}
......@@ -25,19 +25,21 @@ import (
"github.com/apache/dubbo-go/common/constant"
)
type BaseMetadataIdentifier interface {
getFilePathKey(params ...string) string
getIdentifierKey(params ...string) string
// BaseMetadataIdentifier defined for describe the Metadata base identify
type IMetadataIdentifier interface {
GetFilePathKey() string
GetIdentifierKey() string
}
type BaseServiceMetadataIdentifier struct {
serviceInterface string
version string
group string
side string
// BaseMetadataIdentifier is the base implement of BaseMetadataIdentifier interface
type BaseMetadataIdentifier struct {
ServiceInterface string
Version string
Group string
Side string
}
// joinParams...
// joinParams will join the specified char in slice, and build as string
func joinParams(joinChar string, params []string) string {
var joinedStr string
for _, param := range params {
......@@ -47,24 +49,24 @@ func joinParams(joinChar string, params []string) string {
return joinedStr
}
// getIdentifierKey...
func (mdi *BaseServiceMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.serviceInterface +
constant.KEY_SEPARATOR + mdi.version +
constant.KEY_SEPARATOR + mdi.group +
constant.KEY_SEPARATOR + mdi.side +
// getIdentifierKey will return string format as service:Version:Group:Side:param1:param2...
func (mdi *BaseMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.ServiceInterface +
constant.KEY_SEPARATOR + mdi.Version +
constant.KEY_SEPARATOR + mdi.Group +
constant.KEY_SEPARATOR + mdi.Side +
joinParams(constant.KEY_SEPARATOR, params)
}
// getFilePathKey...
func (mdi *BaseServiceMetadataIdentifier) getFilePathKey(params ...string) string {
path := serviceToPath(mdi.serviceInterface)
// getFilePathKey will return string format as metadata/path/Version/Group/Side/param1/param2...
func (mdi *BaseMetadataIdentifier) getFilePathKey(params ...string) string {
path := serviceToPath(mdi.ServiceInterface)
return constant.DEFAULT_PATH_TAG +
withPathSeparator(path) +
withPathSeparator(mdi.version) +
withPathSeparator(mdi.group) +
withPathSeparator(mdi.side) +
withPathSeparator(mdi.Version) +
withPathSeparator(mdi.Group) +
withPathSeparator(mdi.Side) +
joinParams(constant.PATH_SEPARATOR, params)
}
......
......@@ -15,23 +15,27 @@
* limitations under the License.
*/
package metadata
package identifier
import (
"github.com/apache/dubbo-go/common"
gxset "github.com/dubbogo/gost/container/set"
"testing"
)
type MetadataService interface {
ServiceName() string
ExportURL(url *common.URL) bool
UnexportURL(url *common.URL) bool
RefreshMetadata(exportedRevision string, subscribedRevision string) bool
SubscribeURL(url *common.URL) bool
UnsubscribeURL(url *common.URL) bool
PublishServiceDefinition(url *common.URL)
import (
"github.com/stretchr/testify/assert"
)
var baseId = &BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
}
func TestBaseGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/a/b/c", baseId.getFilePathKey("a", "b", "c"))
}
GetExportedURLs(serviceInterface string, group string, version string, protocol string) gxset.HashSet
GetServiceDefinition(interfaceName string, version string, group string) string
GetServiceDefinitionByServiceKey(serviceKey string) string
func TestBaseGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:a:b:c", baseId.getIdentifierKey("a", "b", "c"))
}
......@@ -17,17 +17,18 @@
package identifier
// MetadataIdentifier is inherit baseMetaIdentifier with Application name
type MetadataIdentifier struct {
application string
Application string
BaseMetadataIdentifier
}
// getIdentifierKey...
func (mdi *MetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.application)
// GetIdentifierKey will return string format as service:Version:Group:Side:Application
func (mdi *MetadataIdentifier) GetIdentifierKey() string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.Application)
}
// getIdentifierKey...
func (mdi *MetadataIdentifier) getFilePathKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.application)
// GetFilePathKey will return string format as metadata/path/Version/Group/Side/Application
func (mdi *MetadataIdentifier) GetFilePathKey() string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.Application)
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
var metadataId = &MetadataIdentifier{
Application: "app",
BaseMetadataIdentifier: BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
},
}
func TestGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/app", metadataId.GetFilePathKey())
}
func TestGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:app", metadataId.GetIdentifierKey())
}
......@@ -21,18 +21,19 @@ import (
"github.com/apache/dubbo-go/common/constant"
)
// ServiceMetadataIdentifier is inherit baseMetaIdentifier with service params: Revision and Protocol
type ServiceMetadataIdentifier struct {
revision string
protocol string
Revision string
Protocol string
BaseMetadataIdentifier
}
// getIdentifierKey...
func (mdi *ServiceMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.protocol + constant.KEY_REVISON_PREFIX + mdi.revision)
// GetIdentifierKey will return string format as service:Version:Group:Side:Protocol:"revision"+Revision
func (mdi *ServiceMetadataIdentifier) GetIdentifierKey() string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.Protocol, constant.KEY_REVISON_PREFIX+mdi.Revision)
}
// getIdentifierKey...
func (mdi *ServiceMetadataIdentifier) getFilePathKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.protocol + constant.KEY_REVISON_PREFIX + mdi.revision)
// GetFilePathKey will return string format as metadata/path/Version/Group/Side/Protocol/"revision"+Revision
func (mdi *ServiceMetadataIdentifier) GetFilePathKey() string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.Protocol, constant.KEY_REVISON_PREFIX+mdi.Revision)
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
var serviceMetadataId = &ServiceMetadataIdentifier{
Revision: "1.0",
Protocol: "dubbo",
BaseMetadataIdentifier: BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
},
}
func TestServiceGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/dubbo/revision1.0", serviceMetadataId.GetFilePathKey())
}
func TestServiceGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:dubbo:revision1.0", serviceMetadataId.GetIdentifierKey())
}
......@@ -17,17 +17,18 @@
package identifier
// SubscriberMetadataIdentifier is inherit baseMetaIdentifier with service params: Revision
type SubscriberMetadataIdentifier struct {
revision string
Revision string
BaseMetadataIdentifier
}
// getIdentifierKey...
func (mdi *SubscriberMetadataIdentifier) getIdentifierKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.revision)
// GetIdentifierKey will return string format as service:Version:Group:Side:Revision
func (mdi *SubscriberMetadataIdentifier) GetIdentifierKey() string {
return mdi.BaseMetadataIdentifier.getIdentifierKey(mdi.Revision)
}
// getIdentifierKey...
func (mdi *SubscriberMetadataIdentifier) getFilePathKey(params ...string) string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.revision)
// GetFilePathKey will return string format as metadata/path/Version/Group/Side/Revision
func (mdi *SubscriberMetadataIdentifier) GetFilePathKey() string {
return mdi.BaseMetadataIdentifier.getFilePathKey(mdi.Revision)
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package identifier
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
var subscribeMetadataId = &SubscriberMetadataIdentifier{
Revision: "1.0",
BaseMetadataIdentifier: BaseMetadataIdentifier{
ServiceInterface: "org.apache.pkg.mockService",
Version: "1.0.0",
Group: "Group",
Side: "provider",
},
}
func TestSubscribeGetFilePathKey(t *testing.T) {
assert.Equal(t, "metadata/1.0.0/Group/provider/1.0", subscribeMetadataId.GetFilePathKey())
}
func TestSubscribeGetIdentifierKey(t *testing.T) {
assert.Equal(t, "org.apache.pkg.mockService:1.0.0:Group:provider:1.0", subscribeMetadataId.GetIdentifierKey())
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment