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

Add protobuf based MetadataService support #2723

Merged
merged 18 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ deps: prepare

.PHONY: license
license: clean prepareLic
$(GO_LICENSE_CHECKER) -v -a -r -i vendor,protocol/triple/triple_protocol,protocol/triple/reflection,cmd/protoc-gen-go-triple/internal $(LICENSE_DIR)/license.txt . go && [[ -z `git status -s` ]]
$(GO_LICENSE_CHECKER) -v -a -r -i vendor,protocol/triple/triple_protocol,protocol/triple/reflection,metadata/triple_api/proto $(LICENSE_DIR)/license.txt . go && [[ -z `git status -s` ]]

.PHONY: verify
verify: clean license test
Expand Down
20 changes: 11 additions & 9 deletions client/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import (
// todo(DMwangnima): remove these functions when refactoring dubbo-go
func compatApplicationConfig(c *global.ApplicationConfig) *config.ApplicationConfig {
return &config.ApplicationConfig{
Organization: c.Organization,
Name: c.Name,
Module: c.Module,
Group: c.Group,
Version: c.Version,
Owner: c.Owner,
Environment: c.Environment,
MetadataType: c.MetadataType,
Tag: c.Tag,
Organization: c.Organization,
Name: c.Name,
Module: c.Module,
Group: c.Group,
Version: c.Version,
Owner: c.Owner,
Environment: c.Environment,
MetadataType: c.MetadataType,
Tag: c.Tag,
MetadataServicePort: c.MetadataServicePort,
MetadataServiceProtocol: c.MetadataServiceProtocol,
}
}

Expand Down
8 changes: 4 additions & 4 deletions client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (refOpts *ReferenceOptions) init(opts ...ReferenceOption) error {

// init protocol
if ref.Protocol == "" {
ref.Protocol = "tri"
ref.Protocol = constant.TriProtocol
if refOpts.Consumer != nil && refOpts.Consumer.Protocol != "" {
ref.Protocol = refOpts.Consumer.Protocol
}
Expand Down Expand Up @@ -342,7 +342,7 @@ func WithProtocolDubbo() ReferenceOption {

func WithProtocolTriple() ReferenceOption {
return func(opts *ReferenceOptions) {
opts.Reference.Protocol = "tri"
opts.Reference.Protocol = constant.TriProtocol
}
}

Expand Down Expand Up @@ -514,7 +514,7 @@ func (cliOpts *ClientOptions) init(opts ...ClientOption) error {

// init protocol
if cliOpts.Consumer.Protocol == "" {
cliOpts.Consumer.Protocol = "tri"
cliOpts.Consumer.Protocol = constant.TriProtocol
}

// init serialization
Expand Down Expand Up @@ -766,7 +766,7 @@ func WithClientProtocolDubbo() ClientOption {

func WithClientProtocolTriple() ClientOption {
return func(opts *ClientOptions) {
opts.Consumer.Protocol = "tri"
opts.Consumer.Protocol = constant.TriProtocol
}
}

Expand Down
10 changes: 8 additions & 2 deletions cluster/router/affinity/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@

package affinity

import (
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

import (
"dubbo.apache.org/dubbo-go/v3/cluster/router/condition"
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/protocol"
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
"dubbo.apache.org/dubbo-go/v3/remoting"
"github.com/stretchr/testify/assert"
"testing"
)

var providerUrls = []string{
Expand Down
10 changes: 8 additions & 2 deletions cluster/router/script/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ package script

import (
"context"
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/protocol"
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
"dubbo.apache.org/dubbo-go/v3/remoting"
"github.com/stretchr/testify/assert"
"testing"
)

var url1 = func() *common.URL {
Expand Down
1 change: 1 addition & 0 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
OverrideProtocol = "override" //compatible with 2.6.x
EmptyProtocol = "empty"
RouterProtocol = "router"
TriProtocol = "tri"
)

const (
Expand Down
19 changes: 13 additions & 6 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,19 @@ const (
// metadata report

const (
MetaConfigRemote = "remote"
MetaConfigLocal = "local"
KeySeparator = ":"
DefaultPathTag = "metadata"
KeyRevisionPrefix = "revision"
MetadataServiceName = "org.apache.dubbo.metadata.MetadataService" // metadata service
MetaConfigRemote = "remote"
MetaConfigLocal = "local"
KeySeparator = ":"
DefaultPathTag = "metadata"
KeyRevisionPrefix = "revision"
MetadataServiceName = "org.apache.dubbo.metadata.MetadataService" // metadata service
MetadataServiceV2Name = "org.apache.dubbo.metadata.MetadataServiceV2" // metadata service

MetadataVersion = "meta-v"

MetadataServiceV1 = "MetadataServiceV1"
MetadataServiceV2 = "MetadataServiceV2"
MetadataServiceV2Version = "2.0.0"
)

// service discovery
Expand Down
6 changes: 3 additions & 3 deletions common/extension/metadata_service_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/metadata/service/exporter"
)

type MetadataServiceExporterCreator func(service.MetadataService) exporter.MetadataServiceExporter
type MetadataServiceExporterCreator func(service.MetadataService, service.MetadataServiceV1, service.MetadataServiceV2) exporter.MetadataServiceExporter

var (
metadataServiceExporterInsMap = make(map[string]MetadataServiceExporterCreator, 2)
Expand All @@ -35,12 +35,12 @@ func SetMetadataServiceExporter(key string, creator MetadataServiceExporterCreat
}

// GetMetadataServiceExporter will create a MetadataServiceExporter instance
func GetMetadataServiceExporter(key string, s service.MetadataService) exporter.MetadataServiceExporter {
func GetMetadataServiceExporter(key string, s service.MetadataService, sV1 service.MetadataServiceV1, sV2 service.MetadataServiceV2) exporter.MetadataServiceExporter {
if key == "" {
key = constant.DefaultKey
}
if creator, ok := metadataServiceExporterInsMap[key]; ok {
return creator(s)
return creator(s, sV1, sV2)
}
return nil
}
50 changes: 50 additions & 0 deletions common/extension/metadata_service_proxy_factory_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 extension

import (
"fmt"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metadata/service"
)

var metadataServiceProxyFactoryMapV2 = make(map[string]func() service.MetadataServiceProxyFactoryV2, 2)

type MetadataServiceProxyFactoryFuncV2 func() service.MetadataServiceProxyFactoryV2

// SetMetadataServiceProxyFactory store the name-creator pair
func SetMetadataServiceProxyFactoryV2(name string, creator MetadataServiceProxyFactoryFuncV2) {
metadataServiceProxyFactoryMapV2[name] = creator
}

// GetMetadataServiceProxyFactory will create an instance.
// it will panic if the factory with name not found
func GetMetadataServiceProxyFactoryV2(name string) service.MetadataServiceProxyFactoryV2 {
if name == "" {
name = constant.DefaultKey
}
if f, ok := metadataServiceProxyFactoryMapV2[name]; ok {
return f()
}
panic(fmt.Sprintf("could not find the metadata service factory creator for name: %s, "+
"please check whether you have imported relative packages, "+
"local - dubbo.apache.org/dubbo-go/v3/metadata/service/local", name))
}
55 changes: 55 additions & 0 deletions common/extension/metadata_service_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 extension

import (
"fmt"
)

import (
perrors "github.com/pkg/errors"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metadata/service"
)

type localMetadataServiceCreatorV1 func() (service.MetadataServiceV1, error)

var (
localMetadataServiceInsMapV1 = make(map[string]localMetadataServiceCreatorV1, 2)
)

// SetLocalMetadataService will store the msType => creator pair
func SetLocalMetadataServiceV1(key string, creator localMetadataServiceCreatorV1) {
localMetadataServiceInsMapV1[key] = creator
}

// GetLocalMetadataService will create a local MetadataService instance
func GetLocalMetadataServiceV1(key string) (service.MetadataServiceV1, error) {
if key == "" {
key = constant.DefaultKey
}
if creator, ok := localMetadataServiceInsMapV1[key]; ok {
return creator()
}
return nil, perrors.New(fmt.Sprintf("could not find the metadata service creator for metadataType: local, " +
"please check whether you have imported relative packages, " +
"local - dubbo.apache.org/dubbo-go/v3/metadata/service/local"))
}
55 changes: 55 additions & 0 deletions common/extension/metadata_service_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 extension

import (
"fmt"
)

import (
perrors "github.com/pkg/errors"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metadata/service"
)

type localMetadataServiceCreatorV2 func() (service.MetadataServiceV2, error)

var (
localMetadataServiceInsMapV2 = make(map[string]localMetadataServiceCreatorV2, 2)
)

// SetLocalMetadataService will store the msType => creator pair
func SetLocalMetadataServiceV2(key string, creator localMetadataServiceCreatorV2) {
localMetadataServiceInsMapV2[key] = creator
}

// GetLocalMetadataService will create a local MetadataService instance
func GetLocalMetadataServiceV2(key string) (service.MetadataServiceV2, error) {
if key == "" {
key = constant.DefaultKey
}
if creator, ok := localMetadataServiceInsMapV2[key]; ok {
return creator()
}
return nil, perrors.New(fmt.Sprintf("could not find the metadata service creator for metadataType: local, " +
"please check whether you have imported relative packages, " +
"local - dubbo.apache.org/dubbo-go/v3/metadata/service/local"))
}
12 changes: 12 additions & 0 deletions common/host_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package common

import (
"fmt"
"os"
"strconv"
"strings"
Expand All @@ -26,6 +27,8 @@ import (
import (
"github.com/dubbogo/gost/log/logger"
gxnet "github.com/dubbogo/gost/net"

perrors "github.com/pkg/errors"
)

import (
Expand Down Expand Up @@ -106,3 +109,12 @@ func IsMatchGlobPattern(pattern, value string) bool {
return strings.HasPrefix(value, prefix) && strings.HasSuffix(value, suffix)
}
}

func GetRandomPort(ip string) string {
tcp, err := gxnet.ListenOnTCPRandomPort(ip)
if err != nil {
panic(perrors.New(fmt.Sprintf("Get tcp port error, err is {%v}", err)))
}
defer tcp.Close()
return strings.Split(tcp.Addr().String(), ":")[1]
}
20 changes: 11 additions & 9 deletions compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ func compatApplicationConfig(c *global.ApplicationConfig) *config.ApplicationCon
return nil
}
return &config.ApplicationConfig{
Organization: c.Organization,
Name: c.Name,
Module: c.Module,
Group: c.Group,
Version: c.Version,
Owner: c.Owner,
Environment: c.Environment,
MetadataType: c.MetadataType,
Tag: c.Tag,
Organization: c.Organization,
Name: c.Name,
Module: c.Module,
Group: c.Group,
Version: c.Version,
Owner: c.Owner,
Environment: c.Environment,
MetadataType: c.MetadataType,
Tag: c.Tag,
MetadataServicePort: c.MetadataServicePort,
MetadataServiceProtocol: c.MetadataServiceProtocol,
}
}

Expand Down
Loading
Loading