Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gets the list of schedulers associated with the CDN #1182

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions manager/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package rpcserver
import (
"context"
"errors"
"fmt"
"io"

cachev8 "github.com/go-redis/cache/v8"
Expand Down Expand Up @@ -93,7 +94,7 @@ func (s *Server) GetCDN(ctx context.Context, req *manager.GetCDNRequest) (*manag
// Cache Miss
logger.Infof("%s cache miss", cacheKey)
cdn := model.CDN{}
if err := s.db.WithContext(ctx).Preload("CDNCluster").First(&cdn, &model.CDN{
if err := s.db.WithContext(ctx).Preload("CDNCluster").Preload("CDNCluster.SchedulerClusters.Schedulers").First(&cdn, &model.CDN{
HostName: req.HostName,
CDNClusterID: uint(req.CdnClusterId),
}).Error; err != nil {
Expand All @@ -104,7 +105,12 @@ func (s *Server) GetCDN(ctx context.Context, req *manager.GetCDNRequest) (*manag
if err != nil {
return nil, status.Error(codes.DataLoss, err.Error())
}

var schedulers []*manager.ServiceInstance
for _, schedulerCluster := range cdn.CDNCluster.SchedulerClusters {
for _, scheduler := range schedulerCluster.Schedulers {
schedulers = append(schedulers, &manager.ServiceInstance{Addr: fmt.Sprintf("%s:%d", scheduler.IP, scheduler.Port)})
}
}
pbCDN = manager.CDN{
Id: uint64(cdn.ID),
HostName: cdn.HostName,
Expand All @@ -121,6 +127,7 @@ func (s *Server) GetCDN(ctx context.Context, req *manager.GetCDNRequest) (*manag
Bio: cdn.CDNCluster.BIO,
Config: config,
},
Schedulers: schedulers,
}

if err := s.cache.Once(&cachev8.Item{
Expand Down
Loading