Files
EdgeAdmin/internal/web/actions/default/servers/components/cache/testWrite.go

68 lines
1.7 KiB
Go
Raw Normal View History

2020-10-04 14:27:05 +08:00
package cache
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-10-04 14:27:05 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
2023-06-30 18:08:30 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
2020-10-04 14:27:05 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
2020-10-04 16:09:50 +08:00
"net/http"
"strconv"
2020-10-04 14:27:05 +08:00
)
type TestWriteAction struct {
actionutils.ParentAction
}
func (this *TestWriteAction) RunPost(params struct {
ClusterId int64
CachePolicyId int64
Key string
Value string
}) {
2020-10-04 16:09:50 +08:00
// 记录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})
2020-10-04 14:27:05 +08:00
if err != nil {
this.ErrorPage(err)
return
}
cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON
2020-10-04 14:27:05 +08:00
if len(cachePolicyJSON) == 0 {
this.Fail("找不到要操作的缓存策略")
}
// 发送命令
msg := &messageconfigs.WriteCacheMessage{
CachePolicyJSON: cachePolicyJSON,
Key: params.Key,
Value: []byte(params.Value),
LifeSeconds: 3600,
}
results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodeWriteCache, msg, 10, false)
2020-10-04 14:27:05 +08:00
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
2020-11-10 21:37:48 +08:00
// 创建日志
2023-06-30 18:08:30 +08:00
defer this.CreateLogInfo(codes.ServerCachePolicy_LogTestWriting, params.CachePolicyId)
2020-11-10 21:37:48 +08:00
2020-10-04 14:27:05 +08:00
this.Success()
}