mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	实现缓存策略若干功能
This commit is contained in:
		@@ -1,6 +1,16 @@
 | 
			
		||||
package cache
 | 
			
		||||
 | 
			
		||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strconv"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type CleanAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
@@ -11,5 +21,72 @@ func (this *CleanAction) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CleanAction) RunGet(params struct{}) {
 | 
			
		||||
	// 默认的集群ID
 | 
			
		||||
	cookie, err := this.Request.Cookie("cache_cluster_id")
 | 
			
		||||
	if cookie != nil && err == nil {
 | 
			
		||||
		this.Data["clusterId"] = types.Int64(cookie.Value)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 集群列表
 | 
			
		||||
	clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	clusterMaps := []maps.Map{}
 | 
			
		||||
	for _, cluster := range clustersResp.Clusters {
 | 
			
		||||
		clusterMaps = append(clusterMaps, maps.Map{
 | 
			
		||||
			"id":   cluster.Id,
 | 
			
		||||
			"name": cluster.Name,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["clusters"] = clusterMaps
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CleanAction) RunPost(params struct {
 | 
			
		||||
	CachePolicyId int64
 | 
			
		||||
	ClusterId     int64
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	// 记录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{CachePolicyId: params.CachePolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	cachePolicyJSON := cachePolicyResp.CachePolicyJSON
 | 
			
		||||
	if len(cachePolicyJSON) == 0 {
 | 
			
		||||
		this.Fail("找不到要操作的缓存策略")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 发送命令
 | 
			
		||||
	msg := &messageconfigs.CleanCacheMessage{
 | 
			
		||||
		CachePolicyJSON: cachePolicyJSON,
 | 
			
		||||
	}
 | 
			
		||||
	results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodeCleanCache, 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
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,18 @@
 | 
			
		||||
package cache
 | 
			
		||||
 | 
			
		||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/lists"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type PreheatAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
@@ -11,5 +23,90 @@ func (this *PreheatAction) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *PreheatAction) RunGet(params struct{}) {
 | 
			
		||||
	// 默认的集群ID
 | 
			
		||||
	cookie, err := this.Request.Cookie("cache_cluster_id")
 | 
			
		||||
	if cookie != nil && err == nil {
 | 
			
		||||
		this.Data["clusterId"] = types.Int64(cookie.Value)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 集群列表
 | 
			
		||||
	clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	clusterMaps := []maps.Map{}
 | 
			
		||||
	for _, cluster := range clustersResp.Clusters {
 | 
			
		||||
		clusterMaps = append(clusterMaps, maps.Map{
 | 
			
		||||
			"id":   cluster.Id,
 | 
			
		||||
			"name": cluster.Name,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["clusters"] = clusterMaps
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *PreheatAction) RunPost(params struct {
 | 
			
		||||
	CachePolicyId int64
 | 
			
		||||
	ClusterId     int64
 | 
			
		||||
	Keys          string
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	// 记录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{CachePolicyId: params.CachePolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	cachePolicyJSON := cachePolicyResp.CachePolicyJSON
 | 
			
		||||
	if len(cachePolicyJSON) == 0 {
 | 
			
		||||
		this.Fail("找不到要操作的缓存策略")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(params.Keys) == 0 {
 | 
			
		||||
		this.Fail("请输入要预热的Key列表")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	realKeys := []string{}
 | 
			
		||||
	for _, key := range strings.Split(params.Keys, "\n") {
 | 
			
		||||
		key = strings.TrimSpace(key)
 | 
			
		||||
		if len(key) == 0 {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if lists.ContainsString(realKeys, key) {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		realKeys = append(realKeys, key)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 发送命令
 | 
			
		||||
	msg := &messageconfigs.PreheatCacheMessage{
 | 
			
		||||
		CachePolicyJSON: cachePolicyJSON,
 | 
			
		||||
		Keys:            realKeys,
 | 
			
		||||
	}
 | 
			
		||||
	results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodePreheatCache, msg, 300)
 | 
			
		||||
	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
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,18 @@
 | 
			
		||||
package cache
 | 
			
		||||
 | 
			
		||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/lists"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	strings "strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type PurgeAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
@@ -11,5 +23,89 @@ func (this *PurgeAction) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *PurgeAction) RunGet(params struct{}) {
 | 
			
		||||
	// 默认的集群ID
 | 
			
		||||
	cookie, err := this.Request.Cookie("cache_cluster_id")
 | 
			
		||||
	if cookie != nil && err == nil {
 | 
			
		||||
		this.Data["clusterId"] = types.Int64(cookie.Value)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 集群列表
 | 
			
		||||
	clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	clusterMaps := []maps.Map{}
 | 
			
		||||
	for _, cluster := range clustersResp.Clusters {
 | 
			
		||||
		clusterMaps = append(clusterMaps, maps.Map{
 | 
			
		||||
			"id":   cluster.Id,
 | 
			
		||||
			"name": cluster.Name,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["clusters"] = clusterMaps
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *PurgeAction) RunPost(params struct {
 | 
			
		||||
	CachePolicyId int64
 | 
			
		||||
	ClusterId     int64
 | 
			
		||||
	Keys          string
 | 
			
		||||
	Must          *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	// 记录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{CachePolicyId: params.CachePolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	cachePolicyJSON := cachePolicyResp.CachePolicyJSON
 | 
			
		||||
	if len(cachePolicyJSON) == 0 {
 | 
			
		||||
		this.Fail("找不到要操作的缓存策略")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(params.Keys) == 0 {
 | 
			
		||||
		this.Fail("请输入要删除的Key列表")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	realKeys := []string{}
 | 
			
		||||
	for _, key := range strings.Split(params.Keys, "\n") {
 | 
			
		||||
		key = strings.TrimSpace(key)
 | 
			
		||||
		if len(key) == 0 {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if lists.ContainsString(realKeys, key) {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		realKeys = append(realKeys, key)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 发送命令
 | 
			
		||||
	msg := &messageconfigs.PurgeCacheMessage{
 | 
			
		||||
		CachePolicyJSON: cachePolicyJSON,
 | 
			
		||||
		Keys:            realKeys,
 | 
			
		||||
	}
 | 
			
		||||
	results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodePurgeCache, 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
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,16 @@
 | 
			
		||||
package cache
 | 
			
		||||
 | 
			
		||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strconv"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type StatAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
@@ -11,5 +21,72 @@ func (this *StatAction) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *StatAction) RunGet(params struct{}) {
 | 
			
		||||
	// 默认的集群ID
 | 
			
		||||
	cookie, err := this.Request.Cookie("cache_cluster_id")
 | 
			
		||||
	if cookie != nil && err == nil {
 | 
			
		||||
		this.Data["clusterId"] = types.Int64(cookie.Value)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 集群列表
 | 
			
		||||
	clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	clusterMaps := []maps.Map{}
 | 
			
		||||
	for _, cluster := range clustersResp.Clusters {
 | 
			
		||||
		clusterMaps = append(clusterMaps, maps.Map{
 | 
			
		||||
			"id":   cluster.Id,
 | 
			
		||||
			"name": cluster.Name,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["clusters"] = clusterMaps
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *StatAction) RunPost(params struct {
 | 
			
		||||
	CachePolicyId int64
 | 
			
		||||
	ClusterId     int64
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	// 记录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{CachePolicyId: params.CachePolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	cachePolicyJSON := cachePolicyResp.CachePolicyJSON
 | 
			
		||||
	if len(cachePolicyJSON) == 0 {
 | 
			
		||||
		this.Fail("找不到要操作的缓存策略")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 发送命令
 | 
			
		||||
	msg := &messageconfigs.StatCacheMessage{
 | 
			
		||||
		CachePolicyJSON: cachePolicyJSON,
 | 
			
		||||
	}
 | 
			
		||||
	results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodeStatCache, 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
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type TestAction struct {
 | 
			
		||||
@@ -15,6 +16,12 @@ func (this *TestAction) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *TestAction) RunGet(params struct{}) {
 | 
			
		||||
	// 默认的集群ID
 | 
			
		||||
	cookie, err := this.Request.Cookie("cache_cluster_id")
 | 
			
		||||
	if cookie != nil && err == nil {
 | 
			
		||||
		this.Data["clusterId"] = types.Int64(cookie.Value)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 集群列表
 | 
			
		||||
	clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,8 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strconv"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type TestReadAction struct {
 | 
			
		||||
@@ -16,6 +18,12 @@ func (this *TestReadAction) RunPost(params struct {
 | 
			
		||||
	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{CachePolicyId: params.CachePolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,8 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"strconv"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type TestWriteAction struct {
 | 
			
		||||
@@ -17,6 +19,12 @@ func (this *TestWriteAction) RunPost(params struct {
 | 
			
		||||
	Key           string
 | 
			
		||||
	Value         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{CachePolicyId: params.CachePolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
 
 | 
			
		||||
@@ -49,9 +49,13 @@ Tea.context(function () {
 | 
			
		||||
				this.globalChangedClusters = [];
 | 
			
		||||
			})
 | 
			
		||||
			.done(function () {
 | 
			
		||||
				let delay = 3000
 | 
			
		||||
				if (this.globalChangedClusters.length > 0) {
 | 
			
		||||
					delay = 30000
 | 
			
		||||
				}
 | 
			
		||||
				this.$delay(function () {
 | 
			
		||||
					this.checkClusterChanges()
 | 
			
		||||
				}, 3000)
 | 
			
		||||
				}, delay)
 | 
			
		||||
			})
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								web/views/@default/servers/components/cache/clean.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								web/views/@default/servers/components/cache/clean.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "/left_menu"}
 | 
			
		||||
 | 
			
		||||
<div class="right-box">
 | 
			
		||||
	{$template "policy_menu"}
 | 
			
		||||
 | 
			
		||||
	<h3>选择集群</h3>
 | 
			
		||||
	<select class="ui dropdown auto-width" v-model="clusterId">
 | 
			
		||||
		<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
 | 
			
		||||
	</select>
 | 
			
		||||
	<div class="ui divider"></div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	<h3>清理</h3>
 | 
			
		||||
	<p class=""><span class="red">严重注意:该操作将清理集群所有节点上的所有对应缓存。</span></p>
 | 
			
		||||
	<form data-tea-action="$" data-tea-before="before" data-tea-success="success" data-tea-fail="fail" data-tea-done="done">
 | 
			
		||||
		<input type="hidden" name="cachePolicyId" :value="cachePolicyId"/>
 | 
			
		||||
		<input type="hidden" name="clusterId" :value="clusterId"/>
 | 
			
		||||
		<table class="ui table definition selectable">
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td class="title">操作结果</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<div v-if="isRequesting">数据发送中...</div>
 | 
			
		||||
					<span class="red" v-if="!isRequesting && !isOk && message.length > 0">失败:{{message}}</span>
 | 
			
		||||
					<div v-if="!isRequesting && isOk">
 | 
			
		||||
						<span v-if="results.length == 0" class="red">此集群下没有任何可用的节点。</span>
 | 
			
		||||
						<div class="ui label tiny" v-for="one in results" :class="{green:one.isOk, red:!one.isOk}" style="margin-bottom: 0.5em">{{one.nodeName}}:{{one.message}}</div>
 | 
			
		||||
					</div>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
		</table>
 | 
			
		||||
		<submit-btn v-if="!isRequesting">提交</submit-btn>
 | 
			
		||||
	</form>
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										34
									
								
								web/views/@default/servers/components/cache/clean.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								web/views/@default/servers/components/cache/clean.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
	if (this.clusterId == null) {
 | 
			
		||||
		if (this.clusters.length > 0) {
 | 
			
		||||
			this.clusterId = this.clusters[0].id
 | 
			
		||||
		} else {
 | 
			
		||||
			this.clusterId = 0
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.isRequesting = false
 | 
			
		||||
	this.isOk = false
 | 
			
		||||
	this.message = ""
 | 
			
		||||
	this.results = []
 | 
			
		||||
 | 
			
		||||
	this.before = function () {
 | 
			
		||||
		this.isRequesting = true
 | 
			
		||||
		this.isOk = false
 | 
			
		||||
		this.message = ""
 | 
			
		||||
		this.results = []
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.success = function (resp) {
 | 
			
		||||
		this.isOk = true
 | 
			
		||||
		this.results = resp.data.results
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.fail = function (resp) {
 | 
			
		||||
		this.message = resp.message
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.done = function () {
 | 
			
		||||
		this.isRequesting = false
 | 
			
		||||
	}
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										38
									
								
								web/views/@default/servers/components/cache/preheat.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								web/views/@default/servers/components/cache/preheat.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "/left_menu"}
 | 
			
		||||
 | 
			
		||||
<div class="right-box">
 | 
			
		||||
	{$template "policy_menu"}
 | 
			
		||||
 | 
			
		||||
	<h3>选择集群</h3>
 | 
			
		||||
	<select class="ui dropdown auto-width" v-model="clusterId">
 | 
			
		||||
		<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
 | 
			
		||||
	</select>
 | 
			
		||||
	<div class="ui divider"></div>
 | 
			
		||||
 | 
			
		||||
	<form class="ui form" data-tea-action="$" data-tea-before="before" data-tea-success="success" data-tea-fail="fail" data-tea-done="done" data-tea-timeout="3600">
 | 
			
		||||
		<input type="hidden" name="cachePolicyId" :value="cachePolicyId"/>
 | 
			
		||||
		<input type="hidden" name="clusterId" :value="clusterId"/>
 | 
			
		||||
		<table class="ui table definition selectable">
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td>Key列表</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<textarea name="keys" rows="10" ref="focus"></textarea>
 | 
			
		||||
					<p class="comment">每行一个Key。</p>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td class="title">操作结果</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<div v-if="isRequesting">数据发送中...</div>
 | 
			
		||||
					<span class="red" v-if="!isRequesting && !isOk && message.length > 0">失败:{{message}}</span>
 | 
			
		||||
					<div v-if="!isRequesting && isOk">
 | 
			
		||||
						<span v-if="results.length == 0" class="red">此集群下没有任何可用的节点。</span>
 | 
			
		||||
						<div class="ui label tiny" v-for="one in results" :class="{green:one.isOk, red:!one.isOk}" style="margin-bottom: 0.5em">{{one.nodeName}}:{{one.message}}</div>
 | 
			
		||||
					</div>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
		</table>
 | 
			
		||||
		<submit-btn v-if="!isRequesting">提交</submit-btn>
 | 
			
		||||
	</form>
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										34
									
								
								web/views/@default/servers/components/cache/preheat.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								web/views/@default/servers/components/cache/preheat.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
	if (this.clusterId == null) {
 | 
			
		||||
		if (this.clusters.length > 0) {
 | 
			
		||||
			this.clusterId = this.clusters[0].id
 | 
			
		||||
		} else {
 | 
			
		||||
			this.clusterId = 0
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.isRequesting = false
 | 
			
		||||
	this.isOk = false
 | 
			
		||||
	this.message = ""
 | 
			
		||||
	this.results = []
 | 
			
		||||
 | 
			
		||||
	this.before = function () {
 | 
			
		||||
		this.isRequesting = true
 | 
			
		||||
		this.isOk = false
 | 
			
		||||
		this.message = ""
 | 
			
		||||
		this.results = []
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.success = function (resp) {
 | 
			
		||||
		this.isOk = true
 | 
			
		||||
		this.results = resp.data.results
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.fail = function (resp) {
 | 
			
		||||
		this.message = resp.message
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.done = function () {
 | 
			
		||||
		this.isRequesting = false
 | 
			
		||||
	}
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										40
									
								
								web/views/@default/servers/components/cache/purge.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								web/views/@default/servers/components/cache/purge.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "/left_menu"}
 | 
			
		||||
 | 
			
		||||
<div class="right-box">
 | 
			
		||||
	{$template "policy_menu"}
 | 
			
		||||
 | 
			
		||||
	<h3>选择集群</h3>
 | 
			
		||||
	<select class="ui dropdown auto-width" v-model="clusterId">
 | 
			
		||||
		<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
 | 
			
		||||
	</select>
 | 
			
		||||
	<div class="ui divider"></div>
 | 
			
		||||
 | 
			
		||||
	<h3>批量删除</h3>
 | 
			
		||||
	<p class="comment">可以批量删除一组Key。</p>
 | 
			
		||||
	<form class="ui form" data-tea-action="$" data-tea-before="before" data-tea-success="success" data-tea-fail="fail" data-tea-done="done">
 | 
			
		||||
		<input type="hidden" name="cachePolicyId" :value="cachePolicyId"/>
 | 
			
		||||
		<input type="hidden" name="clusterId" :value="clusterId"/>
 | 
			
		||||
		<table class="ui table definition selectable">
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td>Key列表</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<textarea name="keys" rows="10" ref="focus"></textarea>
 | 
			
		||||
					<p class="comment">每行一个Key。</p>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td class="title">操作结果</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<div v-if="isRequesting">数据发送中...</div>
 | 
			
		||||
					<span class="red" v-if="!isRequesting && !isOk && message.length > 0">失败:{{message}}</span>
 | 
			
		||||
					<div v-if="!isRequesting && isOk">
 | 
			
		||||
						<span v-if="results.length == 0" class="red">此集群下没有任何可用的节点。</span>
 | 
			
		||||
						<div class="ui label tiny" v-for="one in results" :class="{green:one.isOk, red:!one.isOk}" style="margin-bottom: 0.5em">{{one.nodeName}}:{{one.message}}</div>
 | 
			
		||||
					</div>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
		</table>
 | 
			
		||||
		<submit-btn v-if="!isRequesting">提交</submit-btn>
 | 
			
		||||
	</form>
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										34
									
								
								web/views/@default/servers/components/cache/purge.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								web/views/@default/servers/components/cache/purge.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
	if (this.clusterId == null) {
 | 
			
		||||
		if (this.clusters.length > 0) {
 | 
			
		||||
			this.clusterId = this.clusters[0].id
 | 
			
		||||
		} else {
 | 
			
		||||
			this.clusterId = 0
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.isRequesting = false
 | 
			
		||||
	this.isOk = false
 | 
			
		||||
	this.message = ""
 | 
			
		||||
	this.results = []
 | 
			
		||||
 | 
			
		||||
	this.before = function () {
 | 
			
		||||
		this.isRequesting = true
 | 
			
		||||
		this.isOk = false
 | 
			
		||||
		this.message = ""
 | 
			
		||||
		this.results = []
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.success = function (resp) {
 | 
			
		||||
		this.isOk = true
 | 
			
		||||
		this.results = resp.data.results
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.fail = function (resp) {
 | 
			
		||||
		this.message = resp.message
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.done = function () {
 | 
			
		||||
		this.isRequesting = false
 | 
			
		||||
	}
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										34
									
								
								web/views/@default/servers/components/cache/stat.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								web/views/@default/servers/components/cache/stat.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "/left_menu"}
 | 
			
		||||
 | 
			
		||||
<div class="right-box">
 | 
			
		||||
	{$template "policy_menu"}
 | 
			
		||||
 | 
			
		||||
	<h3>选择集群</h3>
 | 
			
		||||
	<select class="ui dropdown auto-width" v-model="clusterId">
 | 
			
		||||
		<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
 | 
			
		||||
	</select>
 | 
			
		||||
 | 
			
		||||
	<div class="ui divider"></div>
 | 
			
		||||
 | 
			
		||||
	<h3>统计</h3>
 | 
			
		||||
	<form data-tea-action="$" data-tea-before="before" data-tea-success="success" data-tea-fail="fail" data-tea-done="done">
 | 
			
		||||
		<input type="hidden" name="cachePolicyId" :value="cachePolicyId"/>
 | 
			
		||||
		<input type="hidden" name="clusterId" :value="clusterId"/>
 | 
			
		||||
 | 
			
		||||
		<table class="ui table definition selectable">
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td class="title">操作结果</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<div v-if="isRequesting">数据发送中...</div>
 | 
			
		||||
					<span class="red" v-if="!isRequesting && !isOk && message.length > 0">失败:{{message}}</span>
 | 
			
		||||
					<div v-if="!isRequesting && isOk">
 | 
			
		||||
						<span v-if="results.length == 0" class="red">此集群下没有任何可用的节点。</span>
 | 
			
		||||
						<div class="ui label tiny" v-for="one in results" :class="{green:one.isOk, red:!one.isOk}" style="margin-bottom: 0.5em">{{one.nodeName}}:{{one.message}}</div>
 | 
			
		||||
					</div>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
		</table>
 | 
			
		||||
		<submit-btn v-if="!isRequesting">提交</submit-btn>
 | 
			
		||||
	</form>
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										34
									
								
								web/views/@default/servers/components/cache/stat.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								web/views/@default/servers/components/cache/stat.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
	if (this.clusterId == null) {
 | 
			
		||||
		if (this.clusters.length > 0) {
 | 
			
		||||
			this.clusterId = this.clusters[0].id
 | 
			
		||||
		} else {
 | 
			
		||||
			this.clusterId = 0
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.isRequesting = false
 | 
			
		||||
	this.isOk = false
 | 
			
		||||
	this.message = ""
 | 
			
		||||
	this.results = []
 | 
			
		||||
 | 
			
		||||
	this.before = function () {
 | 
			
		||||
		this.isRequesting = true
 | 
			
		||||
		this.isOk = false
 | 
			
		||||
		this.message = ""
 | 
			
		||||
		this.results = []
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.success = function (resp) {
 | 
			
		||||
		this.isOk = true
 | 
			
		||||
		this.results = resp.data.results
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.fail = function (resp) {
 | 
			
		||||
		this.message = resp.message
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.done = function () {
 | 
			
		||||
		this.isRequesting = false
 | 
			
		||||
	}
 | 
			
		||||
});
 | 
			
		||||
@@ -1,8 +1,10 @@
 | 
			
		||||
Tea.context(function () {
 | 
			
		||||
	if (this.clusters.length > 0) {
 | 
			
		||||
		this.clusterId = this.clusters[0].id
 | 
			
		||||
	} else {
 | 
			
		||||
		this.clusterId = 0
 | 
			
		||||
	if (this.clusterId == null) {
 | 
			
		||||
		if (this.clusters.length > 0) {
 | 
			
		||||
			this.clusterId = this.clusters[0].id
 | 
			
		||||
		} else {
 | 
			
		||||
			this.clusterId = 0
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.isRequestingWrite = false
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user