mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-08 16:00:25 +08:00
节点配置初始化时返回服务相关错误
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/logs"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -15,6 +14,15 @@ import (
|
|||||||
|
|
||||||
var sharedNodeConfig *NodeConfig = nil
|
var sharedNodeConfig *NodeConfig = nil
|
||||||
|
|
||||||
|
type ServerError struct {
|
||||||
|
Id int64
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServerError(serverId int64, message string) *ServerError {
|
||||||
|
return &ServerError{Id: serverId, Message: message}
|
||||||
|
}
|
||||||
|
|
||||||
// NodeConfig 边缘节点配置
|
// NodeConfig 边缘节点配置
|
||||||
type NodeConfig struct {
|
type NodeConfig struct {
|
||||||
Id int64 `yaml:"id" json:"id"`
|
Id int64 `yaml:"id" json:"id"`
|
||||||
@@ -87,32 +95,32 @@ func ResetNodeConfig(nodeConfig *NodeConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init 初始化
|
// Init 初始化
|
||||||
func (this *NodeConfig) Init() error {
|
func (this *NodeConfig) Init() (err error, serverErrors []*ServerError) {
|
||||||
this.paddedId = fmt.Sprintf("%08d", this.Id)
|
this.paddedId = fmt.Sprintf("%08d", this.Id)
|
||||||
|
|
||||||
// servers
|
// servers
|
||||||
for _, server := range this.Servers {
|
for _, server := range this.Servers {
|
||||||
err := server.Init()
|
err = server.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 这里不返回错误,而是继续往下,防止单个服务错误而影响其他服务
|
// 这里不返回错误,而是继续往下,防止单个服务错误而影响其他服务
|
||||||
logs.Println("[INIT]server '" + strconv.FormatInt(server.Id, 10) + "' init failed: " + err.Error())
|
serverErrors = append(serverErrors, NewServerError(server.Id, "server '"+strconv.FormatInt(server.Id, 10)+"' init failed: "+err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// global config
|
// global config
|
||||||
if this.GlobalConfig != nil {
|
if this.GlobalConfig != nil {
|
||||||
err := this.GlobalConfig.Init()
|
err = this.GlobalConfig.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache policy
|
// cache policy
|
||||||
if len(this.HTTPCachePolicies) > 0 {
|
if len(this.HTTPCachePolicies) > 0 {
|
||||||
for _, policy := range this.HTTPCachePolicies {
|
for _, policy := range this.HTTPCachePolicies {
|
||||||
err := policy.Init()
|
err = policy.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,18 +128,18 @@ func (this *NodeConfig) Init() error {
|
|||||||
// firewall policy
|
// firewall policy
|
||||||
if len(this.HTTPFirewallPolicies) > 0 {
|
if len(this.HTTPFirewallPolicies) > 0 {
|
||||||
for _, policy := range this.HTTPFirewallPolicies {
|
for _, policy := range this.HTTPFirewallPolicies {
|
||||||
err := policy.Init()
|
err = policy.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOA
|
// TOA
|
||||||
if this.TOA != nil {
|
if this.TOA != nil {
|
||||||
err := this.TOA.Init()
|
err = this.TOA.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,25 +198,25 @@ func (this *NodeConfig) Init() error {
|
|||||||
|
|
||||||
// firewall actions
|
// firewall actions
|
||||||
for _, action := range this.FirewallActions {
|
for _, action := range this.FirewallActions {
|
||||||
err := action.Init()
|
err = action.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// metric items
|
// metric items
|
||||||
this.hasHTTPConnectionMetrics = false
|
this.hasHTTPConnectionMetrics = false
|
||||||
for _, item := range this.MetricItems {
|
for _, item := range this.MetricItems {
|
||||||
err := item.Init()
|
err = item.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
if item.IsOn && item.HasHTTPConnectionValue() {
|
if item.IsOn && item.HasHTTPConnectionValue() {
|
||||||
this.hasHTTPConnectionMetrics = true
|
this.hasHTTPConnectionMetrics = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// AvailableGroups 根据网络地址和协议分组
|
// AvailableGroups 根据网络地址和协议分组
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ package nodeconfigs
|
|||||||
type NodeLogType = string
|
type NodeLogType = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NodeLogTypeListenAddressFailed NodeLogType = "listenAddressFailed"
|
NodeLogTypeListenAddressFailed NodeLogType = "listenAddressFailed"
|
||||||
|
NodeLogTypeServerConfigInitFailed NodeLogType = "serverConfigInitFailed"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user