Merge pull request #722 from fanyangyang/configfile

backup and restore config file
This commit is contained in:
黄润豪 2020-04-07 19:34:06 +08:00 committed by GitHub
commit dff3bb6ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 2 deletions

View File

@ -33,12 +33,13 @@ import (
"github.com/goodrain/rainbond/api/util"
"github.com/goodrain/rainbond/db"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/worker/client"
dbmodel "github.com/goodrain/rainbond/db/model"
mqclient "github.com/goodrain/rainbond/mq/client"
core_util "github.com/goodrain/rainbond/util"
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"github.com/goodrain/rainbond/worker/client"
)
//Backup GroupBackup
@ -205,6 +206,7 @@ type RegionServiceSnapshot struct {
ServiceRelation []*dbmodel.TenantServiceRelation
ServiceStatus string
ServiceVolume []*dbmodel.TenantServiceVolume
ServiceConfigFile []*dbmodel.TenantServiceConfigFile
ServicePort []*dbmodel.TenantServicesPort
Versions []*dbmodel.VersionInfo
@ -272,6 +274,11 @@ func (h *BackupHandle) snapshot(ids []string, sourceDir string, force bool) erro
return fmt.Errorf("Get service(%s) volume error %s", id, err)
}
data.ServiceVolume = serviceVolume
serviceConfigFile, err := db.GetManager().TenantServiceConfigFileDao().GetConfigFileByServiceID(id)
if err != nil && err != gorm.ErrRecordNotFound {
return fmt.Errorf("get service(%s) config file error: %s", id, err.Error())
}
data.ServiceConfigFile = serviceConfigFile
servicePorts, err := db.GetManager().TenantServicesPortDao().GetPortsByServiceID(id)
if err != nil && err.Error() != gorm.ErrRecordNotFound.Error() {
return fmt.Errorf("Get service(%s) ports error %s", id, err)

View File

@ -114,6 +114,7 @@ type RegionServiceSnapshot struct {
ServiceRelation []*dbmodel.TenantServiceRelation
ServiceStatus string
ServiceVolume []*dbmodel.TenantServiceVolume
ServiceConfigFile []*dbmodel.TenantServiceConfigFile
ServicePort []*dbmodel.TenantServicesPort
Versions []*dbmodel.VersionInfo

View File

@ -453,6 +453,9 @@ func (b *BackupAPPRestore) modify(appSnapshot *AppSnapshot) error {
for _, a := range app.ServiceVolume {
a.ServiceID = newServiceID
}
for _, a := range app.ServiceConfigFile {
a.ServiceID = newServiceID
}
for _, a := range app.ServicePort {
a.ServiceID = newServiceID
}
@ -588,6 +591,13 @@ func (b *BackupAPPRestore) restoreMetadata(appSnapshot *AppSnapshot) error {
}
b.volumeIDMap[oldVolumeID] = a.ID
}
for _, a := range app.ServiceConfigFile {
a.ID = 0
if err := db.GetManager().TenantServiceConfigFileDao().AddModel(a); err != nil {
tx.Rollback()
return fmt.Errorf("create app config file when restore backup errro. %s", err.Error())
}
}
for _, a := range app.ServicePort {
a.ID = 0
if err := db.GetManager().TenantServicesPortDaoTransactions(tx).AddModel(a); err != nil {

View File

@ -271,6 +271,7 @@ type TenantServiceVolumeDao interface {
//TenantServiceConfigFileDao tenant service config file dao interface
type TenantServiceConfigFileDao interface {
Dao
GetConfigFileByServiceID(serviceID string) ([]*model.TenantServiceConfigFile, error)
GetByVolumeName(sid, volumeName string) (*model.TenantServiceConfigFile, error)
DelByVolumeID(sid string, volumeName string) error
DelByServiceID(sid string) error

View File

@ -1126,6 +1126,15 @@ func (t *TenantServiceConfigFileDaoImpl) UpdateModel(mo model.Interface) error {
Update(configFile).Error
}
// GetConfigFileByServiceID -
func (t *TenantServiceConfigFileDaoImpl) GetConfigFileByServiceID(serviceID string) ([]*model.TenantServiceConfigFile, error) {
var configFiles []*model.TenantServiceConfigFile
if err := t.DB.Where("service_id=?", serviceID).Find(&configFiles).Error; err != nil {
return nil, err
}
return configFiles, nil
}
// GetByVolumeName get config file by volume name
func (t *TenantServiceConfigFileDaoImpl) GetByVolumeName(sid string, volumeName string) (*model.TenantServiceConfigFile, error) {
var res model.TenantServiceConfigFile