mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
[ADD] delete related talbes when deleting service
This commit is contained in:
parent
5f3d72ff61
commit
327f0914a3
@ -216,6 +216,32 @@ func (g *GatewayAction) DeleteHTTPRule(req *apimodel.DeleteHTTPRuleStruct) (stri
|
||||
return svcID, nil
|
||||
}
|
||||
|
||||
// DeleteHTTPRule deletes http rule, including certificate and rule extensions
|
||||
func (g *GatewayAction) DeleteHTTPRuleByServiceIDWithTransaction(sid string, tx *gorm.DB) error {
|
||||
// delete http rule
|
||||
rules, err := g.dbmanager.HTTPRuleDaoTransactions(tx).ListByServiceID(sid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rule := range rules {
|
||||
if err := g.dbmanager.CertificateDaoTransactions(tx).DeleteCertificateByID(rule.CertificateID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.dbmanager.RuleExtensionDaoTransactions(tx).DeleteRuleExtensionByRuleID(rule.UUID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.dbmanager.GwRuleConfigDaoTransactions(tx).DeleteByRuleID(rule.UUID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.dbmanager.HTTPRuleDaoTransactions(tx).DeleteHTTPRuleByID(rule.UUID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddCertificate adds certificate to db if it doesn't exists
|
||||
func (g *GatewayAction) AddCertificate(req *apimodel.AddHTTPRuleStruct, tx *gorm.DB) error {
|
||||
cert := &model.Certificate{
|
||||
@ -385,7 +411,7 @@ func (g *GatewayAction) DeleteTCPRule(req *apimodel.DeleteTCPRuleStruct) (string
|
||||
return "", err
|
||||
}
|
||||
// delete tcp rule
|
||||
if err := db.GetManager().TCPRuleDaoTransactions(tx).DeleteTCPRule(tcpRule); err != nil {
|
||||
if err := db.GetManager().TCPRuleDaoTransactions(tx).DeleteByID(tcpRule.UUID); err != nil {
|
||||
tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
@ -404,6 +430,25 @@ func (g *GatewayAction) DeleteTCPRule(req *apimodel.DeleteTCPRuleStruct) (string
|
||||
return tcpRule.ServiceID, nil
|
||||
}
|
||||
|
||||
// DeleteTCPRule deletes a tcp rule
|
||||
func (g *GatewayAction) DeleteTCPRuleByServiceIDWithTransaction(sid string, tx *gorm.DB) error {
|
||||
rules, err := db.GetManager().TCPRuleDaoTransactions(tx).GetTCPRuleByServiceID(sid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, rule := range rules {
|
||||
// delete rule extensions
|
||||
if err := db.GetManager().RuleExtensionDaoTransactions(tx).DeleteRuleExtensionByRuleID(rule.UUID); err != nil {
|
||||
return err
|
||||
}
|
||||
// delete tcp rule
|
||||
if err := db.GetManager().TCPRuleDaoTransactions(tx).DeleteByID(rule.UUID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddRuleExtensions adds rule extensions to db if any of they doesn't exists
|
||||
func (g *GatewayAction) AddRuleExtensions(ruleID string, ruleExtensions []*apimodel.RuleExtensionStruct,
|
||||
tx *gorm.DB) error {
|
||||
@ -567,7 +612,7 @@ func (g *GatewayAction) RuleConfig(req *apimodel.RuleConfigReq) error {
|
||||
setheaders := make(map[string]string)
|
||||
for _, item := range req.Body.SetHeaders {
|
||||
// filter same key
|
||||
setheaders["set-header-" + item.Key] = item.Value
|
||||
setheaders["set-header-"+item.Key] = item.Value
|
||||
}
|
||||
for k, v := range setheaders {
|
||||
configs = append(configs, &model.GwRuleConfig{
|
||||
|
@ -29,6 +29,7 @@ type GatewayHandler interface {
|
||||
AddHTTPRule(req *apimodel.AddHTTPRuleStruct) (string, error)
|
||||
UpdateHTTPRule(req *apimodel.UpdateHTTPRuleStruct) (string, error)
|
||||
DeleteHTTPRule(req *apimodel.DeleteHTTPRuleStruct) (string, error)
|
||||
DeleteHTTPRuleByServiceIDWithTransaction(sid string, tx *gorm.DB) error
|
||||
|
||||
AddCertificate(req *apimodel.AddHTTPRuleStruct, tx *gorm.DB) error
|
||||
UpdateCertificate(req apimodel.AddHTTPRuleStruct, httpRule *dbmodel.HTTPRule, tx *gorm.DB) error
|
||||
@ -36,6 +37,7 @@ type GatewayHandler interface {
|
||||
AddTCPRule(req *apimodel.AddTCPRuleStruct) (string, error)
|
||||
UpdateTCPRule(req *apimodel.UpdateTCPRuleStruct, minPort int) (string, error)
|
||||
DeleteTCPRule(req *apimodel.DeleteTCPRuleStruct) (string, error)
|
||||
DeleteTCPRuleByServiceIDWithTransaction(sid string, tx *gorm.DB) error
|
||||
|
||||
AddRuleExtensions(ruleID string, ruleExtensions []*apimodel.RuleExtensionStruct, tx *gorm.DB) error
|
||||
|
||||
|
@ -1728,6 +1728,7 @@ func (s *ServiceAction) TransServieToDelete(serviceID string) error {
|
||||
db.GetManager().TenantServiceRelationDaoTransactions(tx).DELRelationsByServiceID,
|
||||
db.GetManager().TenantServiceLBMappingPortDaoTransactions(tx).DELServiceLBMappingPortByServiceID,
|
||||
db.GetManager().TenantServiceVolumeDaoTransactions(tx).DeleteTenantServiceVolumesByServiceID,
|
||||
db.GetManager().TenantServiceConfigFileDaoTransactions(tx).DelByServiceID,
|
||||
db.GetManager().ServiceProbeDaoTransactions(tx).DELServiceProbesByServiceID,
|
||||
db.GetManager().TenantServicePluginRelationDaoTransactions(tx).DeleteALLRelationByServiceID,
|
||||
db.GetManager().TenantServicesStreamPluginPortDaoTransactions(tx).DeleteAllPluginMappingPortByServiceID,
|
||||
@ -1736,6 +1737,16 @@ func (s *ServiceAction) TransServieToDelete(serviceID string) error {
|
||||
db.GetManager().TenantServiceLabelDaoTransactions(tx).DeleteLabelByServiceID,
|
||||
db.GetManager().HTTPRuleDaoTransactions(tx).DeleteHTTPRuleByServiceID,
|
||||
db.GetManager().TCPRuleDaoTransactions(tx).DeleteTCPRuleByServiceID,
|
||||
db.GetManager().ThirdPartySvcDiscoveryCfgDaoTransactions(tx).DeleteByServiceID,
|
||||
db.GetManager().EndpointsDaoTransactions(tx).DeleteByServiceID,
|
||||
}
|
||||
if err := GetGatewayHandler().DeleteTCPRuleByServiceIDWithTransaction(serviceID, tx); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
if err := GetGatewayHandler().DeleteHTTPRuleByServiceIDWithTransaction(serviceID, tx); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
for _, del := range deleteServicePropertyFunc {
|
||||
if err := del(serviceID); err != nil {
|
||||
|
@ -239,6 +239,7 @@ type TenantServiceConfigFileDao interface {
|
||||
Dao
|
||||
GetByVolumeName(sid, volumeName string) (*model.TenantServiceConfigFile, error)
|
||||
DelByVolumeID(sid string, volumeName string) error
|
||||
DelByServiceID(sid string) error
|
||||
}
|
||||
|
||||
//TenantServiceLBMappingPortDao vs lb mapping port dao
|
||||
@ -394,7 +395,8 @@ type TCPRuleDao interface {
|
||||
Dao
|
||||
GetTCPRuleByServiceIDAndContainerPort(serviceID string, containerPort int) ([]*model.TCPRule, error)
|
||||
GetTCPRuleByID(id string) (*model.TCPRule, error)
|
||||
DeleteTCPRule(tcpRule *model.TCPRule) error
|
||||
GetTCPRuleByServiceID(sid string) ([]*model.TCPRule, error)
|
||||
DeleteByID(uuid string) error
|
||||
DeleteTCPRuleByServiceID(serviceID string) error
|
||||
ListByServiceID(serviceID string) ([]*model.TCPRule, error)
|
||||
}
|
||||
@ -421,6 +423,7 @@ type EndpointsDao interface {
|
||||
DelByUUID(uuid string) error
|
||||
List(sid string) ([]*model.Endpoint, error)
|
||||
ListIsOnline(sid string) ([]*model.Endpoint, error)
|
||||
DeleteByServiceID(sid string) error
|
||||
}
|
||||
|
||||
// ThirdPartySvcDiscoveryCfgDao is an interface for defining method
|
||||
@ -428,6 +431,7 @@ type EndpointsDao interface {
|
||||
type ThirdPartySvcDiscoveryCfgDao interface {
|
||||
Dao
|
||||
GetByServiceID(sid string) (*model.ThirdPartySvcDiscoveryCfg, error)
|
||||
DeleteByServiceID(sid string) error
|
||||
}
|
||||
|
||||
// GwRuleConfigDao is the interface that wraps the required methods to execute
|
||||
|
@ -96,12 +96,17 @@ func (e *EndpointDaoImpl) ListIsOnline(sid string) ([]*model.Endpoint, error) {
|
||||
|
||||
// DelByUUID deletes endpoints matching uuid.
|
||||
func (e *EndpointDaoImpl) DelByUUID(uuid string) error {
|
||||
if err := e.DB.Where("uuid=?", uuid).Delete(model.Endpoint{}).Error; err != nil {
|
||||
if err := e.DB.Where("uuid=?", uuid).Delete(&model.Endpoint{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteByServiceID delete endpoints based on service id.
|
||||
func(e *EndpointDaoImpl) DeleteByServiceID(sid string) error {
|
||||
return e.DB.Where("service_id=?", sid).Delete(&model.Endpoint{}).Error
|
||||
}
|
||||
|
||||
// ThirdPartySvcDiscoveryCfgDaoImpl implements ThirdPartySvcDiscoveryCfgDao
|
||||
type ThirdPartySvcDiscoveryCfgDaoImpl struct {
|
||||
DB *gorm.DB
|
||||
@ -141,3 +146,8 @@ func (t *ThirdPartySvcDiscoveryCfgDaoImpl) GetByServiceID(sid string) (*model.Th
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// DeleteByServiceID delete discovery config based on service id.
|
||||
func(t *ThirdPartySvcDiscoveryCfgDaoImpl) DeleteByServiceID(sid string) error {
|
||||
return t.DB.Where("service_id=?", sid).Delete(&model.ThirdPartySvcDiscoveryCfg{}).Error
|
||||
}
|
||||
|
@ -283,9 +283,21 @@ func (t *TCPRuleDaoTmpl) GetTCPRuleByID(id string) (*model.TCPRule, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// DeleteTCPRule deletes model.TCPRule
|
||||
func (t *TCPRuleDaoTmpl) DeleteTCPRule(tcpRule *model.TCPRule) error {
|
||||
return t.DB.Where("uuid = ?", tcpRule.UUID).Delete(tcpRule).Error
|
||||
// GetTCPRuleByServiceID gets a TCPRules based on service id.
|
||||
func (t *TCPRuleDaoTmpl) GetTCPRuleByServiceID(sid string) ([]*model.TCPRule, error) {
|
||||
var result []*model.TCPRule
|
||||
if err := t.DB.Where("service_id = ?", sid).Find(&result).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// DeleteByID deletes model.TCPRule
|
||||
func (t *TCPRuleDaoTmpl) DeleteByID(uuid string) error {
|
||||
return t.DB.Where("uuid = ?", uuid).Delete(&model.TCPRule{}).Error
|
||||
}
|
||||
|
||||
// DeleteTCPRuleByServiceID deletes model.TCPRule
|
||||
|
@ -1037,6 +1037,11 @@ func (t *TenantServiceConfigFileDaoImpl) DelByVolumeID(sid, volumeName string) e
|
||||
return t.DB.Where("service_id=? and volume_name = ?", sid, volumeName).Delete(&cfs).Error
|
||||
}
|
||||
|
||||
// DelByServiceID deletes config files according to service id.
|
||||
func (t *TenantServiceConfigFileDaoImpl) DelByServiceID(sid string) error {
|
||||
return t.DB.Where("service_id=?", sid).Delete(&model.TenantServiceConfigFile{}).Error
|
||||
}
|
||||
|
||||
//TenantServiceLBMappingPortDaoImpl stream服务映射
|
||||
type TenantServiceLBMappingPortDaoImpl struct {
|
||||
DB *gorm.DB
|
||||
|
@ -243,7 +243,6 @@ func (r *RuntimeServer) ListThirdPartyEndpoints(ctx context.Context, re *pb.Serv
|
||||
}
|
||||
var pbeps []*pb.ThirdPartyEndpoint
|
||||
exists := make(map[string]bool)
|
||||
logrus.Debugf("Status from endpoints: %+v", as.GetEndpoints())
|
||||
for _, ep := range as.GetEndpoints() {
|
||||
if exists[ep.GetLabels()["uuid"]] {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user