(ctx *InvokeContext)
| 361 | } |
| 362 | |
| 363 | func (controller *Controller) tryGetRuntime(ctx *InvokeContext) (runtimeType string, err error) { |
| 364 | runtimeType = api.RuntimeViaUnknown |
| 365 | var rt *rtctrl.RuntimeInfo |
| 366 | rt = controller.runtimeDispatcher.FindWarmRuntime(ctx.Input) |
| 367 | if rt != nil { |
| 368 | ctx.Input.Runtime = rt |
| 369 | runtimeType = api.RuntimeViaWarm |
| 370 | return |
| 371 | } |
| 372 | ctx.Logger.Infof("get runtime failed, try to warm up one") |
| 373 | |
| 374 | rt, recommendation := controller.runtimeDispatcher.OccupyColdRuntime(ctx.Input) |
| 375 | if rt == nil { |
| 376 | err = innerErr.NewTooManyRequestsException("empty runtime", nil) |
| 377 | ctx.Logger.V(9).Infof("found empty runtime, all runtime: %s", controller.runtimeDispatcher) |
| 378 | return |
| 379 | } |
| 380 | |
| 381 | ctx.Logger.Infof("warm up container %s", rt.RuntimeID) |
| 382 | input := &api.FuncletClientWarmUpInput{ |
| 383 | ContainerID: rt.RuntimeID, |
| 384 | RequestID: ctx.RequestID, |
| 385 | Code: ctx.Function.Code, |
| 386 | Configuration: ctx.Function.Configuration, |
| 387 | RuntimeConfiguration: ctx.Runtime, |
| 388 | WithStreamMode: ctx.WithStreamMode, |
| 389 | } |
| 390 | if recommendation != nil { |
| 391 | input.NeedScaleUp = true |
| 392 | input.ScaleUpRecommendation = recommendation |
| 393 | } |
| 394 | _, err = ctx.Clients.FuncletClient.WarmUp(input) |
| 395 | if err != nil { |
| 396 | rt.Invalidate() |
| 397 | if err := rt.Release(); err != nil { |
| 398 | ctx.Logger.Errorf("release runtime %s failed: %s", rt.RuntimeID, err) |
| 399 | } |
| 400 | err = fmt.Errorf("warm up runtime %s failed: %s", rt.RuntimeID, err.Error()) |
| 401 | return |
| 402 | } |
| 403 | ctx.Input.Runtime = rt |
| 404 | if ctx.Function.Configuration.PodConcurrentQuota == 0 { |
| 405 | ctx.Input.Runtime.ConcurrentMode = false |
| 406 | } |
| 407 | runtimeType = api.RuntimeViaCold |
| 408 | return |
| 409 | } |
| 410 | |
| 411 | func (controller *Controller) buildResponse(ctx *InvokeContext, output *rtctrl.InvocationResponse) { |
| 412 | status := http.StatusOK |
no test coverage detected