@@ -29,6 +29,7 @@ import (
29
29
namingpb "github.com/polarismesh/polaris-go/pkg/model/pb/v1"
30
30
"github.com/polarismesh/polaris-go/pkg/plugin"
31
31
"github.com/polarismesh/polaris-go/pkg/plugin/localregistry"
32
+ "github.com/polarismesh/polaris-go/pkg/plugin/reporthandler"
32
33
"github.com/polarismesh/polaris-go/pkg/plugin/serverconnector"
33
34
"github.com/polarismesh/polaris-go/pkg/version"
34
35
)
@@ -44,6 +45,9 @@ func NewReportClientCallBack(
44
45
if callback .registry , err = data .GetRegistry (cfg , supplier ); err != nil {
45
46
return nil , err
46
47
}
48
+ if callback .reportChain , err = data .GetReportChain (cfg , supplier ); err != nil {
49
+ return nil , err
50
+ }
47
51
callback .configuration = cfg
48
52
callback .globalCtx = globalCtx
49
53
callback .interval = cfg .GetGlobal ().GetAPI ().GetReportInterval ()
@@ -58,6 +62,7 @@ type ReportClientCallBack struct {
58
62
configuration config.Configuration
59
63
globalCtx model.ValueContext
60
64
interval time.Duration
65
+ reportChain * reporthandler.ReportHandlerChain
61
66
}
62
67
63
68
const (
@@ -74,12 +79,13 @@ func (r *ReportClientCallBack) loadLocalClientReportResult() {
74
79
log .GetBaseLogger ().Warnf ("fail to load local region info from %s, err is %v" , cachedFile , err )
75
80
return
76
81
}
77
- location := resp .GetClient ().GetLocation ()
78
- r .updateLocation (& model.Location {
79
- Region : location .GetRegion ().GetValue (),
80
- Zone : location .GetZone ().GetValue (),
81
- Campus : location .GetCampus ().GetValue (),
82
- }, nil )
82
+
83
+ client := resp .Client
84
+
85
+ for i := range r .reportChain .Chain {
86
+ handler := r .reportChain .Chain [i ]
87
+ handler .InitLocal (client )
88
+ }
83
89
}
84
90
85
91
// reportClientRequest 客户端上报的请求
@@ -113,31 +119,18 @@ func (r *ReportClientCallBack) Process(
113
119
reportClientResp , err := r .connector .ReportClient (reportClientReq )
114
120
if err != nil {
115
121
log .GetBaseLogger ().Errorf ("report client info:%+v, error:%v" , reportClientReq , err )
116
- r .updateLocation (nil , err .(model.SDKError ))
117
122
// 发生错误也要重试,直到获取到地域信息为止
118
123
return model .CONTINUE
119
124
}
120
- r . updateLocation ( & model. Location {
121
- Region : reportClientResp . Region ,
122
- Zone : reportClientResp . Zone ,
123
- Campus : reportClientResp . Campus ,
124
- }, nil )
125
+
126
+ for i := range r . reportChain . Chain {
127
+ handler := r . reportChain . Chain [ i ]
128
+ handler . HandleResponse ( reportClientResp )
129
+ }
125
130
return model .CONTINUE
126
131
}
127
132
128
133
// OnTaskEvent 任务事件回调
129
134
func (r * ReportClientCallBack ) OnTaskEvent (event model.TaskEvent ) {
130
135
131
136
}
132
-
133
- // updateLocation 更新区域属性
134
- func (r * ReportClientCallBack ) updateLocation (location * model.Location , lastErr model.SDKError ) {
135
- if nil != location {
136
- // 已获取到客户端的地域信息,更新到全局上下文
137
- log .GetBaseLogger ().Infof ("current client area info is {Region:%s, Zone:%s, Campus:%s}" ,
138
- location .Region , location .Zone , location .Campus )
139
- }
140
- if r .globalCtx .SetCurrentLocation (location , lastErr ) {
141
- log .GetBaseLogger ().Infof ("client area info is ready" )
142
- }
143
- }
0 commit comments