Commit f3f2421f authored by GLYASAI's avatar GLYASAI
Browse files

[REV] delete config file uuid

parent b48d0472
Showing with 21 additions and 29 deletions
+21 -29
......@@ -1214,7 +1214,7 @@ func (s *ServiceAction) VolumnVar(tsv *dbmodel.TenantServiceVolume, tenantID, fi
if fileContent != "" {
cf := &dbmodel.TenantServiceConfigFile{
UUID: uuid.NewV4().String(),
VolumeID: tsv.UUID,
VolumeName: tsv.VolumeName,
FileContent: fileContent,
}
if err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).AddModel(cf); err != nil {
......@@ -1230,11 +1230,6 @@ func (s *ServiceAction) VolumnVar(tsv *dbmodel.TenantServiceVolume, tenantID, fi
case "delete":
// begin transaction
tx := db.GetManager().Begin()
v, err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).GetVolumeByServiceIDAndName(tsv.ServiceID, tsv.VolumeName)
if err != nil {
tx.Rollback()
return util.CreateAPIHandleErrorFromDBError("error getting volume", err)
}
if tsv.VolumeName != "" {
err := db.GetManager().TenantServiceVolumeDaoTransactions(tx).DeleteModel(tsv.ServiceID, tsv.VolumeName)
if err != nil && err.Error() != gorm.ErrRecordNotFound.Error() {
......@@ -1248,7 +1243,7 @@ func (s *ServiceAction) VolumnVar(tsv *dbmodel.TenantServiceVolume, tenantID, fi
return util.CreateAPIHandleErrorFromDBError("delete volume", err)
}
}
if err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).DelByVolumeID(v.UUID); err != nil {
if err := db.GetManager().TenantServiceConfigFileDaoTransactions(tx).DelByVolumeID(tsv.VolumeName); err != nil {
tx.Rollback()
return util.CreateAPIHandleErrorFromDBError("error deleting config files", err)
}
......
......@@ -221,8 +221,8 @@ type TenantServiceVolumeDao interface {
type TenantServiceConfigFileDao interface {
Dao
ListByVolumeID(volumeID string) ([]*model.TenantServiceConfigFile, error)
DelByVolumeID(volumeID string) error
ListByVolumeID(volumeName string) ([]*model.TenantServiceConfigFile, error)
DelByVolumeID(volumeName string) error
}
//TenantServiceLBMappingPortDao vs lb mapping port dao
......@@ -391,4 +391,4 @@ type IPPortDao interface {
type IPPoolDao interface {
Dao
GetIPPoolByEID(eid string) (*model.IPPool, error)
}
\ No newline at end of file
}
......@@ -311,7 +311,6 @@ func (vt VolumeType) String() string {
//TenantServiceVolume 应用持久化纪录
type TenantServiceVolume struct {
Model
UUID string `gorm:"column:uuid;size:32" json:"uuid"`
ServiceID string `gorm:"column:service_id;size:32" json:"service_id"`
//服务类型
Category string `gorm:"column:category;size:50" json:"category"`
......@@ -336,8 +335,7 @@ func (t *TenantServiceVolume) TableName() string {
type TenantServiceConfigFile struct {
Model
UUID string `gorm:"column:uuid;size:32" json:"uuid"`
VolumeID string `gorm:"column:volume_id;size:32" json:"volume_id"`
Filename string `gorm:"column:filename" json:"filename"`
VolumeName string `gorm:"column:volume_name;size:32" json:"volume_name"`
FileContent string `gorm:"column:file_content;size:65535" json:"filename"`
}
......
......@@ -25,10 +25,8 @@ import (
"strconv"
"time"
"github.com/goodrain/rainbond/db/model"
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/db/model"
"github.com/jinzhu/gorm"
)
......@@ -959,6 +957,7 @@ func (t *TenantServiceConfigFileDaoImpl) AddModel(mo model.Interface) error {
return nil
}
// UpdateModel updates config file
func (t *TenantServiceConfigFileDaoImpl) UpdateModel(mo model.Interface) error {
configFile, ok := mo.(*model.TenantServiceConfigFile)
if !ok {
......@@ -971,9 +970,9 @@ func (t *TenantServiceConfigFileDaoImpl) UpdateModel(mo model.Interface) error {
}
// ListByVolumeID lists configFiles by volumeID
func (t *TenantServiceConfigFileDaoImpl) ListByVolumeID(volumeID string) ([]*model.TenantServiceConfigFile, error) {
func (t *TenantServiceConfigFileDaoImpl) ListByVolumeID(volumeName string) ([]*model.TenantServiceConfigFile, error) {
var res []*model.TenantServiceConfigFile
if err := t.DB.Where("volume_id = ?", volumeID).Find(&res).Error; err != nil {
if err := t.DB.Where("volume_name = ?", volumeName).Find(&res).Error; err != nil {
return nil, err
}
......@@ -981,9 +980,9 @@ func (t *TenantServiceConfigFileDaoImpl) ListByVolumeID(volumeID string) ([]*mod
}
// DelByVolumeID deletes config files according to volume id
func (t *TenantServiceConfigFileDaoImpl) DelByVolumeID(volumeID string) error {
var cfs []model.TenantServiceConfigFile
return t.DB.Where("volume_id = ?", volumeID).Delete(&cfs).Error
func (t *TenantServiceConfigFileDaoImpl) DelByVolumeID(volumeName string) error {
var cfs []model.TenantServiceConfigFile
return t.DB.Where("volume_name = ?", volumeName).Delete(&cfs).Error
}
//TenantServiceLBMappingPortDaoImpl stream服务映射
......
......@@ -37,9 +37,9 @@ func TestManager_TenantServiceConfigFileDaoImpl_UpdateModel(t *testing.T) {
vid := util.NewUUID()
cf := &model.TenantServiceConfigFile{
UUID: util.NewUUID(),
VolumeID: vid,
Filename: "dummy_filename",
UUID: util.NewUUID(),
VolumeName: vid,
Filename: "dummy_filename",
FileContent: "dummy file content",
}
if err := GetManager().TenantServiceConfigFileDao().AddModel(cf); err != nil {
......
......@@ -335,14 +335,14 @@ func createVolumes(as *v1.AppService, version *dbmodel.VersionInfo, dbmanager db
}
// create a configMap which will be mounted as a volume
if v.VolumeType == dbmodel.ConfigFileVolumeType.String() {
cfs, err := dbmanager.TenantServiceConfigFileDao().ListByVolumeID(v.UUID)
cfs, err := dbmanager.TenantServiceConfigFileDao().ListByVolumeID(v.VolumeName)
if err != nil {
logrus.Errorf("error listing config files by volume uuid(%s): %v", v.UUID, err)
return nil, fmt.Errorf("error listing config files by volume uuid(%s): %v", v.UUID, err)
logrus.Errorf("error listing config files by volume name(%s): %v", v.VolumeName, err)
return nil, fmt.Errorf("error listing config files by volume name(%s): %v", v.VolumeName, err)
}
if cfs == nil || len(cfs) == 0 {
logrus.Errorf("there is no config files according to volume id(%s)", v.UUID)
return nil, fmt.Errorf("there is no config files according to volume id(%s)", v.UUID)
logrus.Errorf("there is no config files according to volume name(%s)", v.VolumeName)
return nil, fmt.Errorf("there is no config files according to volume name(%s)", v.VolumeName)
}
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment