节点自动升级功能之前的版本
This commit is contained in:
@@ -34,7 +34,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) CreateCluster(tx *dbs.Tx, name string, serviceDomain string, defaultTTL int32, fallbackTimeoutMs int32, installDir string, tlsPolicyJSON []byte, isOn bool, isDefault bool) (int64, error) {
|
||||
func (this *HTTPDNSClusterDAO) CreateCluster(tx *dbs.Tx, name string, serviceDomain string, defaultTTL int32, fallbackTimeoutMs int32, installDir string, tlsPolicyJSON []byte, isOn bool, isDefault bool, autoRemoteStart bool, accessLogIsOn bool) (int64, error) {
|
||||
if isDefault {
|
||||
err := this.Query(tx).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
@@ -53,6 +53,8 @@ func (this *HTTPDNSClusterDAO) CreateCluster(tx *dbs.Tx, name string, serviceDom
|
||||
op.InstallDir = installDir
|
||||
op.IsOn = isOn
|
||||
op.IsDefault = isDefault
|
||||
op.AutoRemoteStart = autoRemoteStart
|
||||
op.AccessLogIsOn = accessLogIsOn
|
||||
op.CreatedAt = time.Now().Unix()
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
op.State = HTTPDNSClusterStateEnabled
|
||||
@@ -66,7 +68,7 @@ func (this *HTTPDNSClusterDAO) CreateCluster(tx *dbs.Tx, name string, serviceDom
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, serviceDomain string, defaultTTL int32, fallbackTimeoutMs int32, installDir string, tlsPolicyJSON []byte, isOn bool, isDefault bool) error {
|
||||
func (this *HTTPDNSClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, serviceDomain string, defaultTTL int32, fallbackTimeoutMs int32, installDir string, tlsPolicyJSON []byte, isOn bool, isDefault bool, autoRemoteStart bool, accessLogIsOn bool) error {
|
||||
if isDefault {
|
||||
err := this.Query(tx).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
@@ -87,6 +89,8 @@ func (this *HTTPDNSClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name s
|
||||
op.InstallDir = installDir
|
||||
op.IsOn = isOn
|
||||
op.IsDefault = isDefault
|
||||
op.AutoRemoteStart = autoRemoteStart
|
||||
op.AccessLogIsOn = accessLogIsOn
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
if len(tlsPolicyJSON) > 0 {
|
||||
op.TLSPolicy = tlsPolicyJSON
|
||||
|
||||
@@ -13,6 +13,8 @@ type HTTPDNSCluster struct {
|
||||
FallbackTimeoutMs int32 `field:"fallbackTimeoutMs"` // 降级超时
|
||||
InstallDir string `field:"installDir"` // 安装目录
|
||||
TLSPolicy dbs.JSON `field:"tlsPolicy"` // TLS策略
|
||||
AutoRemoteStart bool `field:"autoRemoteStart"` // 自动远程启动
|
||||
AccessLogIsOn bool `field:"accessLogIsOn"` // 访问日志是否开启
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
State uint8 `field:"state"` // 记录状态
|
||||
@@ -28,6 +30,8 @@ type HTTPDNSClusterOperator struct {
|
||||
FallbackTimeoutMs any // 降级超时
|
||||
InstallDir any // 安装目录
|
||||
TLSPolicy any // TLS策略
|
||||
AutoRemoteStart any // 自动远程启动
|
||||
AccessLogIsOn any // 访问日志是否开启
|
||||
CreatedAt any // 创建时间
|
||||
UpdatedAt any // 修改时间
|
||||
State any // 记录状态
|
||||
|
||||
@@ -15,8 +15,9 @@ var SharedDeployManager = NewDeployManager()
|
||||
type DeployManager struct {
|
||||
dir string
|
||||
|
||||
nodeFiles []*DeployFile
|
||||
nsNodeFiles []*DeployFile
|
||||
nodeFiles []*DeployFile
|
||||
nsNodeFiles []*DeployFile
|
||||
httpdnsNodeFiles []*DeployFile
|
||||
|
||||
locker sync.Mutex
|
||||
}
|
||||
@@ -28,6 +29,7 @@ func NewDeployManager() *DeployManager {
|
||||
}
|
||||
manager.LoadNodeFiles()
|
||||
manager.LoadNSNodeFiles()
|
||||
manager.LoadHTTPDNSNodeFiles()
|
||||
return manager
|
||||
}
|
||||
|
||||
@@ -141,6 +143,61 @@ func (this *DeployManager) FindNSNodeFile(os string, arch string) *DeployFile {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadHTTPDNSNodeFiles 加载所有HTTPDNS节点安装文件
|
||||
func (this *DeployManager) LoadHTTPDNSNodeFiles() []*DeployFile {
|
||||
this.locker.Lock()
|
||||
defer this.locker.Unlock()
|
||||
|
||||
if len(this.httpdnsNodeFiles) > 0 {
|
||||
return this.httpdnsNodeFiles
|
||||
}
|
||||
|
||||
var keyMap = map[string]*DeployFile{} // key => File
|
||||
|
||||
var reg = regexp.MustCompile(`^edge-httpdns-(\w+)-(\w+)-v([0-9.]+)\.zip$`)
|
||||
for _, file := range files.NewFile(this.dir).List() {
|
||||
var name = file.Name()
|
||||
if !reg.MatchString(name) {
|
||||
continue
|
||||
}
|
||||
var matches = reg.FindStringSubmatch(name)
|
||||
var osName = matches[1]
|
||||
var arch = matches[2]
|
||||
var version = matches[3]
|
||||
|
||||
var key = osName + "_" + arch
|
||||
oldFile, ok := keyMap[key]
|
||||
if ok && stringutil.VersionCompare(oldFile.Version, version) > 0 {
|
||||
continue
|
||||
}
|
||||
keyMap[key] = &DeployFile{
|
||||
OS: osName,
|
||||
Arch: arch,
|
||||
Version: version,
|
||||
Path: file.Path(),
|
||||
}
|
||||
}
|
||||
|
||||
var result = []*DeployFile{}
|
||||
for _, v := range keyMap {
|
||||
result = append(result, v)
|
||||
}
|
||||
|
||||
this.httpdnsNodeFiles = result
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindHTTPDNSNodeFile 查找特定平台的HTTPDNS节点安装文件
|
||||
func (this *DeployManager) FindHTTPDNSNodeFile(os string, arch string) *DeployFile {
|
||||
for _, file := range this.LoadHTTPDNSNodeFiles() {
|
||||
if file.OS == os && file.Arch == arch {
|
||||
return file
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reload 重置缓存
|
||||
func (this *DeployManager) Reload() {
|
||||
this.locker.Lock()
|
||||
@@ -148,4 +205,5 @@ func (this *DeployManager) Reload() {
|
||||
|
||||
this.nodeFiles = nil
|
||||
this.nsNodeFiles = nil
|
||||
this.httpdnsNodeFiles = nil
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ func toPBCluster(cluster *models.HTTPDNSCluster) *pb.HTTPDNSCluster {
|
||||
TlsPolicyJSON: cluster.TLSPolicy,
|
||||
CreatedAt: int64(cluster.CreatedAt),
|
||||
UpdatedAt: int64(cluster.UpdatedAt),
|
||||
AutoRemoteStart: cluster.AutoRemoteStart,
|
||||
AccessLogIsOn: cluster.AccessLogIsOn,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func (this *HTTPDNSClusterService) CreateHTTPDNSCluster(ctx context.Context, req
|
||||
}
|
||||
var clusterId int64
|
||||
err = this.RunTx(func(tx *dbs.Tx) error {
|
||||
clusterId, err = models.SharedHTTPDNSClusterDAO.CreateCluster(tx, req.Name, req.ServiceDomain, req.DefaultTTL, req.FallbackTimeoutMs, req.InstallDir, req.TlsPolicyJSON, req.IsOn, req.IsDefault)
|
||||
clusterId, err = models.SharedHTTPDNSClusterDAO.CreateCluster(tx, req.Name, req.ServiceDomain, req.DefaultTTL, req.FallbackTimeoutMs, req.InstallDir, req.TlsPolicyJSON, req.IsOn, req.IsDefault, req.AutoRemoteStart, req.AccessLogIsOn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func (this *HTTPDNSClusterService) UpdateHTTPDNSCluster(ctx context.Context, req
|
||||
return nil, err
|
||||
}
|
||||
err = this.RunTx(func(tx *dbs.Tx) error {
|
||||
err = models.SharedHTTPDNSClusterDAO.UpdateCluster(tx, req.ClusterId, req.Name, req.ServiceDomain, req.DefaultTTL, req.FallbackTimeoutMs, req.InstallDir, req.TlsPolicyJSON, req.IsOn, req.IsDefault)
|
||||
err = models.SharedHTTPDNSClusterDAO.UpdateCluster(tx, req.ClusterId, req.Name, req.ServiceDomain, req.DefaultTTL, req.FallbackTimeoutMs, req.InstallDir, req.TlsPolicyJSON, req.IsOn, req.IsDefault, req.AutoRemoteStart, req.AccessLogIsOn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,14 +4,19 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/installers"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/rpc/services"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
)
|
||||
|
||||
// HTTPDNSNodeService HTTPDNS节点服务
|
||||
@@ -216,6 +221,59 @@ func (this *HTTPDNSNodeService) UpdateHTTPDNSNodeLogin(ctx context.Context, req
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// CheckHTTPDNSNodeLatestVersion 检查HTTPDNS节点新版本
|
||||
func (this *HTTPDNSNodeService) CheckHTTPDNSNodeLatestVersion(ctx context.Context, req *pb.CheckHTTPDNSNodeLatestVersionRequest) (*pb.CheckHTTPDNSNodeLatestVersionResponse, error) {
|
||||
_, _, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeHTTPDNS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deployFiles := installers.SharedDeployManager.LoadHTTPDNSNodeFiles()
|
||||
for _, file := range deployFiles {
|
||||
if file.OS == req.Os && file.Arch == req.Arch && stringutil.VersionCompare(file.Version, req.CurrentVersion) > 0 {
|
||||
return &pb.CheckHTTPDNSNodeLatestVersionResponse{
|
||||
HasNewVersion: true,
|
||||
NewVersion: file.Version,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
return &pb.CheckHTTPDNSNodeLatestVersionResponse{HasNewVersion: false}, nil
|
||||
}
|
||||
|
||||
// DownloadHTTPDNSNodeInstallationFile 下载最新HTTPDNS节点安装文件
|
||||
func (this *HTTPDNSNodeService) DownloadHTTPDNSNodeInstallationFile(ctx context.Context, req *pb.DownloadHTTPDNSNodeInstallationFileRequest) (*pb.DownloadHTTPDNSNodeInstallationFileResponse, error) {
|
||||
nodeId, err := this.ValidateHTTPDNSNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var file = installers.SharedDeployManager.FindHTTPDNSNodeFile(req.Os, req.Arch)
|
||||
if file == nil {
|
||||
return &pb.DownloadHTTPDNSNodeInstallationFileResponse{}, nil
|
||||
}
|
||||
|
||||
sum, err := file.Sum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, offset, err := file.Read(req.ChunkOffset)
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 增加下载速度监控
|
||||
installers.SharedUpgradeLimiter.UpdateNodeBytes(nodeconfigs.NodeRoleHTTPDNS, nodeId, int64(len(data)))
|
||||
|
||||
return &pb.DownloadHTTPDNSNodeInstallationFileResponse{
|
||||
Sum: sum,
|
||||
Offset: offset,
|
||||
ChunkData: data,
|
||||
Version: file.Version,
|
||||
Filename: filepath.Base(file.Path),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func shouldTriggerHTTPDNSInstall(installStatusJSON []byte) bool {
|
||||
if len(installStatusJSON) == 0 {
|
||||
return false
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
// FindUserPriceInfo 读取用户计费信息
|
||||
@@ -145,9 +144,6 @@ func (this *UserService) RegisterUser(ctx context.Context, req *pb.RegisterUserR
|
||||
}
|
||||
|
||||
features := registerConfig.Features
|
||||
if registerConfig.HTTPDNSIsOn && !lists.ContainsString(features, userconfigs.UserFeatureCodeHTTPDNS) {
|
||||
features = append(features, userconfigs.UserFeatureCodeHTTPDNS)
|
||||
}
|
||||
|
||||
// 创建用户
|
||||
userId, err := models.SharedUserDAO.CreateUser(tx, req.Username, req.Password, req.Fullname, req.Mobile, "", req.Email, "", req.Source, registerConfig.ClusterId, features, req.Ip, !registerConfig.RequireVerification)
|
||||
|
||||
Reference in New Issue
Block a user