delete metrics

This commit is contained in:
GLYASAI 2019-11-28 17:21:05 +08:00
parent 29fd931b87
commit cebd3601d6
3 changed files with 17 additions and 1 deletions

View File

@ -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
}

View File

@ -465,6 +465,7 @@ type TenantServceAutoscalerRuleMetricsDao interface {
Dao
UpdateOrCreate(metric *model.TenantServiceAutoscalerRuleMetrics) error
ListByRuleID(ruleID string) ([]*model.TenantServiceAutoscalerRuleMetrics, error)
DeleteByRuleID(ruldID string) error
}
// TenantServiceScalingRecordsDao -

View File

@ -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