Skip to content

Commit

Permalink
application service discovery support etcd reporter (#1221)
Browse files Browse the repository at this point in the history
* modify map use in nacos service_discovery

* fix map double write bug

* etcd app level service discovery implement

* ange variable name; add more asserts for etcd_report tes

* Update report.go

Co-authored-by: yexiaobo <yexiaobo@luojilab.com>
Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
  • Loading branch information
3 people authored Jun 14, 2021
1 parent 7fedc22 commit 22bc867
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions metadata/report/delegate/delegate_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ func NewMetadataReport() (*MetadataReport, error) {
return bmr, nil
}

// GetAppMetadata delegate get metadata info
// PublishAppMetadata delegate publish metadata info
func (mr *MetadataReport) PublishAppMetadata(identifier *identifier.SubscriberMetadataIdentifier, info *common.MetadataInfo) error {
report := instance.GetMetadataReportInstance()
return report.PublishAppMetadata(identifier, info)
}

// PublishAppMetadata delegate publish metadata info
// GetAppMetadata delegate get metadata info
func (mr *MetadataReport) GetAppMetadata(identifier *identifier.SubscriberMetadataIdentifier) (*common.MetadataInfo, error) {
report := instance.GetMetadataReportInstance()
return report.GetAppMetadata(identifier)
Expand Down
20 changes: 16 additions & 4 deletions metadata/report/etcd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package etcd

import (
"encoding/json"
"strings"
"time"
)
Expand Down Expand Up @@ -52,14 +53,25 @@ type etcdMetadataReport struct {

// GetAppMetadata get metadata info from etcd
func (e *etcdMetadataReport) GetAppMetadata(metadataIdentifier *identifier.SubscriberMetadataIdentifier) (*common.MetadataInfo, error) {
// TODO will implement
panic("implement me")
key := e.getNodeKey(metadataIdentifier)
data, err := e.client.Get(key)
if err != nil {
return nil, err
}

info := &common.MetadataInfo{}
return info, json.Unmarshal([]byte(data), info)
}

// PublishAppMetadata publish metadata info to etcd
func (e *etcdMetadataReport) PublishAppMetadata(metadataIdentifier *identifier.SubscriberMetadataIdentifier, info *common.MetadataInfo) error {
// TODO will implement
panic("implement me")
key := e.getNodeKey(metadataIdentifier)
value, err := json.Marshal(info)
if err == nil {
err = e.client.Put(key, string(value))
}

return err
}

// StoreProviderMetadata will store the metadata
Expand Down
13 changes: 13 additions & 0 deletions metadata/report/etcd/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,21 @@ func TestEtcdMetadataReport_CRUD(t *testing.T) {
err = metadataReport.SaveSubscribedData(subMi, string(urls))
assert.Nil(t, err)

serviceUrl, _ = common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0")
metadataInfo := common.NewMetadataInfo(subMi.Application, "", map[string]*common.ServiceInfo{
"com.ikurento.user.UserProvider": common.NewServiceInfoWithURL(serviceUrl),
})
err = metadataReport.RemoveServiceMetadata(serviceMi)
assert.Nil(t, err)
err = metadataReport.PublishAppMetadata(subMi, metadataInfo)
assert.Nil(t, err)

mdInfo, err := metadataReport.GetAppMetadata(subMi)
assert.Nil(t, err)
assert.Equal(t, metadataInfo.App, mdInfo.App)
assert.Equal(t, metadataInfo.Revision, mdInfo.Revision)
assert.Equal(t, 1, len(mdInfo.Services))
assert.NotNil(t, metadataInfo.Services["com.ikurento.user.UserProvider"])

e.Close()
}
Expand Down

0 comments on commit 22bc867

Please sign in to comment.