mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-31 18:46:35 +08:00
实现健康检查配置、立即执行健康检查
This commit is contained in:
@@ -3,11 +3,13 @@ package models
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -214,6 +216,39 @@ func (this *NodeClusterDAO) FindAllAPINodeAddrsWithCluster(clusterId int64) (res
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 查找健康检查设置
|
||||
func (this *NodeClusterDAO) FindClusterHealthCheckConfig(clusterId int64) (*serverconfigs.HealthCheckConfig, error) {
|
||||
col, err := this.Query().
|
||||
Pk(clusterId).
|
||||
Result("healthCheck").
|
||||
FindStringCol("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(col) == 0 || col == "null" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
config := &serverconfigs.HealthCheckConfig{}
|
||||
err = json.Unmarshal([]byte(col), config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// 修改健康检查设置
|
||||
func (this *NodeClusterDAO) UpdateClusterHealthCheck(clusterId int64, healthCheckJSON []byte) error {
|
||||
if clusterId <= 0 {
|
||||
return errors.New("invalid clusterId '" + strconv.FormatInt(clusterId, 10) + "'")
|
||||
}
|
||||
op := NewNodeClusterOperator()
|
||||
op.Id = clusterId
|
||||
op.HealthCheck = healthCheckJSON
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 生成唯一ID
|
||||
func (this *NodeClusterDAO) genUniqueId() (string, error) {
|
||||
for {
|
||||
|
||||
@@ -16,6 +16,7 @@ type NodeCluster struct {
|
||||
AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册
|
||||
UniqueId string `field:"uniqueId"` // 唯一ID
|
||||
Secret string `field:"secret"` // 密钥
|
||||
HealthCheck string `field:"healthCheck"` // 健康检查
|
||||
}
|
||||
|
||||
type NodeClusterOperator struct {
|
||||
@@ -33,6 +34,7 @@ type NodeClusterOperator struct {
|
||||
AutoRegister interface{} // 是否开启自动注册
|
||||
UniqueId interface{} // 唯一ID
|
||||
Secret interface{} // 密钥
|
||||
HealthCheck interface{} // 健康检查
|
||||
}
|
||||
|
||||
func NewNodeClusterOperator() *NodeClusterOperator {
|
||||
|
||||
@@ -85,11 +85,12 @@ func (this *NodeIPAddressDAO) FindAddressName(id int64) (string, error) {
|
||||
}
|
||||
|
||||
// 创建IP地址
|
||||
func (this *NodeIPAddressDAO) CreateAddress(nodeId int64, name string, ip string) (addressId int64, err error) {
|
||||
func (this *NodeIPAddressDAO) CreateAddress(nodeId int64, name string, ip string, canAccess bool) (addressId int64, err error) {
|
||||
op := NewNodeIPAddressOperator()
|
||||
op.NodeId = nodeId
|
||||
op.Name = name
|
||||
op.IP = ip
|
||||
op.Ip = ip
|
||||
op.CanAccess = canAccess
|
||||
op.State = NodeIPAddressStateEnabled
|
||||
_, err = this.Save(op)
|
||||
if err != nil {
|
||||
@@ -99,7 +100,7 @@ func (this *NodeIPAddressDAO) CreateAddress(nodeId int64, name string, ip string
|
||||
}
|
||||
|
||||
// 修改IP地址
|
||||
func (this *NodeIPAddressDAO) UpdateAddress(addressId int64, name string, ip string) (err error) {
|
||||
func (this *NodeIPAddressDAO) UpdateAddress(addressId int64, name string, ip string, canAccess bool) (err error) {
|
||||
if addressId <= 0 {
|
||||
return errors.New("invalid addressId")
|
||||
}
|
||||
@@ -107,7 +108,9 @@ func (this *NodeIPAddressDAO) UpdateAddress(addressId int64, name string, ip str
|
||||
op := NewNodeIPAddressOperator()
|
||||
op.Id = addressId
|
||||
op.Name = name
|
||||
op.IP = ip
|
||||
op.Ip = ip
|
||||
op.CanAccess = canAccess
|
||||
op.State = NodeIPAddressStateEnabled // 恢复状态
|
||||
_, err = this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package models
|
||||
|
||||
//
|
||||
// 节点IP地址
|
||||
type NodeIPAddress struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||
Name string `field:"name"` // 名称
|
||||
IP string `field:"ip"` // IP地址
|
||||
Ip string `field:"ip"` // IP地址
|
||||
Description string `field:"description"` // 描述
|
||||
State uint8 `field:"state"` // 状态
|
||||
Order uint32 `field:"order"` // 排序
|
||||
CanAccess uint8 `field:"canAccess"` // 是否可以访问
|
||||
}
|
||||
|
||||
type NodeIPAddressOperator struct {
|
||||
Id interface{} // ID
|
||||
NodeId interface{} // 节点ID
|
||||
Name interface{} // 名称
|
||||
IP interface{} // IP地址
|
||||
Ip interface{} // IP地址
|
||||
Description interface{} // 描述
|
||||
State interface{} // 状态
|
||||
Order interface{} // 排序
|
||||
CanAccess interface{} // 是否可以访问
|
||||
}
|
||||
|
||||
func NewNodeIPAddressOperator() *NodeIPAddressOperator {
|
||||
|
||||
@@ -25,3 +25,4 @@ func (this *Node) DecodeInstallStatus() (*NodeInstallStatus, error) {
|
||||
|
||||
return status, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user