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

75 lines
2.0 KiB
Go
Raw Normal View History

2020-09-13 20:37:07 +08:00
package cache
import (
2020-10-02 17:22:24 +08:00
"encoding/json"
2020-09-13 20:37:07 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-10-02 17:22:24 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
2020-09-13 20:37:07 +08:00
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.FirstMenu("index")
}
2021-06-07 08:43:57 +08:00
func (this *IndexAction) RunGet(params struct {
ClusterId int64
Keyword string
2021-06-07 08:43:57 +08:00
}) {
this.Data["keyword"] = params.Keyword
this.Data["clusterId"] = params.ClusterId
2021-06-07 08:43:57 +08:00
countResp, err := this.RPC().HTTPCachePolicyRPC().CountAllEnabledHTTPCachePolicies(this.AdminContext(), &pb.CountAllEnabledHTTPCachePoliciesRequest{
NodeClusterId: params.ClusterId,
Keyword: params.Keyword,
2021-06-07 08:43:57 +08:00
})
2020-10-02 17:22:24 +08:00
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
listResp, err := this.RPC().HTTPCachePolicyRPC().ListEnabledHTTPCachePolicies(this.AdminContext(), &pb.ListEnabledHTTPCachePoliciesRequest{
Keyword: params.Keyword,
NodeClusterId: params.ClusterId,
Offset: page.Offset,
Size: page.Size,
2020-10-02 17:22:24 +08:00
})
if err != nil {
this.ErrorPage(err)
return
}
cachePoliciesJSON := listResp.HttpCachePoliciesJSON
2020-10-02 17:22:24 +08:00
cachePolicies := []*serverconfigs.HTTPCachePolicy{}
err = json.Unmarshal(cachePoliciesJSON, &cachePolicies)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["cachePolicies"] = cachePolicies
infos := []maps.Map{}
for _, cachePolicy := range cachePolicies {
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: cachePolicy.Id})
2020-10-02 17:22:24 +08:00
if err != nil {
this.ErrorPage(err)
return
}
countClusters := countClustersResp.Count
2020-10-02 17:22:24 +08:00
infos = append(infos, maps.Map{
"typeName": serverconfigs.FindCachePolicyStorageName(cachePolicy.Type),
"countClusters": countClusters,
2020-10-02 17:22:24 +08:00
})
}
this.Data["infos"] = infos
2020-09-13 20:37:07 +08:00
this.Show()
}