mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-12 06:10:26 +08:00
可以在创建、修改节点的时候选择分组,可以根据分组筛选节点
This commit is contained in:
@@ -80,7 +80,7 @@ func (this *NodeDAO) FindNodeName(id uint32) (string, error) {
|
||||
}
|
||||
|
||||
// 创建节点
|
||||
func (this *NodeDAO) CreateNode(name string, clusterId int64) (nodeId int64, err error) {
|
||||
func (this *NodeDAO) CreateNode(name string, clusterId int64, groupId int64) (nodeId int64, err error) {
|
||||
uniqueId, err := this.genUniqueId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -99,6 +99,7 @@ func (this *NodeDAO) CreateNode(name string, clusterId int64) (nodeId int64, err
|
||||
op.UniqueId = uniqueId
|
||||
op.Secret = secret
|
||||
op.ClusterId = clusterId
|
||||
op.GroupId = groupId
|
||||
op.IsOn = 1
|
||||
op.State = NodeStateEnabled
|
||||
_, err = this.Save(op)
|
||||
@@ -110,7 +111,7 @@ func (this *NodeDAO) CreateNode(name string, clusterId int64) (nodeId int64, err
|
||||
}
|
||||
|
||||
// 修改节点
|
||||
func (this *NodeDAO) UpdateNode(nodeId int64, name string, clusterId int64, maxCPU int32, isOn bool) error {
|
||||
func (this *NodeDAO) UpdateNode(nodeId int64, name string, clusterId int64, groupId int64, maxCPU int32, isOn bool) error {
|
||||
if nodeId <= 0 {
|
||||
return errors.New("invalid nodeId")
|
||||
}
|
||||
@@ -118,6 +119,7 @@ func (this *NodeDAO) UpdateNode(nodeId int64, name string, clusterId int64, maxC
|
||||
op.Id = nodeId
|
||||
op.Name = name
|
||||
op.ClusterId = clusterId
|
||||
op.GroupId = groupId
|
||||
op.LatestVersion = dbs.SQL("latestVersion+1")
|
||||
op.MaxCPU = maxCPU
|
||||
op.IsOn = isOn
|
||||
|
||||
@@ -24,7 +24,7 @@ func (this *NodeService) CreateNode(ctx context.Context, req *pb.CreateNodeReque
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(req.Name, req.ClusterId)
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(req.Name, req.ClusterId, req.GroupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func (this *NodeService) RegisterClusterNode(ctx context.Context, req *pb.Regist
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(req.Name, clusterId)
|
||||
nodeId, err := models.SharedNodeDAO.CreateNode(req.Name, clusterId, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,6 +144,21 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
||||
}
|
||||
}
|
||||
|
||||
// 分组信息
|
||||
var pbGroup *pb.NodeGroup = nil
|
||||
if node.GroupId > 0 {
|
||||
group, err := models.SharedNodeGroupDAO.FindEnabledNodeGroup(int64(node.GroupId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if group != nil {
|
||||
pbGroup = &pb.NodeGroup{
|
||||
Id: int64(group.Id),
|
||||
Name: group.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, &pb.Node{
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
@@ -157,6 +172,7 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
||||
InstallStatus: installStatusResult,
|
||||
MaxCPU: types.Int32(node.MaxCPU),
|
||||
IsOn: node.IsOn == 1,
|
||||
Group: pbGroup,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -221,7 +237,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.MaxCPU, req.IsOn)
|
||||
err = models.SharedNodeDAO.UpdateNode(req.NodeId, req.Name, req.ClusterId, req.GroupId, req.MaxCPU, req.IsOn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -301,6 +317,21 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
|
||||
}
|
||||
}
|
||||
|
||||
// 分组信息
|
||||
var pbGroup *pb.NodeGroup = nil
|
||||
if node.GroupId > 0 {
|
||||
group, err := models.SharedNodeGroupDAO.FindEnabledNodeGroup(int64(node.GroupId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if group != nil {
|
||||
pbGroup = &pb.NodeGroup{
|
||||
Id: int64(group.Id),
|
||||
Name: group.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.FindEnabledNodeResponse{Node: &pb.Node{
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
@@ -319,6 +350,7 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
|
||||
InstallStatus: installStatusResult,
|
||||
MaxCPU: types.Int32(node.MaxCPU),
|
||||
IsOn: node.IsOn == 1,
|
||||
Group: pbGroup,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user