@@ -295,10 +295,103 @@ func (s *Server) PublishConfigFileFromClient(ctx context.Context,
295295
296296// GetConfigSubscribers 根据配置视角获取订阅者列表
297297func (s * Server ) GetConfigSubscribers (ctx context.Context , filter map [string ]string ) * model.CommonResponse {
298- return nil
298+ namespace := filter ["namespace" ]
299+ group := filter ["group" ]
300+ fileName := filter ["file_name" ]
301+
302+ key := utils .GenFileId (namespace , group , fileName )
303+ clientIds , _ := s .watchCenter .watchers .Load (key )
304+ if clientIds == nil {
305+ return model .NewCommonResponse (uint32 (apimodel .Code_NotFoundResource ))
306+ }
307+
308+ versionClients := map [uint64 ][]* model.Subscriber {}
309+ clientIds .Range (func (val string ) {
310+ watchCtx , ok := s .watchCenter .clients .Load (val )
311+ if ! ok {
312+ return
313+ }
314+ curVer := watchCtx .CurWatchVersion (key )
315+ if _ , ok := versionClients [curVer ]; ! ok {
316+ versionClients [curVer ] = []* model.Subscriber {}
317+ }
318+
319+ watchCtx .ClientLabels ()
320+
321+ versionClients [curVer ] = append (versionClients [curVer ], & model.Subscriber {
322+ ID : watchCtx .ClientID (),
323+ Host : watchCtx .ClientLabels ()[model .ClientLabel_Host ],
324+ Version : watchCtx .ClientLabels ()[model .ClientLabel_Version ],
325+ ClientType : watchCtx .ClientLabels ()[model .ClientLabel_Language ],
326+ })
327+ })
328+
329+ rsp := model .NewCommonResponse (uint32 (apimodel .Code_ExecuteSuccess ))
330+ rsp .Data = & model.ConfigSubscribers {
331+ Key : model.ConfigFileKey {
332+ Namespace : namespace ,
333+ Group : group ,
334+ Name : fileName ,
335+ },
336+ VersionClients : func () []* model.VersionClient {
337+ ret := make ([]* model.VersionClient , 0 , len (versionClients ))
338+ for ver , clients := range versionClients {
339+ ret = append (ret , & model.VersionClient {
340+ Versoin : ver ,
341+ Subscribers : clients ,
342+ })
343+ }
344+ return ret
345+ }(),
346+ }
347+ return rsp
299348}
300349
301- // GetConfigSubscribers 根据客户端视角获取订阅的配置文件列表
350+ // GetClientSubscribers 根据客户端视角获取订阅的配置文件列表
302351func (s * Server ) GetClientSubscribers (ctx context.Context , filter map [string ]string ) * model.CommonResponse {
303- return nil
352+ clientId := filter ["client_id" ]
353+ watchCtx , ok := s .watchCenter .clients .Load (clientId )
354+ if ! ok {
355+ return model .NewCommonResponse (uint32 (apimodel .Code_NotFoundResource ))
356+ }
357+
358+ watchFiles := watchCtx .ListWatchFiles ()
359+ data := & model.ClientSubscriber {
360+ Subscriber : model.Subscriber {
361+ ID : watchCtx .ClientID (),
362+ Host : watchCtx .ClientLabels ()[model .ClientLabel_Host ],
363+ Version : watchCtx .ClientLabels ()[model .ClientLabel_Version ],
364+ ClientType : watchCtx .ClientLabels ()[model .ClientLabel_Language ],
365+ },
366+ Files : []model.FileReleaseSubscribeInfo {},
367+ }
368+
369+ for _ , file := range watchFiles {
370+ key := model .BuildKeyForClientConfigFileInfo (file )
371+ curVer := watchCtx .CurWatchVersion (key )
372+
373+ ns := file .GetNamespace ().GetValue ()
374+ group := file .GetGroup ().GetValue ()
375+ filename := file .GetFileName ().GetValue ()
376+
377+ data .Files = append (data .Files , model.FileReleaseSubscribeInfo {
378+ Name : file .GetName ().GetValue (),
379+ Namespace : ns ,
380+ Group : group ,
381+ FileName : filename ,
382+ ReleaseType : func () model.ReleaseType {
383+ if gray := s .fileCache .GetActiveGrayRelease (ns , group , filename ); gray != nil {
384+ if gray .Version == curVer {
385+ return model .ReleaseTypeGray
386+ }
387+ }
388+ return model .ReleaseTypeFull
389+ }(),
390+ Version : curVer ,
391+ })
392+ }
393+
394+ rsp := model .NewCommonResponse (uint32 (apimodel .Code_ExecuteSuccess ))
395+ rsp .Data = data
396+ return rsp
304397}
0 commit comments