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

application service discovery support etcd reporter #1221

Merged
merged 6 commits into from
Jun 14, 2021
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	key := e.getNodeKey(metadataIdentifier)
	value, err := json.Marshal(info)
	if err == nil {
	     err = e.client.Put(key, string(value))
	}
	return err

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