Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Rainbond
Commits
132d3af5
Commit
132d3af5
authored
4 years ago
by
yangk
Browse files
Options
Download
Email Patches
Plain Diff
add sync app config groups interface
parent
0789badb
main
Develop-V5.X
V5.3
V5.4
feat-containerd
feat-containerd1
feature-helmapp
feature-helmapp-2
feature-k8s
fixbug-560
master
mesh-start
zqhtest-containerd
v5.8.1-release
v5.8.0-release
v5.7.1-release
v5.7.0-release
v5.6.0-release
v5.5.0-release
v5.5.0-dind
v5.4.1-release
v5.4.0-release
v5.3.3-release
v5.3.2-release
v5.3.1-release
No related merge requests found
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
api/api/api_interface.go
+1
-0
api/api/api_interface.go
api/api_routers/version2/v2Routers.go
+1
-0
api/api_routers/version2/v2Routers.go
api/controller/application_config_group.go
+15
-0
api/controller/application_config_group.go
api/handler/application_config_group.go
+39
-2
api/handler/application_config_group.go
api/handler/application_handler.go
+1
-0
api/handler/application_handler.go
api/model/model.go
+42
-6
api/model/model.go
db/dao/dao.go
+5
-0
db/dao/dao.go
db/mysql/dao/application_config_group.go
+39
-0
db/mysql/dao/application_config_group.go
with
143 additions
and
8 deletions
+143
-8
api/api/api_interface.go
+
1
-
0
View file @
132d3af5
...
...
@@ -169,6 +169,7 @@ type ApplicationInterface interface {
DeleteConfigGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
ListConfigGroups
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
SyncComponents
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
SyncAppConfigGroups
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
}
//Gatewayer gateway api interface
...
...
This diff is collapsed.
Click to expand it.
api/api_routers/version2/v2Routers.go
+
1
-
0
View file @
132d3af5
...
...
@@ -323,6 +323,7 @@ func (v2 *V2) applicationRouter() chi.Router {
// Synchronize component information, full coverage
r
.
Post
(
"/components"
,
controller
.
GetManager
()
.
SyncComponents
)
r
.
Post
(
"/app-config-groups"
,
controller
.
GetManager
()
.
SyncAppConfigGroups
)
return
r
}
...
...
This diff is collapsed.
Click to expand it.
api/controller/application_config_group.go
+
15
-
0
View file @
132d3af5
...
...
@@ -123,3 +123,18 @@ func (a *ApplicationController)SyncComponents(w http.ResponseWriter, r *http.Req
}
httputil
.
ReturnSuccess
(
r
,
w
,
nil
)
}
// SyncAppConfigGroups -
func
(
a
*
ApplicationController
)
SyncAppConfigGroups
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
){
var
syncAppConfigGroupReq
model
.
SyncAppConfigGroup
app
:=
r
.
Context
()
.
Value
(
middleware
.
ContextKey
(
"application"
))
.
(
*
dbmodel
.
Application
)
if
!
httputil
.
ValidatorRequestStructAndErrorResponse
(
r
,
w
,
&
syncAppConfigGroupReq
,
nil
){
return
}
err
:=
handler
.
GetApplicationHandler
()
.
SyncAppConfigGroups
(
app
,
syncAppConfigGroupReq
.
AppConfigGroups
)
if
err
!=
nil
{
httputil
.
ReturnBcodeError
(
r
,
w
,
err
)
return
}
httputil
.
ReturnSuccess
(
r
,
w
,
nil
)
}
This diff is collapsed.
Click to expand it.
api/handler/application_config_group.go
+
39
-
2
View file @
132d3af5
...
...
@@ -264,10 +264,10 @@ func (a *ApplicationAction) ListConfigGroups(appID string, page, pageSize int) (
}
// SyncComponentConfigGroupRels -
func
(
a
*
ApplicationAction
)
SyncComponentConfigGroupRels
(
tx
*
gorm
.
DB
,
app
*
dbmodel
.
Application
,
components
[]
*
model
.
Component
)
error
{
func
(
a
*
ApplicationAction
)
SyncComponentConfigGroupRels
(
tx
*
gorm
.
DB
,
app
*
dbmodel
.
Application
,
components
[]
*
model
.
Component
)
error
{
var
(
componentIDs
[]
string
cgservices
[]
*
dbmodel
.
ConfigGroupService
cgservices
[]
*
dbmodel
.
ConfigGroupService
)
for
_
,
component
:=
range
components
{
if
component
.
AppConfigGroupRels
==
nil
{
...
...
@@ -283,3 +283,40 @@ func (a *ApplicationAction) SyncComponentConfigGroupRels(tx *gorm.DB, app *dbmod
}
return
db
.
GetManager
()
.
AppConfigGroupServiceDaoTransactions
(
tx
)
.
CreateOrUpdateConfigGroupServicesInBatch
(
cgservices
)
}
// SyncAppConfigGroups -
func
(
a
*
ApplicationAction
)
SyncAppConfigGroups
(
app
*
dbmodel
.
Application
,
appConfigGroups
[]
model
.
ApplicationConfigGroup
)
error
{
var
(
cgroups
[]
*
dbmodel
.
ApplicationConfigGroup
cgitems
[]
*
dbmodel
.
ConfigGroupItem
cgservices
[]
*
dbmodel
.
ConfigGroupService
)
for
_
,
configGroup
:=
range
appConfigGroups
{
cgroups
=
append
(
cgroups
,
configGroup
.
DbModel
(
app
.
AppID
))
for
_
,
item
:=
range
configGroup
.
ConfigItems
{
cgitems
=
append
(
cgitems
,
item
.
DbModel
(
app
.
AppID
,
configGroup
.
ConfigGroupName
))
}
for
_
,
cgservice
:=
range
configGroup
.
ConfigGroupServices
{
cgservices
=
append
(
cgservices
,
cgservice
.
DbModel
(
app
.
AppID
,
configGroup
.
ConfigGroupName
))
}
}
return
db
.
GetManager
()
.
DB
()
.
Transaction
(
func
(
tx
*
gorm
.
DB
)
error
{
if
err
:=
db
.
GetManager
()
.
AppConfigGroupDaoTransactions
(
tx
)
.
DeleteByAppID
(
app
.
AppID
);
err
!=
nil
{
return
err
}
if
err
:=
db
.
GetManager
()
.
AppConfigGroupServiceDaoTransactions
(
tx
)
.
DeleteByAppID
(
app
.
AppID
);
err
!=
nil
{
return
err
}
if
err
:=
db
.
GetManager
()
.
AppConfigGroupItemDaoTransactions
(
tx
)
.
DeleteByAppID
(
app
.
AppID
);
err
!=
nil
{
return
err
}
if
err
:=
db
.
GetManager
()
.
AppConfigGroupDaoTransactions
(
tx
)
.
CreateOrUpdateConfigGroupsInBatch
(
cgroups
);
err
!=
nil
{
return
err
}
if
err
:=
db
.
GetManager
()
.
AppConfigGroupServiceDaoTransactions
(
tx
)
.
CreateOrUpdateConfigGroupServicesInBatch
(
cgservices
);
err
!=
nil
{
return
err
}
return
db
.
GetManager
()
.
AppConfigGroupItemDaoTransactions
(
tx
)
.
CreateOrUpdateConfigGroupItemsInBatch
(
cgitems
)
})
}
This diff is collapsed.
Click to expand it.
api/handler/application_handler.go
+
1
-
0
View file @
132d3af5
...
...
@@ -44,6 +44,7 @@ type ApplicationHandler interface {
ListConfigGroups
(
appID
string
,
page
,
pageSize
int
)
(
*
model
.
ListApplicationConfigGroupResp
,
error
)
SyncComponents
(
app
*
dbmodel
.
Application
,
components
[]
*
model
.
Component
)
error
SyncComponentConfigGroupRels
(
tx
*
gorm
.
DB
,
app
*
dbmodel
.
Application
,
components
[]
*
model
.
Component
)
error
SyncAppConfigGroups
(
app
*
dbmodel
.
Application
,
appConfigGroups
[]
model
.
ApplicationConfigGroup
)
error
}
// NewApplicationHandler creates a new Tenant Application Handler.
...
...
This diff is collapsed.
Click to expand it.
api/model/model.go
+
42
-
6
View file @
132d3af5
...
...
@@ -1832,6 +1832,16 @@ type ConfigGroupService struct {
ServiceAlias
string
`json:"service_alias"`
}
// DbModel return database model
func
(
c
ConfigGroupService
)
DbModel
(
appID
,
configGroupName
string
)
*
dbmodel
.
ConfigGroupService
{
return
&
dbmodel
.
ConfigGroupService
{
AppID
:
appID
,
ConfigGroupName
:
configGroupName
,
ServiceID
:
c
.
ServiceID
,
ServiceAlias
:
c
.
ServiceAlias
,
}
}
// ConfigItem -
type
ConfigItem
struct
{
AppID
string
`json:"-"`
...
...
@@ -1840,14 +1850,35 @@ type ConfigItem struct {
ItemValue
string
`json:"item_value" validate:"required,max=65535"`
}
// DbModel return database model
func
(
c
ConfigItem
)
DbModel
(
appID
,
configGroupName
string
)
*
dbmodel
.
ConfigGroupItem
{
return
&
dbmodel
.
ConfigGroupItem
{
AppID
:
appID
,
ConfigGroupName
:
configGroupName
,
ItemKey
:
c
.
ItemKey
,
ItemValue
:
c
.
ItemValue
,
}
}
// 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"`
ConfigItems
[]
ConfigItem
`json:"config_items"`
Enable
bool
`json:"enable"`
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"`
ConfigItems
[]
ConfigItem
`json:"config_items"`
ConfigGroupServices
[]
ConfigGroupService
`json:"config_group_services"`
Enable
bool
`json:"enable"`
}
// DbModel return database model
func
(
a
ApplicationConfigGroup
)
DbModel
(
appID
string
)
*
dbmodel
.
ApplicationConfigGroup
{
return
&
dbmodel
.
ApplicationConfigGroup
{
AppID
:
appID
,
ConfigGroupName
:
a
.
ConfigGroupName
,
DeployType
:
a
.
DeployType
,
Enable
:
a
.
Enable
,
}
}
// ApplicationConfigGroupResp -
...
...
@@ -1890,3 +1921,8 @@ func (a *AppConfigGroupRelations) DbModel(appID, serviceID, serviceAlias string)
ServiceAlias
:
serviceAlias
,
}
}
// SyncAppConfigGroup -
type
SyncAppConfigGroup
struct
{
AppConfigGroups
[]
ApplicationConfigGroup
`json:"app_config_groups"`
}
This diff is collapsed.
Click to expand it.
db/dao/dao.go
+
5
-
0
View file @
132d3af5
...
...
@@ -83,6 +83,8 @@ type AppConfigGroupDao interface {
ListByServiceID
(
sid
string
)
([]
*
model
.
ApplicationConfigGroup
,
error
)
GetConfigGroupsByAppID
(
appID
string
,
page
,
pageSize
int
)
([]
*
model
.
ApplicationConfigGroup
,
int64
,
error
)
DeleteConfigGroup
(
appID
,
configGroupName
string
)
error
DeleteByAppID
(
appID
string
)
error
CreateOrUpdateConfigGroupsInBatch
(
cgroups
[]
*
model
.
ApplicationConfigGroup
)
error
}
//AppConfigGroupServiceDao service config group Dao
...
...
@@ -93,6 +95,7 @@ type AppConfigGroupServiceDao interface {
DeleteEffectiveServiceByServiceID
(
serviceID
string
)
error
DeleteByComponentIDs
(
componentIDs
[]
string
)
error
CreateOrUpdateConfigGroupServicesInBatch
(
cgservices
[]
*
model
.
ConfigGroupService
)
error
DeleteByAppID
(
appID
string
)
error
}
//AppConfigGroupItemDao Application config item group Dao
...
...
@@ -101,6 +104,8 @@ type AppConfigGroupItemDao interface {
GetConfigGroupItemsByID
(
appID
,
configGroupName
string
)
([]
*
model
.
ConfigGroupItem
,
error
)
ListByServiceID
(
sid
string
)
([]
*
model
.
ConfigGroupItem
,
error
)
DeleteConfigGroupItem
(
appID
,
configGroupName
string
)
error
DeleteByAppID
(
appID
string
)
error
CreateOrUpdateConfigGroupItemsInBatch
(
cgitems
[]
*
model
.
ConfigGroupItem
)
error
}
// VolumeTypeDao volume type dao
...
...
This diff is collapsed.
Click to expand it.
db/mysql/dao/application_config_group.go
+
39
-
0
View file @
132d3af5
...
...
@@ -72,6 +72,23 @@ func (a *AppConfigGroupDaoImpl) DeleteConfigGroup(appID, configGroupName string)
return
a
.
DB
.
Where
(
"app_id = ? AND config_group_name = ?"
,
appID
,
configGroupName
)
.
Delete
(
model
.
ApplicationConfigGroup
{})
.
Error
}
//DeleteByAppID -
func
(
a
*
AppConfigGroupDaoImpl
)
DeleteByAppID
(
appID
string
)
error
{
return
a
.
DB
.
Where
(
"app_id = ?"
,
appID
)
.
Delete
(
model
.
ApplicationConfigGroup
{})
.
Error
}
// CreateOrUpdateConfigGroupsInBatch -
func
(
a
*
AppConfigGroupDaoImpl
)
CreateOrUpdateConfigGroupsInBatch
(
cgroups
[]
*
model
.
ApplicationConfigGroup
)
error
{
var
objects
[]
interface
{}
for
_
,
cg
:=
range
cgroups
{
objects
=
append
(
objects
,
*
cg
)
}
if
err
:=
gormbulkups
.
BulkUpsert
(
a
.
DB
,
objects
,
2000
);
err
!=
nil
{
return
pkgerr
.
Wrap
(
err
,
"create or update config groups in batch"
)
}
return
nil
}
// AppConfigGroupServiceDaoImpl -
type
AppConfigGroupServiceDaoImpl
struct
{
DB
*
gorm
.
DB
...
...
@@ -119,6 +136,11 @@ func (a *AppConfigGroupServiceDaoImpl) DeleteByComponentIDs(componentIDs []strin
return
a
.
DB
.
Where
(
"service_id in (?)"
,
componentIDs
)
.
Delete
(
model
.
ConfigGroupService
{})
.
Error
}
//DeleteByAppID -
func
(
a
*
AppConfigGroupServiceDaoImpl
)
DeleteByAppID
(
appID
string
)
error
{
return
a
.
DB
.
Where
(
"app_id = ?"
,
appID
)
.
Delete
(
model
.
ConfigGroupService
{})
.
Error
}
// CreateOrUpdateConfigGroupServicesInBatch -
func
(
a
*
AppConfigGroupServiceDaoImpl
)
CreateOrUpdateConfigGroupServicesInBatch
(
cgservices
[]
*
model
.
ConfigGroupService
)
error
{
var
objects
[]
interface
{}
...
...
@@ -180,3 +202,20 @@ func (a *AppConfigGroupItemDaoImpl) ListByServiceID(sid string) ([]*model.Config
func
(
a
*
AppConfigGroupItemDaoImpl
)
DeleteConfigGroupItem
(
appID
,
configGroupName
string
)
error
{
return
a
.
DB
.
Where
(
"app_id = ? AND config_group_name = ?"
,
appID
,
configGroupName
)
.
Delete
(
model
.
ConfigGroupItem
{})
.
Error
}
//DeleteByAppID -
func
(
a
*
AppConfigGroupItemDaoImpl
)
DeleteByAppID
(
appID
string
)
error
{
return
a
.
DB
.
Where
(
"app_id = ?"
,
appID
)
.
Delete
(
model
.
ConfigGroupItem
{})
.
Error
}
// CreateOrUpdateConfigGroupItemsInBatch -
func
(
a
*
AppConfigGroupItemDaoImpl
)
CreateOrUpdateConfigGroupItemsInBatch
(
cgitems
[]
*
model
.
ConfigGroupItem
)
error
{
var
objects
[]
interface
{}
for
_
,
cgi
:=
range
cgitems
{
objects
=
append
(
objects
,
*
cgi
)
}
if
err
:=
gormbulkups
.
BulkUpsert
(
a
.
DB
,
objects
,
2000
);
err
!=
nil
{
return
pkgerr
.
Wrap
(
err
,
"create or update config group items in batch"
)
}
return
nil
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help