mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-18 03:40:26 +08:00
实现域名、记录同步等API
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/installers"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/rpc/services"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
@@ -314,3 +315,85 @@ func (this *NSNodeService) UpdateNSNodeIsInstalled(ctx context.Context, req *pb.
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// UpdateNSNodeStatus 更新节点状态
|
||||
func (this *NSNodeService) UpdateNSNodeStatus(ctx context.Context, req *pb.UpdateNSNodeStatusRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验节点
|
||||
_, nodeId, err := this.ValidateNodeId(ctx, rpcutils.UserTypeDNS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if req.NodeId > 0 {
|
||||
nodeId = req.NodeId
|
||||
}
|
||||
|
||||
if nodeId <= 0 {
|
||||
return nil, errors.New("'nodeId' should be greater than 0")
|
||||
}
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = nameservers.SharedNSNodeDAO.UpdateNodeStatus(tx, nodeId, req.StatusJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// FindCurrentNSNode 获取当前节点信息
|
||||
func (this *NSNodeService) FindCurrentNSNode(ctx context.Context, req *pb.FindCurrentNSNodeRequest) (*pb.FindCurrentNSNodeResponse, error) {
|
||||
// 校验节点
|
||||
_, nodeId, err := this.ValidateNodeId(ctx, rpcutils.UserTypeDNS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
node, err := nameservers.SharedNSNodeDAO.FindEnabledNSNode(tx, nodeId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if node == nil {
|
||||
return &pb.FindCurrentNSNodeResponse{NsNode: nil}, nil
|
||||
}
|
||||
|
||||
// 集群信息
|
||||
clusterName, err := nameservers.SharedNSClusterDAO.FindEnabledNSClusterName(tx, int64(node.ClusterId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 安装信息
|
||||
installStatus, err := node.DecodeInstallStatus()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
installStatusResult := &pb.NodeInstallStatus{}
|
||||
if installStatus != nil {
|
||||
installStatusResult = &pb.NodeInstallStatus{
|
||||
IsRunning: installStatus.IsRunning,
|
||||
IsFinished: installStatus.IsFinished,
|
||||
IsOk: installStatus.IsOk,
|
||||
Error: installStatus.Error,
|
||||
ErrorCode: installStatus.ErrorCode,
|
||||
UpdatedAt: installStatus.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.FindCurrentNSNodeResponse{NsNode: &pb.NSNode{
|
||||
Id: int64(node.Id),
|
||||
Name: node.Name,
|
||||
StatusJSON: []byte(node.Status),
|
||||
UniqueId: node.UniqueId,
|
||||
Secret: node.Secret,
|
||||
IsInstalled: node.IsInstalled == 1,
|
||||
InstallDir: node.InstallDir,
|
||||
NsCluster: &pb.NSCluster{
|
||||
Id: int64(node.ClusterId),
|
||||
Name: clusterName,
|
||||
},
|
||||
InstallStatus: installStatusResult,
|
||||
IsOn: node.IsOn == 1,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user