Skip to content

Commit

Permalink
Rft: Restructuring remoting metadata service (apache#1227)
Browse files Browse the repository at this point in the history
* restructure remoting metadata serivce

* conform to the code style of imports
  • Loading branch information
justxuewei authored Jun 7, 2021
1 parent 16d8297 commit 3d57cfd
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 38 deletions.
12 changes: 6 additions & 6 deletions common/extension/metadata_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ import (
)

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

type remoteMetadataServiceCreator func() (remote.RemoteMetadataService, error)
type remotingMetadataServiceCreator func() (service.RemotingMetadataService, error)

var (
creator remoteMetadataServiceCreator
creator remotingMetadataServiceCreator
)

// SetRemoteMetadataService will store the remote metadata service
func SetRemoteMetadataService(creatorFunc remoteMetadataServiceCreator) {
// SetRemotingMetadataService will store the remote metadata service
func SetRemotingMetadataService(creatorFunc remotingMetadataServiceCreator) {
creator = creatorFunc
}

// GetRemoteMetadataServiceFactory will create a MetadataService instance
func GetRemoteMetadataService() (remote.RemoteMetadataService, error) {
func GetRemotingMetadataService() (service.RemotingMetadataService, error) {
if creator != nil {
return creator()
}
Expand Down
4 changes: 2 additions & 2 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ func registerServiceInstance() {
}
}
// todo publish metadata to remote
if remoteMetadataServiceImpl, err := extension.GetRemoteMetadataService(); err == nil {
remoteMetadataServiceImpl.PublishMetadata(GetApplicationConfig().Name)
if remotingMetadataService, err := extension.GetRemotingMetadataService(); err == nil {
remotingMetadataService.PublishMetadata(GetApplicationConfig().Name)
}
}

Expand Down
4 changes: 2 additions & 2 deletions config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ func (c *ReferenceConfig) GetInvoker() protocol.Invoker {
}

func publishConsumerDefinition(url *common.URL) {
if remoteMetadataServiceImpl, err := extension.GetRemoteMetadataService(); err == nil && remoteMetadataServiceImpl != nil {
remoteMetadataServiceImpl.PublishServiceDefinition(url)
if remotingMetadataService, err := extension.GetRemotingMetadataService(); err == nil && remotingMetadataService != nil {
remotingMetadataService.PublishServiceDefinition(url)
}
}

Expand Down
4 changes: 2 additions & 2 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ func (c *ServiceConfig) GetExportedUrls() []*common.URL {
}

func publishServiceDefinition(url *common.URL) {
if remoteMetadataServiceImpl, err := extension.GetRemoteMetadataService(); err == nil && remoteMetadataServiceImpl != nil {
remoteMetadataServiceImpl.PublishServiceDefinition(url)
if remotingMetadataService, err := extension.GetRemotingMetadataService(); err == nil && remotingMetadataService != nil {
remotingMetadataService.PublishServiceDefinition(url)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package remote_impl
package remoting

import (
"sync"
Expand All @@ -33,31 +33,29 @@ import (
"dubbo.apache.org/dubbo-go/v3/metadata/definition"
"dubbo.apache.org/dubbo-go/v3/metadata/identifier"
"dubbo.apache.org/dubbo-go/v3/metadata/report/delegate"
"dubbo.apache.org/dubbo-go/v3/metadata/service"
"dubbo.apache.org/dubbo-go/v3/metadata/service/inmemory"
"dubbo.apache.org/dubbo-go/v3/metadata/service/remote"
"dubbo.apache.org/dubbo-go/v3/registry"
)

// MetadataService is a implement of metadata service which will delegate the remote metadata report
// This is singleton
type RemoteMetadataServiceImpl struct {
type MetadataService struct {
*inmemory.MetadataService
exportedRevision atomic.String
subscribedRevision atomic.String
delegateReport *delegate.MetadataReport
}

var (
metadataServiceOnce sync.Once
remoteMetadataServiceImplInstance remote.RemoteMetadataService
metadataServiceOnce sync.Once
remotingMetadataServiceInstance service.RemotingMetadataService
)

func init() {
extension.SetRemoteMetadataService(GetRemoteMetadataService)
extension.SetRemotingMetadataService(GetRemotingMetadataService)
}

// GetRemoteMetadataService will create a new remote MetadataService instance
func GetRemoteMetadataService() (remote.RemoteMetadataService, error) {
// GetRemotingMetadataService will create a new remote MetadataService instance
func GetRemotingMetadataService() (service.RemotingMetadataService, error) {
var err error
metadataServiceOnce.Do(func() {
var mr *delegate.MetadataReport
Expand All @@ -67,19 +65,19 @@ func GetRemoteMetadataService() (remote.RemoteMetadataService, error) {
}
// it will never return error
inms, _ := inmemory.GetInMemoryMetadataService()
remoteMetadataServiceImplInstance = &RemoteMetadataServiceImpl{
remotingMetadataServiceInstance = &MetadataService{
// todo serviceName
//BaseMetadataService: service.NewBaseMetadataService(""),
MetadataService: inms.(*inmemory.MetadataService),
delegateReport: mr,
}
})
return remoteMetadataServiceImplInstance, err
return remotingMetadataServiceInstance, err
}

// PublishMetadata publishes the metadata info of @service to remote metadata center
func (mts *RemoteMetadataServiceImpl) PublishMetadata(service string) {
info, err := mts.MetadataService.GetMetadataInfo("")
func (s *MetadataService) PublishMetadata(service string) {
info, err := s.MetadataService.GetMetadataInfo("")
if err != nil {
logger.Errorf("GetMetadataInfo error[%v]", err)
return
Expand All @@ -88,7 +86,7 @@ func (mts *RemoteMetadataServiceImpl) PublishMetadata(service string) {
return
}
id := identifier.NewSubscriberMetadataIdentifier(service, info.CalAndGetRevision())
err = mts.delegateReport.PublishAppMetadata(id, info)
err = s.delegateReport.PublishAppMetadata(id, info)
if err != nil {
logger.Errorf("Publishing metadata to error[%v]", err)
return
Expand All @@ -97,14 +95,14 @@ func (mts *RemoteMetadataServiceImpl) PublishMetadata(service string) {
}

// GetMetadata get the medata info of service from report
func (mts *RemoteMetadataServiceImpl) GetMetadata(instance registry.ServiceInstance) (*common.MetadataInfo, error) {
func (s *MetadataService) GetMetadata(instance registry.ServiceInstance) (*common.MetadataInfo, error) {
revision := instance.GetMetadata()[constant.EXPORTED_SERVICES_REVISION_PROPERTY_NAME]
id := identifier.NewSubscriberMetadataIdentifier(instance.GetServiceName(), revision)
return mts.delegateReport.GetAppMetadata(id)
return s.delegateReport.GetAppMetadata(id)
}

// PublishServiceDefinition will call remote metadata's StoreProviderMetadata to store url info and service definition
func (mts *RemoteMetadataServiceImpl) PublishServiceDefinition(url *common.URL) error {
func (s *MetadataService) PublishServiceDefinition(url *common.URL) error {
interfaceName := url.GetParam(constant.INTERFACE_KEY, "")
isGeneric := url.GetParamBool(constant.GENERIC_KEY, false)
if common.RoleType(common.PROVIDER).Role() == url.GetParam(constant.SIDE_KEY, "") {
Expand All @@ -119,7 +117,7 @@ func (mts *RemoteMetadataServiceImpl) PublishServiceDefinition(url *common.URL)
Side: url.GetParam(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL),
},
}
mts.delegateReport.StoreProviderMetadata(id, sd)
s.delegateReport.StoreProviderMetadata(id, sd)
return nil
}
logger.Errorf("publishProvider interfaceName is empty . providerUrl:%v ", url)
Expand All @@ -137,7 +135,7 @@ func (mts *RemoteMetadataServiceImpl) PublishServiceDefinition(url *common.URL)
Side: url.GetParam(constant.SIDE_KEY, "consumer"),
},
}
mts.delegateReport.StoreConsumerMetadata(id, params)
s.delegateReport.StoreConsumerMetadata(id, params)
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package remote_impl
package remoting

import (
"fmt"
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestMetadataService(t *testing.T) {
u, err := common.NewURL("mock://127.0.0.1:20000/?sync.report=true")
assert.NoError(t, err)
instance.GetMetadataReportInstance(u)
mts, err := GetRemoteMetadataService()
mts, err := GetRemotingMetadataService()
assert.NoError(t, err)
assert.NotNil(t, mts)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
* limitations under the License.
*/

package remote
package service

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/registry"
)

// RemoteMetadataService for save and get metadata
type RemoteMetadataService interface {
type RemotingMetadataService interface {
// PublishMetadata publish the medata info of service from report
PublishMetadata(service string)
// GetMetadata get the medata info of service from report
Expand Down
2 changes: 1 addition & 1 deletion registry/event/service_instances_changed_listener_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (lstn *ServiceInstancesChangedListenerImpl) getMetadataInfo(instance regist
metadataStorageType = instance.GetMetadata()[constant.METADATA_STORAGE_TYPE_PROPERTY_NAME]
}
if metadataStorageType == constant.REMOTE_METADATA_STORAGE_TYPE {
remoteMetadataServiceImpl, err := extension.GetRemoteMetadataService()
remoteMetadataServiceImpl, err := extension.GetRemotingMetadataService()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 3d57cfd

Please sign in to comment.