From cebd3601d6bf4c77cbf625fd38d3a58be2a99be5 Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Thu, 28 Nov 2019 17:21:05 +0800 Subject: [PATCH] delete metrics --- api/handler/service.go | 8 +++++++- db/dao/dao.go | 1 + db/mysql/dao/tenants.go | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/handler/service.go b/api/handler/service.go index 0aad0382a..84f9cf9e5 100644 --- a/api/handler/service.go +++ b/api/handler/service.go @@ -1953,6 +1953,12 @@ func (s *ServiceAction) UpdAutoscalerRule(req *api_model.AutoscalerRuleReq) erro return err } + // delete metrics + if err := db.GetManager().TenantServceAutoscalerRuleMetricsDaoTransactions(tx).DeleteByRuleID(req.RuleID); err != nil { + tx.Rollback() + return err + } + for _, metric := range req.Metrics { m := &dbmodel.TenantServiceAutoscalerRuleMetrics{ RuleID: req.RuleID, @@ -1961,7 +1967,7 @@ func (s *ServiceAction) UpdAutoscalerRule(req *api_model.AutoscalerRuleReq) erro MetricTargetType: metric.MetricTargetType, MetricTargetValue: metric.MetricTargetValue, } - if err := db.GetManager().TenantServceAutoscalerRuleMetricsDaoTransactions(tx).UpdateOrCreate(m); err != nil { + if err := db.GetManager().TenantServceAutoscalerRuleMetricsDaoTransactions(tx).AddModel(m); err != nil { tx.Rollback() return err } diff --git a/db/dao/dao.go b/db/dao/dao.go index 3aebec5b0..5e1d5a755 100644 --- a/db/dao/dao.go +++ b/db/dao/dao.go @@ -465,6 +465,7 @@ type TenantServceAutoscalerRuleMetricsDao interface { Dao UpdateOrCreate(metric *model.TenantServiceAutoscalerRuleMetrics) error ListByRuleID(ruleID string) ([]*model.TenantServiceAutoscalerRuleMetrics, error) + DeleteByRuleID(ruldID string) error } // TenantServiceScalingRecordsDao - diff --git a/db/mysql/dao/tenants.go b/db/mysql/dao/tenants.go index 006ff4ae8..4c6f96655 100644 --- a/db/mysql/dao/tenants.go +++ b/db/mysql/dao/tenants.go @@ -1569,6 +1569,15 @@ func (t *TenantServceAutoscalerRuleMetricsDaoImpl) ListByRuleID(ruleID string) ( return metrics, nil } +// DeleteByRuleID - +func (t *TenantServceAutoscalerRuleMetricsDaoImpl) DeleteByRuleID(ruldID string) error { + if err := t.DB.Where("rule_id=?", ruldID).Delete(&model.TenantServiceAutoscalerRuleMetrics{}).Error; err != nil { + return err + } + + return nil +} + // TenantServiceScalingRecordsDaoImpl - type TenantServiceScalingRecordsDaoImpl struct { DB *gorm.DB