mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 21:50:28 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			125 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			125 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package node
 | 
						|
 | 
						|
import (
 | 
						|
	"encoding/json"
 | 
						|
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
						|
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
 | 
						|
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						|
	"github.com/iwind/TeaGo/maps"
 | 
						|
)
 | 
						|
 | 
						|
type NodeAction struct {
 | 
						|
	actionutils.ParentAction
 | 
						|
}
 | 
						|
 | 
						|
func (this *NodeAction) Init() {
 | 
						|
	this.Nav("", "node", "node")
 | 
						|
	this.SecondMenu("nodes")
 | 
						|
}
 | 
						|
 | 
						|
func (this *NodeAction) RunGet(params struct {
 | 
						|
	NodeId int64
 | 
						|
}) {
 | 
						|
	this.Data["nodeId"] = params.NodeId
 | 
						|
 | 
						|
	nodeResp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: params.NodeId})
 | 
						|
	if err != nil {
 | 
						|
		this.ErrorPage(err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
	node := nodeResp.Node
 | 
						|
	if node == nil {
 | 
						|
		this.WriteString("找不到要操作的节点")
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	var clusterMap maps.Map = nil
 | 
						|
	if node.Cluster != nil {
 | 
						|
		clusterId := node.Cluster.Id
 | 
						|
		clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: clusterId})
 | 
						|
		if err != nil {
 | 
						|
			this.ErrorPage(err)
 | 
						|
			return
 | 
						|
		}
 | 
						|
		cluster := clusterResp.Cluster
 | 
						|
		if cluster != nil {
 | 
						|
			clusterMap = maps.Map{
 | 
						|
				"id":         cluster.Id,
 | 
						|
				"name":       cluster.Name,
 | 
						|
				"installDir": cluster.InstallDir,
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	// IP地址
 | 
						|
	ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{NodeId: params.NodeId})
 | 
						|
	if err != nil {
 | 
						|
		this.ErrorPage(err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
	ipAddressMaps := []maps.Map{}
 | 
						|
	for _, addr := range ipAddressesResp.Addresses {
 | 
						|
		ipAddressMaps = append(ipAddressMaps, maps.Map{
 | 
						|
			"id":        addr.Id,
 | 
						|
			"name":      addr.Name,
 | 
						|
			"ip":        addr.Ip,
 | 
						|
			"canAccess": addr.CanAccess,
 | 
						|
		})
 | 
						|
	}
 | 
						|
 | 
						|
	// 登录信息
 | 
						|
	var loginMap maps.Map = nil
 | 
						|
	if node.Login != nil {
 | 
						|
		loginParams := maps.Map{}
 | 
						|
		if len(node.Login.Params) > 0 {
 | 
						|
			err = json.Unmarshal(node.Login.Params, &loginParams)
 | 
						|
			if err != nil {
 | 
						|
				this.ErrorPage(err)
 | 
						|
				return
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		grantMap := maps.Map{}
 | 
						|
		grantId := loginParams.GetInt64("grantId")
 | 
						|
		if grantId > 0 {
 | 
						|
			grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: grantId})
 | 
						|
			if err != nil {
 | 
						|
				this.ErrorPage(err)
 | 
						|
				return
 | 
						|
			}
 | 
						|
			if grantResp.Grant != nil {
 | 
						|
				grantMap = maps.Map{
 | 
						|
					"id":         grantResp.Grant.Id,
 | 
						|
					"name":       grantResp.Grant.Name,
 | 
						|
					"method":     grantResp.Grant.Method,
 | 
						|
					"methodName": grantutils.FindGrantMethodName(grantResp.Grant.Method),
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		loginMap = maps.Map{
 | 
						|
			"id":     node.Login.Id,
 | 
						|
			"name":   node.Login.Name,
 | 
						|
			"type":   node.Login.Type,
 | 
						|
			"params": loginParams,
 | 
						|
			"grant":  grantMap,
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	this.Data["node"] = maps.Map{
 | 
						|
		"id":          node.Id,
 | 
						|
		"name":        node.Name,
 | 
						|
		"ipAddresses": ipAddressMaps,
 | 
						|
		"cluster":     clusterMap,
 | 
						|
		"login":       loginMap,
 | 
						|
		"installDir":  node.InstallDir,
 | 
						|
		"isInstalled": node.IsInstalled,
 | 
						|
		"uniqueId":    node.UniqueId,
 | 
						|
		"secret":      node.Secret,
 | 
						|
		"maxCPU":      node.MaxCPU,
 | 
						|
		"isOn":        node.IsOn,
 | 
						|
	}
 | 
						|
 | 
						|
	this.Show()
 | 
						|
}
 |