mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			64 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package cache
 | 
						|
 | 
						|
import (	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
						|
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
 | 
						|
	"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
 | 
						|
	"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
 | 
						|
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						|
	"net/http"
 | 
						|
	"strconv"
 | 
						|
)
 | 
						|
 | 
						|
type TestReadAction struct {
 | 
						|
	actionutils.ParentAction
 | 
						|
}
 | 
						|
 | 
						|
func (this *TestReadAction) RunPost(params struct {
 | 
						|
	ClusterId     int64
 | 
						|
	CachePolicyId int64
 | 
						|
	Key           string
 | 
						|
}) {
 | 
						|
	// 记录clusterId
 | 
						|
	this.AddCookie(&http.Cookie{
 | 
						|
		Name:  "cache_cluster_id",
 | 
						|
		Value: strconv.FormatInt(params.ClusterId, 10),
 | 
						|
	})
 | 
						|
 | 
						|
	cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: params.CachePolicyId})
 | 
						|
	if err != nil {
 | 
						|
		this.ErrorPage(err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
	cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON
 | 
						|
	if len(cachePolicyJSON) == 0 {
 | 
						|
		this.Fail("找不到要操作的缓存策略")
 | 
						|
	}
 | 
						|
 | 
						|
	// 发送命令
 | 
						|
	msg := &messageconfigs.ReadCacheMessage{
 | 
						|
		CachePolicyJSON: cachePolicyJSON,
 | 
						|
		Key:             params.Key,
 | 
						|
	}
 | 
						|
	results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodeReadCache, msg, 10)
 | 
						|
	if err != nil {
 | 
						|
		this.ErrorPage(err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	isAllOk := true
 | 
						|
	for _, result := range results {
 | 
						|
		if !result.IsOK {
 | 
						|
			isAllOk = false
 | 
						|
			break
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	this.Data["isAllOk"] = isAllOk
 | 
						|
	this.Data["results"] = results
 | 
						|
 | 
						|
	// 创建日志
 | 
						|
	defer this.CreateLogInfo(codes.ServerCachePolicy_LogTestReading, params.CachePolicyId)
 | 
						|
 | 
						|
	this.Success()
 | 
						|
}
 |