@@ -3,6 +3,7 @@ package cluster
33import (
44 motan "github.com/weibocom/motan-go/core"
55 vlog "github.com/weibocom/motan-go/log"
6+ "strconv"
67 "strings"
78 "sync/atomic"
89)
@@ -14,6 +15,7 @@ const (
1415type ClusterGroup struct {
1516 sandboxClusters []motan.Cluster
1617 backupClusters []motan.Cluster
18+ greyClusters []motan.Cluster
1719 backupIndex uint32
1820
1921 clusterSelector motan.ClusterSelector
@@ -44,6 +46,13 @@ func NewClusterGroup(context *motan.Context, extFactory motan.ExtensionFactory,
4446 vlog .Infof ("init backup clusters success. master cluster url: %s, backup groups: %s" , url .ToExtInfo (), backupGroup )
4547 }
4648
49+ // gray clusters
50+ greyGroups := url .GetParam (motan .GreyGroupsKey , motan .GetDefaultGreyGroups ())
51+ if greyGroups != "" {
52+ clusterGroup .greyClusters = createMultiClusters (context , extFactory , url , proxy , greyGroups , false , true )
53+ vlog .Infof ("init grey clusters success. master cluster url: %s, grey groups: %s" , url .ToExtInfo (), greyGroups )
54+ }
55+
4756 // cluster selector
4857 clusterSelectorKey := url .GetParam (motan .ClusterSelectorKey , DefaultClusterSelectorName )
4958 clusterSelector := extFactory .GetClusterSelector (clusterSelectorKey )
@@ -72,6 +81,9 @@ func (c *ClusterGroup) GetRuntimeInfo() map[string]interface{} {
7281 for _ , cluster := range c .backupClusters {
7382 info ["backup-" + cluster .GetIdentity ()] = cluster .GetRuntimeInfo ()
7483 }
84+ for _ , cluster := range c .greyClusters {
85+ info ["grey-" + cluster .GetIdentity ()] = cluster .GetRuntimeInfo ()
86+ }
7587 return info
7688}
7789
@@ -114,6 +126,9 @@ func (c *ClusterGroup) Destroy() {
114126 for _ , cluster := range c .backupClusters {
115127 cluster .Destroy ()
116128 }
129+ for _ , cluster := range c .greyClusters {
130+ cluster .Destroy ()
131+ }
117132 c .clusterSelector .Destroy ()
118133}
119134
@@ -129,6 +144,10 @@ func (c *ClusterGroup) GetBackupClusters() []motan.Cluster {
129144 return c .backupClusters
130145}
131146
147+ func (c * ClusterGroup ) GetGreyClusters () []motan.Cluster {
148+ return c .greyClusters
149+ }
150+
132151func (c * ClusterGroup ) SetRefersFilter (rf motan.RefersFilter ) {
133152 c .masterCluster .SetRefersFilter (rf )
134153 for _ , cluster := range c .sandboxClusters {
@@ -144,23 +163,20 @@ func createMultiClusters(context *motan.Context, extFactory motan.ExtensionFacto
144163 groups := motan .TrimSplitSet (groupsStr , motan .GroupNameSeparator )
145164 for group := range groups {
146165 if strings .HasPrefix (group , motan .GroupSuffixString ) {
147- group = url .Group + group [len (motan .GroupSuffixString ):]
166+ group = group [len (motan .GroupSuffixString ):]
167+ // if the url.Group end with the group, skip it
168+ if strings .HasSuffix (url .Group , group ) {
169+ continue
170+ }
171+ group = url .Group + group
148172 }
149173 // if the group same as url.Group, skip it
150174 if group == url .Group {
151175 continue
152176 }
153177 newUrl := url .Copy ()
154- if lazyInit {
155- newUrl .PutParam (motan .LazyInit , "true" )
156- } else {
157- newUrl .PutParam (motan .LazyInit , "false" )
158- }
159- if emptyNodeNotify {
160- newUrl .PutParam (motan .ClusterEmptyNodeNotifyKey , "true" )
161- } else {
162- newUrl .PutParam (motan .ClusterEmptyNodeNotifyKey , "false" )
163- }
178+ newUrl .PutParam (motan .LazyInit , strconv .FormatBool (proxy ))
179+ newUrl .PutParam (motan .ClusterEmptyNodeNotifyKey , strconv .FormatBool (emptyNodeNotify ))
164180 newUrl .Group = group
165181 cluster := NewCluster (context , extFactory , newUrl , proxy )
166182 clusters = append (clusters , cluster )
0 commit comments