mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-06 15:55:48 +08:00
将api.yaml修改为api_node.yaml
This commit is contained in:
@@ -438,10 +438,10 @@ func (this *APIStream) handleChangeAPINode(message *pb.NodeStreamMessage) error
|
||||
return nil
|
||||
}
|
||||
|
||||
config.RPC.Endpoints = []string{messageData.Addr}
|
||||
config.RPCEndpoints = []string{messageData.Addr}
|
||||
|
||||
// 保存到文件
|
||||
err = config.WriteFile(Tea.ConfigFile("api.yaml"))
|
||||
err = config.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||
if err != nil {
|
||||
this.replyFail(message.RequestId, "save config file failed: "+err.Error())
|
||||
return nil
|
||||
|
||||
@@ -314,15 +314,15 @@ func (this *Node) syncConfig(taskVersion int64) error {
|
||||
this.locker.Lock()
|
||||
defer this.locker.Unlock()
|
||||
|
||||
// 检查api.yaml是否存在
|
||||
apiConfigFile := Tea.ConfigFile("api.yaml")
|
||||
// 检查api_node.yaml是否存在
|
||||
var apiConfigFile = Tea.ConfigFile(configs.ConfigFileName)
|
||||
_, err := os.Stat(apiConfigFile)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
clusterErr := this.checkClusterConfig()
|
||||
if clusterErr != nil {
|
||||
if os.IsNotExist(clusterErr) {
|
||||
return errors.New("can not find config file 'configs/api.yaml'")
|
||||
return fmt.Errorf("can not find config file 'configs/%s'", configs.ConfigFileName)
|
||||
}
|
||||
return fmt.Errorf("check cluster config failed: %w", clusterErr)
|
||||
}
|
||||
@@ -524,7 +524,7 @@ func (this *Node) startSyncTimer() {
|
||||
|
||||
// 检查集群设置
|
||||
func (this *Node) checkClusterConfig() error {
|
||||
configFile := Tea.ConfigFile("cluster.yaml")
|
||||
var configFile = Tea.ConfigFile("cluster.yaml")
|
||||
data, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -536,9 +536,10 @@ func (this *Node) checkClusterConfig() error {
|
||||
}
|
||||
|
||||
rpcClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||
RPC: config.RPC,
|
||||
NodeId: config.ClusterId,
|
||||
Secret: config.Secret,
|
||||
RPCEndpoints: config.RPC.Endpoints,
|
||||
RPCDisableUpdate: config.RPC.DisableUpdate,
|
||||
NodeId: config.ClusterId,
|
||||
Secret: config.Secret,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -556,22 +557,17 @@ func (this *Node) checkClusterConfig() error {
|
||||
resp.Endpoints = []string{}
|
||||
}
|
||||
var apiConfig = &configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints" json:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate" json:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: resp.Endpoints,
|
||||
DisableUpdate: false,
|
||||
},
|
||||
NodeId: resp.UniqueId,
|
||||
Secret: resp.Secret,
|
||||
RPCEndpoints: resp.Endpoints,
|
||||
RPCDisableUpdate: false,
|
||||
NodeId: resp.UniqueId,
|
||||
Secret: resp.Secret,
|
||||
}
|
||||
remotelogs.Debug("NODE", "writing 'configs/api.yaml' ...")
|
||||
err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml"))
|
||||
remotelogs.Debug("NODE", "writing 'configs/"+configs.ConfigFileName+"' ...")
|
||||
err = apiConfig.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remotelogs.Debug("NODE", "wrote 'configs/api.yaml' successfully")
|
||||
remotelogs.Debug("NODE", "wrote 'configs/"+configs.ConfigFileName+"' successfully")
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1136,7 +1132,7 @@ func (this *Node) changeAPINodeAddrs(apiNodeAddrs []*serverconfigs.NetworkAddres
|
||||
if config == nil {
|
||||
return
|
||||
}
|
||||
var oldEndpoints = config.RPC.Endpoints
|
||||
var oldEndpoints = config.RPCEndpoints
|
||||
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
@@ -1150,9 +1146,9 @@ func (this *Node) changeAPINodeAddrs(apiNodeAddrs []*serverconfigs.NetworkAddres
|
||||
go func(v int64) {
|
||||
// 测试新的API节点地址
|
||||
if rpcClient.TestEndpoints(addrs) {
|
||||
config.RPC.Endpoints = addrs
|
||||
config.RPCEndpoints = addrs
|
||||
} else {
|
||||
config.RPC.Endpoints = oldEndpoints
|
||||
config.RPCEndpoints = oldEndpoints
|
||||
this.lastAPINodeAddrs = nil // 恢复为空,以便于下次更新重试
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/configs"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/firewalls"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/iplibrary"
|
||||
@@ -26,8 +27,8 @@ func (this *Node) loopTasks() error {
|
||||
var tr = trackers.Begin("CHECK_NODE_CONFIG_CHANGES")
|
||||
defer tr.End()
|
||||
|
||||
// 检查api.yaml是否存在
|
||||
var apiConfigFile = Tea.ConfigFile("api.yaml")
|
||||
// 检查api_node.yaml是否存在
|
||||
var apiConfigFile = Tea.ConfigFile(configs.ConfigFileName)
|
||||
_, err := os.Stat(apiConfigFile)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
||||
@@ -70,7 +70,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
||||
}
|
||||
|
||||
// 是否禁止自动升级
|
||||
if config.RPC.DisableUpdate {
|
||||
if config.RPCDisableUpdate {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
||||
}
|
||||
|
||||
// 和现有的对比
|
||||
if utils.EqualStrings(newEndpoints, config.RPC.Endpoints) {
|
||||
if utils.EqualStrings(newEndpoints, config.RPCEndpoints) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
||||
}
|
||||
|
||||
// 修改RPC对象配置
|
||||
config.RPC.Endpoints = newEndpoints
|
||||
config.RPCEndpoints = newEndpoints
|
||||
|
||||
// 更新当前RPC
|
||||
if !hasCustomizedAPINodeAddrs {
|
||||
@@ -118,7 +118,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
||||
}
|
||||
|
||||
// 保存到文件
|
||||
err = config.WriteFile(Tea.ConfigFile("api.yaml"))
|
||||
err = config.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user