mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-01 19:28:05 +08:00
Merge pull request #722 from fanyangyang/configfile
backup and restore config file
This commit is contained in:
commit
dff3bb6ee7
@ -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)
|
||||
|
@ -114,6 +114,7 @@ type RegionServiceSnapshot struct {
|
||||
ServiceRelation []*dbmodel.TenantServiceRelation
|
||||
ServiceStatus string
|
||||
ServiceVolume []*dbmodel.TenantServiceVolume
|
||||
ServiceConfigFile []*dbmodel.TenantServiceConfigFile
|
||||
ServicePort []*dbmodel.TenantServicesPort
|
||||
Versions []*dbmodel.VersionInfo
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user