Skip to content

Commit

Permalink
feat: manager grpc
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi committed Aug 11, 2021
1 parent 05f56c7 commit 91b91e6
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 648 deletions.
15 changes: 14 additions & 1 deletion manager/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/go-redis/cache/v8"
)

const (
CDNNamespace = "cdn"
SchedulerNamespace = "scheduler"
)

type Cache struct {
*cache.Cache
TTL time.Duration
Expand All @@ -33,5 +38,13 @@ func New(cfg *config.Config) *Cache {
}

func MakeCacheKey(namespace string, id string) string {
return fmt.Sprintf("manager: %s: %s", namespace, id)
return fmt.Sprintf("manager:%s:%s", namespace, id)
}

func MakeCDNCacheKey(hostname, clusterID string) string {
return MakeCacheKey(CDNNamespace, fmt.Sprintf("%s-%s", hostname, clusterID))
}

func MakeSchedulerCacheKey(hostname, clusterID string) string {
return MakeCacheKey(SchedulerNamespace, fmt.Sprintf("%s-%s", hostname, clusterID))
}
4 changes: 2 additions & 2 deletions manager/model/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const (

type CDN struct {
Model
HostName string `gorm:"column:host_name;type:varchar(256);index:uk_scheduler_cluster_name,unique;not null;comment:hostname" json:"host_name"`
HostName string `gorm:"column:host_name;type:varchar(256);index:uk_cdn,unique;not null;comment:hostname" json:"host_name"`
IDC string `gorm:"column:idc;type:varchar(1024);comment:internet data center" json:"idc"`
Location string `gorm:"column:location;type:varchar(1024);comment:location" json:"location"`
IP string `gorm:"column:ip;type:varchar(256);not null;comment:ip address" json:"ip"`
Port int32 `gorm:"column:port;not null;comment:grpc service listening port" json:"port"`
DownloadPort int32 `gorm:"column:download_port;not null;comment:download service listening port" json:"download_port"`
Status string `gorm:"column:status;type:varchar(256);default:'inactive';comment:service status" json:"status"`
CDNClusterID *uint `gorm:"index:idx_cdn_cluster_cd_ns;comment:cdn cluster id"`
CDNClusterID *uint `gorm:"index:uk_cdn,unique;not null;comment:cdn cluster id"`
CDNCluster CDNCluster `json:"-"`
}
4 changes: 2 additions & 2 deletions manager/model/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const (

type Scheduler struct {
Model
HostName string `gorm:"column:host_name;type:varchar(256);index:uk_scheduler_host_name,unique;not null;comment:hostname" json:"host_name"`
HostName string `gorm:"column:host_name;type:varchar(256);index:uk_scheduler,unique;not null;comment:hostname" json:"host_name"`
VIPs string `gorm:"column:vips;type:varchar(1024);comment:virtual ip address" json:"vips"`
IDC string `gorm:"column:idc;type:varchar(1024);comment:internet data center" json:"idc"`
Location string `gorm:"column:location;type:varchar(1024);comment:location" json:"location"`
NetConfig JSONMap `gorm:"column:net_config;comment:network configuration" json:"net_config"`
IP string `gorm:"column:ip;type:varchar(256);not null;comment:ip address" json:"ip"`
Port int32 `gorm:"column:port;not null;comment:grpc service listening port" json:"port"`
Status string `gorm:"column:status;type:varchar(256);default:'inactive';comment:service status" json:"status"`
SchedulerClusterID *uint `gorm:"comment:scheduler cluster id"`
SchedulerClusterID *uint `gorm:"index:uk_scheduler,unique;not null;comment:scheduler cluster id"`
SchedulerCluster SchedulerCluster `json:"-"`
}
4 changes: 4 additions & 0 deletions manager/service/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func (s *rest) CreateCDN(json types.CreateCDNRequest) (*model.CDN, error) {
IP: json.IP,
Port: json.Port,
DownloadPort: json.DownloadPort,
CDNClusterID: json.CDNClusterID,
}

if err := s.db.Create(&cdn).Error; err != nil {
Expand All @@ -38,6 +39,7 @@ func (s *rest) UpdateCDN(id uint, json types.UpdateCDNRequest) (*model.CDN, erro
IP: json.IP,
Port: json.Port,
DownloadPort: json.DownloadPort,
CDNClusterID: json.CDNClusterID,
}).Error; err != nil {
return nil, err
}
Expand All @@ -63,6 +65,7 @@ func (s *rest) GetCDNs(q types.GetCDNsQuery) (*[]model.CDN, error) {
IP: q.IP,
Port: q.Port,
DownloadPort: q.DownloadPort,
CDNClusterID: q.CDNClusterID,
}).Find(&cdns).Error; err != nil {
return nil, err
}
Expand All @@ -79,6 +82,7 @@ func (s *rest) CDNTotalCount(q types.GetCDNsQuery) (int64, error) {
IP: q.IP,
Port: q.Port,
DownloadPort: q.DownloadPort,
CDNClusterID: q.CDNClusterID,
}).Count(&count).Error; err != nil {
return 0, err
}
Expand Down
4 changes: 3 additions & 1 deletion manager/types/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type CreateCDNRequest struct {
IP string `json:"ip" binding:"required"`
Port int32 `json:"port" binding:"required"`
DownloadPort int32 `json:"download_port" binding:"required"`
CDNClusterID *uint `json:"cdn_cluster_id" binding:"required"`
}

type UpdateCDNRequest struct {
Expand All @@ -19,7 +20,7 @@ type UpdateCDNRequest struct {
IP string `json:"ip" binding:"omitempty"`
Port int32 `json:"port" binding:"omitempty"`
DownloadPort int32 `json:"download_port" binding:"omitempty"`
CDNID *uint `json:"cdn_id" binding:"omitempty"`
CDNClusterID *uint `json:"cdn_cluster_id" binding:"omitempty"`
}

type GetCDNsQuery struct {
Expand All @@ -29,6 +30,7 @@ type GetCDNsQuery struct {
IP string `form:"ip" binding:"omitempty"`
Port int32 `form:"port" binding:"omitempty"`
DownloadPort int32 `form:"download_port" binding:"omitempty"`
CDNClusterID *uint `json:"cdn_cluster_id" binding:"omitempty"`
Page int `form:"page" binding:"omitempty,gte=1"`
PerPage int `form:"per_page" binding:"omitempty,gte=1,lte=50"`
Status string `form:"status" binding:"omitempty,oneof=active inactive"`
Expand Down
Loading

0 comments on commit 91b91e6

Please sign in to comment.