Merge pull request #869 from GLYASAI/update-application

New Feature: update application governance_mode
This commit is contained in:
barnettZQG 2020-11-06 21:13:24 -06:00 committed by GitHub
commit 3c7716924e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 8 deletions

View File

@ -72,7 +72,7 @@ func (a *ApplicationAction) CreateApp(req *model.Application) (*model.Applicatio
return nil, err
}
if len(req.ServiceIDs) != 0 {
for _,sid := range req.ServiceIDs {
for _, sid := range req.ServiceIDs {
if _, err := db.GetManager().TenantServiceDao().GetServiceByID(sid); err != nil {
tx.Rollback()
return nil, err
@ -93,7 +93,15 @@ func (a *ApplicationAction) CreateApp(req *model.Application) (*model.Applicatio
// UpdateApp -
func (a *ApplicationAction) UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error) {
srcApp.AppName = req.AppName
if req.AppName != "" {
srcApp.AppName = req.AppName
}
if req.GovernanceMode != "" {
if !dbmodel.IsGovernanceModeValid(req.GovernanceMode) {
return nil, bcode.NewBadRequest(fmt.Sprintf("governance mode '%s' is valid", req.GovernanceMode))
}
srcApp.GovernanceMode = req.GovernanceMode
}
if err := db.GetManager().ApplicationDao().UpdateModel(srcApp); err != nil {
return nil, err
}
@ -249,9 +257,9 @@ func (a *ApplicationAction) getDiskUsage(appID string) float64 {
return result
}
//BatchBindService
// BatchBindService -
func (a *ApplicationAction) BatchBindService(appID string, req model.BindServiceRequest) error {
for _,sid := range req.ServiceIDs {
for _, sid := range req.ServiceIDs {
if _, err := db.GetManager().TenantServiceDao().GetServiceByID(sid); err != nil {
return err
}

View File

@ -1653,7 +1653,8 @@ type ListServiceResponse struct {
// UpdateAppRequest -
type UpdateAppRequest struct {
AppName string `json:"app_name" validate:"required"`
AppName string `json:"app_name"`
GovernanceMode string `json:"governance_mode"`
}
// BindServiceRequest -

View File

@ -2,18 +2,23 @@ package model
const (
// GovernanceModeBuildInServiceMesh means the governance mode is BUILD_IN_SERVICE_MESH
GovernanceModeBuildInServiceMesh = "build_in_service_mesh"
GovernanceModeBuildInServiceMesh = "BUILD_IN_SERVICE_MESH"
// GovernanceModeKubernetesNativeService means the governance mode is KUBERNETES_NATIVE_SERVICE
GovernanceModeKubernetesNativeService = "kubernetes_native_service"
GovernanceModeKubernetesNativeService = "KUBERNETES_NATIVE_SERVICE"
)
// IsGovernanceModeValid checks if the governanceMode is valid.
func IsGovernanceModeValid(governanceMode string) bool {
return governanceMode == GovernanceModeBuildInServiceMesh || governanceMode == GovernanceModeKubernetesNativeService
}
// Application -
type Application struct {
Model
AppName string `gorm:"column:app_name" json:"app_name"`
AppID string `gorm:"column:app_id" json:"app_id"`
TenantID string `gorm:"column:tenant_id" json:"tenant_id"`
GovernanceMode string `gorm:"column:governance_mode;default:'build_in_service_mesh'" json:"governance_mode"`
GovernanceMode string `gorm:"column:governance_mode;default:'BUILD_IN_SERVICE_MESH'" json:"governance_mode"`
}
// TableName return tableName "application"