您最多选择25个标签 标签必须以中文、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

deletealertrulelogic.go 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package monitoring
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. )
  8. type DeleteAlertRuleLogic struct {
  9. logx.Logger
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. }
  13. func NewDeleteAlertRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAlertRuleLogic {
  14. return &DeleteAlertRuleLogic{
  15. Logger: logx.WithContext(ctx),
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. }
  19. }
  20. func (l *DeleteAlertRuleLogic) DeleteAlertRule(req *types.DeleteAlertRuleReq) error {
  21. // Delete data from the database
  22. l.svcCtx.DbEngin.Delete(&types.AlertRule{}, "id = ?", req.Id)
  23. // query cluster http url.
  24. var server string
  25. l.svcCtx.DbEngin.Raw("select ta.server from t_adapter ta,t_cluster tc where ta.id = tc.adapter_id and tc.name = ?", &req.ClusterName).Scan(&server)
  26. // create prometheus rule
  27. response, err := l.svcCtx.HttpClient.R().
  28. SetBody(&CrdStruct{
  29. ClusterName: req.ClusterName,
  30. Name: req.Name,
  31. Grv: Grv{
  32. Group: "monitoring.coreos.com",
  33. Version: "v1",
  34. Resource: "prometheusrules",
  35. },
  36. }).
  37. ForceContentType("application/json").
  38. Delete(server + "/api/v1/crd")
  39. if err != nil {
  40. return err
  41. }
  42. if err != nil || response.IsError() {
  43. return err
  44. }
  45. return nil
  46. }
  47. type Grv struct {
  48. Group string `json:"group"`
  49. Version string `json:"version"`
  50. Resource string `json:"resource"`
  51. }
  52. type CrdStruct struct {
  53. ClusterName string `json:"clusterName"`
  54. Grv Grv `json:"grv"`
  55. Name string `json:"name"`
  56. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.