Merge pull request #873 from yangkaa/ds

New Feature :Delete new data
This commit is contained in:
黄润豪 2020-11-13 10:49:29 +08:00 committed by GitHub
commit 67c0d9b40b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 35 additions and 28 deletions

View File

@ -24,14 +24,14 @@ func (a *ApplicationAction) AddConfigGroup(appID string, req *model.ApplicationC
}() }()
// Create application configGroup-services // Create application configGroup-services
for _, s := range services { for _, s := range services {
serviceConfigGroup := dbmodel.ServiceConfigGroup{ serviceConfigGroup := dbmodel.ConfigGroupService{
AppID: appID, AppID: appID,
ConfigGroupName: req.ConfigGroupName, ConfigGroupName: req.ConfigGroupName,
ServiceID: s.ServiceID, ServiceID: s.ServiceID,
ServiceAlias: s.ServiceAlias, ServiceAlias: s.ServiceAlias,
} }
if err := db.GetManager().AppConfigGroupServiceDaoTransactions(tx).AddModel(&serviceConfigGroup); err != nil { if err := db.GetManager().AppConfigGroupServiceDaoTransactions(tx).AddModel(&serviceConfigGroup); err != nil {
if err == bcode.ErrServiceConfigGroupExist { if err == bcode.ErrConfigGroupServiceExist {
logrus.Warningf("config group \"%s\" under this service \"%s\" already exists.", serviceConfigGroup.ConfigGroupName, serviceConfigGroup.ServiceID) logrus.Warningf("config group \"%s\" under this service \"%s\" already exists.", serviceConfigGroup.ConfigGroupName, serviceConfigGroup.ServiceID)
continue continue
} }
@ -121,7 +121,7 @@ func (a *ApplicationAction) UpdateConfigGroup(appID, configGroupName string, req
return nil, err return nil, err
} }
for _, s := range services { for _, s := range services {
serviceConfigGroup := dbmodel.ServiceConfigGroup{ serviceConfigGroup := dbmodel.ConfigGroupService{
AppID: appID, AppID: appID,
ConfigGroupName: configGroupName, ConfigGroupName: configGroupName,
ServiceID: s.ServiceID, ServiceID: s.ServiceID,

View File

@ -197,7 +197,7 @@ func TestListConfigGroups(t *testing.T) {
}, },
}, },
mockFunc: func(manager *db.MockManager, ctrl *gomock.Controller) { mockFunc: func(manager *db.MockManager, ctrl *gomock.Controller) {
configGroupsServiceResult := []*dbmodel.ServiceConfigGroup{ configGroupsServiceResult := []*dbmodel.ConfigGroupService{
{ServiceID: "sid1", ServiceAlias: "sid1_name"}, {ServiceID: "sid1", ServiceAlias: "sid1_name"},
} }
configGroupsResult := []*dbmodel.ApplicationConfigGroup{ configGroupsResult := []*dbmodel.ApplicationConfigGroup{
@ -251,7 +251,7 @@ func TestListConfigGroups(t *testing.T) {
name: "list config group failed because get config group item error", name: "list config group failed because get config group item error",
appID: "appID1", appID: "appID1",
mockFunc: func(manager *db.MockManager, ctrl *gomock.Controller) { mockFunc: func(manager *db.MockManager, ctrl *gomock.Controller) {
configGroupsServiceResult := []*dbmodel.ServiceConfigGroup{ configGroupsServiceResult := []*dbmodel.ConfigGroupService{
{ServiceID: "sid1", ServiceAlias: "sid1_name"}, {ServiceID: "sid1", ServiceAlias: "sid1_name"},
} }
configGroupsResult := []*dbmodel.ApplicationConfigGroup{ configGroupsResult := []*dbmodel.ApplicationConfigGroup{

View File

@ -2061,6 +2061,7 @@ func (s *ServiceAction) delServiceMetadata(serviceID string) error {
db.GetManager().ServiceProbeDaoTransactions(tx).DELServiceProbesByServiceID, db.GetManager().ServiceProbeDaoTransactions(tx).DELServiceProbesByServiceID,
db.GetManager().ServiceEventDaoTransactions(tx).DelEventByServiceID, db.GetManager().ServiceEventDaoTransactions(tx).DelEventByServiceID,
db.GetManager().TenantServiceMonitorDaoTransactions(tx).DeleteServiceMonitorByServiceID, db.GetManager().TenantServiceMonitorDaoTransactions(tx).DeleteServiceMonitorByServiceID,
db.GetManager().AppConfigGroupServiceDaoTransactions(tx).DeleteEffectiveServiceByServiceID,
} }
if err := GetGatewayHandler().DeleteTCPRuleByServiceIDWithTransaction(serviceID, tx); err != nil { if err := GetGatewayHandler().DeleteTCPRuleByServiceIDWithTransaction(serviceID, tx); err != nil {
tx.Rollback() tx.Rollback()

View File

@ -1674,8 +1674,8 @@ type BindServiceRequest struct {
ServiceIDs []string `json:"service_ids"` ServiceIDs []string `json:"service_ids"`
} }
// ServiceConfigGroup - // ConfigGroupService -
type ServiceConfigGroup struct { type ConfigGroupService struct {
AppID string `json:"app_id"` AppID string `json:"app_id"`
ConfigGroupName string `json:"config_group_name"` ConfigGroupName string `json:"config_group_name"`
ServiceID string `json:"service_id"` ServiceID string `json:"service_id"`
@ -1705,7 +1705,7 @@ type ApplicationConfigGroupResp struct {
AppID string `json:"app_id"` AppID string `json:"app_id"`
ConfigGroupName string `json:"config_group_name"` ConfigGroupName string `json:"config_group_name"`
DeployType string `json:"deploy_type"` DeployType string `json:"deploy_type"`
Services []*dbmodel.ServiceConfigGroup `json:"services"` Services []*dbmodel.ConfigGroupService `json:"services"`
ConfigItems []*dbmodel.ConfigGroupItem `json:"config_items"` ConfigItems []*dbmodel.ConfigGroupItem `json:"config_items"`
} }

View File

@ -20,8 +20,8 @@ var (
var ( var (
//ErrApplicationConfigGroupExist - //ErrApplicationConfigGroupExist -
ErrApplicationConfigGroupExist = newByMessage(409, 11101, "application config group already exist") ErrApplicationConfigGroupExist = newByMessage(409, 11101, "application config group already exist")
//ErrServiceConfigGroupExist - //ErrConfigGroupServiceExist -
ErrServiceConfigGroupExist = newByMessage(409, 11102, "config group under this service already exists") ErrConfigGroupServiceExist = newByMessage(409, 11102, "config group under this service already exists")
//ErrConfigItemExist - //ErrConfigItemExist -
ErrConfigItemExist = newByMessage(409, 11103, "config item under this config group already exist") ErrConfigItemExist = newByMessage(409, 11103, "config item under this config group already exist")
//ErrServiceNotFound - //ErrServiceNotFound -

View File

@ -88,8 +88,9 @@ type AppConfigGroupDao interface {
//AppConfigGroupServiceDao service config group Dao //AppConfigGroupServiceDao service config group Dao
type AppConfigGroupServiceDao interface { type AppConfigGroupServiceDao interface {
Dao Dao
GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ServiceConfigGroup, error) GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ConfigGroupService, error)
DeleteConfigGroupService(appID, configGroupName string) error DeleteConfigGroupService(appID, configGroupName string) error
DeleteEffectiveServiceByServiceID(serviceID string) error
} }
//AppConfigGroupItemDao Application config item group Dao //AppConfigGroupItemDao Application config item group Dao

View File

@ -651,10 +651,10 @@ func (mr *MockAppConfigGroupServiceDaoMockRecorder) UpdateModel(arg0 interface{}
} }
// GetConfigGroupServicesByID mocks base method. // GetConfigGroupServicesByID mocks base method.
func (m *MockAppConfigGroupServiceDao) GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ServiceConfigGroup, error) { func (m *MockAppConfigGroupServiceDao) GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ConfigGroupService, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetConfigGroupServicesByID", appID, configGroupName) ret := m.ctrl.Call(m, "GetConfigGroupServicesByID", appID, configGroupName)
ret0, _ := ret[0].([]*model.ServiceConfigGroup) ret0, _ := ret[0].([]*model.ConfigGroupService)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }

View File

@ -26,8 +26,8 @@ func (t *Application) TableName() string {
return "applications" return "applications"
} }
// ServiceConfigGroup - // ConfigGroupService -
type ServiceConfigGroup struct { type ConfigGroupService struct {
Model Model
AppID string `gorm:"column:app_id" json:"-"` AppID string `gorm:"column:app_id" json:"-"`
ConfigGroupName string `gorm:"column:config_group_name" json:"-"` ConfigGroupName string `gorm:"column:config_group_name" json:"-"`
@ -36,7 +36,7 @@ type ServiceConfigGroup struct {
} }
// TableName return tableName "application" // TableName return tableName "application"
func (t *ServiceConfigGroup) TableName() string { func (t *ConfigGroupService) TableName() string {
return "app_config_group_service" return "app_config_group_service"
} }

View File

@ -3,9 +3,9 @@ package model
//TenantServiceMonitor custom service monitor //TenantServiceMonitor custom service monitor
type TenantServiceMonitor struct { type TenantServiceMonitor struct {
Model Model
TenantID string `gorm:"column:tenant_id;size:40" json:"tenant_id"` TenantID string `gorm:"column:tenant_id;size:40;unique_index:unique_tenant_id_name" json:"tenant_id"`
ServiceID string `gorm:"column:service_id;size:40" json:"service_id"` ServiceID string `gorm:"column:service_id;size:40" json:"service_id"`
Name string `gorm:"column:name;size:40;unique_index" json:"name"` Name string `gorm:"column:name;size:40;unique_index:unique_tenant_id_name" json:"name"`
ServiceShowName string `gorm:"column:service_show_name" json:"service_show_name"` ServiceShowName string `gorm:"column:service_show_name" json:"service_show_name"`
Port int `gorm:"column:port;size:5" json:"port"` Port int `gorm:"column:port;size:5" json:"port"`
Path string `gorm:"column:path;size:255" json:"path"` Path string `gorm:"column:path;size:255" json:"path"`

View File

@ -75,15 +75,15 @@ type AppConfigGroupServiceDaoImpl struct {
//AddModel - //AddModel -
func (a *AppConfigGroupServiceDaoImpl) AddModel(mo model.Interface) error { func (a *AppConfigGroupServiceDaoImpl) AddModel(mo model.Interface) error {
configReq, _ := mo.(*model.ServiceConfigGroup) configReq, _ := mo.(*model.ConfigGroupService)
var oldApp model.ServiceConfigGroup var oldApp model.ConfigGroupService
if err := a.DB.Where("app_id = ? AND config_group_name = ? AND service_id = ?", configReq.AppID, configReq.ConfigGroupName, configReq.ServiceID).Find(&oldApp).Error; err != nil { if err := a.DB.Where("app_id = ? AND config_group_name = ? AND service_id = ?", configReq.AppID, configReq.ConfigGroupName, configReq.ServiceID).Find(&oldApp).Error; err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return a.DB.Create(configReq).Error return a.DB.Create(configReq).Error
} }
return err return err
} }
return bcode.ErrServiceConfigGroupExist return bcode.ErrConfigGroupServiceExist
} }
//UpdateModel - //UpdateModel -
@ -92,8 +92,8 @@ func (a *AppConfigGroupServiceDaoImpl) UpdateModel(mo model.Interface) error {
} }
// GetConfigGroupServicesByID - // GetConfigGroupServicesByID -
func (a *AppConfigGroupServiceDaoImpl) GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ServiceConfigGroup, error) { func (a *AppConfigGroupServiceDaoImpl) GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ConfigGroupService, error) {
var oldApp []*model.ServiceConfigGroup var oldApp []*model.ConfigGroupService
if err := a.DB.Where("app_id = ? AND config_group_name = ?", appID, configGroupName).Find(&oldApp).Error; err != nil { if err := a.DB.Where("app_id = ? AND config_group_name = ?", appID, configGroupName).Find(&oldApp).Error; err != nil {
return nil, err return nil, err
} }
@ -102,7 +102,12 @@ func (a *AppConfigGroupServiceDaoImpl) GetConfigGroupServicesByID(appID, configG
//DeleteConfigGroupService - //DeleteConfigGroupService -
func (a *AppConfigGroupServiceDaoImpl) DeleteConfigGroupService(appID, configGroupName string) error { func (a *AppConfigGroupServiceDaoImpl) DeleteConfigGroupService(appID, configGroupName string) error {
return a.DB.Where("app_id = ? AND config_group_name = ?", appID, configGroupName).Delete(model.ServiceConfigGroup{}).Error return a.DB.Where("app_id = ? AND config_group_name = ?", appID, configGroupName).Delete(model.ConfigGroupService{}).Error
}
//DeleteEffectiveServiceByServiceID -
func (a *AppConfigGroupServiceDaoImpl) DeleteEffectiveServiceByServiceID(serviceID string) error {
return a.DB.Where("service_id = ?", serviceID).Delete(model.ConfigGroupService{}).Error
} }
// AppConfigGroupItemDaoImpl - // AppConfigGroupItemDaoImpl -

View File

@ -191,13 +191,13 @@ func TestDeleteConfigGroup(t *testing.T) {
// Test AppConfigGroup Service Dao // Test AppConfigGroup Service Dao
func TestAppConfigGroupServiceDaoAddModel(t *testing.T) { func TestAppConfigGroupServiceDaoAddModel(t *testing.T) {
req := &model.ServiceConfigGroup{ req := &model.ConfigGroupService{
AppID: "appID", AppID: "appID",
ConfigGroupName: "configname", ConfigGroupName: "configname",
} }
tests := []struct { tests := []struct {
name string name string
request *model.ServiceConfigGroup request *model.ConfigGroupService
mockFunc func(mock sqlmock.Sqlmock) mockFunc func(mock sqlmock.Sqlmock)
wanterr bool wanterr bool
}{ }{
@ -251,7 +251,7 @@ func TestAppConfigGroupServiceDaoAddModel(t *testing.T) {
} }
tc.mockFunc(mock) tc.mockFunc(mock)
req := &model.ServiceConfigGroup{ req := &model.ConfigGroupService{
AppID: "appID", AppID: "appID",
ConfigGroupName: "configname", ConfigGroupName: "configname",
ServiceID: "serviceID", ServiceID: "serviceID",

View File

@ -127,7 +127,7 @@ func (m *Manager) RegisterTableModel() {
m.models = append(m.models, &model.ServiceSourceConfig{}) m.models = append(m.models, &model.ServiceSourceConfig{})
m.models = append(m.models, &model.Application{}) m.models = append(m.models, &model.Application{})
m.models = append(m.models, &model.ApplicationConfigGroup{}) m.models = append(m.models, &model.ApplicationConfigGroup{})
m.models = append(m.models, &model.ServiceConfigGroup{}) m.models = append(m.models, &model.ConfigGroupService{})
m.models = append(m.models, &model.ConfigGroupItem{}) m.models = append(m.models, &model.ConfigGroupItem{})
// gateway // gateway
m.models = append(m.models, &model.Certificate{}) m.models = append(m.models, &model.Certificate{})