域名服务增加访问日志

This commit is contained in:
GoEdgeLab
2021-06-02 11:53:24 +08:00
parent b4bdf7ba8f
commit 637193a270
17 changed files with 829 additions and 121 deletions

View File

@@ -100,8 +100,8 @@ func (this *NSClusterDAO) CountAllEnabledClusters(tx *dbs.Tx) (int64, error) {
Count()
}
// ListEnabledNSClusters 列出单页集群
func (this *NSClusterDAO) ListEnabledNSClusters(tx *dbs.Tx, offset int64, size int64) (result []*NSCluster, err error) {
// ListEnabledClusters 列出单页集群
func (this *NSClusterDAO) ListEnabledClusters(tx *dbs.Tx, offset int64, size int64) (result []*NSCluster, err error) {
_, err = this.Query(tx).
State(NSClusterStateEnabled).
Offset(offset).
@@ -112,8 +112,8 @@ func (this *NSClusterDAO) ListEnabledNSClusters(tx *dbs.Tx, offset int64, size i
return
}
// FindAllEnabledNSClusters 列出所有集群
func (this *NSClusterDAO) FindAllEnabledNSClusters(tx *dbs.Tx) (result []*NSCluster, err error) {
// FindAllEnabledClusters 列出所有集群
func (this *NSClusterDAO) FindAllEnabledClusters(tx *dbs.Tx) (result []*NSCluster, err error) {
_, err = this.Query(tx).
State(NSClusterStateEnabled).
DescPk().
@@ -121,3 +121,20 @@ func (this *NSClusterDAO) FindAllEnabledNSClusters(tx *dbs.Tx) (result []*NSClus
FindAll()
return
}
// UpdateClusterAccessLog 设置访问日志
func (this *NSClusterDAO) UpdateClusterAccessLog(tx *dbs.Tx, clusterId int64, accessLogJSON []byte) error {
return this.Query(tx).
Pk(clusterId).
Set("accessLog", accessLogJSON).
UpdateQuickly()
}
// FindClusterAccessLog 读取访问日志配置
func (this *NSClusterDAO) FindClusterAccessLog(tx *dbs.Tx, clusterId int64) ([]byte, error) {
accessLog, err := this.Query(tx).
Pk(clusterId).
Result("accessLog").
FindStringCol("")
return []byte(accessLog), err
}

View File

@@ -7,6 +7,7 @@ type NSCluster struct {
Name string `field:"name"` // 集群名
InstallDir string `field:"installDir"` // 安装目录
State uint8 `field:"state"` // 状态
AccessLog string `field:"accessLog"` // 访问日志配置
}
type NSClusterOperator struct {
@@ -15,6 +16,7 @@ type NSClusterOperator struct {
Name interface{} // 集群名
InstallDir interface{} // 安装目录
State interface{} // 状态
AccessLog interface{} // 访问日志配置
}
func NewNSClusterOperator() *NSClusterOperator {

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeAPI/internal/errors"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
@@ -330,6 +331,54 @@ func (this NSNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []by
return err
}
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
func (this *NSNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
return this.Query(tx).
State(NSNodeStateEnabled).
Where("status IS NOT NULL").
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
Param("version", utils.VersionToLong(version)).
Count()
}
// ComposeNodeConfig 组合节点配置
func (this *NSNodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64) (*dnsconfigs.NSNodeConfig, error) {
if nodeId <= 0 {
return nil, nil
}
node, err := this.FindEnabledNSNode(tx, nodeId)
if err != nil {
return nil, err
}
if node == nil {
return nil, nil
}
cluster, err := SharedNSClusterDAO.FindEnabledNSCluster(tx, int64(node.ClusterId))
if err != nil {
return nil, err
}
if cluster == nil {
return nil, nil
}
config := &dnsconfigs.NSNodeConfig{
Id: int64(node.Id),
ClusterId: int64(node.ClusterId),
}
if len(cluster.AccessLog) > 0 {
ref := &dnsconfigs.AccessLogRef{}
err = json.Unmarshal([]byte(cluster.AccessLog), ref)
if err != nil {
return nil, err
}
config.AccessLogRef = ref
}
return config, nil
}
// NotifyUpdate 通知更新
func (this *NSNodeDAO) NotifyUpdate(tx *dbs.Tx, nodeId int64) error {
// TODO 先什么都不做