mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-12 14:50:25 +08:00
[节点]可以设置节点区域
This commit is contained in:
@@ -80,7 +80,7 @@ func (this *NodeDAO) FindNodeName(id uint32) (string, error) {
|
||||
}
|
||||
|
||||
// 创建节点
|
||||
func (this *NodeDAO) CreateNode(adminId int64, name string, clusterId int64, groupId int64) (nodeId int64, err error) {
|
||||
func (this *NodeDAO) CreateNode(adminId int64, name string, clusterId int64, groupId int64, regionId int64) (nodeId int64, err error) {
|
||||
uniqueId, err := this.genUniqueId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -101,6 +101,7 @@ func (this *NodeDAO) CreateNode(adminId int64, name string, clusterId int64, gro
|
||||
op.Secret = secret
|
||||
op.ClusterId = clusterId
|
||||
op.GroupId = groupId
|
||||
op.RegionId = regionId
|
||||
op.IsOn = 1
|
||||
op.State = NodeStateEnabled
|
||||
err = this.Save(op)
|
||||
@@ -112,7 +113,7 @@ func (this *NodeDAO) CreateNode(adminId int64, name string, clusterId int64, gro
|
||||
}
|
||||
|
||||
// 修改节点
|
||||
func (this *NodeDAO) UpdateNode(nodeId int64, name string, clusterId int64, groupId int64, maxCPU int32, isOn bool) error {
|
||||
func (this *NodeDAO) UpdateNode(nodeId int64, name string, clusterId int64, groupId int64, regionId int64, maxCPU int32, isOn bool) error {
|
||||
if nodeId <= 0 {
|
||||
return errors.New("invalid nodeId")
|
||||
}
|
||||
@@ -121,6 +122,7 @@ func (this *NodeDAO) UpdateNode(nodeId int64, name string, clusterId int64, grou
|
||||
op.Name = name
|
||||
op.ClusterId = clusterId
|
||||
op.GroupId = groupId
|
||||
op.RegionId = regionId
|
||||
op.LatestVersion = dbs.SQL("latestVersion+1")
|
||||
op.MaxCPU = maxCPU
|
||||
op.IsOn = isOn
|
||||
@@ -187,7 +189,7 @@ func (this *NodeDAO) CountAllEnabledNodes() (int64, error) {
|
||||
}
|
||||
|
||||
// 列出单页节点
|
||||
func (this *NodeDAO) ListEnabledNodesMatch(offset int64, size int64, clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string, groupId int64) (result []*Node, err error) {
|
||||
func (this *NodeDAO) ListEnabledNodesMatch(offset int64, size int64, clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string, groupId int64, regionId int64) (result []*Node, err error) {
|
||||
query := this.Query().
|
||||
State(NodeStateEnabled).
|
||||
Offset(offset).
|
||||
@@ -231,6 +233,11 @@ func (this *NodeDAO) ListEnabledNodesMatch(offset int64, size int64, clusterId i
|
||||
query.Attr("groupId", groupId)
|
||||
}
|
||||
|
||||
// 区域
|
||||
if regionId > 0 {
|
||||
query.Attr("regionId", regionId)
|
||||
}
|
||||
|
||||
_, err = query.FindAll()
|
||||
return
|
||||
}
|
||||
@@ -318,7 +325,7 @@ func (this *NodeDAO) FindAllInactiveNodesWithClusterId(clusterId int64) (result
|
||||
}
|
||||
|
||||
// 计算节点数量
|
||||
func (this *NodeDAO) CountAllEnabledNodesMatch(clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string, groupId int64) (int64, error) {
|
||||
func (this *NodeDAO) CountAllEnabledNodesMatch(clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string, groupId int64, regionId int64) (int64, error) {
|
||||
query := this.Query()
|
||||
query.State(NodeStateEnabled)
|
||||
|
||||
@@ -358,6 +365,11 @@ func (this *NodeDAO) CountAllEnabledNodesMatch(clusterId int64, installState con
|
||||
query.Attr("groupId", groupId)
|
||||
}
|
||||
|
||||
// 区域
|
||||
if regionId > 0 {
|
||||
query.Attr("regionId", regionId)
|
||||
}
|
||||
|
||||
return query.Count()
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func (this *NodeService) CreateNode(ctx context.Context, req *pb.CreateNodeReque
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(adminId, req.Name, req.ClusterId, req.GroupId)
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(adminId, req.Name, req.ClusterId, req.GroupId, req.RegionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func (this *NodeService) RegisterClusterNode(ctx context.Context, req *pb.Regist
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(adminId, req.Name, clusterId, 0)
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(adminId, req.Name, clusterId, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (this *NodeService) CountAllEnabledNodesMatch(ctx context.Context, req *pb.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
count, err := models.SharedNodeDAO.CountAllEnabledNodesMatch(req.ClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.GroupId)
|
||||
count, err := models.SharedNodeDAO.CountAllEnabledNodesMatch(req.ClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.GroupId, req.RegionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -171,7 +171,7 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
||||
}
|
||||
}
|
||||
|
||||
nodes, err := models.SharedNodeDAO.ListEnabledNodesMatch(req.Offset, req.Size, req.ClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.GroupId)
|
||||
nodes, err := models.SharedNodeDAO.ListEnabledNodesMatch(req.Offset, req.Size, req.ClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.GroupId, req.RegionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -233,6 +233,22 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
||||
}
|
||||
}
|
||||
|
||||
// 区域
|
||||
var pbRegion *pb.NodeRegion = nil
|
||||
if node.RegionId > 0 {
|
||||
region, err := models.SharedNodeRegionDAO.FindEnabledNodeRegion(int64(node.RegionId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if region != nil {
|
||||
pbRegion = &pb.NodeRegion{
|
||||
Id: int64(region.Id),
|
||||
IsOn: region.IsOn == 1,
|
||||
Name: region.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, &pb.Node{
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
@@ -248,6 +264,7 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
||||
IsOn: node.IsOn == 1,
|
||||
IsUp: node.IsUp == 1,
|
||||
Group: pbGroup,
|
||||
Region: pbRegion,
|
||||
DnsRoutes: pbRoutes,
|
||||
})
|
||||
}
|
||||
@@ -321,7 +338,7 @@ func (this *NodeService) UpdateNode(ctx context.Context, req *pb.UpdateNodeReque
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedNodeDAO.UpdateNode(req.NodeId, req.Name, req.ClusterId, req.GroupId, req.MaxCPU, req.IsOn)
|
||||
err = models.SharedNodeDAO.UpdateNode(req.NodeId, req.Name, req.ClusterId, req.GroupId, req.RegionId, req.MaxCPU, req.IsOn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -435,6 +452,22 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
|
||||
}
|
||||
}
|
||||
|
||||
// 区域
|
||||
var pbRegion *pb.NodeRegion = nil
|
||||
if node.RegionId > 0 {
|
||||
region, err := models.SharedNodeRegionDAO.FindEnabledNodeRegion(int64(node.RegionId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if region != nil {
|
||||
pbRegion = &pb.NodeRegion{
|
||||
Id: int64(region.Id),
|
||||
IsOn: region.IsOn == 1,
|
||||
Name: region.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.FindEnabledNodeResponse{Node: &pb.Node{
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
@@ -454,6 +487,7 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
|
||||
MaxCPU: types.Int32(node.MaxCPU),
|
||||
IsOn: node.IsOn == 1,
|
||||
Group: pbGroup,
|
||||
Region: pbRegion,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user