mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-10 04:20:26 +08:00
数据看板中增加升级信息
This commit is contained in:
@@ -15,4 +15,11 @@ const (
|
|||||||
ErrServer = "服务器出了点小问题,请稍后重试"
|
ErrServer = "服务器出了点小问题,请稍后重试"
|
||||||
|
|
||||||
SystemdServiceName = "edge-api"
|
SystemdServiceName = "edge-api"
|
||||||
|
|
||||||
|
// 其他节点版本号,用来检测是否有需要升级的节点
|
||||||
|
|
||||||
|
NodeVersion = "0.0.14"
|
||||||
|
UserNodeVersion = "0.0.7"
|
||||||
|
AuthorityNodeVersion = "0.0.1"
|
||||||
|
MonitorNodeVersion = "0.0.1"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
_ "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"
|
||||||
@@ -38,7 +39,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableAPINode 启用条目
|
||||||
func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -47,7 +48,7 @@ func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableAPINode 禁用条目
|
||||||
func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -56,7 +57,7 @@ func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledAPINode 查找启用中的条目
|
||||||
func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, error) {
|
func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -68,7 +69,7 @@ func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, erro
|
|||||||
return result.(*APINode), err
|
return result.(*APINode), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据ID和Secret查找节点
|
// FindEnabledAPINodeWithUniqueIdAndSecret 根据ID和Secret查找节点
|
||||||
func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniqueId string, secret string) (*APINode, error) {
|
func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniqueId string, secret string) (*APINode, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
State(APINodeStateEnabled).
|
State(APINodeStateEnabled).
|
||||||
@@ -81,7 +82,7 @@ func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniq
|
|||||||
return one.(*APINode), nil
|
return one.(*APINode), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindAPINodeName 根据主键查找名称
|
||||||
func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -89,7 +90,7 @@ func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建API节点
|
// CreateAPINode 创建API节点
|
||||||
func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
||||||
uniqueId, err := this.genUniqueId(tx)
|
uniqueId, err := this.genUniqueId(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -134,7 +135,7 @@ func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description strin
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改API节点
|
// UpdateAPINode 修改API节点
|
||||||
func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
||||||
if nodeId <= 0 {
|
if nodeId <= 0 {
|
||||||
return errors.New("invalid nodeId")
|
return errors.New("invalid nodeId")
|
||||||
@@ -177,7 +178,7 @@ func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, des
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有可用API节点
|
// FindAllEnabledAPINodes 列出所有可用API节点
|
||||||
func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("clusterId", 0). // 非集群专用
|
Attr("clusterId", 0). // 非集群专用
|
||||||
@@ -189,7 +190,7 @@ func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有可用而且启用的API节点
|
// FindAllEnabledAndOnAPINodes 列出所有可用而且启用的API节点
|
||||||
func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("clusterId", 0). // 非集群专用
|
Attr("clusterId", 0). // 非集群专用
|
||||||
@@ -202,14 +203,14 @@ func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算API节点数量
|
// CountAllEnabledAPINodes 计算API节点数量
|
||||||
func (this *APINodeDAO) CountAllEnabledAPINodes(tx *dbs.Tx) (int64, error) {
|
func (this *APINodeDAO) CountAllEnabledAPINodes(tx *dbs.Tx) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(APINodeStateEnabled).
|
State(APINodeStateEnabled).
|
||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的API节点
|
// ListEnabledAPINodes 列出单页的API节点
|
||||||
func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64) (result []*APINode, err error) {
|
func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64) (result []*APINode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("clusterId", 0). // 非集群专用
|
Attr("clusterId", 0). // 非集群专用
|
||||||
@@ -223,7 +224,7 @@ func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主机名和端口获取ID
|
// FindEnabledAPINodeIdWithAddr 根据主机名和端口获取ID
|
||||||
func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
||||||
addr := maps.Map{
|
addr := maps.Map{
|
||||||
"protocol": protocol,
|
"protocol": protocol,
|
||||||
@@ -250,7 +251,7 @@ func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string
|
|||||||
return int64(one.(*APINode).Id), nil
|
return int64(one.(*APINode).Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置API节点状态
|
// UpdateAPINodeStatus 设置API节点状态
|
||||||
func (this *APINodeDAO) UpdateAPINodeStatus(tx *dbs.Tx, apiNodeId int64, statusJSON []byte) error {
|
func (this *APINodeDAO) UpdateAPINodeStatus(tx *dbs.Tx, apiNodeId int64, statusJSON []byte) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(apiNodeId).
|
Pk(apiNodeId).
|
||||||
@@ -275,3 +276,13 @@ func (this *APINodeDAO) genUniqueId(tx *dbs.Tx) (string, error) {
|
|||||||
return uniqueId, nil
|
return uniqueId, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *APINodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(APINodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package authority
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
_ "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"
|
||||||
@@ -196,3 +197,13 @@ func (this *AuthorityNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJ
|
|||||||
Update()
|
Update()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *AuthorityNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(AuthorityNodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
_ "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"
|
||||||
@@ -195,3 +196,13 @@ func (this *MonitorNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSO
|
|||||||
Update()
|
Update()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *MonitorNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(MonitorNodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ func (this *NodeDAO) FindAllNotInstalledNodesWithClusterId(tx *dbs.Tx, clusterId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountAllLowerVersionNodesWithClusterId 计算所有低于某个版本的节点数量
|
// CountAllLowerVersionNodesWithClusterId 计算单个集群中所有低于某个版本的节点数量
|
||||||
func (this *NodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (int64, error) {
|
func (this *NodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
@@ -707,7 +707,7 @@ func (this *NodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterI
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindAllLowerVersionNodesWithClusterId 查找所有低于某个版本的节点
|
// FindAllLowerVersionNodesWithClusterId 查找单个集群中所有低于某个版本的节点
|
||||||
func (this *NodeDAO) FindAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (result []*Node, err error) {
|
func (this *NodeDAO) FindAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (result []*Node, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
@@ -725,6 +725,17 @@ func (this *NodeDAO) FindAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有集群中低于某个版本的节点数量
|
||||||
|
func (this *NodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(NodeStateEnabled).
|
||||||
|
Where("clusterId IN (SELECT id FROM "+SharedNodeClusterDAO.Table+" WHERE state=1)").
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
// CountAllEnabledNodesWithGroupId 查找某个节点分组下的所有节点数量
|
// CountAllEnabledNodesWithGroupId 查找某个节点分组下的所有节点数量
|
||||||
func (this *NodeDAO) CountAllEnabledNodesWithGroupId(tx *dbs.Tx, groupId int64) (int64, error) {
|
func (this *NodeDAO) CountAllEnabledNodesWithGroupId(tx *dbs.Tx, groupId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
|
|||||||
@@ -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/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"
|
||||||
@@ -38,7 +39,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableUserNode 启用条目
|
||||||
func (this *UserNodeDAO) EnableUserNode(tx *dbs.Tx, id uint32) error {
|
func (this *UserNodeDAO) EnableUserNode(tx *dbs.Tx, id uint32) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -47,7 +48,7 @@ func (this *UserNodeDAO) EnableUserNode(tx *dbs.Tx, id uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableUserNode 禁用条目
|
||||||
func (this *UserNodeDAO) DisableUserNode(tx *dbs.Tx, id int64) error {
|
func (this *UserNodeDAO) DisableUserNode(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -56,7 +57,7 @@ func (this *UserNodeDAO) DisableUserNode(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledUserNode 查找启用中的条目
|
||||||
func (this *UserNodeDAO) FindEnabledUserNode(tx *dbs.Tx, id int64) (*UserNode, error) {
|
func (this *UserNodeDAO) FindEnabledUserNode(tx *dbs.Tx, id int64) (*UserNode, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -68,7 +69,7 @@ func (this *UserNodeDAO) FindEnabledUserNode(tx *dbs.Tx, id int64) (*UserNode, e
|
|||||||
return result.(*UserNode), err
|
return result.(*UserNode), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindUserNodeName 根据主键查找名称
|
||||||
func (this *UserNodeDAO) FindUserNodeName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *UserNodeDAO) FindUserNodeName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -76,7 +77,7 @@ func (this *UserNodeDAO) FindUserNodeName(tx *dbs.Tx, id int64) (string, error)
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有可用用户节点
|
// FindAllEnabledUserNodes 列出所有可用用户节点
|
||||||
func (this *UserNodeDAO) FindAllEnabledUserNodes(tx *dbs.Tx) (result []*UserNode, err error) {
|
func (this *UserNodeDAO) FindAllEnabledUserNodes(tx *dbs.Tx) (result []*UserNode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(UserNodeStateEnabled).
|
State(UserNodeStateEnabled).
|
||||||
@@ -87,14 +88,14 @@ func (this *UserNodeDAO) FindAllEnabledUserNodes(tx *dbs.Tx) (result []*UserNode
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算用户节点数量
|
// CountAllEnabledUserNodes 计算用户节点数量
|
||||||
func (this *UserNodeDAO) CountAllEnabledUserNodes(tx *dbs.Tx) (int64, error) {
|
func (this *UserNodeDAO) CountAllEnabledUserNodes(tx *dbs.Tx) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(UserNodeStateEnabled).
|
State(UserNodeStateEnabled).
|
||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的用户节点
|
// ListEnabledUserNodes 列出单页的用户节点
|
||||||
func (this *UserNodeDAO) ListEnabledUserNodes(tx *dbs.Tx, offset int64, size int64) (result []*UserNode, err error) {
|
func (this *UserNodeDAO) ListEnabledUserNodes(tx *dbs.Tx, offset int64, size int64) (result []*UserNode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(UserNodeStateEnabled).
|
State(UserNodeStateEnabled).
|
||||||
@@ -107,7 +108,7 @@ func (this *UserNodeDAO) ListEnabledUserNodes(tx *dbs.Tx, offset int64, size int
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主机名和端口获取ID
|
// FindEnabledUserNodeIdWithAddr 根据主机名和端口获取ID
|
||||||
func (this *UserNodeDAO) FindEnabledUserNodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
func (this *UserNodeDAO) FindEnabledUserNodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
||||||
addr := maps.Map{
|
addr := maps.Map{
|
||||||
"protocol": protocol,
|
"protocol": protocol,
|
||||||
@@ -134,7 +135,7 @@ func (this *UserNodeDAO) FindEnabledUserNodeIdWithAddr(tx *dbs.Tx, protocol stri
|
|||||||
return int64(one.(*UserNode).Id), nil
|
return int64(one.(*UserNode).Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建用户节点
|
// CreateUserNode 创建用户节点
|
||||||
func (this *UserNodeDAO) CreateUserNode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
func (this *UserNodeDAO) CreateUserNode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
||||||
uniqueId, err := this.GenUniqueId(tx)
|
uniqueId, err := this.GenUniqueId(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -172,7 +173,7 @@ func (this *UserNodeDAO) CreateUserNode(tx *dbs.Tx, name string, description str
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改用户节点
|
// UpdateUserNode 修改用户节点
|
||||||
func (this *UserNodeDAO) UpdateUserNode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
func (this *UserNodeDAO) UpdateUserNode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
||||||
if nodeId <= 0 {
|
if nodeId <= 0 {
|
||||||
return errors.New("invalid nodeId")
|
return errors.New("invalid nodeId")
|
||||||
@@ -204,7 +205,7 @@ func (this *UserNodeDAO) UpdateUserNode(tx *dbs.Tx, nodeId int64, name string, d
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据唯一ID获取节点信息
|
// FindEnabledUserNodeWithUniqueId 根据唯一ID获取节点信息
|
||||||
func (this *UserNodeDAO) FindEnabledUserNodeWithUniqueId(tx *dbs.Tx, uniqueId string) (*UserNode, error) {
|
func (this *UserNodeDAO) FindEnabledUserNodeWithUniqueId(tx *dbs.Tx, uniqueId string) (*UserNode, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Attr("uniqueId", uniqueId).
|
Attr("uniqueId", uniqueId).
|
||||||
@@ -216,7 +217,7 @@ func (this *UserNodeDAO) FindEnabledUserNodeWithUniqueId(tx *dbs.Tx, uniqueId st
|
|||||||
return result.(*UserNode), err
|
return result.(*UserNode), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据唯一ID获取节点ID
|
// FindEnabledUserNodeIdWithUniqueId 根据唯一ID获取节点ID
|
||||||
func (this *UserNodeDAO) FindEnabledUserNodeIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
func (this *UserNodeDAO) FindEnabledUserNodeIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Attr("uniqueId", uniqueId).
|
Attr("uniqueId", uniqueId).
|
||||||
@@ -225,7 +226,7 @@ func (this *UserNodeDAO) FindEnabledUserNodeIdWithUniqueId(tx *dbs.Tx, uniqueId
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成唯一ID
|
// GenUniqueId 生成唯一ID
|
||||||
func (this *UserNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
func (this *UserNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
||||||
for {
|
for {
|
||||||
uniqueId := rands.HexString(32)
|
uniqueId := rands.HexString(32)
|
||||||
@@ -242,7 +243,7 @@ func (this *UserNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改节点状态
|
// UpdateNodeStatus 更改节点状态
|
||||||
func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
|
func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
|
||||||
if len(statusJSON) == 0 {
|
if len(statusJSON) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@@ -253,3 +254,13 @@ func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON [
|
|||||||
Update()
|
Update()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *UserNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(UserNodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models/authority"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||||
@@ -14,13 +16,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AdminService 管理员相关服务
|
||||||
type AdminService struct {
|
type AdminService struct {
|
||||||
BaseService
|
BaseService
|
||||||
|
|
||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// 登录
|
// LoginAdmin 登录
|
||||||
func (this *AdminService) LoginAdmin(ctx context.Context, req *pb.LoginAdminRequest) (*pb.LoginAdminResponse, error) {
|
func (this *AdminService) LoginAdmin(ctx context.Context, req *pb.LoginAdminRequest) (*pb.LoginAdminResponse, error) {
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx)
|
_, _, err := rpcutils.ValidateRequest(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -57,7 +60,7 @@ func (this *AdminService) LoginAdmin(ctx context.Context, req *pb.LoginAdminRequ
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查管理员是否存在
|
// CheckAdminExists 检查管理员是否存在
|
||||||
func (this *AdminService) CheckAdminExists(ctx context.Context, req *pb.CheckAdminExistsRequest) (*pb.CheckAdminExistsResponse, error) {
|
func (this *AdminService) CheckAdminExists(ctx context.Context, req *pb.CheckAdminExistsRequest) (*pb.CheckAdminExistsResponse, error) {
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,7 +85,7 @@ func (this *AdminService) CheckAdminExists(ctx context.Context, req *pb.CheckAdm
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户名是否存在
|
// CheckAdminUsername 检查用户名是否存在
|
||||||
func (this *AdminService) CheckAdminUsername(ctx context.Context, req *pb.CheckAdminUsernameRequest) (*pb.CheckAdminUsernameResponse, error) {
|
func (this *AdminService) CheckAdminUsername(ctx context.Context, req *pb.CheckAdminUsernameRequest) (*pb.CheckAdminUsernameResponse, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
@@ -100,7 +103,7 @@ func (this *AdminService) CheckAdminUsername(ctx context.Context, req *pb.CheckA
|
|||||||
return &pb.CheckAdminUsernameResponse{Exists: exists}, nil
|
return &pb.CheckAdminUsernameResponse{Exists: exists}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取管理员名称
|
// FindAdminFullname 获取管理员名称
|
||||||
func (this *AdminService) FindAdminFullname(ctx context.Context, req *pb.FindAdminFullnameRequest) (*pb.FindAdminFullnameResponse, error) {
|
func (this *AdminService) FindAdminFullname(ctx context.Context, req *pb.FindAdminFullnameRequest) (*pb.FindAdminFullnameResponse, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
@@ -121,7 +124,7 @@ func (this *AdminService) FindAdminFullname(ctx context.Context, req *pb.FindAdm
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取管理员信息
|
// FindEnabledAdmin 获取管理员信息
|
||||||
func (this *AdminService) FindEnabledAdmin(ctx context.Context, req *pb.FindEnabledAdminRequest) (*pb.FindEnabledAdminResponse, error) {
|
func (this *AdminService) FindEnabledAdmin(ctx context.Context, req *pb.FindEnabledAdminRequest) (*pb.FindEnabledAdminResponse, error) {
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -186,7 +189,7 @@ func (this *AdminService) FindEnabledAdmin(ctx context.Context, req *pb.FindEnab
|
|||||||
return &pb.FindEnabledAdminResponse{Admin: result}, nil
|
return &pb.FindEnabledAdminResponse{Admin: result}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建或修改管理员
|
// CreateOrUpdateAdmin 创建或修改管理员
|
||||||
func (this *AdminService) CreateOrUpdateAdmin(ctx context.Context, req *pb.CreateOrUpdateAdminRequest) (*pb.CreateOrUpdateAdminResponse, error) {
|
func (this *AdminService) CreateOrUpdateAdmin(ctx context.Context, req *pb.CreateOrUpdateAdminRequest) (*pb.CreateOrUpdateAdminResponse, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeAPI)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeAPI)
|
||||||
@@ -214,7 +217,7 @@ func (this *AdminService) CreateOrUpdateAdmin(ctx context.Context, req *pb.Creat
|
|||||||
return &pb.CreateOrUpdateAdminResponse{AdminId: adminId}, nil
|
return &pb.CreateOrUpdateAdminResponse{AdminId: adminId}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改管理员信息
|
// UpdateAdminInfo 修改管理员信息
|
||||||
func (this *AdminService) UpdateAdminInfo(ctx context.Context, req *pb.UpdateAdminInfoRequest) (*pb.RPCSuccess, error) {
|
func (this *AdminService) UpdateAdminInfo(ctx context.Context, req *pb.UpdateAdminInfoRequest) (*pb.RPCSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeAPI)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeAPI)
|
||||||
@@ -231,7 +234,7 @@ func (this *AdminService) UpdateAdminInfo(ctx context.Context, req *pb.UpdateAdm
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改管理员登录信息
|
// UpdateAdminLogin 修改管理员登录信息
|
||||||
func (this *AdminService) UpdateAdminLogin(ctx context.Context, req *pb.UpdateAdminLoginRequest) (*pb.RPCSuccess, error) {
|
func (this *AdminService) UpdateAdminLogin(ctx context.Context, req *pb.UpdateAdminLoginRequest) (*pb.RPCSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeAPI)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeAPI)
|
||||||
@@ -256,7 +259,7 @@ func (this *AdminService) UpdateAdminLogin(ctx context.Context, req *pb.UpdateAd
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有管理员的权限列表
|
// FindAllAdminModules 获取所有管理员的权限列表
|
||||||
func (this *AdminService) FindAllAdminModules(ctx context.Context, req *pb.FindAllAdminModulesRequest) (*pb.FindAllAdminModulesResponse, error) {
|
func (this *AdminService) FindAllAdminModules(ctx context.Context, req *pb.FindAllAdminModulesRequest) (*pb.FindAllAdminModulesResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -302,7 +305,7 @@ func (this *AdminService) FindAllAdminModules(ctx context.Context, req *pb.FindA
|
|||||||
return &pb.FindAllAdminModulesResponse{AdminModules: result}, nil
|
return &pb.FindAllAdminModulesResponse{AdminModules: result}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建管理员
|
// CreateAdmin 创建管理员
|
||||||
func (this *AdminService) CreateAdmin(ctx context.Context, req *pb.CreateAdminRequest) (*pb.CreateAdminResponse, error) {
|
func (this *AdminService) CreateAdmin(ctx context.Context, req *pb.CreateAdminRequest) (*pb.CreateAdminResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -321,7 +324,7 @@ func (this *AdminService) CreateAdmin(ctx context.Context, req *pb.CreateAdminRe
|
|||||||
return &pb.CreateAdminResponse{AdminId: adminId}, nil
|
return &pb.CreateAdminResponse{AdminId: adminId}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改管理员
|
// UpdateAdmin 修改管理员
|
||||||
func (this *AdminService) UpdateAdmin(ctx context.Context, req *pb.UpdateAdminRequest) (*pb.RPCSuccess, error) {
|
func (this *AdminService) UpdateAdmin(ctx context.Context, req *pb.UpdateAdminRequest) (*pb.RPCSuccess, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -340,7 +343,7 @@ func (this *AdminService) UpdateAdmin(ctx context.Context, req *pb.UpdateAdminRe
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算管理员数量
|
// CountAllEnabledAdmins 计算管理员数量
|
||||||
func (this *AdminService) CountAllEnabledAdmins(ctx context.Context, req *pb.CountAllEnabledAdminsRequest) (*pb.RPCCountResponse, error) {
|
func (this *AdminService) CountAllEnabledAdmins(ctx context.Context, req *pb.CountAllEnabledAdminsRequest) (*pb.RPCCountResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -358,7 +361,7 @@ func (this *AdminService) CountAllEnabledAdmins(ctx context.Context, req *pb.Cou
|
|||||||
return this.SuccessCount(count)
|
return this.SuccessCount(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的管理员
|
// ListEnabledAdmins 列出单页的管理员
|
||||||
func (this *AdminService) ListEnabledAdmins(ctx context.Context, req *pb.ListEnabledAdminsRequest) (*pb.ListEnabledAdminsResponse, error) {
|
func (this *AdminService) ListEnabledAdmins(ctx context.Context, req *pb.ListEnabledAdminsRequest) (*pb.ListEnabledAdminsResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -407,7 +410,7 @@ func (this *AdminService) ListEnabledAdmins(ctx context.Context, req *pb.ListEna
|
|||||||
return &pb.ListEnabledAdminsResponse{Admins: result}, nil
|
return &pb.ListEnabledAdminsResponse{Admins: result}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除管理员
|
// DeleteAdmin 删除管理员
|
||||||
func (this *AdminService) DeleteAdmin(ctx context.Context, req *pb.DeleteAdminRequest) (*pb.RPCSuccess, error) {
|
func (this *AdminService) DeleteAdmin(ctx context.Context, req *pb.DeleteAdminRequest) (*pb.RPCSuccess, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -428,7 +431,7 @@ func (this *AdminService) DeleteAdmin(ctx context.Context, req *pb.DeleteAdminRe
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否需要输入OTP
|
// CheckAdminOTPWithUsername 检查是否需要输入OTP
|
||||||
func (this *AdminService) CheckAdminOTPWithUsername(ctx context.Context, req *pb.CheckAdminOTPWithUsernameRequest) (*pb.CheckAdminOTPWithUsernameResponse, error) {
|
func (this *AdminService) CheckAdminOTPWithUsername(ctx context.Context, req *pb.CheckAdminOTPWithUsernameRequest) (*pb.CheckAdminOTPWithUsernameResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -456,7 +459,7 @@ func (this *AdminService) CheckAdminOTPWithUsername(ctx context.Context, req *pb
|
|||||||
return &pb.CheckAdminOTPWithUsernameResponse{RequireOTP: otpIsOn}, nil
|
return &pb.CheckAdminOTPWithUsernameResponse{RequireOTP: otpIsOn}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 取得管理员Dashboard数据
|
// ComposeAdminDashboard 取得管理员Dashboard数据
|
||||||
func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.ComposeAdminDashboardRequest) (*pb.ComposeAdminDashboardResponse, error) {
|
func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.ComposeAdminDashboardRequest) (*pb.ComposeAdminDashboardResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx, 0)
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -543,5 +546,70 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 边缘节点升级信息
|
||||||
|
{
|
||||||
|
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||||
|
NewVersion: teaconst.NodeVersion,
|
||||||
|
}
|
||||||
|
countNodes, err := models.SharedNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
upgradeInfo.CountNodes = countNodes
|
||||||
|
resp.NodeUpgradeInfo = upgradeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监控节点升级信息
|
||||||
|
{
|
||||||
|
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||||
|
NewVersion: teaconst.MonitorNodeVersion,
|
||||||
|
}
|
||||||
|
countNodes, err := models.SharedMonitorNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
upgradeInfo.CountNodes = countNodes
|
||||||
|
resp.MonitorNodeUpgradeInfo = upgradeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// 认证节点升级信息
|
||||||
|
{
|
||||||
|
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||||
|
NewVersion: teaconst.AuthorityNodeVersion,
|
||||||
|
}
|
||||||
|
countNodes, err := authority.SharedAuthorityNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
upgradeInfo.CountNodes = countNodes
|
||||||
|
resp.AuthorityNodeUpgradeInfo = upgradeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户节点升级信息
|
||||||
|
{
|
||||||
|
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||||
|
NewVersion: teaconst.UserNodeVersion,
|
||||||
|
}
|
||||||
|
countNodes, err := models.SharedUserNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
upgradeInfo.CountNodes = countNodes
|
||||||
|
resp.UserNodeUpgradeInfo = upgradeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// API节点升级信息
|
||||||
|
{
|
||||||
|
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||||
|
NewVersion: teaconst.Version,
|
||||||
|
}
|
||||||
|
countNodes, err := models.SharedAPINodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
upgradeInfo.CountNodes = countNodes
|
||||||
|
resp.ApiNodeUpgradeInfo = upgradeInfo
|
||||||
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user