Skip to content

Commit

Permalink
code review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FoghostCn committed Jan 15, 2024
1 parent 2e5a4ea commit a9894b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
20 changes: 9 additions & 11 deletions metadata/mapping/metadata/service_name_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,17 @@ func (d *ServiceNameMapping) Map(url *common.URL) error {
metadataReports := instance.GetMetadataReports()
if len(metadataReports) == 0 {
return perrors.New("can not registering mapping to remote cause no metadata report instance found")
} else {
for _, metadataReport := range metadataReports {
var err error
for i := 0; i < retryTimes; i++ {
err = metadataReport.RegisterServiceAppMapping(serviceInterface, DefaultGroup, appName)
if err == nil {
break
}
}
if err != nil {
logger.Errorf("Failed registering mapping to remote, &v", err)
}
for _, metadataReport := range metadataReports {
var err error
for i := 0; i < retryTimes; i++ {
if err = metadataReport.RegisterServiceAppMapping(serviceInterface, DefaultGroup, appName); err == nil {
break
}
}
if err != nil {
logger.Errorf("Failed registering mapping to remote, &v", err)
}
}
return nil
}
Expand Down
16 changes: 9 additions & 7 deletions metadata/report/instance/metadata_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func Init(urls []*common.URL, metaType string) {
if len(urls) != 0 {
for _, url := range urls {
fac := extension.GetMetadataReportFactory(url.Protocol)
if fac != nil {
key := url.GetParam(constant.RegistryKey, constant.DefaultKey)
instances[key] = &DelegateMetadataReport{instance: fac.CreateMetadataReport(url)}
} else {
logger.Warnf("metadata report factory is not found, url: %s", url.String())
if fac == nil {
logger.Warnf("no metadata report factory of protocol %s found!", url.Protocol)
continue
}
key := url.GetParam(constant.RegistryKey, constant.DefaultKey)
instances[key] = &DelegateMetadataReport{instance: fac.CreateMetadataReport(url)}
}
}
})
Expand All @@ -79,9 +79,11 @@ func GetMetadataReportByRegistry(registry string) report.MetadataReport {
}

func GetMetadataReports() []report.MetadataReport {
reports := make([]report.MetadataReport, 0)
reports := make([]report.MetadataReport, len(instances))
index := 0
for _, r := range instances {
reports = append(reports, r)
reports[index] = r
index++
}
return reports
}
Expand Down
3 changes: 1 addition & 2 deletions registry/exposed_tmp/exposed.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func RegisterServiceInstance() error {
if rf, ok := protocol.(registry.RegistryFactory); ok {
for _, r := range rf.GetRegistries() {
if sdr, ok := r.(registry.ServiceDiscoveryRegistry); ok {
err := sdr.RegisterService()
if err != nil {
if err := sdr.RegisterService(); err != nil {
return err
}
}
Expand Down

0 comments on commit a9894b4

Please sign in to comment.