2021-08-08 15:47:48 +08:00
|
|
|
|
package models
|
2021-05-26 14:40:05 +08:00
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
2022-08-22 15:11:22 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
2021-05-26 14:40:05 +08:00
|
|
|
|
"time"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// DecodeInstallStatus 安装状态
|
2021-08-08 15:47:48 +08:00
|
|
|
|
func (this *NSNode) DecodeInstallStatus() (*NodeInstallStatus, error) {
|
2022-03-21 21:39:36 +08:00
|
|
|
|
if len(this.InstallStatus) == 0 {
|
2021-08-08 15:47:48 +08:00
|
|
|
|
return NewNodeInstallStatus(), nil
|
2021-05-26 14:40:05 +08:00
|
|
|
|
}
|
2021-08-08 15:47:48 +08:00
|
|
|
|
status := &NodeInstallStatus{}
|
2022-03-22 19:30:30 +08:00
|
|
|
|
err := json.Unmarshal(this.InstallStatus, status)
|
2021-05-26 14:40:05 +08:00
|
|
|
|
if err != nil {
|
2021-08-08 15:47:48 +08:00
|
|
|
|
return NewNodeInstallStatus(), err
|
2021-05-26 14:40:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果N秒钟没有更新状态,则认为不在运行
|
|
|
|
|
|
if status.IsRunning && status.UpdatedAt < time.Now().Unix()-10 {
|
|
|
|
|
|
status.IsRunning = false
|
|
|
|
|
|
status.IsFinished = true
|
|
|
|
|
|
status.Error = "timeout"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return status, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DecodeStatus 节点状态
|
|
|
|
|
|
func (this *NSNode) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
|
2022-03-21 21:39:36 +08:00
|
|
|
|
if len(this.Status) == 0 {
|
2021-05-26 14:40:05 +08:00
|
|
|
|
return nil, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
status := &nodeconfigs.NodeStatus{}
|
2022-03-22 19:30:30 +08:00
|
|
|
|
err := json.Unmarshal(this.Status, status)
|
2021-05-26 14:40:05 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return status, nil
|
|
|
|
|
|
}
|
2022-08-22 15:11:22 +08:00
|
|
|
|
|
|
|
|
|
|
// DecodeDDoSProtection 解析DDoS Protection设置
|
|
|
|
|
|
func (this *NSNode) DecodeDDoSProtection() *ddosconfigs.ProtectionConfig {
|
|
|
|
|
|
if IsNull(this.DdosProtection) {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var result = &ddosconfigs.ProtectionConfig{}
|
|
|
|
|
|
err := json.Unmarshal(this.DdosProtection, &result)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
// ignore err
|
|
|
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// HasDDoSProtection 检查是否有DDOS设置
|
|
|
|
|
|
func (this *NSNode) HasDDoSProtection() bool {
|
|
|
|
|
|
var config = this.DecodeDDoSProtection()
|
|
|
|
|
|
if config != nil {
|
|
|
|
|
|
return !config.IsPriorEmpty()
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DecodeConnectedAPINodes 解析连接的API节点列表
|
|
|
|
|
|
func (this *NSNode) DecodeConnectedAPINodes() []int64 {
|
|
|
|
|
|
if IsNull(this.ConnectedAPINodes) {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var result = []int64{}
|
|
|
|
|
|
err := json.Unmarshal(this.ConnectedAPINodes, &result)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
// ignore err
|
|
|
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|