diff --git a/internal/web/actions/default/clusters/cluster/settings/thresholds/createPopup.go b/internal/web/actions/default/clusters/cluster/settings/thresholds/createPopup.go deleted file mode 100644 index f62d2938..00000000 --- a/internal/web/actions/default/clusters/cluster/settings/thresholds/createPopup.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package thresholds - -import ( - "encoding/json" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/actions" -) - -type CreatePopupAction struct { - actionutils.ParentAction -} - -func (this *CreatePopupAction) Init() { - this.Nav("", "", "") -} - -func (this *CreatePopupAction) RunGet(params struct { - ClusterId int64 - NodeId int64 -}) { - this.Data["clusterId"] = params.ClusterId - this.Data["nodeId"] = params.NodeId - this.Data["items"] = nodeconfigs.FindAllNodeValueItemDefinitions() - this.Data["operators"] = nodeconfigs.FindAllNodeValueOperatorDefinitions() - - this.Show() -} - -func (this *CreatePopupAction) RunPost(params struct { - ClusterId int64 - NodeId int64 - Item string - Param string - SumMethod string - Operator string - Value string - Duration int32 - DurationUnit string - Message string - NotifyDuration int32 - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - if params.ClusterId <= 0 && params.NodeId >= 0 { - this.Fail("集群或者节点至少需要填写其中一个参数") - } - - valueJSON, err := json.Marshal(params.Value) - if err != nil { - this.ErrorPage(err) - return - } - resp, err := this.RPC().NodeThresholdRPC().CreateNodeThreshold(this.AdminContext(), &pb.CreateNodeThresholdRequest{ - Role: "node", - NodeClusterId: params.ClusterId, - NodeId: params.NodeId, - Item: params.Item, - Param: params.Param, - Operator: params.Operator, - ValueJSON: valueJSON, - Message: params.Message, - Duration: params.Duration, - DurationUnit: params.DurationUnit, - SumMethod: params.SumMethod, - NotifyDuration: params.NotifyDuration, - }) - if err != nil { - this.ErrorPage(err) - return - } - defer this.CreateLogInfo("创建节点阈值 %d", resp.NodeThresholdId) - - this.Success() -} diff --git a/internal/web/actions/default/clusters/cluster/settings/thresholds/delete.go b/internal/web/actions/default/clusters/cluster/settings/thresholds/delete.go deleted file mode 100644 index 48c9b293..00000000 --- a/internal/web/actions/default/clusters/cluster/settings/thresholds/delete.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package thresholds - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" -) - -// DeleteAction 删除阈值 -type DeleteAction struct { - actionutils.ParentAction -} - -func (this *DeleteAction) RunPost(params struct { - ThresholdId int64 -}) { - defer this.CreateLogInfo("删除阈值 %d", params.ThresholdId) - - _, err := this.RPC().NodeThresholdRPC().DeleteNodeThreshold(this.AdminContext(), &pb.DeleteNodeThresholdRequest{NodeThresholdId: params.ThresholdId}) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -} diff --git a/internal/web/actions/default/clusters/cluster/settings/thresholds/index.go b/internal/web/actions/default/clusters/cluster/settings/thresholds/index.go deleted file mode 100644 index 9911e2c0..00000000 --- a/internal/web/actions/default/clusters/cluster/settings/thresholds/index.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package thresholds - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/maps" -) - -type IndexAction struct { - actionutils.ParentAction -} - -func (this *IndexAction) Init() { - this.Nav("", "setting", "setting") - this.SecondMenu("threshold") -} - -func (this *IndexAction) RunGet(params struct { - ClusterId int64 -}) { - // 列出所有阈值 - thresholdsResp, err := this.RPC().NodeThresholdRPC().FindAllEnabledNodeThresholds(this.AdminContext(), &pb.FindAllEnabledNodeThresholdsRequest{ - Role: "node", - NodeClusterId: params.ClusterId, - NodeId: 0, - }) - if err != nil { - this.ErrorPage(err) - return - } - - thresholdMaps := []maps.Map{} - for _, threshold := range thresholdsResp.NodeThresholds { - var nodeMap maps.Map = nil - if threshold.Node != nil { - nodeMap = maps.Map{ - "id": threshold.Node.Id, - "name": threshold.Node.Name, - } - } - - thresholdMaps = append(thresholdMaps, maps.Map{ - "id": threshold.Id, - "itemName": nodeconfigs.FindNodeValueItemName(threshold.Item), - "paramName": nodeconfigs.FindNodeValueItemParamName(threshold.Item, threshold.Param), - "operatorName": nodeconfigs.FindNodeValueOperatorName(threshold.Operator), - "value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON), - "sumMethodName": nodeconfigs.FindNodeValueSumMethodName(threshold.SumMethod), - "duration": threshold.Duration, - "durationUnitName": nodeconfigs.FindNodeValueDurationUnitName(threshold.DurationUnit), - "isOn": threshold.IsOn, - "node": nodeMap, - }) - } - this.Data["thresholds"] = thresholdMaps - - this.Show() -} diff --git a/internal/web/actions/default/clusters/cluster/settings/thresholds/updatePopup.go b/internal/web/actions/default/clusters/cluster/settings/thresholds/updatePopup.go deleted file mode 100644 index a0647786..00000000 --- a/internal/web/actions/default/clusters/cluster/settings/thresholds/updatePopup.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package thresholds - -import ( - "encoding/json" - "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" - "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/actions" - "github.com/iwind/TeaGo/maps" -) - -type UpdatePopupAction struct { - actionutils.ParentAction -} - -func (this *UpdatePopupAction) Init() { - this.Nav("", "", "") -} - -func (this *UpdatePopupAction) RunGet(params struct { - ThresholdId int64 -}) { - // 通用参数 - this.Data["items"] = nodeconfigs.FindAllNodeValueItemDefinitions() - this.Data["operators"] = nodeconfigs.FindAllNodeValueOperatorDefinitions() - - // 阈值详情 - thresholdResp, err := this.RPC().NodeThresholdRPC().FindEnabledNodeThreshold(this.AdminContext(), &pb.FindEnabledNodeThresholdRequest{NodeThresholdId: params.ThresholdId}) - if err != nil { - this.ErrorPage(err) - return - } - threshold := thresholdResp.NodeThreshold - if threshold == nil { - this.NotFound("nodeThreshold", params.ThresholdId) - return - } - - valueInterface := new(interface{}) - err = json.Unmarshal(threshold.ValueJSON, valueInterface) - if err != nil { - this.ErrorPage(err) - return - } - - this.Data["threshold"] = maps.Map{ - "id": threshold.Id, - "item": threshold.Item, - "param": threshold.Param, - "message": threshold.Message, - "notifyDuration": threshold.NotifyDuration, - "value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON), - "operator": threshold.Operator, - "duration": threshold.Duration, - "durationUnit": threshold.DurationUnit, - "isOn": threshold.IsOn, - } - - this.Show() -} - -func (this *UpdatePopupAction) RunPost(params struct { - ThresholdId int64 - Item string - Param string - SumMethod string - Operator string - Value string - Duration int32 - DurationUnit string - Message string - NotifyDuration int32 - IsOn bool - - Must *actions.Must - CSRF *actionutils.CSRF -}) { - defer this.CreateLogInfo("修改节点阈值 %d", params.ThresholdId) - - valueJSON, err := json.Marshal(params.Value) - if err != nil { - this.ErrorPage(err) - return - } - _, err = this.RPC().NodeThresholdRPC().UpdateNodeThreshold(this.AdminContext(), &pb.UpdateNodeThresholdRequest{ - NodeThresholdId: params.ThresholdId, - Item: params.Item, - Param: params.Param, - Operator: params.Operator, - ValueJSON: valueJSON, - Message: params.Message, - NotifyDuration: params.NotifyDuration, - Duration: params.Duration, - DurationUnit: params.DurationUnit, - SumMethod: params.SumMethod, - IsOn: params.IsOn, - }) - if err != nil { - this.ErrorPage(err) - return - } - - this.Success() -}