feat: sync httpdns sdk/platform updates without large binaries
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpgradeNodeAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpgradeNodeAction) RunPost(params struct {
|
||||
Module string // node, dns, httpdns
|
||||
Scope string // all, module, cluster, node
|
||||
ClusterId int64
|
||||
NodeId int64
|
||||
}) {
|
||||
switch params.Scope {
|
||||
case "node":
|
||||
err := this.upgradeSingleNode(params.Module, params.NodeId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
case "cluster":
|
||||
err := this.upgradeCluster(params.Module, params.ClusterId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
case "module":
|
||||
err := this.upgradeModule(params.Module)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
case "all":
|
||||
_ = this.upgradeModule("node")
|
||||
_ = this.upgradeModule("dns")
|
||||
_ = this.upgradeModule("httpdns")
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
func (this *UpgradeNodeAction) upgradeSingleNode(module string, nodeId int64) error {
|
||||
switch module {
|
||||
case "node":
|
||||
_, err := this.RPC().NodeRPC().UpgradeNode(this.AdminContext(), &pb.UpgradeNodeRequest{NodeId: nodeId})
|
||||
return err
|
||||
case "dns":
|
||||
return upgradeDNSNode(&this.ParentAction, nodeId)
|
||||
case "httpdns":
|
||||
_, err := this.RPC().HTTPDNSNodeRPC().UpgradeHTTPDNSNode(this.AdminContext(), &pb.UpgradeHTTPDNSNodeRequest{NodeId: nodeId})
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *UpgradeNodeAction) upgradeCluster(module string, clusterId int64) error {
|
||||
switch module {
|
||||
case "node":
|
||||
resp, err := this.RPC().NodeRPC().FindAllUpgradeNodesWithNodeClusterId(this.AdminContext(), &pb.FindAllUpgradeNodesWithNodeClusterIdRequest{
|
||||
NodeClusterId: clusterId,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, nodeUpgrade := range resp.Nodes {
|
||||
if nodeUpgrade.Node == nil {
|
||||
continue
|
||||
}
|
||||
_, _ = this.RPC().NodeRPC().UpgradeNode(this.AdminContext(), &pb.UpgradeNodeRequest{NodeId: nodeUpgrade.Node.Id})
|
||||
}
|
||||
case "dns":
|
||||
this.upgradeDNSCluster(clusterId)
|
||||
case "httpdns":
|
||||
resp, err := this.RPC().HTTPDNSNodeRPC().FindAllUpgradeHTTPDNSNodesWithClusterId(this.AdminContext(), &pb.FindAllUpgradeHTTPDNSNodesWithClusterIdRequest{
|
||||
ClusterId: clusterId,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, nodeUpgrade := range resp.Nodes {
|
||||
if nodeUpgrade.Node == nil {
|
||||
continue
|
||||
}
|
||||
_, _ = this.RPC().HTTPDNSNodeRPC().UpgradeHTTPDNSNode(this.AdminContext(), &pb.UpgradeHTTPDNSNodeRequest{NodeId: nodeUpgrade.Node.Id})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *UpgradeNodeAction) upgradeModule(module string) error {
|
||||
switch module {
|
||||
case "node":
|
||||
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{
|
||||
Offset: 0,
|
||||
Size: 10000,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, cluster := range clustersResp.NodeClusters {
|
||||
_ = this.upgradeCluster("node", cluster.Id)
|
||||
}
|
||||
case "dns":
|
||||
dnsClusters := loadDNSUpgradeModules(&this.ParentAction)
|
||||
for _, c := range dnsClusters {
|
||||
this.upgradeDNSClusterFromMap(c)
|
||||
}
|
||||
case "httpdns":
|
||||
clustersResp, err := this.RPC().HTTPDNSClusterRPC().ListHTTPDNSClusters(this.AdminContext(), &pb.ListHTTPDNSClustersRequest{
|
||||
Offset: 0,
|
||||
Size: 10000,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, cluster := range clustersResp.Clusters {
|
||||
_ = this.upgradeCluster("httpdns", cluster.Id)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// upgradeDNSCluster 根据集群ID升级DNS节点
|
||||
func (this *UpgradeNodeAction) upgradeDNSCluster(clusterId int64) {
|
||||
dnsClusters := loadDNSUpgradeModules(&this.ParentAction)
|
||||
for _, c := range dnsClusters {
|
||||
if c.GetInt64("id") == clusterId {
|
||||
this.upgradeDNSClusterFromMap(c)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// upgradeDNSClusterFromMap 从maps.Map中提取节点ID并升级
|
||||
func (this *UpgradeNodeAction) upgradeDNSClusterFromMap(c maps.Map) {
|
||||
nodesVal := c.Get("nodes")
|
||||
if nodeMaps, ok := nodesVal.([]maps.Map); ok {
|
||||
for _, n := range nodeMaps {
|
||||
nodeId := n.GetInt64("id")
|
||||
if nodeId > 0 {
|
||||
_ = upgradeDNSNode(&this.ParentAction, nodeId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user