diff --git a/api/handler/application_config_group.go b/api/handler/application_config_group.go index 4b8a6d6cd..04ad4a7ae 100644 --- a/api/handler/application_config_group.go +++ b/api/handler/application_config_group.go @@ -24,14 +24,14 @@ func (a *ApplicationAction) AddConfigGroup(appID string, req *model.ApplicationC }() // Create application configGroup-services for _, s := range services { - serviceConfigGroup := dbmodel.ServiceConfigGroup{ + serviceConfigGroup := dbmodel.ConfigGroupService{ AppID: appID, ConfigGroupName: req.ConfigGroupName, ServiceID: s.ServiceID, ServiceAlias: s.ServiceAlias, } 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) continue } @@ -121,7 +121,7 @@ func (a *ApplicationAction) UpdateConfigGroup(appID, configGroupName string, req return nil, err } for _, s := range services { - serviceConfigGroup := dbmodel.ServiceConfigGroup{ + serviceConfigGroup := dbmodel.ConfigGroupService{ AppID: appID, ConfigGroupName: configGroupName, ServiceID: s.ServiceID, diff --git a/api/handler/application_config_group_test.go b/api/handler/application_config_group_test.go index 8d86d6f2c..286af3803 100644 --- a/api/handler/application_config_group_test.go +++ b/api/handler/application_config_group_test.go @@ -197,7 +197,7 @@ func TestListConfigGroups(t *testing.T) { }, }, mockFunc: func(manager *db.MockManager, ctrl *gomock.Controller) { - configGroupsServiceResult := []*dbmodel.ServiceConfigGroup{ + configGroupsServiceResult := []*dbmodel.ConfigGroupService{ {ServiceID: "sid1", ServiceAlias: "sid1_name"}, } configGroupsResult := []*dbmodel.ApplicationConfigGroup{ @@ -251,7 +251,7 @@ func TestListConfigGroups(t *testing.T) { name: "list config group failed because get config group item error", appID: "appID1", mockFunc: func(manager *db.MockManager, ctrl *gomock.Controller) { - configGroupsServiceResult := []*dbmodel.ServiceConfigGroup{ + configGroupsServiceResult := []*dbmodel.ConfigGroupService{ {ServiceID: "sid1", ServiceAlias: "sid1_name"}, } configGroupsResult := []*dbmodel.ApplicationConfigGroup{ diff --git a/api/handler/service.go b/api/handler/service.go index d8dfdf833..c52cfa42b 100644 --- a/api/handler/service.go +++ b/api/handler/service.go @@ -2061,6 +2061,7 @@ func (s *ServiceAction) delServiceMetadata(serviceID string) error { db.GetManager().ServiceProbeDaoTransactions(tx).DELServiceProbesByServiceID, db.GetManager().ServiceEventDaoTransactions(tx).DelEventByServiceID, db.GetManager().TenantServiceMonitorDaoTransactions(tx).DeleteServiceMonitorByServiceID, + db.GetManager().AppConfigGroupServiceDaoTransactions(tx).DeleteEffectiveServiceByServiceID, } if err := GetGatewayHandler().DeleteTCPRuleByServiceIDWithTransaction(serviceID, tx); err != nil { tx.Rollback() diff --git a/api/model/model.go b/api/model/model.go index 95efa8523..7ab775907 100644 --- a/api/model/model.go +++ b/api/model/model.go @@ -1674,8 +1674,8 @@ type BindServiceRequest struct { ServiceIDs []string `json:"service_ids"` } -// ServiceConfigGroup - -type ServiceConfigGroup struct { +// ConfigGroupService - +type ConfigGroupService struct { AppID string `json:"app_id"` ConfigGroupName string `json:"config_group_name"` ServiceID string `json:"service_id"` @@ -1705,7 +1705,7 @@ type ApplicationConfigGroupResp struct { AppID string `json:"app_id"` ConfigGroupName string `json:"config_group_name"` DeployType string `json:"deploy_type"` - Services []*dbmodel.ServiceConfigGroup `json:"services"` + Services []*dbmodel.ConfigGroupService `json:"services"` ConfigItems []*dbmodel.ConfigGroupItem `json:"config_items"` } diff --git a/api/util/bcode/application.go b/api/util/bcode/application.go index f9dfa745b..a096f4786 100644 --- a/api/util/bcode/application.go +++ b/api/util/bcode/application.go @@ -20,8 +20,8 @@ var ( var ( //ErrApplicationConfigGroupExist - ErrApplicationConfigGroupExist = newByMessage(409, 11101, "application config group already exist") - //ErrServiceConfigGroupExist - - ErrServiceConfigGroupExist = newByMessage(409, 11102, "config group under this service already exists") + //ErrConfigGroupServiceExist - + ErrConfigGroupServiceExist = newByMessage(409, 11102, "config group under this service already exists") //ErrConfigItemExist - ErrConfigItemExist = newByMessage(409, 11103, "config item under this config group already exist") //ErrServiceNotFound - diff --git a/db/dao/dao.go b/db/dao/dao.go index a88782e5b..6ad905e3c 100644 --- a/db/dao/dao.go +++ b/db/dao/dao.go @@ -88,8 +88,9 @@ type AppConfigGroupDao interface { //AppConfigGroupServiceDao service config group Dao type AppConfigGroupServiceDao interface { Dao - GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ServiceConfigGroup, error) + GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ConfigGroupService, error) DeleteConfigGroupService(appID, configGroupName string) error + DeleteEffectiveServiceByServiceID(serviceID string) error } //AppConfigGroupItemDao Application config item group Dao diff --git a/db/dao/dao_mock.go b/db/dao/dao_mock.go index 56d21bd41..e8887d809 100644 --- a/db/dao/dao_mock.go +++ b/db/dao/dao_mock.go @@ -651,10 +651,10 @@ func (mr *MockAppConfigGroupServiceDaoMockRecorder) UpdateModel(arg0 interface{} } // 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() ret := m.ctrl.Call(m, "GetConfigGroupServicesByID", appID, configGroupName) - ret0, _ := ret[0].([]*model.ServiceConfigGroup) + ret0, _ := ret[0].([]*model.ConfigGroupService) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/db/model/application.go b/db/model/application.go index 4007c7189..345c41bf4 100644 --- a/db/model/application.go +++ b/db/model/application.go @@ -26,8 +26,8 @@ func (t *Application) TableName() string { return "applications" } -// ServiceConfigGroup - -type ServiceConfigGroup struct { +// ConfigGroupService - +type ConfigGroupService struct { Model AppID string `gorm:"column:app_id" json:"-"` ConfigGroupName string `gorm:"column:config_group_name" json:"-"` @@ -36,7 +36,7 @@ type ServiceConfigGroup struct { } // TableName return tableName "application" -func (t *ServiceConfigGroup) TableName() string { +func (t *ConfigGroupService) TableName() string { return "app_config_group_service" } diff --git a/db/model/monitor.go b/db/model/monitor.go index e2446a9f3..539ce56f5 100644 --- a/db/model/monitor.go +++ b/db/model/monitor.go @@ -3,9 +3,9 @@ package model //TenantServiceMonitor custom service monitor type TenantServiceMonitor struct { 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"` - 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"` Port int `gorm:"column:port;size:5" json:"port"` Path string `gorm:"column:path;size:255" json:"path"` diff --git a/db/mysql/dao/application_config_group.go b/db/mysql/dao/application_config_group.go index c5dcd2156..a28c65eb6 100644 --- a/db/mysql/dao/application_config_group.go +++ b/db/mysql/dao/application_config_group.go @@ -75,15 +75,15 @@ type AppConfigGroupServiceDaoImpl struct { //AddModel - func (a *AppConfigGroupServiceDaoImpl) AddModel(mo model.Interface) error { - configReq, _ := mo.(*model.ServiceConfigGroup) - var oldApp model.ServiceConfigGroup + configReq, _ := mo.(*model.ConfigGroupService) + 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 == gorm.ErrRecordNotFound { return a.DB.Create(configReq).Error } return err } - return bcode.ErrServiceConfigGroupExist + return bcode.ErrConfigGroupServiceExist } //UpdateModel - @@ -92,8 +92,8 @@ func (a *AppConfigGroupServiceDaoImpl) UpdateModel(mo model.Interface) error { } // GetConfigGroupServicesByID - -func (a *AppConfigGroupServiceDaoImpl) GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ServiceConfigGroup, error) { - var oldApp []*model.ServiceConfigGroup +func (a *AppConfigGroupServiceDaoImpl) GetConfigGroupServicesByID(appID, configGroupName string) ([]*model.ConfigGroupService, error) { + var oldApp []*model.ConfigGroupService if err := a.DB.Where("app_id = ? AND config_group_name = ?", appID, configGroupName).Find(&oldApp).Error; err != nil { return nil, err } @@ -102,7 +102,12 @@ func (a *AppConfigGroupServiceDaoImpl) GetConfigGroupServicesByID(appID, configG //DeleteConfigGroupService - 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 - diff --git a/db/mysql/dao/application_config_group_test.go b/db/mysql/dao/application_config_group_test.go index 0acfd2910..82476ac5a 100644 --- a/db/mysql/dao/application_config_group_test.go +++ b/db/mysql/dao/application_config_group_test.go @@ -191,13 +191,13 @@ func TestDeleteConfigGroup(t *testing.T) { // Test AppConfigGroup Service Dao func TestAppConfigGroupServiceDaoAddModel(t *testing.T) { - req := &model.ServiceConfigGroup{ + req := &model.ConfigGroupService{ AppID: "appID", ConfigGroupName: "configname", } tests := []struct { name string - request *model.ServiceConfigGroup + request *model.ConfigGroupService mockFunc func(mock sqlmock.Sqlmock) wanterr bool }{ @@ -251,7 +251,7 @@ func TestAppConfigGroupServiceDaoAddModel(t *testing.T) { } tc.mockFunc(mock) - req := &model.ServiceConfigGroup{ + req := &model.ConfigGroupService{ AppID: "appID", ConfigGroupName: "configname", ServiceID: "serviceID", diff --git a/db/mysql/mysql.go b/db/mysql/mysql.go index e2251a390..1662257db 100644 --- a/db/mysql/mysql.go +++ b/db/mysql/mysql.go @@ -127,7 +127,7 @@ func (m *Manager) RegisterTableModel() { m.models = append(m.models, &model.ServiceSourceConfig{}) m.models = append(m.models, &model.Application{}) 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{}) // gateway m.models = append(m.models, &model.Certificate{})