mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-27 15:46:35 +08:00
集群设置中增加服务设置
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/andybalholm/brotli"
|
||||
@@ -1891,6 +1892,55 @@ func (this *NodeService) UpdateNodeDDoSProtection(ctx context.Context, req *pb.U
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// FindNodeGlobalServerConfig 取得节点的服务全局配置
|
||||
func (this *NodeService) FindNodeGlobalServerConfig(ctx context.Context, req *pb.FindNodeGlobalServerConfigRequest) (*pb.FindNodeGlobalServerConfigResponse, error) {
|
||||
var nodeId = req.NodeId
|
||||
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
// 检查是否来自节点
|
||||
currentNodeId, err2 := this.ValidateNode(ctx)
|
||||
if err2 != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if nodeId > 0 && currentNodeId != nodeId {
|
||||
return nil, errors.New("invalid 'nodeId'")
|
||||
}
|
||||
|
||||
nodeId = currentNodeId
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
clusterId, err := models.SharedNodeDAO.FindNodeClusterId(tx, nodeId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config *serverconfigs.GlobalServerConfig
|
||||
if clusterId > 0 {
|
||||
config, err = models.SharedNodeClusterDAO.FindClusterGlobalServerConfig(tx, clusterId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if config == nil {
|
||||
config = serverconfigs.DefaultGlobalServerConfig()
|
||||
}
|
||||
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result = &pb.FindNodeGlobalServerConfigResponse{
|
||||
GlobalServerConfigJSON: configJSON,
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FindEnabledNodeConfigInfo 取得节点的配置概要信息
|
||||
func (this *NodeService) FindEnabledNodeConfigInfo(ctx context.Context, req *pb.FindEnabledNodeConfigInfoRequest) (*pb.FindEnabledNodeConfigInfoResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
|
||||
@@ -103,7 +103,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
|
||||
}
|
||||
}
|
||||
|
||||
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts, clockConfig)
|
||||
err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts, clockConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1253,3 +1253,53 @@ func (this *NodeClusterService) UpdateNodeClusterDDoSProtection(ctx context.Cont
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// FindNodeClusterGlobalServerConfig 获取集群的全局服务设置
|
||||
func (this *NodeClusterService) FindNodeClusterGlobalServerConfig(ctx context.Context, req *pb.FindNodeClusterGlobalServerConfigRequest) (*pb.FindNodeClusterGlobalServerConfigResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
config, err := models.SharedNodeClusterDAO.FindClusterGlobalServerConfig(tx, req.NodeClusterId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindNodeClusterGlobalServerConfigResponse{
|
||||
GlobalServerConfigJSON: configJSON,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateNodeClusterGlobalServerConfig 修改集群的全局服务设置
|
||||
func (this *NodeClusterService) UpdateNodeClusterGlobalServerConfig(ctx context.Context, req *pb.UpdateNodeClusterGlobalServerConfigRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config = serverconfigs.DefaultGlobalServerConfig()
|
||||
err = json.Unmarshal(req.GlobalServerConfigJSON, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = config.Init()
|
||||
if err != nil {
|
||||
return nil, errors.New("validate config failed: " + err.Error())
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = models.SharedNodeClusterDAO.UpdateClusterGlobalServerConfig(tx, req.NodeClusterId, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user