Skip to content

Commit

Permalink
Merge 2e06de9 into a0e298a
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulijian1 committed Mar 2, 2020
2 parents a0e298a + 2e06de9 commit 48105f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
7 changes: 6 additions & 1 deletion pkg/stringutil/string_util.go
Expand Up @@ -22,10 +22,15 @@ import (
"strings"
)

const (
// LabelNone is the format string when the map is none
LabelNone = "none"
)

//FormatMap format map to string
func FormatMap(m map[string]string) string {
if len(m) == 0 {
return "none"
return LabelNone
}
sb := strings.Builder{}
s := make([]string, 0, len(m))
Expand Down
2 changes: 1 addition & 1 deletion server/pubsub/event_handler.go
Expand Up @@ -49,7 +49,7 @@ func handleKVEvent(e serf.Event) {
topics.Range(func(key, value interface{}) bool { //range all topics
t, err := ParseTopicString(key.(string))
if err != nil {
openlogging.Error("can not parse topic:" + key.(string))
openlogging.Error("can not parse topic " + key.(string) + ": " + err.Error())
return true
}
if t.Match(ke) {
Expand Down
32 changes: 20 additions & 12 deletions server/pubsub/struct.go
Expand Up @@ -20,9 +20,11 @@ package pubsub
import (
"encoding/json"
"errors"
"github.com/apache/servicecomb-kie/pkg/common"
"reflect"
"strings"

"github.com/apache/servicecomb-kie/pkg/common"
"github.com/apache/servicecomb-kie/pkg/stringutil"
)

//KVChangeEvent is event between kie nodes, and broadcast by serf
Expand Down Expand Up @@ -60,14 +62,16 @@ func ParseTopicString(s string) (*Topic, error) {
if err != nil {
return nil, err
}
ls := strings.Split(t.LabelsFormat, "::")
if len(ls) != 0 {
for _, l := range ls {
s := strings.Split(l, "=")
if len(s) != 2 {
return nil, errors.New("invalid label:" + l)
if t.LabelsFormat != stringutil.LabelNone {
ls := strings.Split(t.LabelsFormat, "::")
if len(ls) != 0 {
for _, l := range ls {
s := strings.Split(l, "=")
if len(s) != 2 {
return nil, errors.New("invalid label:" + l)
}
t.Labels[s[0]] = s[1]
}
t.Labels[s[0]] = s[1]
}
}
return t, err
Expand All @@ -86,11 +90,15 @@ func (t *Topic) Match(event *KVChangeEvent) bool {
return false
}
}
for k, v := range t.Labels {
if event.Labels[k] != v {
return false
}
if len(t.Labels) == 0 {
match = true
} else {
for k, v := range t.Labels {
if event.Labels[k] != v {
return false
}
match = true
}
}
return match
}
Expand Down

0 comments on commit 48105f2

Please sign in to comment.