mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
支持设置单节点最大线程数、单节点TCP最大连接数
This commit is contained in:
@@ -178,7 +178,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCluster 修改集群
|
// UpdateCluster 修改集群
|
||||||
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string) error {
|
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string, nodeMaxThreads int32, nodeTCPMaxConnections int32) error {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return errors.New("invalid clusterId")
|
return errors.New("invalid clusterId")
|
||||||
}
|
}
|
||||||
@@ -188,6 +188,17 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri
|
|||||||
op.GrantId = grantId
|
op.GrantId = grantId
|
||||||
op.InstallDir = installDir
|
op.InstallDir = installDir
|
||||||
op.TimeZone = timezone
|
op.TimeZone = timezone
|
||||||
|
|
||||||
|
if nodeMaxThreads < 0 {
|
||||||
|
nodeMaxThreads = 0
|
||||||
|
}
|
||||||
|
op.NodeMaxThreads = nodeMaxThreads
|
||||||
|
|
||||||
|
if nodeTCPMaxConnections < 0 {
|
||||||
|
nodeTCPMaxConnections = 0
|
||||||
|
}
|
||||||
|
op.NodeTCPMaxConnections = nodeTCPMaxConnections
|
||||||
|
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -864,27 +875,27 @@ func (this *NodeClusterDAO) ExistsEnabledCluster(tx *dbs.Tx, clusterId int64) (b
|
|||||||
Exist()
|
Exist()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindClusterTimezone 查找时区
|
// FindClusterBasicInfo 查找集群基础信息
|
||||||
func (this *NodeClusterDAO) FindClusterTimezone(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (string, error) {
|
func (this *NodeClusterDAO) FindClusterBasicInfo(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (*NodeCluster, error) {
|
||||||
var cacheKey = this.Table + ":FindEnabledTimeZone:" + types.String(clusterId)
|
var cacheKey = this.Table + ":FindClusterBasicInfo:" + types.String(clusterId)
|
||||||
if cacheMap != nil {
|
if cacheMap != nil {
|
||||||
cache, ok := cacheMap.Get(cacheKey)
|
cache, ok := cacheMap.Get(cacheKey)
|
||||||
if ok {
|
if ok {
|
||||||
return cache.(string), nil
|
return cache.(*NodeCluster), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeZone, err := this.Query(tx).
|
cluster, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
Result("timeZone").
|
Result("timeZone", "nodeMaxThreads", "nodeTCPMaxConnections", "cachePolicyId", "httpFirewallPolicyId").
|
||||||
FindStringCol("")
|
Find()
|
||||||
if err != nil {
|
if err != nil || cluster == nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
if cacheMap != nil {
|
if cacheMap != nil {
|
||||||
cacheMap.Put(cacheKey, timeZone)
|
cacheMap.Put(cacheKey, cluster)
|
||||||
}
|
}
|
||||||
return timeZone, nil
|
return cluster.(*NodeCluster), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyUpdate 通知更新
|
// NotifyUpdate 通知更新
|
||||||
|
|||||||
@@ -2,59 +2,63 @@ package models
|
|||||||
|
|
||||||
// NodeCluster 节点集群
|
// NodeCluster 节点集群
|
||||||
type NodeCluster struct {
|
type NodeCluster struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
UserId uint32 `field:"userId"` // 用户ID
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
IsOn uint8 `field:"isOn"` // 是否启用
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
Name string `field:"name"` // 名称
|
Name string `field:"name"` // 名称
|
||||||
UseAllAPINodes uint8 `field:"useAllAPINodes"` // 是否使用所有API节点
|
UseAllAPINodes uint8 `field:"useAllAPINodes"` // 是否使用所有API节点
|
||||||
ApiNodes string `field:"apiNodes"` // 使用的API节点
|
ApiNodes string `field:"apiNodes"` // 使用的API节点
|
||||||
InstallDir string `field:"installDir"` // 安装目录
|
InstallDir string `field:"installDir"` // 安装目录
|
||||||
Order uint32 `field:"order"` // 排序
|
Order uint32 `field:"order"` // 排序
|
||||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
GrantId uint32 `field:"grantId"` // 默认认证方式
|
GrantId uint32 `field:"grantId"` // 默认认证方式
|
||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册
|
AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册
|
||||||
UniqueId string `field:"uniqueId"` // 唯一ID
|
UniqueId string `field:"uniqueId"` // 唯一ID
|
||||||
Secret string `field:"secret"` // 密钥
|
Secret string `field:"secret"` // 密钥
|
||||||
HealthCheck string `field:"healthCheck"` // 健康检查
|
HealthCheck string `field:"healthCheck"` // 健康检查
|
||||||
DnsName string `field:"dnsName"` // DNS名称
|
DnsName string `field:"dnsName"` // DNS名称
|
||||||
DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID
|
DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID
|
||||||
Dns string `field:"dns"` // DNS配置
|
Dns string `field:"dns"` // DNS配置
|
||||||
Toa string `field:"toa"` // TOA配置
|
Toa string `field:"toa"` // TOA配置
|
||||||
CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID
|
CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID
|
||||||
HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID
|
HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID
|
||||||
AccessLog string `field:"accessLog"` // 访问日志设置
|
AccessLog string `field:"accessLog"` // 访问日志设置
|
||||||
SystemServices string `field:"systemServices"` // 系统服务设置
|
SystemServices string `field:"systemServices"` // 系统服务设置
|
||||||
TimeZone string `field:"timeZone"` // 时区
|
TimeZone string `field:"timeZone"` // 时区
|
||||||
|
NodeMaxThreads uint32 `field:"nodeMaxThreads"` // 节点最大线程数
|
||||||
|
NodeTCPMaxConnections uint32 `field:"nodeTCPMaxConnections"` // TCP最大连接数
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeClusterOperator struct {
|
type NodeClusterOperator struct {
|
||||||
Id interface{} // ID
|
Id interface{} // ID
|
||||||
AdminId interface{} // 管理员ID
|
AdminId interface{} // 管理员ID
|
||||||
UserId interface{} // 用户ID
|
UserId interface{} // 用户ID
|
||||||
IsOn interface{} // 是否启用
|
IsOn interface{} // 是否启用
|
||||||
Name interface{} // 名称
|
Name interface{} // 名称
|
||||||
UseAllAPINodes interface{} // 是否使用所有API节点
|
UseAllAPINodes interface{} // 是否使用所有API节点
|
||||||
ApiNodes interface{} // 使用的API节点
|
ApiNodes interface{} // 使用的API节点
|
||||||
InstallDir interface{} // 安装目录
|
InstallDir interface{} // 安装目录
|
||||||
Order interface{} // 排序
|
Order interface{} // 排序
|
||||||
CreatedAt interface{} // 创建时间
|
CreatedAt interface{} // 创建时间
|
||||||
GrantId interface{} // 默认认证方式
|
GrantId interface{} // 默认认证方式
|
||||||
State interface{} // 状态
|
State interface{} // 状态
|
||||||
AutoRegister interface{} // 是否开启自动注册
|
AutoRegister interface{} // 是否开启自动注册
|
||||||
UniqueId interface{} // 唯一ID
|
UniqueId interface{} // 唯一ID
|
||||||
Secret interface{} // 密钥
|
Secret interface{} // 密钥
|
||||||
HealthCheck interface{} // 健康检查
|
HealthCheck interface{} // 健康检查
|
||||||
DnsName interface{} // DNS名称
|
DnsName interface{} // DNS名称
|
||||||
DnsDomainId interface{} // 域名ID
|
DnsDomainId interface{} // 域名ID
|
||||||
Dns interface{} // DNS配置
|
Dns interface{} // DNS配置
|
||||||
Toa interface{} // TOA配置
|
Toa interface{} // TOA配置
|
||||||
CachePolicyId interface{} // 缓存策略ID
|
CachePolicyId interface{} // 缓存策略ID
|
||||||
HttpFirewallPolicyId interface{} // WAF策略ID
|
HttpFirewallPolicyId interface{} // WAF策略ID
|
||||||
AccessLog interface{} // 访问日志设置
|
AccessLog interface{} // 访问日志设置
|
||||||
SystemServices interface{} // 系统服务设置
|
SystemServices interface{} // 系统服务设置
|
||||||
TimeZone interface{} // 时区
|
TimeZone interface{} // 时区
|
||||||
|
NodeMaxThreads interface{} // 节点最大线程数
|
||||||
|
NodeTCPMaxConnections interface{} // TCP最大连接数
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeClusterOperator() *NodeClusterOperator {
|
func NewNodeClusterOperator() *NodeClusterOperator {
|
||||||
|
|||||||
@@ -782,11 +782,17 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
|
|||||||
var primaryClusterId = int64(node.ClusterId)
|
var primaryClusterId = int64(node.ClusterId)
|
||||||
var clusterIds = []int64{primaryClusterId}
|
var clusterIds = []int64{primaryClusterId}
|
||||||
clusterIds = append(clusterIds, node.DecodeSecondaryClusterIds()...)
|
clusterIds = append(clusterIds, node.DecodeSecondaryClusterIds()...)
|
||||||
|
var clusterIndex = 0
|
||||||
for _, clusterId := range clusterIds {
|
for _, clusterId := range clusterIds {
|
||||||
httpFirewallPolicyId, err := SharedNodeClusterDAO.FindClusterHTTPFirewallPolicyId(tx, clusterId, cacheMap)
|
nodeCluster, err := SharedNodeClusterDAO.FindClusterBasicInfo(tx, clusterId, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if nodeCluster == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var httpFirewallPolicyId = int64(nodeCluster.HttpFirewallPolicyId)
|
||||||
if httpFirewallPolicyId > 0 {
|
if httpFirewallPolicyId > 0 {
|
||||||
firewallPolicy, err := SharedHTTPFirewallPolicyDAO.ComposeFirewallPolicy(tx, httpFirewallPolicyId, cacheMap)
|
firewallPolicy, err := SharedHTTPFirewallPolicyDAO.ComposeFirewallPolicy(tx, httpFirewallPolicyId, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -798,10 +804,7 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 缓存策略
|
// 缓存策略
|
||||||
httpCachePolicyId, err := SharedNodeClusterDAO.FindClusterHTTPCachePolicyId(tx, clusterId, cacheMap)
|
var httpCachePolicyId = int64(nodeCluster.CachePolicyId)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if httpCachePolicyId > 0 {
|
if httpCachePolicyId > 0 {
|
||||||
cachePolicy, err := SharedHTTPCachePolicyDAO.ComposeCachePolicy(tx, httpCachePolicyId, cacheMap)
|
cachePolicy, err := SharedHTTPCachePolicyDAO.ComposeCachePolicy(tx, httpCachePolicyId, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -813,13 +816,20 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 时区
|
// 时区
|
||||||
timeZone, err := SharedNodeClusterDAO.FindClusterTimezone(tx, clusterId, cacheMap)
|
if len(config.TimeZone) == 0 {
|
||||||
if err != nil {
|
var timeZone = nodeCluster.TimeZone
|
||||||
return nil, err
|
if len(timeZone) > 0 {
|
||||||
|
config.TimeZone = timeZone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(timeZone) > 0 {
|
|
||||||
config.TimeZone = timeZone
|
// 最大线程数、TCP连接数
|
||||||
|
if clusterIndex == 0 {
|
||||||
|
config.MaxThreads = int(nodeCluster.NodeMaxThreads)
|
||||||
|
config.TCPMaxConnections = int(nodeCluster.NodeTCPMaxConnections)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clusterIndex++
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存最大容量设置
|
// 缓存最大容量设置
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
|
|||||||
|
|
||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone)
|
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.NodeTCPMaxConnections)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -148,19 +148,21 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &pb.FindEnabledNodeClusterResponse{NodeCluster: &pb.NodeCluster{
|
return &pb.FindEnabledNodeClusterResponse{NodeCluster: &pb.NodeCluster{
|
||||||
Id: int64(cluster.Id),
|
Id: int64(cluster.Id),
|
||||||
Name: cluster.Name,
|
Name: cluster.Name,
|
||||||
CreatedAt: int64(cluster.CreatedAt),
|
CreatedAt: int64(cluster.CreatedAt),
|
||||||
InstallDir: cluster.InstallDir,
|
InstallDir: cluster.InstallDir,
|
||||||
NodeGrantId: int64(cluster.GrantId),
|
NodeGrantId: int64(cluster.GrantId),
|
||||||
UniqueId: cluster.UniqueId,
|
UniqueId: cluster.UniqueId,
|
||||||
Secret: cluster.Secret,
|
Secret: cluster.Secret,
|
||||||
HttpCachePolicyId: int64(cluster.CachePolicyId),
|
HttpCachePolicyId: int64(cluster.CachePolicyId),
|
||||||
HttpFirewallPolicyId: int64(cluster.HttpFirewallPolicyId),
|
HttpFirewallPolicyId: int64(cluster.HttpFirewallPolicyId),
|
||||||
DnsName: cluster.DnsName,
|
DnsName: cluster.DnsName,
|
||||||
DnsDomainId: int64(cluster.DnsDomainId),
|
DnsDomainId: int64(cluster.DnsDomainId),
|
||||||
IsOn: cluster.IsOn == 1,
|
IsOn: cluster.IsOn == 1,
|
||||||
TimeZone: cluster.TimeZone,
|
TimeZone: cluster.TimeZone,
|
||||||
|
NodeMaxThreads: int32(cluster.NodeMaxThreads),
|
||||||
|
NodeTCPMaxConnections: int32(cluster.NodeTCPMaxConnections),
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user