mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-04 20:57:38 +08:00
commit
67c0d9b40b
@ -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,
|
||||
|
@ -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{
|
||||
|
@ -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()
|
||||
|
@ -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"`
|
||||
}
|
||||
|
||||
|
@ -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 -
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
||||
|
@ -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"`
|
||||
|
@ -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 -
|
||||
|
@ -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",
|
||||
|
@ -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{})
|
||||
|
Loading…
Reference in New Issue
Block a user