feat: sync httpdns sdk/platform updates without large binaries
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type StatusAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *StatusAction) RunPost(params struct {
|
||||
NodeIdsJSON []byte // JSON: {"node": [1,2], "dns": [3], "httpdns": [4,5]}
|
||||
}) {
|
||||
var nodeIdsMap map[string][]int64
|
||||
if len(params.NodeIdsJSON) > 0 {
|
||||
_ = json.Unmarshal(params.NodeIdsJSON, &nodeIdsMap)
|
||||
}
|
||||
|
||||
result := maps.Map{}
|
||||
|
||||
// EdgeNode 状态
|
||||
if nodeIds, ok := nodeIdsMap["node"]; ok && len(nodeIds) > 0 {
|
||||
var nodeStatuses []maps.Map
|
||||
for _, nodeId := range nodeIds {
|
||||
resp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: nodeId})
|
||||
if err != nil || resp.Node == nil {
|
||||
continue
|
||||
}
|
||||
var installStatusMap maps.Map
|
||||
if resp.Node.InstallStatus != nil {
|
||||
installStatusMap = maps.Map{
|
||||
"isRunning": resp.Node.InstallStatus.IsRunning,
|
||||
"isFinished": resp.Node.InstallStatus.IsFinished,
|
||||
"isOk": resp.Node.InstallStatus.IsOk,
|
||||
"error": resp.Node.InstallStatus.Error,
|
||||
"errorCode": resp.Node.InstallStatus.ErrorCode,
|
||||
"updatedAt": resp.Node.InstallStatus.UpdatedAt,
|
||||
}
|
||||
}
|
||||
nodeStatuses = append(nodeStatuses, maps.Map{
|
||||
"id": nodeId,
|
||||
"installStatus": installStatusMap,
|
||||
})
|
||||
}
|
||||
result["node"] = nodeStatuses
|
||||
}
|
||||
|
||||
// DNS 状态
|
||||
if nodeIds, ok := nodeIdsMap["dns"]; ok && len(nodeIds) > 0 {
|
||||
result["dns"] = loadDNSNodeStatus(&this.ParentAction, nodeIds)
|
||||
}
|
||||
|
||||
// HTTPDNS 状态
|
||||
if nodeIds, ok := nodeIdsMap["httpdns"]; ok && len(nodeIds) > 0 {
|
||||
var nodeStatuses []maps.Map
|
||||
for _, nodeId := range nodeIds {
|
||||
resp, err := this.RPC().HTTPDNSNodeRPC().FindHTTPDNSNode(this.AdminContext(), &pb.FindHTTPDNSNodeRequest{NodeId: nodeId})
|
||||
if err != nil || resp.Node == nil {
|
||||
continue
|
||||
}
|
||||
var installStatusMap maps.Map
|
||||
if len(resp.Node.InstallStatusJSON) > 0 {
|
||||
installStatusMap = maps.Map{}
|
||||
_ = json.Unmarshal(resp.Node.InstallStatusJSON, &installStatusMap)
|
||||
}
|
||||
nodeStatuses = append(nodeStatuses, maps.Map{
|
||||
"id": nodeId,
|
||||
"installStatus": installStatusMap,
|
||||
})
|
||||
}
|
||||
result["httpdns"] = nodeStatuses
|
||||
}
|
||||
|
||||
this.Data["statuses"] = result
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user