delete handle component attributes method

This commit is contained in:
yangk 2021-06-07 16:22:45 +08:00
parent 08fe1db2c8
commit 3dbc68a698
24 changed files with 398 additions and 407 deletions

View File

@ -168,7 +168,7 @@ type ApplicationInterface interface {
DeleteConfigGroup(w http.ResponseWriter, r *http.Request)
ListConfigGroups(w http.ResponseWriter, r *http.Request)
SyncComponent(w http.ResponseWriter, r *http.Request)
SyncComponents(w http.ResponseWriter, r *http.Request)
}
//Gatewayer gateway api interface

View File

@ -322,7 +322,7 @@ func (v2 *V2) applicationRouter() chi.Router {
r.Get("/configgroups", controller.GetManager().ListConfigGroups)
// Synchronize component information, full coverage
r.Post("/components", controller.GetManager().SyncComponent)
r.Post("/components", controller.GetManager().SyncComponents)
return r
}

View File

@ -110,14 +110,13 @@ func (a *ApplicationController) ListConfigGroups(w http.ResponseWriter, r *http.
}
// SyncComponent -
func (a *ApplicationController)SyncComponent(w http.ResponseWriter, r *http.Request){
func (a *ApplicationController)SyncComponents(w http.ResponseWriter, r *http.Request){
var syncComponentReq model.SyncComponentReq
tenant := r.Context().Value(middleware.ContextKey("tenant")).(*dbmodel.Tenants)
appID := r.Context().Value(middleware.ContextKey("app_id")).(string)
app := r.Context().Value(middleware.ContextKey("application")).(*dbmodel.Application)
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &syncComponentReq, nil){
return
}
err := handler.GetApplicationHandler().SyncComponent(tenant, appID, syncComponentReq.Components)
err := handler.GetApplicationHandler().SyncComponents(app, syncComponentReq.Components)
if err != nil {
httputil.ReturnBcodeError(r, w, err)
return

View File

@ -264,12 +264,21 @@ func (a *ApplicationAction) ListConfigGroups(appID string, page, pageSize int) (
}
// SyncComponentConfigGroupRels -
func (a *ApplicationAction) SyncComponentConfigGroupRels(tx *gorm.DB, componentIDs []string, cgservices []dbmodel.ConfigGroupService) error{
func (a *ApplicationAction) SyncComponentConfigGroupRels(tx *gorm.DB, app *dbmodel.Application, components []*model.Component) error{
var (
componentIDs []string
cgservices []*dbmodel.ConfigGroupService
)
for _, component := range components {
if component.AppConfigGroupRels != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, acgr := range component.AppConfigGroupRels {
cgservices = append(cgservices, acgr.DbModel(app.AppID, component.ComponentBase.ComponentID, component.ComponentBase.ComponentAlias))
}
}
}
if err := db.GetManager().AppConfigGroupServiceDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().AppConfigGroupServiceDaoTransactions(tx).CreateOrUpdateConfigGroupServicesInBatch(cgservices); err != nil {
return err
}
return nil
return db.GetManager().AppConfigGroupServiceDaoTransactions(tx).CreateOrUpdateConfigGroupServicesInBatch(cgservices)
}

View File

@ -42,8 +42,8 @@ type ApplicationHandler interface {
DeleteConfigGroup(appID, configGroupName string) error
ListConfigGroups(appID string, page, pageSize int) (*model.ListApplicationConfigGroupResp, error)
SyncComponent(tenant *dbmodel.Tenants, appID string, components []model.Component) error
SyncComponentConfigGroupRels(tx *gorm.DB, componentIDs []string, cgservices []dbmodel.ConfigGroupService) error
SyncComponents(app *dbmodel.Application, components []*model.Component) error
SyncComponentConfigGroupRels(tx *gorm.DB, app *dbmodel.Application, components []*model.Component) error
}
// NewApplicationHandler creates a new Tenant Application Handler.
@ -291,165 +291,50 @@ func (a *ApplicationAction) BatchBindService(appID string, req model.BindService
}
// SyncComponent -
func (a *ApplicationAction) SyncComponent(tenant *dbmodel.Tenants, appID string, components []model.Component) error {
dbComponents := a.HandleComponentAttrs(tenant, appID, components)
func (a *ApplicationAction) SyncComponents(app *dbmodel.Application, components []*model.Component) error {
return db.GetManager().DB().Transaction(func(tx *gorm.DB) error {
if err := GetServiceManager().SyncComponentBasicInfo(tx, tenant.UUID, appID, dbComponents.ComponentIDs, dbComponents.ComponentBases); err != nil {
if err := GetServiceManager().SyncComponentBase(tx, app, components); err != nil {
return err
}
if err := GetGatewayHandler().SyncHTTPRules(tx, dbComponents.NeedOperatedID.HttpRuleComponentIDs, dbComponents.HTTPRules); err != nil {
if err := GetGatewayHandler().SyncHTTPRules(tx, components); err != nil {
return err
}
if err := GetGatewayHandler().SyncTCPRules(tx, dbComponents.NeedOperatedID.TCPRuleComponentIDs, dbComponents.TCPRules); err != nil {
if err := GetGatewayHandler().SyncTCPRules(tx, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentMonitors(tx, dbComponents.NeedOperatedID.MonitorComponentIDs, dbComponents.Monitors); err != nil {
if err := GetServiceManager().SyncComponentMonitors(tx, app, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentPlugins(tx, dbComponents); err != nil {
if err := GetServiceManager().SyncComponentPlugins(tx, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentPorts(tx, dbComponents.NeedOperatedID.PortComponentIDs, dbComponents.Ports); err != nil {
if err := GetServiceManager().SyncComponentPorts(tx, app, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentRelations(tx, dbComponents.NeedOperatedID.RelationComponentIDs, dbComponents.Relations); err != nil {
if err := GetServiceManager().SyncComponentRelations(tx, app, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentEnvs(tx, dbComponents.NeedOperatedID.EnvComponentIDs, dbComponents.Envs); err != nil {
if err := GetServiceManager().SyncComponentEnvs(tx, app, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentVolumeRels(tx, dbComponents.NeedOperatedID.VolumeRelationComponentIDs, dbComponents.VolumeRelations); err != nil {
if err := GetServiceManager().SyncComponentVolumeRels(tx, app, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentVolumes(tx, dbComponents.NeedOperatedID.VolumeComponentIDs, dbComponents.Volumes); err != nil {
if err := GetServiceManager().SyncComponentVolumes(tx, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentConfigFiles(tx, dbComponents.NeedOperatedID.ConfigFileComponentIDs, dbComponents.ConfigFiles); err != nil {
if err := GetServiceManager().SyncComponentConfigFiles(tx, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentProbes(tx, dbComponents.NeedOperatedID.ProbeComponentIDs, dbComponents.Probes); err != nil {
if err := GetServiceManager().SyncComponentProbes(tx, components); err != nil {
return err
}
if err := GetApplicationHandler().SyncComponentConfigGroupRels(tx, dbComponents.NeedOperatedID.ConfigGroupComponentIDs, dbComponents.AppConfigGroupRels); err != nil {
if err := GetApplicationHandler().SyncComponentConfigGroupRels(tx, app, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentLabels(tx, dbComponents.NeedOperatedID.LabelComponentIDs, dbComponents.Labels); err != nil {
if err := GetServiceManager().SyncComponentLabels(tx, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentScaleRules(tx, dbComponents); err != nil {
return err
}
return nil
return GetServiceManager().SyncComponentScaleRules(tx, components)
})
}
// HandleComponentAttrs Convert api model to database model
func (a *ApplicationAction) HandleComponentAttrs(tenant *dbmodel.Tenants, appID string, components []model.Component) dbmodel.Components {
var dbComponents dbmodel.Components
for _, attr := range components {
dbComponents.ComponentIDs = append(dbComponents.ComponentIDs, attr.ComponentBase.ComponentID)
dbComponents.ComponentBases = append(dbComponents.ComponentBases, attr.ComponentBase.DbModel(tenant.UUID, appID))
// handle http rules
if attr.HTTPRules != nil {
dbComponents.NeedOperatedID.HttpRuleComponentIDs = append(dbComponents.NeedOperatedID.HttpRuleComponentIDs, attr.ComponentBase.ComponentID)
for _, httpRule := range attr.HTTPRules {
dbComponents.HTTPRules = append(dbComponents.HTTPRules, httpRule.DbModel(attr.ComponentBase.ComponentID))
}
}
// handle tcp rules
if attr.TCPRules != nil {
dbComponents.NeedOperatedID.TCPRuleComponentIDs = append(dbComponents.NeedOperatedID.TCPRuleComponentIDs, attr.ComponentBase.ComponentID)
for _, tcpRule := range attr.TCPRules {
dbComponents.TCPRules = append(dbComponents.TCPRules, tcpRule.DbModel(attr.ComponentBase.ComponentID))
}
}
// handle monitors
if attr.Monitors != nil {
dbComponents.NeedOperatedID.MonitorComponentIDs = append(dbComponents.NeedOperatedID.MonitorComponentIDs, attr.ComponentBase.ComponentID)
for _, monitor := range attr.Monitors {
dbComponents.Monitors = append(dbComponents.Monitors, monitor.DbModel(tenant.UUID, attr.ComponentBase.ComponentID))
}
}
// handle plugin
if attr.Plugins != nil {
dbComponents.NeedOperatedID.PluginComponentIDs = append(dbComponents.NeedOperatedID.PluginComponentIDs, attr.ComponentBase.ComponentID)
for _, plugin := range attr.Plugins {
dbComponents.TenantServicePluginRelations = append(dbComponents.TenantServicePluginRelations, plugin.DbModel(attr.ComponentBase.ComponentID))
dbComponents.TenantPluginVersionDiscoverConfigs = append(dbComponents.TenantPluginVersionDiscoverConfigs, plugin.VersionConfig.DbModel(attr.ComponentBase.ComponentID, plugin.PluginID))
for _, versionEnv := range plugin.PluginVersionEnvs {
dbComponents.TenantPluginVersionEnvs = append(dbComponents.TenantPluginVersionEnvs, versionEnv.DbModel(attr.ComponentBase.ComponentID, plugin.PluginID))
}
}
}
// handle ports
if attr.Ports != nil {
dbComponents.NeedOperatedID.PortComponentIDs = append(dbComponents.NeedOperatedID.PortComponentIDs, attr.ComponentBase.ComponentID)
for _, port := range attr.Ports {
dbComponents.Ports = append(dbComponents.Ports, port.DbModel(tenant.UUID, attr.ComponentBase.ComponentID))
}
}
// handle depend relations
if attr.Relations != nil {
dbComponents.NeedOperatedID.RelationComponentIDs = append(dbComponents.NeedOperatedID.RelationComponentIDs, attr.ComponentBase.ComponentID)
for _, relation := range attr.Relations {
dbComponents.Relations = append(dbComponents.Relations, relation.DbModel(tenant.UUID, attr.ComponentBase.ComponentID))
}
}
// handle envs
if attr.Envs != nil {
dbComponents.NeedOperatedID.EnvComponentIDs = append(dbComponents.NeedOperatedID.EnvComponentIDs, attr.ComponentBase.ComponentID)
for _, env := range attr.Envs {
dbComponents.Envs = append(dbComponents.Envs, env.DbModel(tenant.UUID, attr.ComponentBase.ComponentID))
}
}
// handle volume_relations
if attr.VolumeRelations != nil {
dbComponents.NeedOperatedID.VolumeRelationComponentIDs = append(dbComponents.NeedOperatedID.VolumeRelationComponentIDs, attr.ComponentBase.ComponentID)
for _, volumeRelation := range attr.VolumeRelations {
dbComponents.VolumeRelations = append(dbComponents.VolumeRelations, volumeRelation.DbModel(tenant.UUID, attr.ComponentBase.ComponentID))
}
}
// handle volumes
if attr.Volumes !=nil{
dbComponents.NeedOperatedID.VolumeComponentIDs = append(dbComponents.NeedOperatedID.VolumeComponentIDs, attr.ComponentBase.ComponentID)
for _, volume := range attr.Volumes {
dbComponents.Volumes = append(dbComponents.Volumes, volume.DbModel(attr.ComponentBase.ComponentID))
}
}
// handle config_files
if attr.ConfigFiles != nil {
dbComponents.NeedOperatedID.ConfigFileComponentIDs = append(dbComponents.NeedOperatedID.ConfigFileComponentIDs, attr.ComponentBase.ComponentID)
for _, configFile := range attr.ConfigFiles {
dbComponents.ConfigFiles = append(dbComponents.ConfigFiles, configFile.DbModel(attr.ComponentBase.ComponentID))
}
}
// handle probes
if attr.Probes != nil {
dbComponents.NeedOperatedID.ProbeComponentIDs = append(dbComponents.NeedOperatedID.ProbeComponentIDs, attr.ComponentBase.ComponentID)
for _, probe := range attr.Probes {
dbComponents.Probes = append(dbComponents.Probes, probe.DbModel(attr.ComponentBase.ComponentID))
}
}
// handle app_config_groups
if attr.AppConfigGroupRels != nil {
dbComponents.NeedOperatedID.ConfigGroupComponentIDs = append(dbComponents.NeedOperatedID.ConfigGroupComponentIDs, attr.ComponentBase.ComponentID)
for _, acgr := range attr.AppConfigGroupRels {
dbComponents.AppConfigGroupRels = append(dbComponents.AppConfigGroupRels, acgr.DbModel(appID, attr.ComponentBase.ComponentID, attr.ComponentBase.ComponentAlias))
}
}
// handle auto_scale_rule
dbComponents.AutoScaleRules = append(dbComponents.AutoScaleRules, attr.AutoScaleRule.DbModel(attr.ComponentBase.ComponentID))
dbComponents.NeedOperatedID.AutoScaleRuleIDs = append(dbComponents.NeedOperatedID.AutoScaleRuleIDs, attr.AutoScaleRule.RuleID)
for _, metric := range attr.AutoScaleRule.RuleMetrics {
dbComponents.AutoScaleRuleMetrics = append(dbComponents.AutoScaleRuleMetrics, metric.DbModel(attr.AutoScaleRule.RuleID))
}
// handle labels
if attr.Labels != nil {
dbComponents.NeedOperatedID.LabelComponentIDs = append(dbComponents.NeedOperatedID.LabelComponentIDs, attr.ComponentBase.ComponentID)
for _, label := range attr.Labels {
dbComponents.Labels = append(dbComponents.Labels, label.DbModel(attr.ComponentBase.ComponentID))
}
}
}
return dbComponents
}

View File

@ -857,22 +857,40 @@ func (g *GatewayAction) listHTTPRuleIDs(componentID string, port int) ([]string,
return ruleIDs, nil
}
func (g *GatewayAction) SyncHTTPRules(tx *gorm.DB, componentIDs []string, httpRules []model.HTTPRule) error {
func (g *GatewayAction) SyncHTTPRules(tx *gorm.DB, components []*apimodel.Component) error {
var (
componentIDs []string
httpRules []*model.HTTPRule
)
for _, component := range components {
if component.HTTPRules != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, httpRule := range component.HTTPRules {
httpRules = append(httpRules, httpRule.DbModel(component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().HTTPRuleDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().HTTPRuleDaoTransactions(tx).CreateOrUpdateHTTPRuleInBatch(httpRules); err != nil {
return err
}
return nil
return db.GetManager().HTTPRuleDaoTransactions(tx).CreateOrUpdateHTTPRuleInBatch(httpRules)
}
func (g *GatewayAction) SyncTCPRules(tx *gorm.DB, componentIDs []string, tcpRules []model.TCPRule) error {
func (g *GatewayAction) SyncTCPRules(tx *gorm.DB, components []*apimodel.Component) error {
var (
componentIDs []string
tcpRules []*model.TCPRule
)
for _, component := range components {
if component.TCPRules != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, tcpRule := range component.TCPRules {
tcpRules = append(tcpRules, tcpRule.DbModel(component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TCPRuleDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TCPRuleDaoTransactions(tx).CreateOrUpdateTCPRuleInBatch(tcpRules); err != nil {
return err
}
return nil
return db.GetManager().TCPRuleDaoTransactions(tx).CreateOrUpdateTCPRuleInBatch(tcpRules)
}

View File

@ -49,6 +49,6 @@ type GatewayHandler interface {
GetGatewayIPs() []IPAndAvailablePort
ListHTTPRulesByCertID(certID string) ([]*dbmodel.HTTPRule, error)
DeleteIngressRulesByComponentPort(tx *gorm.DB, componentID string, port int) error
SyncHTTPRules(tx *gorm.DB,componentIDs []string,httpRules []dbmodel.HTTPRule)error
SyncTCPRules(tx *gorm.DB, componentIDs []string, tcpRules []dbmodel.TCPRule) error
SyncHTTPRules(tx *gorm.DB, components []*apimodel.Component) error
SyncTCPRules(tx *gorm.DB, components []*apimodel.Component) error
}

View File

@ -535,11 +535,12 @@ func (s *ServiceAction) ServiceCreate(sc *api_model.ServiceStruct) error {
}
//set app envs
if len(envs) > 0 {
var batchEnvs []dbmodel.TenantServiceEnvVar
var batchEnvs []*dbmodel.TenantServiceEnvVar
for _, env := range envs {
env := env
env.ServiceID = ts.ServiceID
env.TenantID = ts.TenantID
batchEnvs = append(batchEnvs, env)
batchEnvs = append(batchEnvs, &env)
}
if err := db.GetManager().TenantServiceEnvVarDaoTransactions(tx).CreateOrUpdateEnvsInBatch(batchEnvs); err != nil {
logrus.Errorf("batch add env error, %v", err)
@ -549,11 +550,12 @@ func (s *ServiceAction) ServiceCreate(sc *api_model.ServiceStruct) error {
}
//set app port
if len(ports) > 0 {
var batchPorts []dbmodel.TenantServicesPort
var batchPorts []*dbmodel.TenantServicesPort
for _, port := range ports {
port := port
port.ServiceID = ts.ServiceID
port.TenantID = ts.TenantID
batchPorts = append(batchPorts, port)
batchPorts = append(batchPorts, &port)
}
if err := db.GetManager().TenantServicesPortDaoTransactions(tx).CreateOrUpdatePortsInBatch(batchPorts); err != nil {
logrus.Errorf("batch add port error, %v", err)
@ -1231,14 +1233,23 @@ func (s *ServiceAction) deletePorts(componentID string, ports *api_model.Service
}
// SyncComponentPorts -
func (s *ServiceAction) SyncComponentPorts(tx *gorm.DB, componentsIDs []string, ports []dbmodel.TenantServicesPort) error {
if err := db.GetManager().TenantServicesPortDaoTransactions(tx).DeleteByComponentIDs(componentsIDs); err != nil {
func (s *ServiceAction) SyncComponentPorts(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error {
var (
componentIDs []string
ports []*dbmodel.TenantServicesPort
)
for _, component := range components {
if component.Ports != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, port := range component.Ports {
ports = append(ports, port.DbModel(app.TenantID, component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TenantServicesPortDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServicesPortDaoTransactions(tx).CreateOrUpdatePortsInBatch(ports); err != nil {
return err
}
return nil
return db.GetManager().TenantServicesPortDaoTransactions(tx).CreateOrUpdatePortsInBatch(ports)
}
//PortVar port var
@ -2440,121 +2451,214 @@ func (s *ServiceAction) ListScalingRecords(serviceID string, page, pageSize int)
return records, count, nil
}
func (s *ServiceAction) SyncComponentBasicInfo(tx *gorm.DB, tenantID, appID string, componentIDs []string, components []dbmodel.TenantServices) error {
if err := db.GetManager().TenantServiceDaoTransactions(tx).DeleteByComponentIDs(tenantID, appID, componentIDs); err != nil {
func (s *ServiceAction) SyncComponentBase(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error {
var (
componentIDs []string
dbComponents []*dbmodel.TenantServices
)
for _, component := range components {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
dbComponents = append(dbComponents, component.ComponentBase.DbModel(app.TenantID, app.AppID))
}
if err := db.GetManager().TenantServiceDaoTransactions(tx).DeleteByComponentIDs(app.TenantID, app.AppID, componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceDaoTransactions(tx).CreateOrUpdateComponentsInBatch(components); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceDaoTransactions(tx).CreateOrUpdateComponentsInBatch(dbComponents)
}
func (s *ServiceAction) SyncComponentRelations(tx *gorm.DB, componentIDs []string, relations []dbmodel.TenantServiceRelation) error {
func (s *ServiceAction) SyncComponentRelations(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error {
var (
componentIDs []string
relations []*dbmodel.TenantServiceRelation
)
for _, component := range components {
if component.Relations != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, relation := range component.Relations {
relations = append(relations, relation.DbModel(app.TenantID, component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TenantServiceRelationDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceRelationDaoTransactions(tx).CreateOrUpdateRelationsInBatch(relations); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceRelationDaoTransactions(tx).CreateOrUpdateRelationsInBatch(relations)
}
func (s *ServiceAction) SyncComponentEnvs(tx *gorm.DB, componentIDs []string, envs []dbmodel.TenantServiceEnvVar) error {
func (s *ServiceAction) SyncComponentEnvs(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error {
var (
componentIDs []string
envs []*dbmodel.TenantServiceEnvVar
)
for _, component := range components {
if component.Envs != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, env := range component.Envs {
envs = append(envs, env.DbModel(app.TenantID, component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TenantServiceEnvVarDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceEnvVarDaoTransactions(tx).CreateOrUpdateEnvsInBatch(envs); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceEnvVarDaoTransactions(tx).CreateOrUpdateEnvsInBatch(envs)
}
func (s *ServiceAction) SyncComponentVolumeRels(tx *gorm.DB, componentIDs []string, volRels []dbmodel.TenantServiceMountRelation) error {
func (s *ServiceAction) SyncComponentVolumeRels(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error {
var (
componentIDs []string
volRels []*dbmodel.TenantServiceMountRelation
)
for _, component := range components {
if component.VolumeRelations != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, volumeRelation := range component.VolumeRelations {
volRels = append(volRels, volumeRelation.DbModel(app.TenantID, component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TenantServiceMountRelationDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceMountRelationDaoTransactions(tx).CreateOrUpdateVolumeRelsInBatch(volRels); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceMountRelationDaoTransactions(tx).CreateOrUpdateVolumeRelsInBatch(volRels)
}
func (s *ServiceAction) SyncComponentVolumes(tx *gorm.DB, componentIDs []string, volumes []dbmodel.TenantServiceVolume) error {
func (s *ServiceAction) SyncComponentVolumes(tx *gorm.DB, components []*api_model.Component) error {
var (
deleteComponentIDs []string
deleteVolumeNames []string
createVolumes []dbmodel.TenantServiceVolume
componentIDs []string
volumes []*dbmodel.TenantServiceVolume
)
allVolumes := make(map[string]struct{})
existVolumes := make(map[string]struct{})
// Get related storage based on the component ID of the operation
oldVolumes, err := db.GetManager().TenantServiceVolumeDao().ListVolumesByComponentIDs(componentIDs)
for _, component := range components {
if component.Volumes != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, volume := range component.Volumes {
volumes = append(volumes, volume.DbModel(component.ComponentBase.ComponentID))
}
}
}
existVolumes, err := s.getExistVolumes(componentIDs)
if err != nil {
return err
}
for _, ov := range oldVolumes {
existVolumes[ov.Key()] = struct{}{}
}
// If the incoming storage already exists, update it
for _, volume := range volumes {
allVolumes[volume.Key()] = struct{}{}
if _, ok := existVolumes[volume.Key()]; ok {
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).UpdateModel(&volume); err != nil {
return err
}
continue
}
createVolumes = append(createVolumes, volume)
}
// If the old storage is not in the incoming list, it means it needs to be deleted
for _, ov := range oldVolumes {
if _, ok := allVolumes[ov.Key()]; !ok {
deleteComponentIDs = append(deleteComponentIDs, ov.ServiceID)
deleteVolumeNames = append(deleteVolumeNames, ov.VolumeName)
}
}
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).DeleteByComponentIDVolNames(deleteComponentIDs, deleteVolumeNames); err != nil {
deleteVolumeIDs := s.getDeleteVolumeIDs(existVolumes, volumes)
createOrUpdates := s.getCreateOrUpdateVolumes(existVolumes, volumes)
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).DeleteByVolumeIDs(deleteVolumeIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).CreateOrUpdateVolumesInBatch(createVolumes); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceVolumeDaoTransactions(tx).CreateOrUpdateVolumesInBatch(createOrUpdates)
}
func (s *ServiceAction) SyncComponentConfigFiles(tx *gorm.DB, componentIDs []string, configFiles []dbmodel.TenantServiceConfigFile) error {
func (s *ServiceAction) getExistVolumes(componentIDs []string) (existVolumes map[string]*dbmodel.TenantServiceVolume, err error) {
existVolumes = make(map[string]*dbmodel.TenantServiceVolume)
volumes, err := db.GetManager().TenantServiceVolumeDao().ListVolumesByComponentIDs(componentIDs)
if err != nil {
return nil, err
}
for _, volume := range volumes {
existVolumes[volume.Key()] = volume
}
return existVolumes, nil
}
func (s *ServiceAction) getCreateOrUpdateVolumes(existVolumes map[string]*dbmodel.TenantServiceVolume, incomeVolumes []*dbmodel.TenantServiceVolume) (volumes []*dbmodel.TenantServiceVolume) {
for _, incomeVolume := range incomeVolumes {
if _, ok := existVolumes[incomeVolume.Key()]; ok {
incomeVolume.ID = existVolumes[incomeVolume.Key()].ID
}
volumes = append(volumes, incomeVolume)
}
return volumes
}
func (s *ServiceAction) getDeleteVolumeIDs(existVolumes map[string]*dbmodel.TenantServiceVolume, incomeVolumes []*dbmodel.TenantServiceVolume) (deleteVolumeIDs []uint) {
newVolumes := make(map[string]struct{})
for _, volume := range incomeVolumes {
newVolumes[volume.Key()] = struct{}{}
}
for existKey, existVolume := range existVolumes {
if _, ok := newVolumes[existKey]; !ok {
deleteVolumeIDs = append(deleteVolumeIDs, existVolume.ID)
}
}
return deleteVolumeIDs
}
func (s *ServiceAction) SyncComponentConfigFiles(tx *gorm.DB, components []*api_model.Component) error {
var (
componentIDs []string
configFiles []*dbmodel.TenantServiceConfigFile
)
for _, component := range components {
if component.ConfigFiles != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, configFile := range component.ConfigFiles {
configFiles = append(configFiles, configFile.DbModel(component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).CreateOrUpdateConfigFilesInBatch(configFiles); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceConfigFileDaoTransactions(tx).CreateOrUpdateConfigFilesInBatch(configFiles)
}
func (s *ServiceAction) SyncComponentProbes(tx *gorm.DB, componentIDs []string, probes []dbmodel.TenantServiceProbe) error {
func (s *ServiceAction) SyncComponentProbes(tx *gorm.DB, components []*api_model.Component) error {
var (
componentIDs []string
probes []*dbmodel.TenantServiceProbe
)
for _, component := range components {
if component.Probes != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, probe := range component.Probes {
probes = append(probes, probe.DbModel(component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().ServiceProbeDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().ServiceProbeDaoTransactions(tx).CreateOrUpdateProbesInBatch(probes); err != nil {
return err
}
return nil
return db.GetManager().ServiceProbeDaoTransactions(tx).CreateOrUpdateProbesInBatch(probes)
}
func (s *ServiceAction) SyncComponentLabels(tx *gorm.DB, componentIDs []string, labels []dbmodel.TenantServiceLable) error {
func (s *ServiceAction) SyncComponentLabels(tx *gorm.DB, components []*api_model.Component) error {
var (
componentIDs []string
labels []*dbmodel.TenantServiceLable
)
for _, component := range components {
if component.Labels != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, label := range component.Labels {
labels = append(labels, label.DbModel(component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TenantServiceLabelDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceLabelDaoTransactions(tx).CreateOrUpdateLabelsInBatch(labels); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceLabelDaoTransactions(tx).CreateOrUpdateLabelsInBatch(labels)
}
func (s *ServiceAction) SyncComponentPlugins(tx *gorm.DB, dbComponents dbmodel.Components) error {
componentIDs := dbComponents.NeedOperatedID.PluginComponentIDs
func (s *ServiceAction) SyncComponentPlugins(tx *gorm.DB, components []*api_model.Component) error {
var (
componentIDs []string
pluginRelations []*dbmodel.TenantServicePluginRelation
pluginVersionEnvs []*dbmodel.TenantPluginVersionEnv
pluginVersionConfigs []*dbmodel.TenantPluginVersionDiscoverConfig
)
for _, component := range components {
if component.Plugins != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, plugin := range component.Plugins {
pluginRelations = append(pluginRelations, plugin.DbModel(component.ComponentBase.ComponentID))
pluginVersionConfigs = append(pluginVersionConfigs, plugin.VersionConfig.DbModel(component.ComponentBase.ComponentID, plugin.PluginID))
for _, versionEnv := range plugin.PluginVersionEnvs {
pluginVersionEnvs = append(pluginVersionEnvs, versionEnv.DbModel(component.ComponentBase.ComponentID, plugin.PluginID))
}
}
}
}
// TODO: plugin stream port delete and create
if err := db.GetManager().TenantServicePluginRelationDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
@ -2566,34 +2670,41 @@ func (s *ServiceAction) SyncComponentPlugins(tx *gorm.DB, dbComponents dbmodel.C
return err
}
if err := db.GetManager().TenantServicePluginRelationDaoTransactions(tx).CreateOrUpdatePluginRelsInBatch(dbComponents.TenantServicePluginRelations); err != nil {
if err := db.GetManager().TenantServicePluginRelationDaoTransactions(tx).CreateOrUpdatePluginRelsInBatch(pluginRelations); err != nil {
return err
}
if err := db.GetManager().TenantPluginVersionENVDaoTransactions(tx).CreateOrUpdatePluginVersionEnvsInBatch(dbComponents.TenantPluginVersionEnvs); err != nil {
if err := db.GetManager().TenantPluginVersionENVDaoTransactions(tx).CreateOrUpdatePluginVersionEnvsInBatch(pluginVersionEnvs); err != nil {
return err
}
if err := db.GetManager().TenantPluginVersionConfigDaoTransactions(tx).CreateOrUpdatePluginVersionConfigsInBatch(dbComponents.TenantPluginVersionDiscoverConfigs); err != nil {
return err
}
return nil
return db.GetManager().TenantPluginVersionConfigDaoTransactions(tx).CreateOrUpdatePluginVersionConfigsInBatch(pluginVersionConfigs)
}
func (s *ServiceAction) SyncComponentScaleRules(tx *gorm.DB, dbComponents dbmodel.Components) error {
if err := db.GetManager().TenantServceAutoscalerRulesDaoTransactions(tx).DeleteByComponentIDs(dbComponents.ComponentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServceAutoscalerRuleMetricsDaoTransactions(tx).DeleteByRuleIDs(dbComponents.NeedOperatedID.AutoScaleRuleIDs); err != nil {
return err
}
func (s *ServiceAction) SyncComponentScaleRules(tx *gorm.DB, components []*api_model.Component) error {
var (
componentIDs []string
autoScaleRuleIDs []string
autoScaleRules []*dbmodel.TenantServiceAutoscalerRules
autoScaleRuleMetrics []*dbmodel.TenantServiceAutoscalerRuleMetrics
)
for _, component := range components {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
autoScaleRuleIDs = append(autoScaleRuleIDs, component.AutoScaleRule.RuleID)
autoScaleRules = append(autoScaleRules, component.AutoScaleRule.DbModel(component.ComponentBase.ComponentID))
if err := db.GetManager().TenantServceAutoscalerRulesDaoTransactions(tx).CreateOrUpdateScaleRulesInBatch(dbComponents.AutoScaleRules); err != nil {
for _, metric := range component.AutoScaleRule.RuleMetrics {
autoScaleRuleMetrics = append(autoScaleRuleMetrics, metric.DbModel(component.AutoScaleRule.RuleID))
}
}
if err := db.GetManager().TenantServceAutoscalerRulesDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServceAutoscalerRuleMetricsDaoTransactions(tx).CreateOrUpdateScaleRuleMetricsInBatch(dbComponents.AutoScaleRuleMetrics); err != nil {
if err := db.GetManager().TenantServceAutoscalerRuleMetricsDaoTransactions(tx).DeleteByRuleIDs(autoScaleRuleIDs); err != nil {
return err
}
return nil
if err := db.GetManager().TenantServceAutoscalerRulesDaoTransactions(tx).CreateOrUpdateScaleRulesInBatch(autoScaleRules); err != nil {
return err
}
return db.GetManager().TenantServceAutoscalerRuleMetricsDaoTransactions(tx).CreateOrUpdateScaleRuleMetricsInBatch(autoScaleRuleMetrics)
}
//TransStatus trans service status

View File

@ -89,16 +89,16 @@ type ServiceHandler interface {
DeleteServiceMonitor(tenantID, serviceID, name string) (*dbmodel.TenantServiceMonitor, error)
AddServiceMonitor(tenantID, serviceID string, add api_model.AddServiceMonitorRequestStruct) (*dbmodel.TenantServiceMonitor, error)
SyncComponentBasicInfo(tx *gorm.DB, tenantID, appID string, componentIDs []string, components []dbmodel.TenantServices) error
SyncComponentMonitors(tx *gorm.DB, componentIDs []string, monitors []dbmodel.TenantServiceMonitor) error
SyncComponentPorts(tx *gorm.DB, componentsIDs []string, ports []dbmodel.TenantServicesPort) error
SyncComponentRelations(tx *gorm.DB, componentIDs []string, relations []dbmodel.TenantServiceRelation) error
SyncComponentEnvs(tx *gorm.DB, componentIDs []string, envs []dbmodel.TenantServiceEnvVar) error
SyncComponentVolumeRels(tx *gorm.DB, componentIDs []string, volRels []dbmodel.TenantServiceMountRelation) error
SyncComponentVolumes(tx *gorm.DB, componentIDs []string, volumes []dbmodel.TenantServiceVolume) error
SyncComponentConfigFiles(tx *gorm.DB, componentIDs []string, configFiles []dbmodel.TenantServiceConfigFile) error
SyncComponentProbes(tx *gorm.DB, componentIDs []string, probes []dbmodel.TenantServiceProbe) error
SyncComponentLabels(tx *gorm.DB, componentIDs []string, labels []dbmodel.TenantServiceLable) error
SyncComponentPlugins(tx *gorm.DB, components dbmodel.Components) error
SyncComponentScaleRules(tx *gorm.DB, components dbmodel.Components) error
SyncComponentBase(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error
SyncComponentMonitors(tx *gorm.DB,app *dbmodel.Application, components []*api_model.Component) error
SyncComponentPorts(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error
SyncComponentRelations(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error
SyncComponentEnvs(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error
SyncComponentVolumeRels(tx *gorm.DB, app *dbmodel.Application, components []*api_model.Component) error
SyncComponentVolumes(tx *gorm.DB, components []*api_model.Component) error
SyncComponentConfigFiles(tx *gorm.DB, components []*api_model.Component) error
SyncComponentProbes(tx *gorm.DB, components []*api_model.Component) error
SyncComponentLabels(tx *gorm.DB, components []*api_model.Component) error
SyncComponentPlugins(tx *gorm.DB, components []*api_model.Component) error
SyncComponentScaleRules(tx *gorm.DB, components []*api_model.Component) error
}

View File

@ -58,12 +58,21 @@ func (s *ServiceAction) AddServiceMonitor(tenantID, serviceID string, add api_mo
return &sm, db.GetManager().TenantServiceMonitorDao().AddModel(&sm)
}
func (s *ServiceAction) SyncComponentMonitors(tx *gorm.DB, componentIDs []string, monitors []dbmodel.TenantServiceMonitor) error {
func (s *ServiceAction) SyncComponentMonitors(tx *gorm.DB,app *dbmodel.Application, components []*api_model.Component) error {
var (
componentIDs []string
monitors []*dbmodel.TenantServiceMonitor
)
for _, component := range components {
if component.Monitors != nil {
componentIDs = append(componentIDs, component.ComponentBase.ComponentID)
for _, monitor := range component.Monitors {
monitors = append(monitors, monitor.DbModel(app.TenantID, component.ComponentBase.ComponentID))
}
}
}
if err := db.GetManager().TenantServiceMonitorDaoTransactions(tx).DeleteByComponentIDs(componentIDs); err != nil {
return err
}
if err := db.GetManager().TenantServiceMonitorDaoTransactions(tx).CreateOrUpdateMonitorInBatch(monitors); err != nil {
return err
}
return nil
return db.GetManager().TenantServiceMonitorDaoTransactions(tx).CreateOrUpdateMonitorInBatch(monitors)
}

View File

@ -62,8 +62,8 @@ type AutoScalerRule struct {
RuleMetrics []RuleMetric `json:"metrics"`
}
func (a AutoScalerRule) DbModel(componentID string) dbmodel.TenantServiceAutoscalerRules {
return dbmodel.TenantServiceAutoscalerRules{
func (a AutoScalerRule) DbModel(componentID string) *dbmodel.TenantServiceAutoscalerRules {
return &dbmodel.TenantServiceAutoscalerRules{
RuleID: a.RuleID,
ServiceID: componentID,
MinReplicas: a.MinReplicas,
@ -80,8 +80,8 @@ type RuleMetric struct {
MetricTargetValue int `json:"metric_target_value"`
}
func (r RuleMetric) DbModel(ruleID string) dbmodel.TenantServiceAutoscalerRuleMetrics {
return dbmodel.TenantServiceAutoscalerRuleMetrics{
func (r RuleMetric) DbModel(ruleID string) *dbmodel.TenantServiceAutoscalerRuleMetrics {
return &dbmodel.TenantServiceAutoscalerRuleMetrics{
RuleID: ruleID,
MetricsType: r.MetricsType,
MetricsName: r.MetricsName,

View File

@ -73,8 +73,8 @@ type ComponentBase struct {
}
// DbModel -
func (c *ComponentBase) DbModel(tenantID, appID string) dbmodel.TenantServices {
return dbmodel.TenantServices{
func (c *ComponentBase) DbModel(tenantID, appID string) *dbmodel.TenantServices {
return &dbmodel.TenantServices{
TenantID: tenantID,
ServiceID: c.ComponentID,
ServiceAlias: c.ComponentAlias,
@ -102,8 +102,8 @@ type TenantComponentRelation struct {
DependOrder int `json:"dep_order"`
}
func (t *TenantComponentRelation) DbModel(tenantID, componentID string) dbmodel.TenantServiceRelation {
return dbmodel.TenantServiceRelation{
func (t *TenantComponentRelation) DbModel(tenantID, componentID string) *dbmodel.TenantServiceRelation {
return &dbmodel.TenantServiceRelation{
TenantID: tenantID,
ServiceID: componentID,
DependServiceID: t.DependServiceID,
@ -117,8 +117,8 @@ type ComponentConfigFile struct {
FileContent string `json:"filename"`
}
func (c *ComponentConfigFile) DbModel(componentID string) dbmodel.TenantServiceConfigFile {
return dbmodel.TenantServiceConfigFile{
func (c *ComponentConfigFile) DbModel(componentID string) *dbmodel.TenantServiceConfigFile {
return &dbmodel.TenantServiceConfigFile{
ServiceID: componentID,
VolumeName: c.VolumeName,
FileContent: c.FileContent,
@ -133,8 +133,8 @@ type VolumeRelation struct {
VolumeType string `json:"volume_type"`
}
func (v *VolumeRelation) DbModel(tenantID, componentID string) dbmodel.TenantServiceMountRelation {
return dbmodel.TenantServiceMountRelation{
func (v *VolumeRelation) DbModel(tenantID, componentID string) *dbmodel.TenantServiceMountRelation {
return &dbmodel.TenantServiceMountRelation{
TenantID: tenantID,
ServiceID: componentID,
DependServiceID: v.DependServiceID,
@ -161,8 +161,8 @@ type ComponentVolume struct {
VolumeProviderName string `json:"volume_provider_name"`
}
func (v *ComponentVolume) DbModel(componentID string) dbmodel.TenantServiceVolume {
return dbmodel.TenantServiceVolume{
func (v *ComponentVolume) DbModel(componentID string) *dbmodel.TenantServiceVolume {
return &dbmodel.TenantServiceVolume{
ServiceID: componentID,
Category: v.Category,
VolumeType: v.VolumeType,
@ -185,8 +185,8 @@ type ComponentLabel struct {
LabelValue string `json:"label_value"`
}
func (l *ComponentLabel) DbModel(componentID string) dbmodel.TenantServiceLable {
return dbmodel.TenantServiceLable{
func (l *ComponentLabel) DbModel(componentID string) *dbmodel.TenantServiceLable {
return &dbmodel.TenantServiceLable{
ServiceID: componentID,
LabelKey: l.LabelKey,
LabelValue: l.LabelValue,
@ -214,5 +214,5 @@ type Component struct {
// SyncComponentReq -
type SyncComponentReq struct {
Components []Component `json:"components"`
Components []*Component `json:"-"`
}

View File

@ -40,8 +40,8 @@ type AddHTTPRuleStruct struct {
RuleExtensions []*RuleExtensionStruct `json:"rule_extensions"`
}
func (h *AddHTTPRuleStruct) DbModel(serviceID string) dbmodel.HTTPRule {
return dbmodel.HTTPRule{
func (h *AddHTTPRuleStruct) DbModel(serviceID string) *dbmodel.HTTPRule {
return &dbmodel.HTTPRule{
UUID: h.HTTPRuleID,
ServiceID: serviceID,
ContainerPort: h.ContainerPort,
@ -92,8 +92,8 @@ type AddTCPRuleStruct struct {
RuleExtensions []*RuleExtensionStruct `json:"rule_extensions"`
}
func (a *AddTCPRuleStruct) DbModel(serviceID string) dbmodel.TCPRule {
return dbmodel.TCPRule{
func (a *AddTCPRuleStruct) DbModel(serviceID string) *dbmodel.TCPRule {
return &dbmodel.TCPRule{
UUID: a.TCPRuleID,
ServiceID: serviceID,
ContainerPort: a.ContainerPort,

View File

@ -1262,8 +1262,8 @@ type AddTenantServiceEnvVar struct {
Scope string `validate:"scope|in:outer,inner,both,build" json:"scope"`
}
func (a *AddTenantServiceEnvVar) DbModel(tenantID, componentID string) dbmodel.TenantServiceEnvVar {
return dbmodel.TenantServiceEnvVar{
func (a *AddTenantServiceEnvVar) DbModel(tenantID, componentID string) *dbmodel.TenantServiceEnvVar {
return &dbmodel.TenantServiceEnvVar{
TenantID: tenantID,
ServiceID: componentID,
Name: a.Name,
@ -1307,8 +1307,8 @@ type TenantServicesPort struct {
IsOuterService bool `gorm:"column:is_outer_service" validate:"is_outer_service|bool" json:"is_outer_service"`
}
func (p *TenantServicesPort) DbModel(tenantID, componentID string) dbmodel.TenantServicesPort {
return dbmodel.TenantServicesPort{
func (p *TenantServicesPort) DbModel(tenantID, componentID string) *dbmodel.TenantServicesPort {
return &dbmodel.TenantServicesPort{
TenantID: tenantID,
ServiceID: componentID,
ContainerPort: p.ContainerPort,
@ -1389,8 +1389,8 @@ type ServiceProbe struct {
FailureAction string `json:"failure_action" validate:"failure_action"`
}
func (p *ServiceProbe) DbModel(componentID string) dbmodel.TenantServiceProbe {
return dbmodel.TenantServiceProbe{
func (p *ServiceProbe) DbModel(componentID string) *dbmodel.TenantServiceProbe {
return &dbmodel.TenantServiceProbe{
ServiceID: componentID,
Cmd: p.Cmd,
FailureThreshold: p.FailureThreshold,
@ -1877,8 +1877,8 @@ type AppConfigGroupRelations struct {
ConfigGroupName string `json:"config_group_name"`
}
func (a *AppConfigGroupRelations) DbModel(appID, serviceID, serviceAlias string) dbmodel.ConfigGroupService {
return dbmodel.ConfigGroupService{
func (a *AppConfigGroupRelations) DbModel(appID, serviceID, serviceAlias string) *dbmodel.ConfigGroupService {
return &dbmodel.ConfigGroupService{
AppID: appID,
ConfigGroupName: a.ConfigGroupName,
ServiceID: serviceID,

View File

@ -450,8 +450,8 @@ type PluginVersionEnv struct {
EnvValue string `json:"env_value" validate:"env_value"`
}
func (p *PluginVersionEnv) DbModel(componentID, pluginID string) dbmodel.TenantPluginVersionEnv {
return dbmodel.TenantPluginVersionEnv{
func (p *PluginVersionEnv) DbModel(componentID, pluginID string) *dbmodel.TenantPluginVersionEnv {
return &dbmodel.TenantPluginVersionEnv{
ServiceID: componentID,
PluginID: pluginID,
EnvName: p.EnvName,
@ -464,8 +464,8 @@ type TenantPluginVersionConfig struct {
ConfigStr string `json:"config_str" validate:"config_str"`
}
func (p *TenantPluginVersionConfig) DbModel(componentID, pluginID string) dbmodel.TenantPluginVersionDiscoverConfig {
return dbmodel.TenantPluginVersionDiscoverConfig{
func (p *TenantPluginVersionConfig) DbModel(componentID, pluginID string) *dbmodel.TenantPluginVersionDiscoverConfig {
return &dbmodel.TenantPluginVersionDiscoverConfig{
ServiceID: componentID,
PluginID: pluginID,
ConfigStr: p.ConfigStr,
@ -484,8 +484,8 @@ type ComponentPlugin struct {
PluginVersionEnvs []PluginVersionEnv `json:"tenant_plugin_version_envs"`
}
func (p *ComponentPlugin) DbModel(componentID string) dbmodel.TenantServicePluginRelation {
return dbmodel.TenantServicePluginRelation{
func (p *ComponentPlugin) DbModel(componentID string) *dbmodel.TenantServicePluginRelation {
return &dbmodel.TenantServicePluginRelation{
VersionID: p.VersionID,
ServiceID: componentID,
PluginID: p.PluginID,

View File

@ -26,8 +26,8 @@ type AddServiceMonitorRequestStruct struct {
Interval string `json:"interval" validate:"interval|required"`
}
func (a *AddServiceMonitorRequestStruct) DbModel(tenantID, serviceID string) dbmodel.TenantServiceMonitor {
return dbmodel.TenantServiceMonitor{
func (a *AddServiceMonitorRequestStruct) DbModel(tenantID, serviceID string) *dbmodel.TenantServiceMonitor {
return &dbmodel.TenantServiceMonitor{
Name: a.Name,
TenantID: tenantID,
ServiceID: serviceID,

View File

@ -92,7 +92,7 @@ type AppConfigGroupServiceDao interface {
DeleteConfigGroupService(appID, configGroupName string) error
DeleteEffectiveServiceByServiceID(serviceID string) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateConfigGroupServicesInBatch(cgservices []model.ConfigGroupService) error
CreateOrUpdateConfigGroupServicesInBatch(cgservices []*model.ConfigGroupService) error
}
//AppConfigGroupItemDao Application config item group Dao
@ -147,7 +147,7 @@ type TenantServiceDao interface {
GetServiceTypeByID(serviceID string) (*model.TenantServices, error)
ListByAppID(appID string) ([]*model.TenantServices, error)
BindAppByServiceIDs(appID string, serviceIDs []string) error
CreateOrUpdateComponentsInBatch(components []model.TenantServices) error
CreateOrUpdateComponentsInBatch(components []*model.TenantServices) error
DeleteByComponentIDs(tenantID, appID string, componentIDs []string) error
}
@ -176,7 +176,7 @@ type TenantServicesPortDao interface {
DelByServiceID(sid string) error
ListInnerPortsByServiceIDs(serviceIDs []string) ([]*model.TenantServicesPort, error)
ListByK8sServiceNames(serviceIDs []string) ([]*model.TenantServicesPort, error)
CreateOrUpdatePortsInBatch(ports []model.TenantServicesPort) error
CreateOrUpdatePortsInBatch(ports []*model.TenantServicesPort) error
DeleteByComponentIDs(componentIDs []string) error
}
@ -225,7 +225,7 @@ type TenantPluginVersionEnvDao interface {
ListByServiceID(serviceID string) ([]*model.TenantPluginVersionEnv, error)
GetVersionEnvByEnvName(serviceID, pluginID, envName string) (*model.TenantPluginVersionEnv, error)
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdatePluginVersionEnvsInBatch(versionEnvs []model.TenantPluginVersionEnv) error
CreateOrUpdatePluginVersionEnvsInBatch(versionEnvs []*model.TenantPluginVersionEnv) error
}
//TenantPluginVersionConfigDao service plugin config that can be dynamic discovery dao interface
@ -236,7 +236,7 @@ type TenantPluginVersionConfigDao interface {
DeletePluginConfig(serviceID, pluginID string) error
DeletePluginConfigByServiceID(serviceID string) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdatePluginVersionConfigsInBatch(versionConfigs []model.TenantPluginVersionDiscoverConfig) error
CreateOrUpdatePluginVersionConfigsInBatch(versionConfigs []*model.TenantPluginVersionDiscoverConfig) error
}
//TenantServicePluginRelationDao TenantServicePluginRelationDao
@ -250,7 +250,7 @@ type TenantServicePluginRelationDao interface {
CheckSomeModelPluginByServiceID(serviceID, pluginModel string) (bool, error)
CheckSomeModelLikePluginByServiceID(serviceID, pluginModel string) (bool, error)
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdatePluginRelsInBatch(relations []model.TenantServicePluginRelation) error
CreateOrUpdatePluginRelsInBatch(relations []*model.TenantServicePluginRelation) error
}
//TenantServiceRelationDao TenantServiceRelationDao
@ -264,7 +264,7 @@ type TenantServiceRelationDao interface {
DELRelationsByServiceID(serviceID string) error
DeleteRelationByDepID(serviceID, depID string) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateRelationsInBatch(relations []model.TenantServiceRelation) error
CreateOrUpdateRelationsInBatch(relations []*model.TenantServiceRelation) error
}
//TenantServicesStreamPluginPortDao TenantServicesStreamPluginPortDao
@ -301,7 +301,7 @@ type TenantServiceEnvVarDao interface {
GetEnv(serviceID, envName string) (*model.TenantServiceEnvVar, error)
DELServiceEnvsByServiceID(serviceID string) error
DelByServiceIDAndScope(sid, scope string) error
CreateOrUpdateEnvsInBatch(envs []model.TenantServiceEnvVar) error
CreateOrUpdateEnvsInBatch(envs []*model.TenantServiceEnvVar) error
DeleteByComponentIDs(componentIDs []string) error
}
@ -313,7 +313,7 @@ type TenantServiceMountRelationDao interface {
DELTenantServiceMountRelationByServiceID(serviceID string) error
DElTenantServiceMountRelationByDepService(serviceID, depServiceID string) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateVolumeRelsInBatch(volRels []model.TenantServiceMountRelation) error
CreateOrUpdateVolumeRelsInBatch(volRels []*model.TenantServiceMountRelation) error
}
//TenantServiceVolumeDao TenantServiceVolumeDao
@ -328,8 +328,8 @@ type TenantServiceVolumeDao interface {
GetVolumeByID(id int) (*model.TenantServiceVolume, error)
DelShareableBySID(sid string) error
ListVolumesByComponentIDs(componentIDs []string) ([]*model.TenantServiceVolume, error)
DeleteByComponentIDVolNames(componentIDs, volumeNames []string) error
CreateOrUpdateVolumesInBatch(volumes []model.TenantServiceVolume) error
DeleteByVolumeIDs(volumeIDs []uint) error
CreateOrUpdateVolumesInBatch(volumes []*model.TenantServiceVolume) error
}
//TenantServiceConfigFileDao tenant service config file dao interface
@ -340,7 +340,7 @@ type TenantServiceConfigFileDao interface {
DelByVolumeID(sid string, volumeName string) error
DelByServiceID(sid string) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateConfigFilesInBatch(configFiles []model.TenantServiceConfigFile) error
CreateOrUpdateConfigFilesInBatch(configFiles []*model.TenantServiceConfigFile) error
}
//TenantServiceLBMappingPortDao vs lb mapping port dao
@ -373,7 +373,7 @@ type TenantServiceLabelDao interface {
GetLabelByNodeSelectorKey(serviceID string, labelValue string) (*model.TenantServiceLable, error)
GetPrivilegedLabel(serviceID string) (*model.TenantServiceLable, error)
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateLabelsInBatch(labels []model.TenantServiceLable) error
CreateOrUpdateLabelsInBatch(labels []*model.TenantServiceLable) error
}
//LocalSchedulerDao 本地调度信息
@ -391,7 +391,7 @@ type ServiceProbeDao interface {
DELServiceProbesByServiceID(serviceID string) error
DelByServiceID(sid string) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateProbesInBatch(probes []model.TenantServiceProbe) error
CreateOrUpdateProbesInBatch(probes []*model.TenantServiceProbe) error
}
//CodeCheckResultDao CodeCheckResultDao
@ -505,7 +505,7 @@ type HTTPRuleDao interface {
ListByCertID(certID string) ([]*model.HTTPRule, error)
DeleteByComponentPort(componentID string, port int) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateHTTPRuleInBatch(httpRules []model.HTTPRule) error
CreateOrUpdateHTTPRuleInBatch(httpRules []*model.HTTPRule) error
}
// TCPRuleDao -
@ -520,7 +520,7 @@ type TCPRuleDao interface {
GetUsedPortsByIP(ip string) ([]*model.TCPRule, error)
DeleteByComponentPort(componentID string, port int) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateTCPRuleInBatch(tcpRules []model.TCPRule) error
CreateOrUpdateTCPRuleInBatch(tcpRules []*model.TCPRule) error
}
// EndpointsDao is an interface for defining method
@ -558,7 +558,7 @@ type TenantServceAutoscalerRulesDao interface {
ListByServiceID(serviceID string) ([]*model.TenantServiceAutoscalerRules, error)
ListEnableOnesByServiceID(serviceID string) ([]*model.TenantServiceAutoscalerRules, error)
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateScaleRulesInBatch(rules []model.TenantServiceAutoscalerRules) error
CreateOrUpdateScaleRulesInBatch(rules []*model.TenantServiceAutoscalerRules) error
}
// TenantServceAutoscalerRuleMetricsDao -
@ -568,7 +568,7 @@ type TenantServceAutoscalerRuleMetricsDao interface {
ListByRuleID(ruleID string) ([]*model.TenantServiceAutoscalerRuleMetrics, error)
DeleteByRuleID(ruldID string) error
DeleteByRuleIDs(ruleIDs []string) error
CreateOrUpdateScaleRuleMetricsInBatch(metrics []model.TenantServiceAutoscalerRuleMetrics) error
CreateOrUpdateScaleRuleMetricsInBatch(metrics []*model.TenantServiceAutoscalerRuleMetrics) error
}
// TenantServiceScalingRecordsDao -
@ -587,5 +587,5 @@ type TenantServiceMonitorDao interface {
DeleteServiceMonitor(mo *model.TenantServiceMonitor) error
DeleteServiceMonitorByServiceID(serviceID string) error
DeleteByComponentIDs(componentIDs []string) error
CreateOrUpdateMonitorInBatch(monitors []model.TenantServiceMonitor) error
CreateOrUpdateMonitorInBatch(monitors []*model.TenantServiceMonitor) error
}

View File

@ -619,43 +619,3 @@ func (t *TenantServiceScalingRecords) TableName() string {
type ServiceID struct {
ServiceID string `gorm:"column:service_id" json:"-"`
}
type Components struct {
NeedOperatedID NeedOperatedID
ComponentIDs []string `json:"-"`
ComponentBases []TenantServices `json:"component_bases"`
HTTPRules []HTTPRule `json:"http_rules"`
TCPRules []TCPRule `json:"tcp_rules"`
Monitors []TenantServiceMonitor `json:"monitors"`
Ports []TenantServicesPort `json:"ports"`
Relations []TenantServiceRelation `json:"relations"`
Envs []TenantServiceEnvVar `json:"envs"`
Probes []TenantServiceProbe `json:"probes"`
AppConfigGroupRels []ConfigGroupService `json:"app_config_groups"`
Labels []TenantServiceLable `json:"labels"`
TenantServicePluginRelations []TenantServicePluginRelation `json:"plugins"`
TenantPluginVersionEnvs []TenantPluginVersionEnv `json:"-"`
TenantPluginVersionDiscoverConfigs []TenantPluginVersionDiscoverConfig `json:"-"`
AutoScaleRules []TenantServiceAutoscalerRules `json:"auto_scale_rule"`
AutoScaleRuleMetrics []TenantServiceAutoscalerRuleMetrics `json:"-"`
ConfigFiles []TenantServiceConfigFile `json:"config_files"`
VolumeRelations []TenantServiceMountRelation `json:"volume_relations"`
Volumes []TenantServiceVolume `json:"volumes"`
}
type NeedOperatedID struct {
HttpRuleComponentIDs []string
TCPRuleComponentIDs []string
MonitorComponentIDs []string
PortComponentIDs []string
RelationComponentIDs []string
EnvComponentIDs []string
ProbeComponentIDs []string
ConfigGroupComponentIDs []string
LabelComponentIDs []string
PluginComponentIDs []string
AutoScaleRuleIDs []string
ConfigFileComponentIDs []string
VolumeRelationComponentIDs []string
VolumeComponentIDs []string
}

View File

@ -119,10 +119,10 @@ func (a *AppConfigGroupServiceDaoImpl) DeleteByComponentIDs(componentIDs []strin
}
// CreateOrUpdateConfigGroupServicesInBatch -
func (a *AppConfigGroupServiceDaoImpl) CreateOrUpdateConfigGroupServicesInBatch(cgservices []model.ConfigGroupService) error {
func (a *AppConfigGroupServiceDaoImpl) CreateOrUpdateConfigGroupServicesInBatch(cgservices []*model.ConfigGroupService) error {
var objects []interface{}
for _, cgs := range cgservices {
objects = append(objects, cgs)
objects = append(objects, *cgs)
}
if err := gormbulkups.BulkUpsert(a.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update config group services in batch")

View File

@ -281,10 +281,10 @@ func (h *HTTPRuleDaoImpl) DeleteByComponentIDs(componentIDs []string) error{
}
// CreateOrUpdateHTTPRuleInBatch Batch insert or update http rule
func (h *HTTPRuleDaoImpl) CreateOrUpdateHTTPRuleInBatch(httpRules []model.HTTPRule) error {
func (h *HTTPRuleDaoImpl) CreateOrUpdateHTTPRuleInBatch(httpRules []*model.HTTPRule) error {
var objects []interface{}
for _, httpRule := range httpRules {
objects = append(objects, httpRule)
objects = append(objects, *httpRule)
}
if err := gormbulkups.BulkUpsert(h.DB, objects, 2000); err != nil {
return errors.Wrap(err, "create or update http rule in batch")
@ -412,10 +412,10 @@ func (t *TCPRuleDaoTmpl) DeleteByComponentIDs(componentIDs []string) error{
}
// CreateOrUpdateTCPRuleInBatch Batch insert or update http rule
func (t *TCPRuleDaoTmpl) CreateOrUpdateTCPRuleInBatch(tcpRules []model.TCPRule) error {
func (t *TCPRuleDaoTmpl) CreateOrUpdateTCPRuleInBatch(tcpRules []*model.TCPRule) error {
var objects []interface{}
for _, tcpRule := range tcpRules {
objects = append(objects, tcpRule)
objects = append(objects, *tcpRule)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return errors.Wrap(err, "create or update tcp rule in batch")

View File

@ -121,10 +121,10 @@ func (t *ServiceProbeDaoImpl) DeleteByComponentIDs(componentIDs []string) error
}
// CreateOrUpdateProbesInBatch -
func (t *ServiceProbeDaoImpl) CreateOrUpdateProbesInBatch(probes []model.TenantServiceProbe) error {
func (t *ServiceProbeDaoImpl) CreateOrUpdateProbesInBatch(probes []*model.TenantServiceProbe) error {
var objects []interface{}
for _, probe := range probes {
objects = append(objects, probe)
objects = append(objects, *probe)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update probe in batch")

View File

@ -58,10 +58,10 @@ func (t *TenantServiceMonitorDaoImpl) DeleteByComponentIDs(componentIDs []string
}
//CreateOrUpdateMonitorInBatch -
func (t *TenantServiceMonitorDaoImpl) CreateOrUpdateMonitorInBatch(monitors []model.TenantServiceMonitor) error {
func (t *TenantServiceMonitorDaoImpl) CreateOrUpdateMonitorInBatch(monitors []*model.TenantServiceMonitor) error {
var objects []interface{}
for _, monitor := range monitors {
objects = append(objects, monitor)
objects = append(objects, *monitor)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update component monitors in batch")

View File

@ -405,10 +405,10 @@ func (t *PluginVersionEnvDaoImpl) DeleteByComponentIDs(componentIDs []string) er
}
// CreateOrUpdatePluginVersionEnvsInBatch -
func (t *PluginVersionEnvDaoImpl) CreateOrUpdatePluginVersionEnvsInBatch(versionEnvs []model.TenantPluginVersionEnv) error {
func (t *PluginVersionEnvDaoImpl) CreateOrUpdatePluginVersionEnvsInBatch(versionEnvs []*model.TenantPluginVersionEnv) error {
var objects []interface{}
for _, env := range versionEnvs {
objects = append(objects, env)
objects = append(objects, *env)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update plugin version env in batch")
@ -491,10 +491,10 @@ func (t *PluginVersionConfigDaoImpl) DeleteByComponentIDs(componentIDs []string)
}
// CreateOrUpdatePluginVersionConfigsInBatch -
func (t *PluginVersionConfigDaoImpl) CreateOrUpdatePluginVersionConfigsInBatch(versionConfigs []model.TenantPluginVersionDiscoverConfig) error {
func (t *PluginVersionConfigDaoImpl) CreateOrUpdatePluginVersionConfigsInBatch(versionConfigs []*model.TenantPluginVersionDiscoverConfig) error {
var objects []interface{}
for _, config := range versionConfigs {
objects = append(objects, config)
objects = append(objects, *config)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update plugin version config in batch")
@ -612,10 +612,10 @@ func (t *TenantServicePluginRelationDaoImpl) DeleteByComponentIDs(componentIDs [
}
// CreateOrUpdatePluginRelsInBatch -
func (t *TenantServicePluginRelationDaoImpl) CreateOrUpdatePluginRelsInBatch(relations []model.TenantServicePluginRelation) error {
func (t *TenantServicePluginRelationDaoImpl) CreateOrUpdatePluginRelsInBatch(relations []*model.TenantServicePluginRelation) error {
var objects []interface{}
for _, relation := range relations {
objects = append(objects, relation)
objects = append(objects, *relation)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update plugin relation in batch")

View File

@ -554,10 +554,10 @@ func (t *TenantServicesDaoImpl) BindAppByServiceIDs(appID string, serviceIDs []s
}
// CreateOrUpdateComponentsInBatch Batch insert or update component
func (t *TenantServicesDaoImpl) CreateOrUpdateComponentsInBatch(components []model.TenantServices) error {
func (t *TenantServicesDaoImpl) CreateOrUpdateComponentsInBatch(components []*model.TenantServices) error {
var objects []interface{}
for _, component := range components {
objects = append(objects, component)
objects = append(objects, *component)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update component in batch")
@ -660,7 +660,7 @@ func (t *TenantServicesPortDaoImpl) UpdateModel(mo model.Interface) error {
}
// CreateOrUpdatePortsInBatch Batch insert or update ports variables
func (t *TenantServicesPortDaoImpl) CreateOrUpdatePortsInBatch(ports []model.TenantServicesPort) error {
func (t *TenantServicesPortDaoImpl) CreateOrUpdatePortsInBatch(ports []*model.TenantServicesPort) error {
var objects []interface{}
// dedup
existPorts := make(map[string]struct{})
@ -670,7 +670,7 @@ func (t *TenantServicesPortDaoImpl) CreateOrUpdatePortsInBatch(ports []model.Ten
}
existPorts[port.Key()] = struct{}{}
objects = append(objects, port)
objects = append(objects, *port)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update ports in batch")
@ -887,10 +887,10 @@ func (t *TenantServiceRelationDaoImpl) DeleteByComponentIDs(componentIDs []strin
}
// CreateOrUpdateRelationsInBatch -
func (t *TenantServiceRelationDaoImpl) CreateOrUpdateRelationsInBatch(relations []model.TenantServiceRelation) error {
func (t *TenantServiceRelationDaoImpl) CreateOrUpdateRelationsInBatch(relations []*model.TenantServiceRelation) error {
var objects []interface{}
for _, relation := range relations {
objects = append(objects, relation)
objects = append(objects, *relation)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update relation in batch")
@ -991,7 +991,7 @@ func (t *TenantServiceEnvVarDaoImpl) DeleteByComponentIDs(componentIDs []string)
}
// CreateOrUpdateEnvsInBatch Batch insert or update environment variables
func (t *TenantServiceEnvVarDaoImpl) CreateOrUpdateEnvsInBatch(envs []model.TenantServiceEnvVar) error {
func (t *TenantServiceEnvVarDaoImpl) CreateOrUpdateEnvsInBatch(envs []*model.TenantServiceEnvVar) error {
var objects []interface{}
existEnvs := make(map[string]struct{})
for _, env := range envs {
@ -1001,7 +1001,7 @@ func (t *TenantServiceEnvVarDaoImpl) CreateOrUpdateEnvsInBatch(envs []model.Tena
}
existEnvs[key] = struct{}{}
objects = append(objects, env)
objects = append(objects, *env)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update envs in batch")
@ -1167,10 +1167,10 @@ func (t *TenantServiceMountRelationDaoImpl) DeleteByComponentIDs(componentIDs []
}
// CreateOrUpdateVolumeRelsInBatch -
func (t *TenantServiceMountRelationDaoImpl) CreateOrUpdateVolumeRelsInBatch(volRels []model.TenantServiceMountRelation) error {
func (t *TenantServiceMountRelationDaoImpl) CreateOrUpdateVolumeRelsInBatch(volRels []*model.TenantServiceMountRelation) error {
var objects []interface{}
for _, volRel := range volRels {
objects = append(objects, volRel)
objects = append(objects, *volRel)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update volume relation in batch")
@ -1242,16 +1242,16 @@ func (t *TenantServiceVolumeDaoImpl) ListVolumesByComponentIDs(componentIDs []st
return volumes, nil
}
//DeleteByComponentIDVolNames -
func (t *TenantServiceVolumeDaoImpl) DeleteByComponentIDVolNames(componentIDs, volumeNames []string) error {
return t.DB.Where("service_id in (?) and volume_name in (?)", componentIDs, volumeNames).Delete(&model.TenantServiceVolume{}).Error
//DeleteByVolumeIDs -
func (t *TenantServiceVolumeDaoImpl) DeleteByVolumeIDs(volumeIDs []uint) error {
return t.DB.Where("ID in (?)", volumeIDs).Delete(&model.TenantServiceVolume{}).Error
}
// CreateOrUpdateVolumesInBatch -
func (t *TenantServiceVolumeDaoImpl) CreateOrUpdateVolumesInBatch(volumes []model.TenantServiceVolume) error {
func (t *TenantServiceVolumeDaoImpl) CreateOrUpdateVolumesInBatch(volumes []*model.TenantServiceVolume) error {
var objects []interface{}
for _, volume := range volumes {
objects = append(objects, volume)
objects = append(objects, *volume)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update volumes in batch")
@ -1393,10 +1393,10 @@ func (t *TenantServiceConfigFileDaoImpl) DeleteByComponentIDs(componentIDs []str
}
// CreateOrUpdateConfigFilesInBatch -
func (t *TenantServiceConfigFileDaoImpl) CreateOrUpdateConfigFilesInBatch(configFiles []model.TenantServiceConfigFile) error {
func (t *TenantServiceConfigFileDaoImpl) CreateOrUpdateConfigFilesInBatch(configFiles []*model.TenantServiceConfigFile) error {
var objects []interface{}
for _, configFile := range configFiles {
objects = append(objects, configFile)
objects = append(objects, *configFile)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update config files in batch")
@ -1758,10 +1758,10 @@ func (t *ServiceLabelDaoImpl) DeleteByComponentIDs(componentIDs []string) error
}
// CreateOrUpdateLabelsInBatch -
func (t *ServiceLabelDaoImpl) CreateOrUpdateLabelsInBatch(labels []model.TenantServiceLable) error {
func (t *ServiceLabelDaoImpl) CreateOrUpdateLabelsInBatch(labels []*model.TenantServiceLable) error {
var objects []interface{}
for _, label := range labels {
objects = append(objects, label)
objects = append(objects, *label)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update label in batch")
@ -1830,10 +1830,10 @@ func (t *TenantServceAutoscalerRulesDaoImpl) DeleteByComponentIDs(componentIDs [
}
// CreateOrUpdateLabelsInBatch -
func (t *TenantServceAutoscalerRulesDaoImpl) CreateOrUpdateScaleRulesInBatch(rules []model.TenantServiceAutoscalerRules) error {
func (t *TenantServceAutoscalerRulesDaoImpl) CreateOrUpdateScaleRulesInBatch(rules []*model.TenantServiceAutoscalerRules) error {
var objects []interface{}
for _, rule := range rules {
objects = append(objects, rule)
objects = append(objects, *rule)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update scale rule in batch")
@ -1910,10 +1910,10 @@ func (t *TenantServceAutoscalerRuleMetricsDaoImpl) DeleteByRuleIDs(ruleIDs []str
}
// CreateOrUpdateScaleRulesInBatch -
func (t *TenantServceAutoscalerRuleMetricsDaoImpl) CreateOrUpdateScaleRuleMetricsInBatch(metrics []model.TenantServiceAutoscalerRuleMetrics) error {
func (t *TenantServceAutoscalerRuleMetricsDaoImpl) CreateOrUpdateScaleRuleMetricsInBatch(metrics []*model.TenantServiceAutoscalerRuleMetrics) error {
var objects []interface{}
for _, metric := range metrics {
objects = append(objects, metric)
objects = append(objects, *metric)
}
if err := gormbulkups.BulkUpsert(t.DB, objects, 2000); err != nil {
return pkgerr.Wrap(err, "create or update rule metric in batch")