This commit is contained in:
barnettZQG 2019-12-02 10:55:57 +08:00
commit 69a133868a
3 changed files with 17 additions and 1 deletions

View File

@ -1962,6 +1962,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,
@ -1970,7 +1976,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