mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-12 18:11:34 +08:00
修复动态模块上下线失败的问题
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
*.DS_Store
|
||||
/.idea/
|
||||
/config.yml
|
||||
/build/
|
||||
/apipark
|
||||
|
||||
@@ -16,8 +16,8 @@ type IDynamicModuleController interface {
|
||||
List(ctx *gin.Context, module string, keyword string, cluster string, page string, pageSize string) ([]map[string]interface{}, *dynamic_module_dto.PluginInfo, int64, error)
|
||||
Render(ctx *gin.Context, module string) (*dynamic_module_dto.PluginBasic, map[string]interface{}, error)
|
||||
ModuleDrivers(ctx *gin.Context, group string) ([]*dynamic_module_dto.ModuleDriver, error)
|
||||
Online(ctx *gin.Context, module string, id string, partitionInput *dynamic_module_dto.ClusterInput) error
|
||||
Offline(ctx *gin.Context, module string, id string, partitionInput *dynamic_module_dto.ClusterInput) error
|
||||
Online(ctx *gin.Context, module string, id string) error
|
||||
Offline(ctx *gin.Context, module string, id string) error
|
||||
//PartitionStatuses(ctx *gin.Context, module string, keyword string, page string, pageSize string) (map[string]map[string]string, error)
|
||||
//PartitionStatus(ctx *gin.Context, module string, id string) (*dynamic_module_dto.OnlineInfo, error)
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ type imlDynamicModuleController struct {
|
||||
module dynamic_module.IDynamicModuleModule `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlDynamicModuleController) Online(ctx *gin.Context, module string, id string, partitionInput *dynamic_module_dto.ClusterInput) error {
|
||||
return i.module.Online(ctx, module, id, partitionInput)
|
||||
func (i *imlDynamicModuleController) Online(ctx *gin.Context, module string, id string) error {
|
||||
return i.module.Online(ctx, module, id)
|
||||
}
|
||||
|
||||
func (i *imlDynamicModuleController) Offline(ctx *gin.Context, module string, id string, partitionInput *dynamic_module_dto.ClusterInput) error {
|
||||
return i.module.Offline(ctx, module, id, partitionInput)
|
||||
func (i *imlDynamicModuleController) Offline(ctx *gin.Context, module string, id string) error {
|
||||
return i.module.Offline(ctx, module, id)
|
||||
}
|
||||
|
||||
//func (i *imlDynamicModuleController) PartitionStatuses(ctx *gin.Context, module string, keyword string, page string, pageSize string) (map[string]map[string]string, error) {
|
||||
|
||||
@@ -66,4 +66,4 @@ require (
|
||||
gorm.io/driver/mysql v1.5.2 // indirect
|
||||
)
|
||||
|
||||
//replace github.com/eolinker/ap-account v1.0.4 => ../ap-account
|
||||
//replace github.com/eolinker/ap-account => ../../eolinker/ap-account
|
||||
|
||||
@@ -23,7 +23,6 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eolinker/ap-account v1.0.6 h1:lzkmaItUoIguEKneUbP387qdgsUgjonKjHDnXsu6lTc=
|
||||
github.com/eolinker/ap-account v1.0.6/go.mod h1:MViCOvUaS2QrVift1Be3yGjjMywzICL9317eOxoixSI=
|
||||
github.com/eolinker/eosc v0.17.3 h1:sr2yT+v/AsqEdciRaaZZj0zL9pTufR5RvDW6+65hraQ=
|
||||
github.com/eolinker/eosc v0.17.3/go.mod h1:xgq816hpanlMXFtZw7Ztdctb1eEk9UPHchY4NfFO6Cw=
|
||||
|
||||
@@ -6,6 +6,7 @@ type Item struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Children []*Item `json:"children"`
|
||||
Sort int `json:"-"`
|
||||
}
|
||||
|
||||
type ServiceItem struct {
|
||||
|
||||
@@ -347,9 +347,10 @@ func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*c
|
||||
|
||||
func (i *imlCatalogueModule) recurseUpdateSort(ctx context.Context, parent string, sorts []*catalogue_dto.SortItem) error {
|
||||
for index, item := range sorts {
|
||||
s := index
|
||||
err := i.catalogueService.Save(ctx, item.Id, &catalogue.EditCatalogue{
|
||||
Parent: &parent,
|
||||
Sort: &index,
|
||||
Sort: &s,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -488,8 +489,12 @@ func treeItems(parentId string, parentMap map[string][]*catalogue.Catalogue) []*
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
Children: childItems,
|
||||
Sort: v.Sort,
|
||||
})
|
||||
}
|
||||
}
|
||||
sort.Slice(items, func(i, j int) bool {
|
||||
return items[i].Sort < items[j].Sort
|
||||
})
|
||||
return items
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ func NewRoot(list []*catalogue.Catalogue) *Root {
|
||||
Name: i.Name,
|
||||
Depth: 0,
|
||||
children: nil,
|
||||
sort: i.Sort,
|
||||
}
|
||||
l = append(l, g)
|
||||
m[g.Uuid] = g
|
||||
@@ -137,7 +138,7 @@ func (g Groups) Less(i, j int) bool {
|
||||
}
|
||||
return g[i].sort < g[j].sort
|
||||
}
|
||||
return g[i].Parent < g[i].Parent
|
||||
return g[i].Parent < g[j].Parent
|
||||
}
|
||||
return g[i].Depth < g[j].Depth
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ type IDynamicModuleModule interface {
|
||||
Render(ctx context.Context, module string) (map[string]interface{}, error)
|
||||
ModuleDrivers(ctx context.Context, group string) ([]*dynamic_module_dto.ModuleDriver, error)
|
||||
|
||||
Online(ctx context.Context, module string, id string, clusterInput *dynamic_module_dto.ClusterInput) error
|
||||
Offline(ctx context.Context, module string, id string, clusterInput *dynamic_module_dto.ClusterInput) error
|
||||
Online(ctx context.Context, module string, id string) error
|
||||
Offline(ctx context.Context, module string, id string) error
|
||||
//PartitionStatuses(ctx context.Context, module string, keyword string, page int, pageSize int) (map[string]map[string]string, error)
|
||||
//PartitionStatus(ctx context.Context, module string, id string) (*dynamic_module_dto.OnlineInfo, error)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func (i *imlDynamicModule) initGateway(ctx context.Context, clusterId string, cl
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *imlDynamicModule) Online(ctx context.Context, module string, id string, clusterInput *dynamic_module_dto.ClusterInput) error {
|
||||
func (i *imlDynamicModule) Online(ctx context.Context, module string, id string) error {
|
||||
_, has := driver.Get(module)
|
||||
if !has {
|
||||
return fmt.Errorf("模块【%s】不存在", module)
|
||||
@@ -56,7 +56,7 @@ func (i *imlDynamicModule) Online(ctx context.Context, module string, id string,
|
||||
if err != nil {
|
||||
return fmt.Errorf("上线失败,配置不存在")
|
||||
}
|
||||
clusters, err := i.clusterService.List(ctx, clusterInput.Clusters...)
|
||||
clusters, err := i.clusterService.List(ctx)
|
||||
if err != nil || len(clusters) == 0 {
|
||||
return fmt.Errorf("上线失败,集群不存在")
|
||||
}
|
||||
@@ -102,28 +102,21 @@ func (i *imlDynamicModule) Online(ctx context.Context, module string, id string,
|
||||
})
|
||||
}
|
||||
|
||||
func (i *imlDynamicModule) Offline(ctx context.Context, module string, id string, clusterInput *dynamic_module_dto.ClusterInput) error {
|
||||
func (i *imlDynamicModule) Offline(ctx context.Context, module string, id string) error {
|
||||
_, has := driver.Get(module)
|
||||
if !has {
|
||||
return fmt.Errorf("模块【%s】不存在", module)
|
||||
}
|
||||
//if len(clusterInput.Clusters) == 0 {
|
||||
// return fmt.Errorf("下线分区失败,分区为空")
|
||||
//}
|
||||
|
||||
return i.transaction.Transaction(ctx, func(ctx context.Context) error {
|
||||
id = strings.ToLower(fmt.Sprintf("%s_%s", id, module))
|
||||
if len(clusterInput.Clusters) == 0 {
|
||||
clusters, err := i.clusterService.List(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clusterInput.Clusters = make([]string, 0)
|
||||
for _, c := range clusters {
|
||||
clusterInput.Clusters = append(clusterInput.Clusters, c.Uuid)
|
||||
}
|
||||
clusters, err := i.clusterService.List(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, clusterId := range clusterInput.Clusters {
|
||||
clusterIds := utils.SliceToSlice(clusters, func(s *cluster.Cluster) string {
|
||||
return s.Uuid
|
||||
})
|
||||
for _, clusterId := range clusterIds {
|
||||
err := i.dynamicClient(ctx, clusterId, module, func(dynamicClient gateway.IDynamicClient) error {
|
||||
return dynamicClient.Offline(ctx, &gateway.DynamicRelease{
|
||||
BasicItem: &gateway.BasicItem{
|
||||
|
||||
@@ -64,6 +64,7 @@ type Member struct {
|
||||
User auto.Label `json:"user" aolabel:"user"`
|
||||
Roles []auto.Label `json:"roles" aolabel:"role"`
|
||||
AttachTime auto.TimeLabel `json:"attach_time"`
|
||||
IsDelete bool `json:"is_delete"`
|
||||
}
|
||||
|
||||
func ToMember(model *team_member.Member, roles ...string) *Member {
|
||||
|
||||
@@ -48,6 +48,7 @@ func (m *imlTeamModule) UpdateMemberRole(ctx context.Context, id string, input *
|
||||
if len(input.Roles) < 1 {
|
||||
return errors.New("at least one role")
|
||||
}
|
||||
|
||||
err = m.roleMemberService.RemoveUserRole(ctx, role.TeamTarget(id), input.Users...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -2,7 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
|
||||
"github.com/eolinker/go-common/pm3"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ func (p *plugin) DynamicModuleApis() []pm3.Api {
|
||||
pm3.CreateApiWidthDoc(http.MethodDelete, "/api/v1/dynamic/:name/batch", []string{"context", "rest:name", "query:ids"}, nil, p.dynamicModuleController.Delete),
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/dynamic/:name/render", []string{"context", "rest:name"}, []string{"basic", "render"}, p.dynamicModuleController.Render),
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/simple/dynamics/:group", []string{"context", "rest:group"}, []string{"dynamics"}, p.dynamicModuleController.ModuleDrivers),
|
||||
pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/dynamic/:name/online", []string{"context", "rest:name", "query:id", "body"}, nil, p.dynamicModuleController.Online),
|
||||
pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/dynamic/:name/offline", []string{"context", "rest:name", "query:id", "body"}, nil, p.dynamicModuleController.Offline),
|
||||
pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/dynamic/:name/online", []string{"context", "rest:name", "query:id"}, nil, p.dynamicModuleController.Online),
|
||||
pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/dynamic/:name/offline", []string{"context", "rest:name", "query:id"}, nil, p.dynamicModuleController.Offline),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user