Skip to content

Commit 9192b39

Browse files
authored
Merge pull request #409 from APIParkLab/feature/liujian-1.9
fix bug
2 parents 8857fc4 + 7b54e12 commit 9192b39

File tree

3 files changed

+65
-49
lines changed

3 files changed

+65
-49
lines changed

controller/ai-api/iml.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,13 @@ func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string
113113
if input.AiModel.Type != "local" {
114114
provider = input.AiModel.Provider
115115
}
116+
modelName := input.AiModel.Name
117+
if modelName == "" {
118+
modelName = input.AiModel.Id
119+
}
116120
proxy.Plugins["ai_formatter"] = api.PluginSetting{
117121
Config: plugin_model.ConfigType{
118-
"model": input.AiModel.Name,
122+
"model": modelName,
119123
"provider": provider,
120124
"config": input.AiModel.Config,
121125
},

controller/service/iml.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,16 +520,21 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
520520
modelId := ""
521521
modelCfg := ""
522522
modelType := "online"
523+
if input.Model != nil {
524+
modelId = *input.Model
525+
}
523526
if *input.Provider == ai_provider_local.ProviderLocal {
524527
modelType = "local"
525-
list, err := i.aiLocalModel.SimpleList(ctx)
526-
if err != nil {
527-
return nil, err
528+
if modelId == "" {
529+
list, err := i.aiLocalModel.SimpleList(ctx)
530+
if err != nil {
531+
return nil, err
532+
}
533+
if len(list) == 0 {
534+
return nil, fmt.Errorf("no local model")
535+
}
536+
modelId = list[0].Id
528537
}
529-
if len(list) == 0 {
530-
return nil, fmt.Errorf("no local model")
531-
}
532-
modelId = list[0].Id
533538
modelCfg = ai_provider_local.LocalConfig
534539
} else {
535540
pv, err := i.providerModule.Provider(ctx, *input.Provider)
@@ -540,14 +545,15 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
540545
if !has {
541546
return nil, fmt.Errorf("provider not found")
542547
}
543-
m, has := p.GetModel(pv.DefaultLLM)
548+
if modelId == "" {
549+
modelId = pv.DefaultLLM
550+
}
551+
m, has := p.GetModel(modelId)
544552
if !has {
545553
return nil, fmt.Errorf("model %s not found", pv.DefaultLLM)
546554
}
547-
//modelId = m.ID()
548555
modelId = m.Name()
549556
modelCfg = m.DefaultConfig()
550-
551557
}
552558

553559
var info *service_dto.Service

module/application-authorization/iml.go

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,19 @@ func (i *imlAuthorizationModule) initGateway(ctx context.Context, partitionId st
219219
return clientDriver.Application().Online(ctx, applications...)
220220
}
221221

222-
func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service) error {
223-
clusters, err := i.clusterService.List(ctx)
224-
if err != nil {
225-
return err
226-
}
227-
if len(clusters) < 1 {
228-
return nil
229-
}
222+
func (i *imlAuthorizationModule) getApplicationRelease(ctx context.Context, s *service.Service) (*gateway.ApplicationRelease, error) {
230223
authorizations, err := i.authorizationService.ListByApp(ctx, s.Id)
231224
if err != nil {
232-
return err
225+
return nil, err
226+
}
227+
if len(authorizations) < 1 {
228+
return &gateway.ApplicationRelease{
229+
BasicItem: &gateway.BasicItem{
230+
ID: s.Id,
231+
},
232+
}, nil
233233
}
234-
app := &gateway.ApplicationRelease{
234+
return &gateway.ApplicationRelease{
235235
BasicItem: &gateway.BasicItem{
236236
ID: s.Id,
237237
Description: s.Description,
@@ -256,10 +256,40 @@ func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service)
256256
},
257257
}
258258
}),
259+
}, nil
260+
}
261+
func (i *imlAuthorizationModule) doOffline(ctx context.Context, clusterId string, app *gateway.ApplicationRelease) error {
262+
client, err := i.clusterService.GatewayClient(ctx, clusterId)
263+
if err != nil {
264+
return err
259265
}
266+
defer func() {
267+
_ = client.Close(ctx)
268+
}()
269+
return client.Application().Offline(ctx, app)
270+
}
260271

272+
func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service) error {
273+
clusters, err := i.clusterService.List(ctx)
274+
if err != nil {
275+
return err
276+
}
277+
if len(clusters) < 1 {
278+
return nil
279+
}
280+
release, err := i.getApplicationRelease(ctx, s)
281+
if err != nil {
282+
return err
283+
}
261284
for _, c := range clusters {
262-
err := i.doOnline(ctx, c.Uuid, app)
285+
if len(release.Authorizations) < 1 {
286+
err = i.doOffline(ctx, c.Uuid, release)
287+
if err != nil {
288+
log.Warnf("service authorization offline for cluster[%s] %v", c.Name, err)
289+
}
290+
continue
291+
}
292+
err = i.doOnline(ctx, c.Uuid, release)
263293
if err != nil {
264294
log.Warnf("service authorization online for cluster[%s] %v", c.Name, err)
265295
}
@@ -375,7 +405,7 @@ func (i *imlAuthorizationModule) EditAuthorization(ctx context.Context, appId st
375405
}
376406

377407
func (i *imlAuthorizationModule) DeleteAuthorization(ctx context.Context, pid string, aid string) error {
378-
_, err := i.serviceService.Get(ctx, pid)
408+
s, err := i.serviceService.Get(ctx, pid)
379409
if err != nil {
380410
return err
381411
}
@@ -385,35 +415,11 @@ func (i *imlAuthorizationModule) DeleteAuthorization(ctx context.Context, pid st
385415
if err != nil {
386416
return err
387417
}
388-
clusters, err := i.clusterService.List(ctx)
389-
if err != nil {
390-
return err
391-
}
392-
app := &gateway.ApplicationRelease{
393-
BasicItem: &gateway.BasicItem{
394-
ID: pid,
395-
},
396-
}
397-
for _, c := range clusters {
398-
err := i.doOffline(ctx, c.Uuid, app)
399-
if err != nil {
400-
log.Warnf("service authorization offline for cluster[%s] %v", c.Name, err)
401-
}
402-
}
403-
return nil
418+
419+
return i.online(ctx, s)
404420
})
405421
}
406-
func (i *imlAuthorizationModule) doOffline(ctx context.Context, clusterId string, app *gateway.ApplicationRelease) error {
407-
client, err := i.clusterService.GatewayClient(ctx, clusterId)
408-
if err != nil {
409-
return err
410-
}
411-
defer func() {
412-
_ = client.Close(ctx)
413-
}()
414-
return client.Application().Offline(ctx, app)
415422

416-
}
417423
func (i *imlAuthorizationModule) Authorizations(ctx context.Context, pid string) ([]*application_authorization_dto.AuthorizationItem, error) {
418424
_, err := i.serviceService.Get(ctx, pid)
419425
if err != nil {

0 commit comments

Comments
 (0)