feat: sync httpdns sdk/platform updates without large binaries
This commit is contained in:
@@ -1,16 +1,108 @@
|
||||
package clusters
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpgradeRemoteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpgradeRemoteAction) Init() {
|
||||
this.Nav("httpdns", "cluster", "index")
|
||||
}
|
||||
|
||||
func (this *UpgradeRemoteAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
ClusterId int64
|
||||
}) {
|
||||
this.Data["nodeId"] = params.NodeId
|
||||
httpdnsutils.AddLeftMenu(this.Parent())
|
||||
|
||||
cluster, err := findClusterMap(this.Parent(), params.ClusterId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
httpdnsutils.AddClusterTabbar(this.Parent(), cluster.GetString("name"), params.ClusterId, "node")
|
||||
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["cluster"] = cluster
|
||||
|
||||
resp, err := this.RPC().HTTPDNSNodeRPC().FindAllUpgradeHTTPDNSNodesWithClusterId(this.AdminContext(), &pb.FindAllUpgradeHTTPDNSNodesWithClusterIdRequest{
|
||||
ClusterId: params.ClusterId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
nodes := make([]maps.Map, 0, len(resp.GetNodes()))
|
||||
for _, upgradeNode := range resp.GetNodes() {
|
||||
node := upgradeNode.Node
|
||||
if node == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
loginParams := maps.Map{}
|
||||
if node.GetNodeLogin() != nil && len(node.GetNodeLogin().GetParams()) > 0 {
|
||||
_ = json.Unmarshal(node.GetNodeLogin().GetParams(), &loginParams)
|
||||
}
|
||||
|
||||
status := decodeNodeStatus(node.GetStatusJSON())
|
||||
accessIP := strings.TrimSpace(status.GetString("hostIP"))
|
||||
if len(accessIP) == 0 {
|
||||
accessIP = strings.TrimSpace(node.GetName())
|
||||
}
|
||||
|
||||
nodes = append(nodes, maps.Map{
|
||||
"id": node.GetId(),
|
||||
"name": node.GetName(),
|
||||
"accessIP": accessIP,
|
||||
"oldVersion": upgradeNode.OldVersion,
|
||||
"newVersion": upgradeNode.NewVersion,
|
||||
"login": node.GetNodeLogin(),
|
||||
"loginParams": loginParams,
|
||||
"installStatus": decodeUpgradeInstallStatus(node.GetInstallStatusJSON()),
|
||||
})
|
||||
}
|
||||
this.Data["nodes"] = nodes
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpgradeRemoteAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
_, err := this.RPC().HTTPDNSNodeRPC().UpgradeHTTPDNSNode(this.AdminContext(), &pb.UpgradeHTTPDNSNodeRequest{
|
||||
NodeId: params.NodeId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
|
||||
func decodeUpgradeInstallStatus(raw []byte) maps.Map {
|
||||
result := maps.Map{
|
||||
"isRunning": false,
|
||||
"isFinished": false,
|
||||
"isOk": false,
|
||||
"error": "",
|
||||
"errorCode": "",
|
||||
}
|
||||
if len(raw) == 0 {
|
||||
return result
|
||||
}
|
||||
|
||||
_ = json.Unmarshal(raw, &result)
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user