Skip to content

Commit

Permalink
Enable publish servicedefinition to metadata center (#2025)
Browse files Browse the repository at this point in the history
* fix zk invalid path when metadata-type: remote

* format the file

* add log record when joinParams early return

* fix type conversion bug

* add json format

* modify unit test

* fix typo
  • Loading branch information
Leospard authored Sep 24, 2022
1 parent 96683b0 commit 5268c26
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
30 changes: 15 additions & 15 deletions metadata/definition/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ type ServiceDefiner interface {

// ServiceDefinition is the describer of service definition
type ServiceDefinition struct {
CanonicalName string
CodeSource string
Methods []MethodDefinition
Types []TypeDefinition
CanonicalName string `json:"canonicalName"`
CodeSource string `json:"codeSource"`
Methods []MethodDefinition `json:"methods"`
Types []TypeDefinition `json:"types"`
}

// ToBytes convert ServiceDefinition to json string
Expand Down Expand Up @@ -71,26 +71,26 @@ func (def *ServiceDefinition) String() string {

// FullServiceDefinition is the describer of service definition with parameters
type FullServiceDefinition struct {
Parameters map[string]string
Parameters map[string]string `json:"parameters"`
ServiceDefinition
}

// MethodDefinition is the describer of method definition
type MethodDefinition struct {
Name string
ParameterTypes []string
ReturnType string
Parameters []TypeDefinition
Name string `json:"name"`
ParameterTypes []string `json:"parameterTypes"`
ReturnType string `json:"returnType"`
Parameters []TypeDefinition `json:"parameters"`
}

// TypeDefinition is the describer of type definition
type TypeDefinition struct {
ID string
Type string
Items []TypeDefinition
Enums []string
Properties map[string]TypeDefinition
TypeBuilderName string
ID string `json:"id"`
Type string `json:"type"`
Items []TypeDefinition `json:"items"`
Enums []string `json:"enums"`
Properties map[string]TypeDefinition `json:"properties"`
TypeBuilderName string `json:"typeBuilderName"`
}

// BuildServiceDefinition can build service definition which will be used to describe a service
Expand Down
8 changes: 8 additions & 0 deletions metadata/identifier/base_metadata_identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"net/url"
)

import (
"github.com/dubbogo/gost/log/logger"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
)
Expand All @@ -43,6 +47,10 @@ type BaseMetadataIdentifier struct {
func joinParams(joinChar string, params []string) string {
var joinedStr string
for _, param := range params {
if param == "" {
logger.Info("[Metadata report] Break loop in `joinParams` to avoid invalid path when meeting empty param")
break
}
joinedStr += joinChar
joinedStr += param
}
Expand Down
2 changes: 1 addition & 1 deletion metadata/report/delegate/delegate_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (mr *MetadataReport) doHandlerMetadataCollection(metadataMap map[*identifie
}
for e := range metadataMap {
if common.RoleType(common.PROVIDER).Role() == e.Side {
mr.StoreProviderMetadata(e, metadataMap[e].(*definition.ServiceDefinition))
mr.StoreProviderMetadata(e, metadataMap[e].(*definition.FullServiceDefinition))
} else if common.RoleType(common.CONSUMER).Role() == e.Side {
mr.StoreConsumerMetadata(e, metadataMap[e].(map[string]string))
}
Expand Down
8 changes: 4 additions & 4 deletions metadata/service/local/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ func TestMetadataService(t *testing.T) {
assert.NoError(t, err)
err = mts.PublishServiceDefinition(u)
assert.NoError(t, err)
expected := "{\"Parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," +
expected := "{\"parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," +
"\"bean.name\":\"UserProvider\",\"category\":\"providers\",\"default.timeout\":\"10000\"," +
"\"dubbo\":\"dubbo-provider-golang-1.0.0\",\"environment\":\"dev\",\"group\":\"group1\"," +
"\"interface\":\"com.ikurento.user.UserProvider\",\"ip\":\"192.168.56.1\"," +
"\"methods\":\"GetUser\",\"module\":\"dubbogo user-info server\",\"org\":\"ikurento.com\"," +
"\"owner\":\"ZX\",\"pid\":\"1447\",\"revision\":\"0.0.1\",\"side\":\"provider\"," +
"\"timeout\":\"3000\",\"timestamp\":\"1556509797245\",\"version\":\"0.0.1\"}," +
"\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
"\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," +
"\"Parameters\":null}],\"Types\":null}"
"\"canonicalName\":\"com.ikurento.user.UserProvider\",\"codeSource\":\"\"," +
"\"methods\":[{\"name\":\"GetUser\",\"parameterTypes\":[\"slice\"],\"returnType\":\"ptr\"," +
"\"parameters\":null}],\"types\":null}"
def1, err := mts.GetServiceDefinition(serviceName, group, version)
assert.Equal(t, expected, def1)
assert.NoError(t, err)
Expand Down
9 changes: 4 additions & 5 deletions metadata/service/remote/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,16 @@ func TestMockInmemoryProc(t *testing.T) {
err = mts.PublishServiceDefinition(u)
assert.NoError(t, err)

expected := "{\"Parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," +
expected := "{\"parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," +
"\"bean.name\":\"UserProvider\",\"category\":\"providers\",\"default.timeout\":\"10000\"," +
"\"dubbo\":\"dubbo-provider-golang-1.0.0\",\"environment\":\"dev\",\"group\":\"group1\"," +
"\"interface\":\"com.ikurento.user.UserProvider\",\"ip\":\"192.168.56.1\"," +
"\"methods\":\"GetUser\",\"module\":\"dubbogo user-info server\",\"org\":\"ikurento.com\"," +
"\"owner\":\"ZX\",\"pid\":\"1447\",\"revision\":\"0.0.1\",\"side\":\"provider\"," +
"\"timeout\":\"3000\",\"timestamp\":\"1556509797245\",\"version\":\"0.0.1\"}," +
"\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
"\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," +
"\"Parameters\":null}],\"Types\":null}"

"\"canonicalName\":\"com.ikurento.user.UserProvider\",\"codeSource\":\"\"," +
"\"methods\":[{\"name\":\"GetUser\",\"parameterTypes\":[\"slice\"],\"returnType\":\"ptr\"," +
"\"parameters\":null}],\"types\":null}"
def1, _ := mts.GetServiceDefinition(serviceName, group, version)
assert.Equal(t, expected, def1)
serviceKey := definition.ServiceDescriperBuild(serviceName, group, version)
Expand Down

0 comments on commit 5268c26

Please sign in to comment.