mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-11 22:00:27 +08:00
修复待升级节点版本号对比错误
This commit is contained in:
@@ -3,6 +3,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
@@ -603,10 +605,10 @@ func (this *NodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterI
|
|||||||
Where("status IS NOT NULL").
|
Where("status IS NOT NULL").
|
||||||
Where("JSON_EXTRACT(status, '$.os')=:os").
|
Where("JSON_EXTRACT(status, '$.os')=:os").
|
||||||
Where("JSON_EXTRACT(status, '$.arch')=:arch").
|
Where("JSON_EXTRACT(status, '$.arch')=:arch").
|
||||||
Where("INET_ATON(JSON_UNQUOTE(JSON_EXTRACT(status, '$.buildVersion')))<INET_ATON(:version)").
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
Param("os", os).
|
Param("os", os).
|
||||||
Param("arch", arch).
|
Param("arch", arch).
|
||||||
Param("version", version).
|
Param("version", utils.VersionToLong(version)).
|
||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -618,13 +620,14 @@ func (this *NodeDAO) FindAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId
|
|||||||
Where("status IS NOT NULL").
|
Where("status IS NOT NULL").
|
||||||
Where("JSON_EXTRACT(status, '$.os')=:os").
|
Where("JSON_EXTRACT(status, '$.os')=:os").
|
||||||
Where("JSON_EXTRACT(status, '$.arch')=:arch").
|
Where("JSON_EXTRACT(status, '$.arch')=:arch").
|
||||||
Where("INET_ATON(JSON_UNQUOTE(JSON_EXTRACT(status, '$.buildVersion')))<INET_ATON(:version)").
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
Param("os", os).
|
Param("os", os).
|
||||||
Param("arch", arch).
|
Param("arch", arch).
|
||||||
Param("version", version).
|
Param("version", utils.VersionToLong(version)).
|
||||||
DescPk().
|
DescPk().
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
|
logs.Println(len(result), version) // TODO
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/events"
|
"github.com/TeaOSLab/EdgeAPI/internal/events"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
@@ -54,6 +55,7 @@ func (this *NodeStatusExecutor) update() {
|
|||||||
|
|
||||||
status := &nodeconfigs.NodeStatus{}
|
status := &nodeconfigs.NodeStatus{}
|
||||||
status.BuildVersion = teaconst.Version
|
status.BuildVersion = teaconst.Version
|
||||||
|
status.BuildVersionCode = utils.VersionToLong(teaconst.Version)
|
||||||
status.OS = runtime.GOOS
|
status.OS = runtime.GOOS
|
||||||
status.Arch = runtime.GOARCH
|
status.Arch = runtime.GOARCH
|
||||||
status.ConfigVersion = 0
|
status.ConfigVersion = 0
|
||||||
|
|||||||
19
internal/utils/ip.go
Normal file
19
internal/utils/ip.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 将IP转换为整型
|
||||||
|
func IP2Long(ip string) uint32 {
|
||||||
|
s := net.ParseIP(ip)
|
||||||
|
if s == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(s) == 16 {
|
||||||
|
return binary.BigEndian.Uint32(s[12:16])
|
||||||
|
}
|
||||||
|
return binary.BigEndian.Uint32(s)
|
||||||
|
}
|
||||||
18
internal/utils/version.go
Normal file
18
internal/utils/version.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 计算版本代号
|
||||||
|
func VersionToLong(version string) uint32 {
|
||||||
|
countDots := strings.Count(version, ".")
|
||||||
|
if countDots == 2 {
|
||||||
|
version += ".0"
|
||||||
|
} else if countDots == 1 {
|
||||||
|
version += ".0.0"
|
||||||
|
} else if countDots == 0 {
|
||||||
|
version += ".0.0.0"
|
||||||
|
}
|
||||||
|
return IP2Long(version)
|
||||||
|
}
|
||||||
31
internal/utils/version_test.go
Normal file
31
internal/utils/version_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestNodeStatus_ComputerBuildVersionCode(t *testing.T) {
|
||||||
|
{
|
||||||
|
t.Log("", VersionToLong(""))
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
t.Log("0.0.6", VersionToLong("0.0.6"))
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
t.Log("0.0.6.1", VersionToLong("0.0.6.1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
t.Log("0.0.7", VersionToLong("0.0.7"))
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
t.Log("0.7", VersionToLong("0.7"))
|
||||||
|
}
|
||||||
|
{
|
||||||
|
t.Log("7", VersionToLong("7"))
|
||||||
|
}
|
||||||
|
{
|
||||||
|
t.Log("7.0.1", VersionToLong("7.0.1"))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user