mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
added config group model
This commit is contained in:
parent
83ce4cf54d
commit
1009b8192c
@ -153,6 +153,7 @@ type ApplicationInterface interface {
|
||||
ListApps(w http.ResponseWriter, r *http.Request)
|
||||
ListServices(w http.ResponseWriter, r *http.Request)
|
||||
DeleteApp(w http.ResponseWriter, r *http.Request)
|
||||
AddConfigGroup(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
//Gatewayer gateway api interface
|
||||
|
@ -290,10 +290,15 @@ func (v2 *V2) applicationRouter() chi.Router {
|
||||
// Init Application
|
||||
r.Use(middleware.InitApplication)
|
||||
|
||||
// Operation application
|
||||
r.Put("/", controller.GetManager().UpdateApp)
|
||||
r.Delete("/", controller.GetManager().DeleteApp)
|
||||
|
||||
// Get services under application
|
||||
r.Get("/services", controller.GetManager().ListServices)
|
||||
|
||||
// Application configuration group
|
||||
r.Post("/configgroups", controller.GetManager().AddConfigGroup)
|
||||
return r
|
||||
}
|
||||
|
||||
|
28
api/controller/application_config_group.go
Normal file
28
api/controller/application_config_group.go
Normal file
@ -0,0 +1,28 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/goodrain/rainbond/api/handler"
|
||||
"github.com/goodrain/rainbond/api/middleware"
|
||||
"github.com/goodrain/rainbond/api/model"
|
||||
httputil "github.com/goodrain/rainbond/util/http"
|
||||
)
|
||||
|
||||
// AddConfigGroup -
|
||||
func (a *ApplicationStruct) AddConfigGroup(w http.ResponseWriter, r *http.Request) {
|
||||
var configReq model.ApplicationConfigGroup
|
||||
if !httputil.ValidatorRequestStructAndErrorResponse(r, w, &configReq, nil) {
|
||||
return
|
||||
}
|
||||
|
||||
appID := r.Context().Value(middleware.ContextKey("app_id")).(string)
|
||||
// create app ConfigGroups
|
||||
app, err := handler.GetApplicationHandler().AddConfigGroup(appID, &configReq)
|
||||
if err != nil {
|
||||
httputil.ReturnBcodeError(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
httputil.ReturnSuccess(r, w, app)
|
||||
}
|
37
api/handler/application_config_group.go
Normal file
37
api/handler/application_config_group.go
Normal file
@ -0,0 +1,37 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/api/model"
|
||||
"github.com/goodrain/rainbond/db"
|
||||
dbmodel "github.com/goodrain/rainbond/db/model"
|
||||
)
|
||||
|
||||
// AddConfigGroup -
|
||||
func (a *ApplicationAction) AddConfigGroup(appID string, req *model.ApplicationConfigGroup) (*dbmodel.ApplicationConfigGroup, error) {
|
||||
var (
|
||||
serviceIDs []string
|
||||
configItems []*dbmodel.ConfigItem
|
||||
)
|
||||
for _, sID := range req.ServiceIDs {
|
||||
serviceIDs = append(serviceIDs, sID)
|
||||
}
|
||||
for _, it := range req.ConfigItems {
|
||||
item := &dbmodel.ConfigItem{
|
||||
Key: it.Key,
|
||||
Value: it.Value,
|
||||
}
|
||||
configItems = append(configItems, item)
|
||||
}
|
||||
|
||||
config := &dbmodel.ApplicationConfigGroup{
|
||||
AppID: appID,
|
||||
ConfigGroupName: req.ConfigGroupName,
|
||||
DeployType: req.DeployType,
|
||||
ServiceIDs: serviceIDs,
|
||||
ConfigItems: configItems,
|
||||
}
|
||||
if err := db.GetManager().ApplicationConfigDao().AddModel(config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return config, nil
|
||||
}
|
@ -18,6 +18,7 @@ type ApplicationHandler interface {
|
||||
ListApps(tenantID, appName string, page, pageSize int) (*model.ListAppResponse, error)
|
||||
GetAppByID(appID string) (*dbmodel.Application, error)
|
||||
DeleteApp(appID string) error
|
||||
AddConfigGroup(appID string, req *model.ApplicationConfigGroup) (*dbmodel.ApplicationConfigGroup, error)
|
||||
}
|
||||
|
||||
// NewApplicationHandler creates a new Tenant Application Handler.
|
||||
|
@ -1653,3 +1653,18 @@ type ListServiceResponse struct {
|
||||
type UpdateAppRequest struct {
|
||||
AppName string `json:"app_name" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigItem -
|
||||
type ConfigItem struct {
|
||||
Key string `json:"key" validate:"required,max=255"`
|
||||
Value string `json:"value" validate:"required,max=65535"`
|
||||
}
|
||||
|
||||
// ApplicationConfigGroup -
|
||||
type ApplicationConfigGroup struct {
|
||||
AppID string `json:"app_id"`
|
||||
ConfigGroupName string `json:"config_group_name" validate:"required,alphanum,min=2,max=64"`
|
||||
DeployType string `json:"deploy_type" validate:"required,oneof=env configfile"`
|
||||
ServiceIDs []string `json:"service_ids" validate:"required"`
|
||||
ConfigItems []*ConfigItem `json:"config_items"`
|
||||
}
|
||||
|
@ -13,3 +13,9 @@ var (
|
||||
//ErrDeleteDueToBindService
|
||||
ErrDeleteDueToBindService = newByMessage(400, 11005, "the application cannot be deleted because there are bound services")
|
||||
)
|
||||
|
||||
// tenant application 11100~11199
|
||||
var (
|
||||
//ErrApplicationConfigGroupExist -
|
||||
ErrApplicationConfigGroupExist = newByMessage(400, 11101, "application config group already exist")
|
||||
)
|
||||
|
@ -75,6 +75,11 @@ type TenantApplicationDao interface {
|
||||
DeleteApp(appID string) error
|
||||
}
|
||||
|
||||
//ApplicationConfigDao Application config group Dao
|
||||
type ApplicationConfigDao interface {
|
||||
Dao
|
||||
}
|
||||
|
||||
// VolumeTypeDao volume type dao
|
||||
type VolumeTypeDao interface {
|
||||
Dao
|
||||
|
1
db/db.go
1
db/db.go
@ -39,6 +39,7 @@ type Manager interface {
|
||||
LicenseDao() dao.LicenseDao
|
||||
AppDao() dao.AppDao
|
||||
TenantApplicationDao() dao.TenantApplicationDao
|
||||
ApplicationConfigDao() dao.ApplicationConfigDao
|
||||
EnterpriseDao() dao.EnterpriseDao
|
||||
TenantDao() dao.TenantDao
|
||||
TenantDaoTransactions(db *gorm.DB) dao.TenantDao
|
||||
|
@ -12,3 +12,24 @@ type Application struct {
|
||||
func (t *Application) TableName() string {
|
||||
return "application"
|
||||
}
|
||||
|
||||
// ConfigItem -
|
||||
type ConfigItem struct {
|
||||
Key string `gorm:"column:key" json:"key"`
|
||||
Value string `gorm:"column:value" json:"value"`
|
||||
}
|
||||
|
||||
// ApplicationConfigGroup -
|
||||
type ApplicationConfigGroup struct {
|
||||
Model
|
||||
AppID string `gorm:"column:app_id" json:"app_id"`
|
||||
ConfigGroupName string `gorm:"column:config_group_name" json:"config_group_name"`
|
||||
DeployType string `gorm:"column:deploy_type,default:'env'" json:"deploy_type"`
|
||||
ServiceIDs []string `gorm:"-" json:"service_ids"`
|
||||
ConfigItems []*ConfigItem `gorm:"-" json:"config_items"`
|
||||
}
|
||||
|
||||
// TableName return tableName "application"
|
||||
func (t *ApplicationConfigGroup) TableName() string {
|
||||
return "application_config_group"
|
||||
}
|
||||
|
31
db/mysql/dao/application_config_group.go
Normal file
31
db/mysql/dao/application_config_group.go
Normal file
@ -0,0 +1,31 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/api/util/bcode"
|
||||
"github.com/goodrain/rainbond/db/model"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
// ApplicationConfigDaoImpl -
|
||||
type ApplicationConfigDaoImpl struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
//AddModel -
|
||||
func (a *ApplicationConfigDaoImpl) AddModel(mo model.Interface) error {
|
||||
configReq, _ := mo.(*model.ApplicationConfigGroup)
|
||||
var oldApp model.ApplicationConfigGroup
|
||||
if err := a.DB.Where("config_group_name = ?", configReq.ConfigGroupName).Find(&oldApp).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return a.DB.Create(configReq).Error
|
||||
}
|
||||
return err
|
||||
}
|
||||
return bcode.ErrApplicationConfigGroupExist
|
||||
}
|
||||
|
||||
//UpdateModel -
|
||||
func (a *ApplicationConfigDaoImpl) UpdateModel(mo model.Interface) error {
|
||||
// updateReq := mo.(*model.Application)
|
||||
return nil
|
||||
}
|
@ -424,6 +424,13 @@ func (m *Manager) TenantApplicationDao() dao.TenantApplicationDao {
|
||||
}
|
||||
}
|
||||
|
||||
// ApplicationConfigDao -
|
||||
func (m *Manager) ApplicationConfigDao() dao.ApplicationConfigDao {
|
||||
return &mysqldao.ApplicationConfigDaoImpl{
|
||||
DB: m.db,
|
||||
}
|
||||
}
|
||||
|
||||
//AppBackupDao group app backup info
|
||||
func (m *Manager) AppBackupDao() dao.AppBackupDao {
|
||||
return &mysqldao.AppBackupDaoImpl{
|
||||
|
@ -126,6 +126,7 @@ func (m *Manager) RegisterTableModel() {
|
||||
m.models = append(m.models, &model.AppBackup{})
|
||||
m.models = append(m.models, &model.ServiceSourceConfig{})
|
||||
m.models = append(m.models, &model.Application{})
|
||||
m.models = append(m.models, &model.ApplicationConfigGroup{})
|
||||
// gateway
|
||||
m.models = append(m.models, &model.Certificate{})
|
||||
m.models = append(m.models, &model.RuleExtension{})
|
||||
|
Loading…
Reference in New Issue
Block a user