实现HTTP部分功能

This commit is contained in:
GoEdgeLab
2020-09-26 08:07:18 +08:00
parent 72865127b7
commit 86229e5a6f
32 changed files with 280 additions and 147 deletions

View File

@@ -2,6 +2,9 @@ package nodes
// 节点状态
type NodeStatus struct {
BuildVersion string `json:"buildVersion"` // 编译版本
ConfigVersion int64 `json:"configVersion"` // 节点配置版本
Hostname string `json:"hostname"`
HostIP string `json:"hostIP"`
CPUUsage float64 `json:"cpuUsage"`

View File

@@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/configs/nodes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
@@ -24,12 +24,15 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ClusterId int64
InstalledState int
ActiveState int
}) {
this.Data["installState"] = params.InstalledState
this.Data["activeState"] = params.ActiveState
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
ClusterId: params.ClusterId,
InstallState: types.Int32(params.InstalledState),
ActiveState: types.Int32(params.ActiveState),
})
if err != nil {
this.ErrorPage(err)
@@ -44,10 +47,12 @@ func (this *IndexAction) RunGet(params struct {
Size: page.Size,
ClusterId: params.ClusterId,
InstallState: types.Int32(params.InstalledState),
ActiveState: types.Int32(params.ActiveState),
})
nodeMaps := []maps.Map{}
for _, node := range nodesResp.Nodes {
// 状态
isSynced := false
status := &nodes.NodeStatus{}
if len(node.Status) > 0 && node.Status != "null" {
err = json.Unmarshal([]byte(node.Status), &status)
@@ -55,7 +60,8 @@ func (this *IndexAction) RunGet(params struct {
logs.Error(err)
continue
}
status.IsActive = time.Now().Unix()-status.UpdatedAt < 120 // 2分钟之内认为活跃
status.IsActive = time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
isSynced = status.ConfigVersion == node.Version
}
// IP
@@ -96,6 +102,7 @@ func (this *IndexAction) RunGet(params struct {
"id": node.Cluster.Id,
"name": node.Cluster.Name,
},
"isSynced": isSynced,
"ipAddresses": ipAddresses,
})
}

View File

@@ -1,9 +1,11 @@
package clusters
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
type IndexAction struct {
@@ -35,19 +37,30 @@ func (this *IndexAction) RunGet(params struct{}) {
return
}
for _, cluster := range clustersResp.Clusters {
// 节点数量
// 全部节点数量
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ClusterId: cluster.Id})
if err != nil {
this.ErrorPage(err)
return
}
// 在线节点
countActiveNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
ClusterId: cluster.Id,
ActiveState: types.Int32(configutils.BoolStateYes),
})
if err != nil {
this.ErrorPage(err)
return
}
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
"hasGrant": cluster.GrantId > 0,
"countNodes": countNodesResp.Count,
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
"hasGrant": cluster.GrantId > 0,
"countAllNodes": countNodesResp.Count,
"countActiveNodes": countActiveNodesResp.Count,
})
}
}

View File

@@ -1,11 +1,13 @@
package common
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"time"
)
// 检查变更的集群列表
type ChangedClustersAction struct {
actionutils.ParentAction
}
@@ -14,22 +16,50 @@ func (this *ChangedClustersAction) Init() {
this.Nav("", "", "")
}
func (this *ChangedClustersAction) RunGet(params struct{}) {
resp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
func (this *ChangedClustersAction) RunGet(params struct {
IsNotifying bool
}) {
timeout := time.NewTimer(55 * time.Second) // 比客户端提前结束,避免在客户端产生一个请求错误
result := []maps.Map{}
for _, cluster := range resp.Clusters {
result = append(result, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
this.Data["clusters"] = []interface{}{}
this.Data["clusters"] = result
Loop:
for {
select {
case <-this.Request.Context().Done():
break Loop
case <-timeout.C:
break Loop
default:
// 继续
}
resp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
result := []maps.Map{}
for _, cluster := range resp.Clusters {
result = append(result, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
// 从提醒到提醒消失
if len(result) == 0 && params.IsNotifying {
break
}
this.Data["clusters"] = result
if len(result) > 0 {
break
}
time.Sleep(1 * time.Second)
}
this.Success()
}

View File

@@ -1,10 +1,11 @@
package common
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
// 同步集群
type SyncClustersAction struct {
actionutils.ParentAction
}

View File

@@ -3,8 +3,8 @@ package charset
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/configutils"
"github.com/iwind/TeaGo/actions"
)

View File

@@ -42,7 +42,7 @@ func (this *CreateDeletePopupAction) RunPost(params struct {
return
}
deleteHeaders := policyConfig.DeletedHeaders
deleteHeaders := policyConfig.DeleteHeaders
deleteHeaders = append(deleteHeaders, params.Name)
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyDeletingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyDeletingHeadersRequest{
HeaderPolicyId: params.HeaderPolicyId,

View File

@@ -60,14 +60,12 @@ func (this *CreateSetPopupAction) RunPost(params struct {
headerId := createHeaderResp.HeaderId
// 保存
policyConfig.SetHeaders = append(policyConfig.SetHeaders, &shared.HTTPHeaderConfig{
Id: headerId,
IsOn: true,
Name: params.Name,
Value: params.Value,
Status: nil,
refs := policyConfig.SetHeaderRefs
refs = append(refs, &shared.HTTPHeaderRef{
IsOn: true,
HeaderId: headerId,
})
setHeadersJSON, err := json.Marshal(policyConfig.SetHeaders)
refsJSON, err := json.Marshal(refs)
if err != nil {
this.ErrorPage(err)
return
@@ -75,7 +73,7 @@ func (this *CreateSetPopupAction) RunPost(params struct {
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicySettingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicySettingHeadersRequest{
HeaderPolicyId: params.HeaderPolicyId,
HeadersJSON: setHeadersJSON,
HeadersJSON: refsJSON,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -33,9 +33,9 @@ func (this *DeleteAction) RunPost(params struct {
switch params.Type {
case "addHeader":
result := []*shared.HTTPHeaderConfig{}
for _, h := range policyConfig.AddHeaders {
if h.Id != params.HeaderId {
result := []*shared.HTTPHeaderRef{}
for _, h := range policyConfig.AddHeaderRefs {
if h.HeaderId != params.HeaderId {
result = append(result, h)
}
}
@@ -53,9 +53,9 @@ func (this *DeleteAction) RunPost(params struct {
return
}
case "setHeader":
result := []*shared.HTTPHeaderConfig{}
for _, h := range policyConfig.SetHeaders {
if h.Id != params.HeaderId {
result := []*shared.HTTPHeaderRef{}
for _, h := range policyConfig.SetHeaderRefs {
if h.HeaderId != params.HeaderId {
result = append(result, h)
}
}
@@ -73,9 +73,9 @@ func (this *DeleteAction) RunPost(params struct {
return
}
case "replace":
result := []*shared.HTTPHeaderConfig{}
for _, h := range policyConfig.ReplaceHeaders {
if h.Id != params.HeaderId {
result := []*shared.HTTPHeaderRef{}
for _, h := range policyConfig.ReplaceHeaderRefs {
if h.HeaderId != params.HeaderId {
result = append(result, h)
}
}
@@ -93,9 +93,9 @@ func (this *DeleteAction) RunPost(params struct {
return
}
case "addTrailer":
result := []*shared.HTTPHeaderConfig{}
for _, h := range policyConfig.AddTrailers {
if h.Id != params.HeaderId {
result := []*shared.HTTPHeaderRef{}
for _, h := range policyConfig.AddTrailerRefs {
if h.HeaderId != params.HeaderId {
result = append(result, h)
}
}

View File

@@ -29,7 +29,7 @@ func (this *DeleteDeletingHeaderAction) RunPost(params struct {
}
headerNames := []string{}
for _, h := range policyConfig.DeletedHeaders {
for _, h := range policyConfig.DeleteHeaders {
if h == params.HeaderName {
continue
}

View File

@@ -3,8 +3,8 @@ package charset
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/configutils"
"github.com/iwind/TeaGo/actions"
)

View File

@@ -78,7 +78,7 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
// TABBAR
selectedTabbar, _ := action.Data["mainTab"]
tabbar := actionutils.NewTabbar()
tabbar.Add("当前服务:"+serverConfig.Name, "", "/servers", "left long alternate arrow", false)
tabbar.Add("当前服务:"+server.Name, "", "/servers", "left long alternate arrow", false)
//tabbar.Add("看板", "", "/servers/server/board?serverId="+serverIdString, "dashboard", selectedTabbar == "board")
tabbar.Add("日志", "", "/servers/server/log?serverId="+serverIdString, "history", selectedTabbar == "log")
//tabbar.Add("统计", "", "/servers/server/stat?serverId="+serverIdString, "chart area", selectedTabbar == "stat")