增加DNS同步任务状态显示

This commit is contained in:
GoEdgeLab
2021-01-27 23:00:02 +08:00
parent ff722baf22
commit a73a04521d
19 changed files with 1087 additions and 243 deletions

View File

@@ -11,7 +11,6 @@ import (
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
timeutil "github.com/iwind/TeaGo/utils/time"
@@ -119,17 +118,6 @@ func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.Update
return nil, err
}
// 检查服务变化
oldIsOn := server.IsOn == 1
if oldIsOn != req.IsOn {
go func() {
err := this.notifyServerDNSChanged(req.ServerId)
if err != nil {
logs.Println("[DNS]notify server changed: " + err.Error())
}
}()
}
return this.Success()
}
@@ -373,7 +361,7 @@ func (this *ServerService) FindServerNames(ctx context.Context, req *pb.FindServ
}
}
serverNamesJSON, isAuditing, auditingServerNamesJSON, auditingResultJSON, err := models.SharedServerDAO.FindServerNames(tx, req.ServerId)
serverNamesJSON, isAuditing, auditingServerNamesJSON, auditingResultJSON, err := models.SharedServerDAO.FindServerServerNames(tx, req.ServerId)
if err != nil {
return nil, err
}
@@ -474,14 +462,6 @@ func (this *ServerService) UpdateServerNamesAuditing(ctx context.Context, req *p
}
}
// 通知服务更新
go func() {
err := this.notifyServerDNSChanged(req.ServerId)
if err != nil {
logs.Println("[DNS]notify server changed: " + err.Error())
}
}()
return this.Success()
}
@@ -1095,50 +1075,6 @@ func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.Fin
}, nil
}
// 自动同步DNS状态
func (this *ServerService) notifyServerDNSChanged(serverId int64) error {
tx := this.NullTx()
clusterId, err := models.SharedServerDAO.FindServerClusterId(tx, serverId)
if err != nil {
return err
}
dnsInfo, err := models.SharedNodeClusterDAO.FindClusterDNSInfo(tx, clusterId)
if err != nil {
return err
}
if dnsInfo == nil {
return nil
}
if len(dnsInfo.DnsName) == 0 || dnsInfo.DnsDomainId == 0 {
return nil
}
dnsConfig, err := dnsInfo.DecodeDNSConfig()
if err != nil {
return err
}
if !dnsConfig.ServersAutoSync {
return nil
}
// 执行同步
domainService := &DNSDomainService{}
resp, err := domainService.syncClusterDNS(&pb.SyncDNSDomainDataRequest{
DnsDomainId: int64(dnsInfo.DnsDomainId),
NodeClusterId: clusterId,
})
if err != nil {
return err
}
if !resp.IsOk {
err = models.SharedMessageDAO.CreateClusterMessage(tx, clusterId, models.MessageTypeClusterDNSSyncFailed, models.LevelError, "集群DNS同步失败"+resp.Error, nil)
if err != nil {
logs.Println("[NODE_SERVICE]" + err.Error())
}
}
return nil
}
// 检查服务是否属于某个用户
func (this *ServerService) CheckUserServer(ctx context.Context, req *pb.CheckUserServerRequest) (*pb.RPCSuccess, error) {
userId, err := this.ValidateUser(ctx)