mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	记录和显示最近常用的集群
This commit is contained in:
		
							
								
								
									
										51
									
								
								internal/db/models/latest_item_dao.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								internal/db/models/latest_item_dao.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	"github.com/iwind/TeaGo/Tea"
 | 
			
		||||
	"github.com/iwind/TeaGo/dbs"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type LatestItemType = string
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	LatestItemTypeCluster LatestItemType = "cluster"
 | 
			
		||||
	LatestItemTypeServer  LatestItemType = "server"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type LatestItemDAO dbs.DAO
 | 
			
		||||
 | 
			
		||||
func NewLatestItemDAO() *LatestItemDAO {
 | 
			
		||||
	return dbs.NewDAO(&LatestItemDAO{
 | 
			
		||||
		DAOObject: dbs.DAOObject{
 | 
			
		||||
			DB:     Tea.Env,
 | 
			
		||||
			Table:  "edgeLatestItems",
 | 
			
		||||
			Model:  new(LatestItem),
 | 
			
		||||
			PkName: "id",
 | 
			
		||||
		},
 | 
			
		||||
	}).(*LatestItemDAO)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var SharedLatestItemDAO *LatestItemDAO
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	dbs.OnReady(func() {
 | 
			
		||||
		SharedLatestItemDAO = NewLatestItemDAO()
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IncreaseItemCount 增加数量
 | 
			
		||||
func (this *LatestItemDAO) IncreaseItemCount(tx *dbs.Tx, itemType LatestItemType, itemId int64) error {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		InsertOrUpdateQuickly(maps.Map{
 | 
			
		||||
			"itemType":  itemType,
 | 
			
		||||
			"itemId":    itemId,
 | 
			
		||||
			"count":     1,
 | 
			
		||||
			"updatedAt": time.Now().Unix(),
 | 
			
		||||
		}, maps.Map{
 | 
			
		||||
			"count":     dbs.SQL("count+1"),
 | 
			
		||||
			"updatedAt": time.Now().Unix(),
 | 
			
		||||
		})
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								internal/db/models/latest_item_dao_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								internal/db/models/latest_item_dao_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	_ "github.com/iwind/TeaGo/bootstrap"
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										22
									
								
								internal/db/models/latest_item_model.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								internal/db/models/latest_item_model.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
// LatestItem 最近的条目统计
 | 
			
		||||
type LatestItem struct {
 | 
			
		||||
	Id        uint64 `field:"id"`        // ID
 | 
			
		||||
	ItemType  string `field:"itemType"`  // Item类型
 | 
			
		||||
	ItemId    uint64 `field:"itemId"`    // itemID
 | 
			
		||||
	Count     uint64 `field:"count"`     // 数量
 | 
			
		||||
	UpdatedAt uint64 `field:"updatedAt"` // 更新时间
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type LatestItemOperator struct {
 | 
			
		||||
	Id        interface{} // ID
 | 
			
		||||
	ItemType  interface{} // Item类型
 | 
			
		||||
	ItemId    interface{} // itemID
 | 
			
		||||
	Count     interface{} // 数量
 | 
			
		||||
	UpdatedAt interface{} // 更新时间
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewLatestItemOperator() *LatestItemOperator {
 | 
			
		||||
	return &LatestItemOperator{}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								internal/db/models/latest_item_model_ext.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								internal/db/models/latest_item_model_ext.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
package models
 | 
			
		||||
@@ -44,7 +44,7 @@ func init() {
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 启用条目
 | 
			
		||||
// EnableNodeCluster 启用条目
 | 
			
		||||
func (this *NodeClusterDAO) EnableNodeCluster(tx *dbs.Tx, id int64) error {
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
		Pk(id).
 | 
			
		||||
@@ -53,7 +53,7 @@ func (this *NodeClusterDAO) EnableNodeCluster(tx *dbs.Tx, id int64) error {
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 禁用条目
 | 
			
		||||
// DisableNodeCluster 禁用条目
 | 
			
		||||
func (this *NodeClusterDAO) DisableNodeCluster(tx *dbs.Tx, id int64) error {
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
		Pk(id).
 | 
			
		||||
@@ -62,7 +62,7 @@ func (this *NodeClusterDAO) DisableNodeCluster(tx *dbs.Tx, id int64) error {
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群
 | 
			
		||||
// FindEnabledNodeCluster 查找集群
 | 
			
		||||
func (this *NodeClusterDAO) FindEnabledNodeCluster(tx *dbs.Tx, id int64) (*NodeCluster, error) {
 | 
			
		||||
	result, err := this.Query(tx).
 | 
			
		||||
		Pk(id).
 | 
			
		||||
@@ -74,7 +74,7 @@ func (this *NodeClusterDAO) FindEnabledNodeCluster(tx *dbs.Tx, id int64) (*NodeC
 | 
			
		||||
	return result.(*NodeCluster), err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 根据UniqueId获取ID
 | 
			
		||||
// FindEnabledClusterIdWithUniqueId 根据UniqueId获取ID
 | 
			
		||||
// TODO 增加缓存
 | 
			
		||||
func (this *NodeClusterDAO) FindEnabledClusterIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
@@ -84,7 +84,7 @@ func (this *NodeClusterDAO) FindEnabledClusterIdWithUniqueId(tx *dbs.Tx, uniqueI
 | 
			
		||||
		FindInt64Col(0)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 根据主键查找名称
 | 
			
		||||
// FindNodeClusterName 根据主键查找名称
 | 
			
		||||
func (this *NodeClusterDAO) FindNodeClusterName(tx *dbs.Tx, id int64) (string, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Pk(id).
 | 
			
		||||
@@ -92,7 +92,7 @@ func (this *NodeClusterDAO) FindNodeClusterName(tx *dbs.Tx, id int64) (string, e
 | 
			
		||||
		FindStringCol("")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找所有可用的集群
 | 
			
		||||
// FindAllEnableClusters 查找所有可用的集群
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnableClusters(tx *dbs.Tx) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -103,7 +103,7 @@ func (this *NodeClusterDAO) FindAllEnableClusters(tx *dbs.Tx) (result []*NodeClu
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找所有可用的集群Ids
 | 
			
		||||
// FindAllEnableClusterIds 查找所有可用的集群Ids
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnableClusterIds(tx *dbs.Tx) (result []int64, err error) {
 | 
			
		||||
	ones, err := this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -118,7 +118,7 @@ func (this *NodeClusterDAO) FindAllEnableClusterIds(tx *dbs.Tx) (result []int64,
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 创建集群
 | 
			
		||||
// CreateCluster 创建集群
 | 
			
		||||
func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, cachePolicyId int64, httpFirewallPolicyId int64, systemServices map[string]maps.Map) (clusterId int64, err error) {
 | 
			
		||||
	uniqueId, err := this.GenUniqueId(tx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -176,7 +176,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string
 | 
			
		||||
	return types.Int64(op.Id), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群
 | 
			
		||||
// UpdateCluster 修改集群
 | 
			
		||||
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string) error {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
		return errors.New("invalid clusterId")
 | 
			
		||||
@@ -190,7 +190,7 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算所有集群数量
 | 
			
		||||
// CountAllEnabledClusters 计算所有集群数量
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string) (int64, error) {
 | 
			
		||||
	query := this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled)
 | 
			
		||||
@@ -201,7 +201,7 @@ func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string)
 | 
			
		||||
	return query.Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 列出单页集群
 | 
			
		||||
// ListEnabledClusters 列出单页集群
 | 
			
		||||
func (this *NodeClusterDAO) ListEnabledClusters(tx *dbs.Tx, keyword string, offset, size int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	query := this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled)
 | 
			
		||||
@@ -218,7 +218,7 @@ func (this *NodeClusterDAO) ListEnabledClusters(tx *dbs.Tx, keyword string, offs
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找所有API节点地址
 | 
			
		||||
// FindAllAPINodeAddrsWithCluster 查找所有API节点地址
 | 
			
		||||
func (this *NodeClusterDAO) FindAllAPINodeAddrsWithCluster(tx *dbs.Tx, clusterId int64) (result []string, err error) {
 | 
			
		||||
	one, err := this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -274,7 +274,7 @@ func (this *NodeClusterDAO) FindAllAPINodeAddrsWithCluster(tx *dbs.Tx, clusterId
 | 
			
		||||
	return result, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找健康检查设置
 | 
			
		||||
// FindClusterHealthCheckConfig 查找健康检查设置
 | 
			
		||||
func (this *NodeClusterDAO) FindClusterHealthCheckConfig(tx *dbs.Tx, clusterId int64) (*serverconfigs.HealthCheckConfig, error) {
 | 
			
		||||
	col, err := this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -295,7 +295,7 @@ func (this *NodeClusterDAO) FindClusterHealthCheckConfig(tx *dbs.Tx, clusterId i
 | 
			
		||||
	return config, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改健康检查设置
 | 
			
		||||
// UpdateClusterHealthCheck 修改健康检查设置
 | 
			
		||||
func (this *NodeClusterDAO) UpdateClusterHealthCheck(tx *dbs.Tx, clusterId int64, healthCheckJSON []byte) error {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
		return errors.New("invalid clusterId '" + strconv.FormatInt(clusterId, 10) + "'")
 | 
			
		||||
@@ -310,7 +310,7 @@ func (this *NodeClusterDAO) UpdateClusterHealthCheck(tx *dbs.Tx, clusterId int64
 | 
			
		||||
	return this.NotifyUpdate(tx, clusterId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个认证的集群数量
 | 
			
		||||
// CountAllEnabledClustersWithGrantId 计算使用某个认证的集群数量
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithGrantId(tx *dbs.Tx, grantId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -318,7 +318,7 @@ func (this *NodeClusterDAO) CountAllEnabledClustersWithGrantId(tx *dbs.Tx, grant
 | 
			
		||||
		Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取使用某个认证的所有集群
 | 
			
		||||
// FindAllEnabledClustersWithGrantId 获取使用某个认证的所有集群
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledClustersWithGrantId(tx *dbs.Tx, grantId int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -329,7 +329,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersWithGrantId(tx *dbs.Tx, grantI
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个DNS服务商的集群数量
 | 
			
		||||
// CountAllEnabledClustersWithDNSProviderId 计算使用某个DNS服务商的集群数量
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSProviderId(tx *dbs.Tx, dnsProviderId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -338,7 +338,7 @@ func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSProviderId(tx *dbs.Tx,
 | 
			
		||||
		Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取所有使用某个DNS服务商的集群
 | 
			
		||||
// FindAllEnabledClustersWithDNSProviderId 获取所有使用某个DNS服务商的集群
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSProviderId(tx *dbs.Tx, dnsProviderId int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -350,7 +350,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSProviderId(tx *dbs.Tx,
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个DNS域名的集群数量
 | 
			
		||||
// CountAllEnabledClustersWithDNSDomainId 计算使用某个DNS域名的集群数量
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -358,7 +358,7 @@ func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, d
 | 
			
		||||
		Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查询使用某个DNS域名的集群ID列表
 | 
			
		||||
// FindAllEnabledClusterIdsWithDNSDomainId 查询使用某个DNS域名的集群ID列表
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledClusterIdsWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) ([]int64, error) {
 | 
			
		||||
	ones, err := this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -375,7 +375,7 @@ func (this *NodeClusterDAO) FindAllEnabledClusterIdsWithDNSDomainId(tx *dbs.Tx,
 | 
			
		||||
	return result, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查询使用某个DNS域名的所有集群域名
 | 
			
		||||
// FindAllEnabledClustersWithDNSDomainId 查询使用某个DNS域名的所有集群域名
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -386,7 +386,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dn
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查询已经设置了域名的集群
 | 
			
		||||
// FindAllEnabledClustersHaveDNSDomain 查询已经设置了域名的集群
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledClustersHaveDNSDomain(tx *dbs.Tx) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -397,7 +397,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersHaveDNSDomain(tx *dbs.Tx) (res
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的认证ID
 | 
			
		||||
// FindClusterGrantId 查找集群的认证ID
 | 
			
		||||
func (this *NodeClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -405,7 +405,7 @@ func (this *NodeClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int
 | 
			
		||||
		FindInt64Col(0)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找DNS信息
 | 
			
		||||
// FindClusterDNSInfo 查找DNS信息
 | 
			
		||||
func (this *NodeClusterDAO) FindClusterDNSInfo(tx *dbs.Tx, clusterId int64) (*NodeCluster, error) {
 | 
			
		||||
	one, err := this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -420,7 +420,7 @@ func (this *NodeClusterDAO) FindClusterDNSInfo(tx *dbs.Tx, clusterId int64) (*No
 | 
			
		||||
	return one.(*NodeCluster), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 检查某个子域名是否可用
 | 
			
		||||
// ExistClusterDNSName 检查某个子域名是否可用
 | 
			
		||||
func (this *NodeClusterDAO) ExistClusterDNSName(tx *dbs.Tx, dnsName string, excludeClusterId int64) (bool, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Attr("dnsName", dnsName).
 | 
			
		||||
@@ -430,7 +430,7 @@ func (this *NodeClusterDAO) ExistClusterDNSName(tx *dbs.Tx, dnsName string, excl
 | 
			
		||||
		Exist()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群DNS相关信息
 | 
			
		||||
// UpdateClusterDNS 修改集群DNS相关信息
 | 
			
		||||
func (this *NodeClusterDAO) UpdateClusterDNS(tx *dbs.Tx, clusterId int64, dnsName string, dnsDomainId int64, nodesAutoSync bool, serversAutoSync bool) error {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
		return errors.New("invalid clusterId")
 | 
			
		||||
@@ -461,7 +461,7 @@ func (this *NodeClusterDAO) UpdateClusterDNS(tx *dbs.Tx, clusterId int64, dnsNam
 | 
			
		||||
	return this.NotifyDNSUpdate(tx, clusterId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 检查集群的DNS问题
 | 
			
		||||
// CheckClusterDNS 检查集群的DNS问题
 | 
			
		||||
func (this *NodeClusterDAO) CheckClusterDNS(tx *dbs.Tx, cluster *NodeCluster) (issues []*pb.DNSIssue, err error) {
 | 
			
		||||
	clusterId := int64(cluster.Id)
 | 
			
		||||
	domainId := int64(cluster.DnsDomainId)
 | 
			
		||||
@@ -573,7 +573,7 @@ func (this *NodeClusterDAO) CheckClusterDNS(tx *dbs.Tx, cluster *NodeCluster) (i
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群所属管理员
 | 
			
		||||
// FindClusterAdminId 查找集群所属管理员
 | 
			
		||||
func (this *NodeClusterDAO) FindClusterAdminId(tx *dbs.Tx, clusterId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -581,7 +581,7 @@ func (this *NodeClusterDAO) FindClusterAdminId(tx *dbs.Tx, clusterId int64) (int
 | 
			
		||||
		FindInt64Col(0)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的TOA设置
 | 
			
		||||
// FindClusterTOAConfig 查找集群的TOA设置
 | 
			
		||||
func (this *NodeClusterDAO) FindClusterTOAConfig(tx *dbs.Tx, clusterId int64) (*nodeconfigs.TOAConfig, error) {
 | 
			
		||||
	toa, err := this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -602,7 +602,7 @@ func (this *NodeClusterDAO) FindClusterTOAConfig(tx *dbs.Tx, clusterId int64) (*
 | 
			
		||||
	return config, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群的TOA设置
 | 
			
		||||
// UpdateClusterTOA 修改集群的TOA设置
 | 
			
		||||
func (this *NodeClusterDAO) UpdateClusterTOA(tx *dbs.Tx, clusterId int64, toaJSON []byte) error {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
		return errors.New("invalid clusterId")
 | 
			
		||||
@@ -617,7 +617,7 @@ func (this *NodeClusterDAO) UpdateClusterTOA(tx *dbs.Tx, clusterId int64, toaJSO
 | 
			
		||||
	return this.NotifyUpdate(tx, clusterId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个缓存策略的集群数量
 | 
			
		||||
// CountAllEnabledNodeClustersWithHTTPCachePolicyId 计算使用某个缓存策略的集群数量
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPCachePolicyId(tx *dbs.Tx, httpCachePolicyId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -625,7 +625,7 @@ func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPCachePolicyId(tx
 | 
			
		||||
		Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用缓存策略的所有集群
 | 
			
		||||
// FindAllEnabledNodeClustersWithHTTPCachePolicyId 查找使用缓存策略的所有集群
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPCachePolicyId(tx *dbs.Tx, httpCachePolicyId int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -636,7 +636,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPCachePolicyId(tx *
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个WAF策略的集群数量
 | 
			
		||||
// CountAllEnabledNodeClustersWithHTTPFirewallPolicyId 计算使用某个WAF策略的集群数量
 | 
			
		||||
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -644,7 +644,7 @@ func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(
 | 
			
		||||
		Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用WAF策略的所有集群
 | 
			
		||||
// FindAllEnabledNodeClustersWithHTTPFirewallPolicyId 查找使用WAF策略的所有集群
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -655,7 +655,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(t
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用WAF策略的所有集群Ids
 | 
			
		||||
// FindAllEnabledNodeClusterIdsWithHTTPFirewallPolicyId 查找使用WAF策略的所有集群Ids
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (result []int64, err error) {
 | 
			
		||||
	ones, err := this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -668,7 +668,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithHTTPFirewallPolicyId
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用缓存策略的所有集群Ids
 | 
			
		||||
// FindAllEnabledNodeClusterIdsWithCachePolicyId 查找使用缓存策略的所有集群Ids
 | 
			
		||||
func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId int64) (result []int64, err error) {
 | 
			
		||||
	ones, err := this.Query(tx).
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
@@ -681,7 +681,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithCachePolicyId(tx *db
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取集群的WAF策略ID
 | 
			
		||||
// FindClusterHTTPFirewallPolicyId 获取集群的WAF策略ID
 | 
			
		||||
func (this *NodeClusterDAO) FindClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -689,7 +689,7 @@ func (this *NodeClusterDAO) FindClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterI
 | 
			
		||||
		FindInt64Col(0)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 设置集群的缓存策略
 | 
			
		||||
// UpdateNodeClusterHTTPCachePolicyId 设置集群的缓存策略
 | 
			
		||||
func (this *NodeClusterDAO) UpdateNodeClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId int64, httpCachePolicyId int64) error {
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -701,7 +701,7 @@ func (this *NodeClusterDAO) UpdateNodeClusterHTTPCachePolicyId(tx *dbs.Tx, clust
 | 
			
		||||
	return this.NotifyUpdate(tx, clusterId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取集群的缓存策略ID
 | 
			
		||||
// FindClusterHTTPCachePolicyId 获取集群的缓存策略ID
 | 
			
		||||
func (this *NodeClusterDAO) FindClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId int64) (int64, error) {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -709,7 +709,7 @@ func (this *NodeClusterDAO) FindClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId i
 | 
			
		||||
		FindInt64Col(0)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 设置集群的WAF策略
 | 
			
		||||
// UpdateNodeClusterHTTPFirewallPolicyId 设置集群的WAF策略
 | 
			
		||||
func (this *NodeClusterDAO) UpdateNodeClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterId int64, httpFirewallPolicyId int64) error {
 | 
			
		||||
	_, err := this.Query(tx).
 | 
			
		||||
		Pk(clusterId).
 | 
			
		||||
@@ -721,7 +721,7 @@ func (this *NodeClusterDAO) UpdateNodeClusterHTTPFirewallPolicyId(tx *dbs.Tx, cl
 | 
			
		||||
	return this.NotifyUpdate(tx, clusterId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群的系统服务设置
 | 
			
		||||
// UpdateNodeClusterSystemService 修改集群的系统服务设置
 | 
			
		||||
func (this *NodeClusterDAO) UpdateNodeClusterSystemService(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType, params maps.Map) error {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
		return errors.New("invalid clusterId")
 | 
			
		||||
@@ -760,7 +760,7 @@ func (this *NodeClusterDAO) UpdateNodeClusterSystemService(tx *dbs.Tx, clusterId
 | 
			
		||||
	return this.NotifyUpdate(tx, clusterId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的系统服务设置
 | 
			
		||||
// FindNodeClusterSystemServiceParams 查找集群的系统服务设置
 | 
			
		||||
func (this *NodeClusterDAO) FindNodeClusterSystemServiceParams(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType) (params maps.Map, err error) {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
		return nil, errors.New("invalid clusterId")
 | 
			
		||||
@@ -782,7 +782,7 @@ func (this *NodeClusterDAO) FindNodeClusterSystemServiceParams(tx *dbs.Tx, clust
 | 
			
		||||
	return servicesMap[serviceType], nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的所有服务设置
 | 
			
		||||
// FindNodeClusterSystemServices 查找集群的所有服务设置
 | 
			
		||||
func (this *NodeClusterDAO) FindNodeClusterSystemServices(tx *dbs.Tx, clusterId int64) (services map[string]maps.Map, err error) {
 | 
			
		||||
	if clusterId <= 0 {
 | 
			
		||||
		return nil, errors.New("invalid clusterId")
 | 
			
		||||
@@ -804,7 +804,7 @@ func (this *NodeClusterDAO) FindNodeClusterSystemServices(tx *dbs.Tx, clusterId
 | 
			
		||||
	return servicesMap, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 生成唯一ID
 | 
			
		||||
// GenUniqueId 生成唯一ID
 | 
			
		||||
func (this *NodeClusterDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
 | 
			
		||||
	for {
 | 
			
		||||
		uniqueId := rands.HexString(32)
 | 
			
		||||
@@ -821,12 +821,26 @@ func (this *NodeClusterDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 通知更新
 | 
			
		||||
// FindLatestNodeClusters 查询最近访问的集群
 | 
			
		||||
func (this *NodeClusterDAO) FindLatestNodeClusters(tx *dbs.Tx, size int64) (result []*NodeCluster, err error) {
 | 
			
		||||
	_, err = this.Query(tx).
 | 
			
		||||
		Result(this.Table+".id", this.Table+".name").
 | 
			
		||||
		Join(SharedLatestItemDAO, dbs.QueryJoinRight, this.Table+".id="+SharedLatestItemDAO.Table+".itemId AND "+SharedLatestItemDAO.Table+".itemType='cluster'").
 | 
			
		||||
		Asc("CEIL((UNIX_TIMESTAMP() - updatedAt)/(7 * 86400))"). // 优先一个星期以内的
 | 
			
		||||
		Desc(SharedLatestItemDAO.Table + ".count").
 | 
			
		||||
		State(NodeClusterStateEnabled).
 | 
			
		||||
		Limit(size).
 | 
			
		||||
		Slice(&result).
 | 
			
		||||
		FindAll()
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NotifyUpdate 通知更新
 | 
			
		||||
func (this *NodeClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
 | 
			
		||||
	return SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeConfigChanged)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 通知DNS更新
 | 
			
		||||
// NotifyDNSUpdate 通知DNS更新
 | 
			
		||||
// TODO 更新新的DNS解析记录的同时,需要删除老的DNS解析记录
 | 
			
		||||
func (this *NodeClusterDAO) NotifyDNSUpdate(tx *dbs.Tx, clusterId int64) error {
 | 
			
		||||
	err := dns.SharedDNSTaskDAO.CreateClusterTask(tx, clusterId, dns.DNSTaskTypeClusterChange)
 | 
			
		||||
 
 | 
			
		||||
@@ -264,6 +264,7 @@ func (this *APINode) listenRPC(listener net.Listener, tlsConfig *tls.Config) err
 | 
			
		||||
	pb.RegisterMonitorNodeServiceServer(rpcServer, &services.MonitorNodeService{})
 | 
			
		||||
	pb.RegisterAuthorityKeyServiceServer(rpcServer, &services.AuthorityKeyService{})
 | 
			
		||||
	pb.RegisterAuthorityNodeServiceServer(rpcServer, &services.AuthorityNodeService{})
 | 
			
		||||
	pb.RegisterLatestItemServiceServer(rpcServer, &services.LatestItemService{})
 | 
			
		||||
	err := rpcServer.Serve(listener)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errors.New("[API_NODE]start rpc failed: " + err.Error())
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								internal/rpc/services/service_latest_item.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								internal/rpc/services/service_latest_item.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// LatestItemService 最近使用的条目服务
 | 
			
		||||
type LatestItemService struct {
 | 
			
		||||
	BaseService
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IncreaseLatestItem 记录最近使用的条目
 | 
			
		||||
func (this *LatestItemService) IncreaseLatestItem(ctx context.Context, req *pb.IncreaseLatestItemRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	err = models.SharedLatestItemDAO.IncreaseItemCount(tx, req.ItemType, req.ItemId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
@@ -22,7 +22,7 @@ type NodeClusterService struct {
 | 
			
		||||
	BaseService
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 创建集群
 | 
			
		||||
// CreateNodeCluster 创建集群
 | 
			
		||||
func (this *NodeClusterService) CreateNodeCluster(ctx context.Context, req *pb.CreateNodeClusterRequest) (*pb.CreateNodeClusterResponse, error) {
 | 
			
		||||
	adminId, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -53,7 +53,7 @@ func (this *NodeClusterService) CreateNodeCluster(ctx context.Context, req *pb.C
 | 
			
		||||
	return &pb.CreateNodeClusterResponse{NodeClusterId: clusterId}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群
 | 
			
		||||
// UpdateNodeCluster 修改集群
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.UpdateNodeClusterRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -70,7 +70,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 禁用集群
 | 
			
		||||
// DeleteNodeCluster 禁用集群
 | 
			
		||||
func (this *NodeClusterService) DeleteNodeCluster(ctx context.Context, req *pb.DeleteNodeClusterRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -93,7 +93,7 @@ func (this *NodeClusterService) DeleteNodeCluster(ctx context.Context, req *pb.D
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找单个集群
 | 
			
		||||
// FindEnabledNodeCluster 查找单个集群
 | 
			
		||||
func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req *pb.FindEnabledNodeClusterRequest) (*pb.FindEnabledNodeClusterResponse, error) {
 | 
			
		||||
	_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -130,7 +130,7 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req
 | 
			
		||||
	}}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的API节点信息
 | 
			
		||||
// FindAPINodesWithNodeCluster 查找集群的API节点信息
 | 
			
		||||
func (this *NodeClusterService) FindAPINodesWithNodeCluster(ctx context.Context, req *pb.FindAPINodesWithNodeClusterRequest) (*pb.FindAPINodesWithNodeClusterResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -184,7 +184,7 @@ func (this *NodeClusterService) FindAPINodesWithNodeCluster(ctx context.Context,
 | 
			
		||||
	return result, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找所有可用的集群
 | 
			
		||||
// FindAllEnabledNodeClusters 查找所有可用的集群
 | 
			
		||||
func (this *NodeClusterService) FindAllEnabledNodeClusters(ctx context.Context, req *pb.FindAllEnabledNodeClustersRequest) (*pb.FindAllEnabledNodeClustersResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -215,7 +215,7 @@ func (this *NodeClusterService) FindAllEnabledNodeClusters(ctx context.Context,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算所有集群数量
 | 
			
		||||
// CountAllEnabledNodeClusters 计算所有集群数量
 | 
			
		||||
func (this *NodeClusterService) CountAllEnabledNodeClusters(ctx context.Context, req *pb.CountAllEnabledNodeClustersRequest) (*pb.RPCCountResponse, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -232,7 +232,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClusters(ctx context.Context,
 | 
			
		||||
	return this.SuccessCount(count)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 列出单页集群
 | 
			
		||||
// ListEnabledNodeClusters 列出单页集群
 | 
			
		||||
func (this *NodeClusterService) ListEnabledNodeClusters(ctx context.Context, req *pb.ListEnabledNodeClustersRequest) (*pb.ListEnabledNodeClustersResponse, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -264,7 +264,7 @@ func (this *NodeClusterService) ListEnabledNodeClusters(ctx context.Context, req
 | 
			
		||||
	return &pb.ListEnabledNodeClustersResponse{NodeClusters: result}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的健康检查配置
 | 
			
		||||
// FindNodeClusterHealthCheckConfig 查找集群的健康检查配置
 | 
			
		||||
func (this *NodeClusterService) FindNodeClusterHealthCheckConfig(ctx context.Context, req *pb.FindNodeClusterHealthCheckConfigRequest) (*pb.FindNodeClusterHealthCheckConfigResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -285,7 +285,7 @@ func (this *NodeClusterService) FindNodeClusterHealthCheckConfig(ctx context.Con
 | 
			
		||||
	return &pb.FindNodeClusterHealthCheckConfigResponse{HealthCheckJSON: configJSON}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群健康检查设置
 | 
			
		||||
// UpdateNodeClusterHealthCheck 修改集群健康检查设置
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeClusterHealthCheck(ctx context.Context, req *pb.UpdateNodeClusterHealthCheckRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -302,7 +302,7 @@ func (this *NodeClusterService) UpdateNodeClusterHealthCheck(ctx context.Context
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 执行健康检查
 | 
			
		||||
// ExecuteNodeClusterHealthCheck 执行健康检查
 | 
			
		||||
func (this *NodeClusterService) ExecuteNodeClusterHealthCheck(ctx context.Context, req *pb.ExecuteNodeClusterHealthCheckRequest) (*pb.ExecuteNodeClusterHealthCheckResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -331,7 +331,7 @@ func (this *NodeClusterService) ExecuteNodeClusterHealthCheck(ctx context.Contex
 | 
			
		||||
	return &pb.ExecuteNodeClusterHealthCheckResponse{Results: pbResults}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个认证的集群数量
 | 
			
		||||
// CountAllEnabledNodeClustersWithGrantId 计算使用某个认证的集群数量
 | 
			
		||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithGrantId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithGrantIdRequest) (*pb.RPCCountResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -348,7 +348,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithGrantId(ctx conte
 | 
			
		||||
	return this.SuccessCount(count)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用某个认证的所有集群
 | 
			
		||||
// FindAllEnabledNodeClustersWithGrantId 查找使用某个认证的所有集群
 | 
			
		||||
func (this *NodeClusterService) FindAllEnabledNodeClustersWithGrantId(ctx context.Context, req *pb.FindAllEnabledNodeClustersWithGrantIdRequest) (*pb.FindAllEnabledNodeClustersWithGrantIdResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -376,7 +376,7 @@ func (this *NodeClusterService) FindAllEnabledNodeClustersWithGrantId(ctx contex
 | 
			
		||||
	return &pb.FindAllEnabledNodeClustersWithGrantIdResponse{NodeClusters: result}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的DNS配置
 | 
			
		||||
// FindEnabledNodeClusterDNS 查找集群的DNS配置
 | 
			
		||||
func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, req *pb.FindEnabledNodeClusterDNSRequest) (*pb.FindEnabledNodeClusterDNSResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
			
		||||
@@ -454,7 +454,7 @@ func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, r
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个DNS服务商的集群数量
 | 
			
		||||
// CountAllEnabledNodeClustersWithDNSProviderId 计算使用某个DNS服务商的集群数量
 | 
			
		||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSProviderId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithDNSProviderIdRequest) (*pb.RPCCountResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -471,7 +471,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSProviderId(ctx
 | 
			
		||||
	return this.SuccessCount(count)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个DNS域名的集群数量
 | 
			
		||||
// CountAllEnabledNodeClustersWithDNSDomainId 计算使用某个DNS域名的集群数量
 | 
			
		||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSDomainId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithDNSDomainIdRequest) (*pb.RPCCountResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -488,7 +488,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSDomainId(ctx c
 | 
			
		||||
	return this.SuccessCount(count)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用某个域名的所有集群
 | 
			
		||||
// FindAllEnabledNodeClustersWithDNSDomainId 查找使用某个域名的所有集群
 | 
			
		||||
func (this *NodeClusterService) FindAllEnabledNodeClustersWithDNSDomainId(ctx context.Context, req *pb.FindAllEnabledNodeClustersWithDNSDomainIdRequest) (*pb.FindAllEnabledNodeClustersWithDNSDomainIdResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -515,7 +515,7 @@ func (this *NodeClusterService) FindAllEnabledNodeClustersWithDNSDomainId(ctx co
 | 
			
		||||
	return &pb.FindAllEnabledNodeClustersWithDNSDomainIdResponse{NodeClusters: result}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 检查集群域名是否已经被使用
 | 
			
		||||
// CheckNodeClusterDNSName 检查集群域名是否已经被使用
 | 
			
		||||
func (this *NodeClusterService) CheckNodeClusterDNSName(ctx context.Context, req *pb.CheckNodeClusterDNSNameRequest) (*pb.CheckNodeClusterDNSNameResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -532,7 +532,7 @@ func (this *NodeClusterService) CheckNodeClusterDNSName(ctx context.Context, req
 | 
			
		||||
	return &pb.CheckNodeClusterDNSNameResponse{IsUsed: exists}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群的域名设置
 | 
			
		||||
// UpdateNodeClusterDNS 修改集群的域名设置
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeClusterDNS(ctx context.Context, req *pb.UpdateNodeClusterDNSRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -549,7 +549,7 @@ func (this *NodeClusterService) UpdateNodeClusterDNS(ctx context.Context, req *p
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 检查集群的DNS是否有变化
 | 
			
		||||
// CheckNodeClusterDNSChanges 检查集群的DNS是否有变化
 | 
			
		||||
func (this *NodeClusterService) CheckNodeClusterDNSChanges(ctx context.Context, req *pb.CheckNodeClusterDNSChangesRequest) (*pb.CheckNodeClusterDNSChangesResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
@@ -590,7 +590,7 @@ func (this *NodeClusterService) CheckNodeClusterDNSChanges(ctx context.Context,
 | 
			
		||||
	return &pb.CheckNodeClusterDNSChangesResponse{IsChanged: len(changes) > 0}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的TOA配置
 | 
			
		||||
// FindEnabledNodeClusterTOA 查找集群的TOA配置
 | 
			
		||||
func (this *NodeClusterService) FindEnabledNodeClusterTOA(ctx context.Context, req *pb.FindEnabledNodeClusterTOARequest) (*pb.FindEnabledNodeClusterTOAResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -612,7 +612,7 @@ func (this *NodeClusterService) FindEnabledNodeClusterTOA(ctx context.Context, r
 | 
			
		||||
	return &pb.FindEnabledNodeClusterTOAResponse{ToaJSON: configJSON}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群的TOA设置
 | 
			
		||||
// UpdateNodeClusterTOA 修改集群的TOA设置
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeClusterTOA(ctx context.Context, req *pb.UpdateNodeClusterTOARequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -631,7 +631,7 @@ func (this *NodeClusterService) UpdateNodeClusterTOA(ctx context.Context, req *p
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个缓存策略的集群数量
 | 
			
		||||
// CountAllEnabledNodeClustersWithHTTPCachePolicyId 计算使用某个缓存策略的集群数量
 | 
			
		||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithHTTPCachePolicyId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithHTTPCachePolicyIdRequest) (*pb.RPCCountResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -647,7 +647,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithHTTPCachePolicyId
 | 
			
		||||
	return this.SuccessCount(count)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用缓存策略的所有集群
 | 
			
		||||
// FindAllEnabledNodeClustersWithHTTPCachePolicyId 查找使用缓存策略的所有集群
 | 
			
		||||
func (this *NodeClusterService) FindAllEnabledNodeClustersWithHTTPCachePolicyId(ctx context.Context, req *pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest) (*pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -672,7 +672,7 @@ func (this *NodeClusterService) FindAllEnabledNodeClustersWithHTTPCachePolicyId(
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算使用某个WAF策略的集群数量
 | 
			
		||||
// CountAllEnabledNodeClustersWithHTTPFirewallPolicyId 计算使用某个WAF策略的集群数量
 | 
			
		||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest) (*pb.RPCCountResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -688,7 +688,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithHTTPFirewallPolic
 | 
			
		||||
	return this.SuccessCount(count)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找使用WAF策略的所有集群
 | 
			
		||||
// FindAllEnabledNodeClustersWithHTTPFirewallPolicyId 查找使用WAF策略的所有集群
 | 
			
		||||
func (this *NodeClusterService) FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(ctx context.Context, req *pb.FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdRequest) (*pb.FindAllEnabledNodeClustersWithHTTPFirewallPolicyIdResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -713,7 +713,7 @@ func (this *NodeClusterService) FindAllEnabledNodeClustersWithHTTPFirewallPolicy
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群的缓存策略
 | 
			
		||||
// UpdateNodeClusterHTTPCachePolicyId 修改集群的缓存策略
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeClusterHTTPCachePolicyId(ctx context.Context, req *pb.UpdateNodeClusterHTTPCachePolicyIdRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -730,7 +730,7 @@ func (this *NodeClusterService) UpdateNodeClusterHTTPCachePolicyId(ctx context.C
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群的WAF策略
 | 
			
		||||
// UpdateNodeClusterHTTPFirewallPolicyId 修改集群的WAF策略
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeClusterHTTPFirewallPolicyId(ctx context.Context, req *pb.UpdateNodeClusterHTTPFirewallPolicyIdRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -747,7 +747,7 @@ func (this *NodeClusterService) UpdateNodeClusterHTTPFirewallPolicyId(ctx contex
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群的系统服务设置
 | 
			
		||||
// UpdateNodeClusterSystemService 修改集群的系统服务设置
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeClusterSystemService(ctx context.Context, req *pb.UpdateNodeClusterSystemServiceRequest) (*pb.RPCSuccess, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -771,7 +771,7 @@ func (this *NodeClusterService) UpdateNodeClusterSystemService(ctx context.Conte
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找集群的系统服务设置
 | 
			
		||||
// FindNodeClusterSystemService 查找集群的系统服务设置
 | 
			
		||||
func (this *NodeClusterService) FindNodeClusterSystemService(ctx context.Context, req *pb.FindNodeClusterSystemServiceRequest) (*pb.FindNodeClusterSystemServiceResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -793,7 +793,7 @@ func (this *NodeClusterService) FindNodeClusterSystemService(ctx context.Context
 | 
			
		||||
	return &pb.FindNodeClusterSystemServiceResponse{ParamsJSON: paramsJSON}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取集群中可以使用的端口
 | 
			
		||||
// FindFreePortInNodeCluster 获取集群中可以使用的端口
 | 
			
		||||
func (this *NodeClusterService) FindFreePortInNodeCluster(ctx context.Context, req *pb.FindFreePortInNodeClusterRequest) (*pb.FindFreePortInNodeClusterResponse, error) {
 | 
			
		||||
	_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -851,7 +851,7 @@ func (this *NodeClusterService) FindFreePortInNodeCluster(ctx context.Context, r
 | 
			
		||||
	return nil, errors.New("can not find random port")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 检查端口是否已经被使用
 | 
			
		||||
// CheckPortIsUsingInNodeCluster 检查端口是否已经被使用
 | 
			
		||||
func (this *NodeClusterService) CheckPortIsUsingInNodeCluster(ctx context.Context, req *pb.CheckPortIsUsingInNodeClusterRequest) (*pb.CheckPortIsUsingInNodeClusterResponse, error) {
 | 
			
		||||
	_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -865,3 +865,25 @@ func (this *NodeClusterService) CheckPortIsUsingInNodeCluster(ctx context.Contex
 | 
			
		||||
	}
 | 
			
		||||
	return &pb.CheckPortIsUsingInNodeClusterResponse{IsUsing: isUsing}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindLatestNodeClusters 查找最近访问的集群
 | 
			
		||||
func (this *NodeClusterService) FindLatestNodeClusters(ctx context.Context, req *pb.FindLatestNodeClustersRequest) (*pb.FindLatestNodeClustersResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	clusters, err := models.SharedNodeClusterDAO.FindLatestNodeClusters(tx, req.Size)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	pbClusters := []*pb.NodeCluster{}
 | 
			
		||||
	for _, cluster := range clusters {
 | 
			
		||||
		pbClusters = append(pbClusters, &pb.NodeCluster{
 | 
			
		||||
			Id:   int64(cluster.Id),
 | 
			
		||||
			Name: cluster.Name,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	return &pb.FindLatestNodeClustersResponse{NodeClusters: pbClusters}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user