Skip to content

Commit

Permalink
etcd app level service discovery implement
Browse files Browse the repository at this point in the history
  • Loading branch information
yexiaobo committed May 27, 2021
1 parent cbbbd8d commit a030216
Show file tree
Hide file tree
Showing 3 changed files with 27 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
23 changes: 19 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,28 @@ 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{}
err = json.Unmarshal([]byte(_data), info)
if err != nil {
return nil, err
}
return info, nil
}

// 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 {
return err
}
err = e.client.Put(key, string(value))
return err
}

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

metadataInfo := common.NewMetadataInfWithApp(subMi.Application)
err = metadataReport.RemoveServiceMetadata(serviceMi)
assert.Nil(t, err)
err = metadataReport.PublishAppMetadata(subMi, metadataInfo)
assert.Nil(t, err)

_, err = metadataReport.GetAppMetadata(subMi)
assert.Nil(t, err)

e.Close()
}
Expand Down

0 comments on commit a030216

Please sign in to comment.