Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22857,9 +22857,21 @@ const docTemplate = `{
"type": "string",
"maxLength": 64
},
"protocols": {
"type": "array",
"items": {
"type": "string"
}
},
"routeID": {
"type": "integer"
},
"routeIDs": {
"type": "array",
"items": {
"type": "integer"
}
},
"source": {
"type": "string",
"maxLength": 64
Expand Down
12 changes: 12 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -22850,9 +22850,21 @@
"type": "string",
"maxLength": 64
},
"protocols": {
"type": "array",
"items": {
"type": "string"
}
},
"routeID": {
"type": "integer"
},
"routeIDs": {
"type": "array",
"items": {
"type": "integer"
}
},
"source": {
"type": "string",
"maxLength": 64
Expand Down
8 changes: 8 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7508,8 +7508,16 @@ definitions:
protocol:
maxLength: 64
type: string
protocols:
items:
type: string
type: array
routeID:
type: integer
routeIDs:
items:
type: integer
type: array
source:
maxLength: 64
type: string
Expand Down
2 changes: 2 additions & 0 deletions backend/internal/application/channel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ type UpdateModelDisplayGroupInput struct {
// UpsertUpstreamModelInput 定义上游真实模型与平台路由保存入参。
type UpsertUpstreamModelInput struct {
RouteID uint
RouteIDs []uint
PlatformModelName string
UpstreamModelName string
Protocol string
Protocols []string
KindsJSON string
Status string
Priority int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ func (r *modelUpdateRepo) UpsertPlatformModelRoute(context.Context, *domainchann
return nil
}

func (r *modelUpdateRepo) ReplacePlatformModelRoutes(context.Context, uint, repository.ReplaceChannelPlatformRoutesInput) ([]domainchannel.PlatformModelRoute, error) {
return nil, nil
}

func (r *modelUpdateRepo) GetModelUpstreamSourceByRouteID(context.Context, string, uint) (*repository.ChannelModelSourceRow, error) {
if r.source.ID == 0 {
return nil, repository.ErrNotFound
Expand Down
39 changes: 17 additions & 22 deletions backend/internal/application/channel/service_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,33 +414,28 @@ func (s *Service) importSingleUpstreamModel(ctx context.Context, upstreamItem *d
Protocols: protocols,
}
for _, protocol := range protocols {
createdRoute := !s.routeExists(ctx, upstreamItem.ID, platformModelName, upstreamModelName, protocol)
view, err := s.UpsertUpstreamModel(ctx, upstreamItem.ID, UpsertUpstreamModelInput{
PlatformModelName: platformModelName,
UpstreamModelName: upstreamModelName,
Protocol: protocol,
KindsJSON: kindsJSON,
Status: input.Status,
Priority: input.Priority,
Weight: 1,
Source: "import",
})
if err != nil {
return ImportUpstreamModelResultView{}, err
}
if result.BindingCode == "" {
result.BindingCode = view.BindingCode
}
if result.PlatformModelID == 0 {
result.PlatformModelID = view.PlatformModelID
}
if createdRoute {
if !s.routeExists(ctx, upstreamItem.ID, platformModelName, upstreamModelName, protocol) {
result.CreatedRoutes++
result.CreatedRoute = true
} else {
result.ExistingRoutes++
}
}
view, err := s.UpsertUpstreamModel(ctx, upstreamItem.ID, UpsertUpstreamModelInput{
PlatformModelName: platformModelName,
UpstreamModelName: upstreamModelName,
Protocols: protocols,
KindsJSON: kindsJSON,
Status: input.Status,
Priority: input.Priority,
Weight: 1,
Source: "import",
})
if err != nil {
return ImportUpstreamModelResultView{}, err
}
result.BindingCode = view.BindingCode
result.PlatformModelID = view.PlatformModelID
result.CreatedRoute = result.CreatedRoutes > 0
return result, nil
}

Expand Down
47 changes: 46 additions & 1 deletion backend/internal/application/channel/service_upstream_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,21 @@ func (s *Service) UpsertUpstreamModel(ctx context.Context, upstreamID uint, inpu
if err != nil {
return nil, err
}
protocol, err := resolveRouteProtocol(input.Protocol, upstream.Compatible, upstream.ProtocolDefaultsJSON, kindsJSON)
replaceRouteSet := len(input.Protocols) > 0 || len(input.RouteIDs) > 0
protocols := make([]string, 0, len(input.Protocols)+1)
if replaceRouteSet {
protocols, err = resolveRouteProtocols(input.Protocols, upstream.Compatible, upstream.ProtocolDefaultsJSON, kindsJSON)
} else {
var protocol string
protocol, err = resolveRouteProtocol(input.Protocol, upstream.Compatible, upstream.ProtocolDefaultsJSON, kindsJSON)
if err == nil {
protocols = append(protocols, protocol)
}
}
if err != nil {
return nil, err
}
protocol := protocols[0]

platformModel, platformModelCreated, err := s.ensurePlatformModel(ctx, platformModelName, kindsJSON, upstreamModelName)
if err != nil {
Expand All @@ -99,6 +110,40 @@ func (s *Service) UpsertUpstreamModel(ctx context.Context, upstreamID uint, inpu
if err != nil {
return nil, err
}
if replaceRouteSet {
routes := make([]domainchannel.PlatformModelRoute, 0, len(protocols))
for _, desiredProtocol := range protocols {
routes = append(routes, domainchannel.PlatformModelRoute{
PlatformModelID: platformModel.ID,
UpstreamModelID: upstreamModel.ID,
Protocol: desiredProtocol,
Status: normalizeStatus(input.Status),
Priority: normalizePriority(input.Priority),
Weight: normalizeWeight(input.Weight),
Source: normalizeSource(input.Source),
CbFailureThreshold: input.CbFailureThreshold,
CbDurationMin: input.CbDurationMin,
CbWindowMin: input.CbWindowMin,
HeadersJSON: strings.TrimSpace(input.HeadersJSON),
})
}
routeIDs := append([]uint{}, input.RouteIDs...)
if input.RouteID > 0 {
routeIDs = append(routeIDs, input.RouteID)
}
replaced, replaceErr := s.repo.ReplacePlatformModelRoutes(ctx, upstream.ID, repository.ReplaceChannelPlatformRoutesInput{
ExistingRouteIDs: routeIDs,
Routes: routes,
})
if replaceErr != nil {
if isDuplicateKeyError(replaceErr) {
return nil, ErrUpstreamModelConflict
}
return nil, replaceErr
}
s.InvalidateModelCatalog()
return s.findUpstreamModelViewByRoute(ctx, upstream.ID, replaced[0].ID, upstreamModel.ID)
}
if err := s.validateRouteProtocolCombination(ctx, upstream.ID, platformModel.ID, upstreamModel.ID, input.RouteID, protocol); err != nil {
return nil, err
}
Expand Down
Loading
Loading